4 ms·
I've contributed to a little JS lib [1] that takes a similar approach, but expands all of its predicates with two modifiers: a `maybe` modifier that tolerates n
by philbo 13y ago
I've contributed to a little JS lib [1] that takes a similar approach, but expands all of its predicates with two modifiers: a `maybe` modifier that tolerates null and undefined; and a `verify` modifier that throws if the predicate returns false. I've found it quite useful for eradicating some common boilerplate from my code.
e.g.:
var check = require('check-types');
check.unemptyString(''); // returns false
check.maybe.unemptyString(); // returns true
check.verify.unemptyString(''); // throws Error
check.verify.maybe.unemptyString(); // doesn't throw
[1] https://github.com/philbooth/check-types.js https://github.com/philbooth/check-types.js