filtrate
Function argument and JSON schema type checking for Node.js
npm install filtrate
Usage
Wrap a function
var bar =;; // executes foo.fn; // throws!
Modify an object method
var foo ={console;};;foo; // executes foo.fnfoo; // throws!
Compare a pattern against a value
filtrate; //truefiltrate; //falsefiltrate; //truefiltrate; //falsefiltrate; //falsefiltrate; //false
Compare a pattern against a value with a helpful message
filtrate; //nullfiltrate; //"Filtrate Error: input[1] is not a function (got: 42)"
API
patterns
, function
);
filtrate(Wrap a function
patterns
(Patterns Object
) - Patterns to match against (see below)
function
(Function
) - The function to be filtered
returns filtered function
object
, methodName
, patterns
);
filtrate(Modify object method
object
(Object
) - Parent object containing the method
methodName
(String
) - Name of the method
patterns
(Patterns Object
) - Patterns to match against (see below)
returns undefined
patterns
, input
);
filtrate.compare(Pattern match, boolean result
input
(Function
) - An object to match
patterns
(Patterns Object
) - Patterns to match against (see below)
returns true
/false
patterns
, input
);
filtrate.check(Pattern match, string result
Patterns Object
A patterns
object is recursively defined as:
patterns =
true ||
false ||
String ||
Number ||
Boolean ||
Function ||
Array ||
Object ||
undefined ||
[patterns, ...] ||
{key: patterns, ... }
true
is a truthy comparison
false
is a falsy comparison
String
, Number
, Boolean
, Function
, Array
and Object
are all essentially typeof
comparisons
undefined
skips comparison
[]
does a recursive comparison of these types listed
{}
does a recursive comparison of these types listed (also matches key names)