News for hackers. Stuff that matters.
Re:Type Checking in JavaScript by philbo on Wednesday November 06, 2013 @08:06AM (#6682463)
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

There are no comments on this comment yet.