simplecheck
This is a simple variable type-checking library inspired by the check
and Match
functions and behaviors in MeteorJS.
Why?
I love Meteor's check
function but you can't use it outside of Meteor due to the way it is written, and I want to use it in my pure node projects.
Usage
Import the library
;
Check a variable's type
; // true
oneOf
Use ; // true ; // false ; // true
Check an object's schema
; // true
optional
function for optional keys
Use the (if they exist, they must match, but they aren't required)
; // true ; // true ; // false ("baz" is not a number)
Check for array of type
Note that this library doesn't support type-checking of elements at specific indices in the array (yet)
; // true ; // false ; // true
Check on a regular expression
; // true ; // true ; // false ; // true
anything
Accept ; // true; // true ### Throw an error instead of returning a boolean?Use `ensure`: ```jsensure('foo', Number); // "MatchError: Expected 'foo' to be a number"
Find a bug?
Please add a test in check_test.js
and we will try to fix.