npm install typist.js

Type check function return values at run time, or type check any value any time.
1. Install
1. All In One Example
1. Return Values
1. Any Value
```
npm install typist.js --save
Seamlessly type check the return type as well as input types for the life of the function.
`js
var makeArray = type.takes(Array, String, Number)
.does(function(input, foo, bar) {
input.push(foo, bar);
return input;
})
.returns(Array)
.done();
makeArray([], "1", 2); // ["1", 2]
makeArray([], 1, 2); // Throws TypistError
`
Or you can use the features separately but all together for the same effect.
`js
var type = require("typist");
var makeArray = type(Array, function(input, foo, bar) {
type.checks([Array, input], [String, foo], [Number, bar]);
input.push(foo, bar);
return input;
});
makeArray([], 1, 2); // throws TypistError
makeArray([], "1", 2); // ["1", 2]
`
Typist creates a curried function of your type and will check against that type any time a value is returned from it. Ensure your function will always return what you expect it to.
`js
var type = require("typist");
var makeArray = type(Array, function(input) {
return input.push("Foo");
});
makeArray("string"); // throws TypistError
makeArray([]); // ["Foo"]
`
Type check any value any time
`js
var type = require("typist");
type.is.array(["Foo"]); // true
type.is.string(["Bar"]); // false
type.array(["Foo"]); // ["Foo"]
type.array("Bar"); // throws TypistError
`
You can also type check many values, which is useful for checking all your function arguments at the top of the function.
`js
var type = require("typist");
var makeArray = function(input, foo, bar) {
type.checks([Array, input], [String, foo], [Number, bar]);
input.push(foo, bar);
return input;
});
makeArray([], 1, 2); // throws TypistError
makeArray([], "1", 2); // ["1", 2]
`
I'm adding more types as I have time, but currently have:
- Object
- Array
- String
- Number
- Function
- Boolean
- Date
- RegEpx
- Error
You will need to install grunt-cli if you haven't already.grunt test
Run to run tests and coverage. Coverage is saved in coverage` folder.