Allege
Make complex conditionals easier to read and write.
Introduction
Sometimes, if
statements can get very complex. For example:
if foo.bar === 'value_a' || foo.bar === 'value_b' || foo.bar === 'value_c' || foo.bar === 'value_d' || foo.bar === 'value_e'
With Allege, you can simplify your if
like so:
if allege.thatfoo.bar.isIn 'value_a', 'value_b', 'value_c', 'value_d', 'value_e'
API & Methods
Allege exposes different functions based on what you're trying to compare.
Single Input Commands
To use these methods, call allege.that()
with just a single argument,
like so: allege.that(foo)
. Then, these methods will be available:
isIn(possibility1, ..., possibilityN) -> boolean
Determines whether foo
is referentially equal (===
) to any of the possibility
items.
allege;// --> true allege;// --> false
isNotIn(possibility1, ..., possibilityN) -> boolean
Determines whether foo
is referentially unequal (!==
) to all of the possibility
items.
allege;// --> true allege;// --> false
Multiple Input Commands
To use these methods, call allege.these()
with more than one argument,
like so: allege.these(foo, bar, baz, quux)
. Then, these methods will be available:
areAll(possibility) -> boolean
Determines whether all input
s are referentially equal (===
) to the possibility
item.
allege;// --> true allege;// --> false
areAllNot(possibility) -> boolean
Determines whether all input
s are referentially unequal (!==
) to the possibility
item.
allege;// --> true allege;// --> false
Installation
Grab this module from npm
with the following command:
yarn add allege
Then you can use it in your project like so:
;if allege.that5.isNotIn1,2,3 // or:;if that5.isNotIn1,2,3
Versioning
This module follows SemVer.
License
MIT. See the LICENSE
file for more details.
Testing
You can execute the existing test suite by running the following in your terminal:
yarn installyarn test
Building From Source
The code that resides in the index.js
file is transpiled from an ES6 source. The original source
files reside in the src/
directory. These can be built with the following command:
yarn build