A small JavaScript library for checking types and throwing exceptions.
npm install check-types
git clone [email protected]:philbooth/check-types.js.git
var check = require('check-types');
<script type="text/javascript" src=".../check-types.js/src/check-types.min.js"></script>
A number of different functions are exported:
Tests whether an object 'quacks like a duck'.
Returns true
if the first argument has all of the properties
of the second, archetypal argument (the 'duck').
Returns false
otherwise.
If either argument is not an object,
an exception is thrown.
Returns true
if an object is an instance of a prototype,
false
otherwise.
Throws an exception if an object is not an instance of a prototype.
Returns true
if something is a non-null, non-array object,
false
otherwise.
Throws an exception unless something is a non-null, non-array object.
Returns true
something is an array,
false
otherwise.
Throws an exception unless something is an array.
Returns true
if something is function,
false
otherwise.
Throws an exception unless something is function.
Returns true
if something is a non-empty string,
false
otherwise.
Throws an exception unless something is a non-empty string.
Returns true
if something is a string,
false
otherwise.
Throws an exception unless something is a string.
Returns true
if something is a number,
false
otherwise.
In this instance, NaN
is not considered a number.
Throws an exception unless something is a number.
In this instance, NaN
is not considered a number.
The build environment relies on
Node.js,
NPM,
Jake,
JSHint,
Mocha,
Chai and
UglifyJS.
Assuming that you already have Node.js and NPM set up,
you just need to run npm install
to
install all of the dependencies as listed in package.json
.
The unit tests are in test/check-types.coffee
.
You can run them with the command npm test
or jake jstest
.