Exports check-args
if it is available,
else falls back to empty placeholder. Use check-args-lib
in libraries
and when if you want to turn on argument type checking in your application,
make sure check-args
is available (in node_modules).
Very simple usage example of check-args(-lib)
var fn = accept(String).accept(Number).to(function(stringOrNumber){
// do something with stringOrNumber
});
if you want to test if checking is working properly...
npm install check-args
Then call npm prune
to disable type checking.
Note, that you should not add check-args
to dependencies in your library.
Library users determine themselves if they want to utilize arguments
checking or not.
You can add check-args
to devDependencies. That way you always have
argument type checking enabled during development.
For more usage instructions see check-args
.
You may know that this does not work in coffeescript:
class X
constructor: ->
return []
get: -> 'asdf'
new X().get()
That is because constructors are special creatures.
They may not return anything.
Normally the last statement is the one that is the return statement in compiled javascript.
In constructors last statement does not compile to return statement.
If there is a return statement and it returns any kind of object,
javascript's new
does not return the instantiated function object.
Instead it decides to return whatever was returned.
Consider following javascript:
X = function() {
// this is the constructor
this.prototype.xxx = function() { ... }
return {};
};
// later...
var x = new X();
x.xxx(); // this throws an exception, because x is now an empty object
Without the return statement code above would work.
So...
When you wrap the constructor with accept().to() then coffeescript compiler does not know that an exception to the rule should be made.
You must be careful with coffeescript class constructors and a good convention
is to put undefined at the end of it, if you are using check-args-lib
.
Lisencse MIT.