is.js - Adding clarity and conciseness to your JS through predicates
is.js
is a predicate library for JS. is
doesn't have any dependencies which makes it easy to integrate into new and existing projects.
Docs
landau.github.io/is
install
npm install --save is-predicate
or
download the file from the dist directory
Usage
is.equal(1, 1);
is.not.pos(-1);
is.ternary(true, 'foo', 'bar');
is.fn(function () {});
is.not.equal(1, 3);
Every/Some
Every and some are functions that allow you to chain predicate calls. The calls are not evaluated until .val()
is executed on the chain.
is.every().equal(1, 1).contains([1, 2, 3], 2).val();
is.all().equal(1, 5).contains([1, 2, 3], 2).val();
is.some().equal(1, 1).contains([1, 2, 3], 2).val();
is.any().equal(1, 5).contains([1, 2, 3], 2).val();
is.some().equal(1, 5).contains([1, 2, 3], 5).val();
Alternaively to .val
you can execute valueOf
!!is.every().equal(1, 1).contains([1, 2, 3], 2);
Notice the alias of all/any
if you prefer that flavor
NOTE: Chaining doesnt work with .not
yet.
Author
Trevor Landau
contributing
- Suggestions welcome!
- Tests!
- Ping me on twitter if I take too long to respond! That probably means I missed the alert/email.
Tests
To run tests, install devDeps and type npm ts
Building
To build, type npm run build
.
This will create a UMDified version of is in the dist
directory along with a minified version.