1.2.3 • Published 8 years ago

typed-contract v1.2.3

Weekly downloads
52
License
MIT
Repository
github
Last release
8 years ago

typed-contract

typed-contract is a library to help guard against invalid function inputs and outputs. Using a fluent syntax, it allows a short and descriptive way to protect the system and return useful error messages.

Our goals are:

As the size and complexity of your JavaScript and TypeScript projects continues to grow, edge cases and regressions will occur. Help find them quickly before your users do!

The simple definition of what TypeScript is, is this.... "TypeScript is a superset of JavaScript which primarily provides optional static typing, classes and interfaces. This allows much more insightful and transparent JavaScript and TypeScript application development. Allowing Integrated Development Environments to provide a richer environment for spotting common errors as you type and build your application." - Andre Fischbacher

Code contracts allow you to ensure that your intentions for any property or method are ensured using a code contract. When you are developing an application you can list and specify as many preconditions and postconditions in your code as needed. In typed-contract preconditions are strict requirements that must be met when entering executing an application at runtime. Postconditions describe expectations at the time the method or property code exits at runtime.

Typed-contract allows you to set pre and postconditions in your code to check for certain invariants that you set while writing out a typed-contract. Once you execute a project, a set of classes or functions, the typed-contract can then check that every condition successfully passes, which allows your intentions when building your app to run as smooth as butter.

Typed-contract will allow you and your projects to have more descriptive syntax for your variables, functions, interfaces and classes

typed-contract can be used in either JavaScript or TypeScript environments so the freedom of choice is always yours. See https://github.com/randarp/typed-contract/wiki/Setup-typed-contract.

Here is an example of what a typed-contract looks like... myVar: number = 3.14159265359; Contract.In(myVar, "PI"). IsNotNull(). IsDefined(). IsGreaterThan(3.13). IsNotLessThan(3);

and the same goes for postconditions as well

myVar: number = 3.14159265359;

Contract.Out(myVar, "PI").
	IsNotNull().
	IsDefined().
	IsGreaterThan(3.13).
	IsNotLessThan(3);

As you can see we can use something known as Function/Method chaining to allow any typed-contract to check for many conditions in one instance of a contract. Each contract that is created will have specific functions based on the data type passed in as a pre or post condition in, making good use of TypeScripts static typing. Here is an example.

varArray: any[] = [1, 2, 3];
varNumber: number = 100;
varString: string = "Hello World";
varBoolean: boolean = true;<br/>

Contract.In(varNumber).
	IsLessThan(101).
	IsNotNull().
	IsGreaterThan(99);<br/>

Contract.In(varArray).
	IsDefined().
	IsEqualTo([1, 2, 3], 1);<br/>

Contract.In(varString).
	Contains("Hello").
	NotContains("Goodbye");

If you would like to see all of the documentation click here https://github.com/randarp/typed-contract/wiki

Of course you would like to know what is included in this wonderful code contract library so you can utilize it to the best of it's ability.

Here are the list of the classes that are included in this npm module, and were always thinking of adding more to make the experience even better!

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.0

8 years ago

1.1.1

8 years ago

0.0.1

8 years ago

1.0.4

8 years ago

0.9.100

8 years ago

1.0.0

8 years ago

0.9.9

8 years ago

0.9.10

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago