anyone
Anyone contains a small group of functions that check whether a number of given expressions evaluate to be truthy based on the number of times a truthy value appears.
Anyone has four functions:
any
- Checks that at least one of the supplied expressions evaluates to true.one
- Checks that only one of the supplied expressions evaluates to true (Mutual exclusion).all
- Checks that all of the supplied expressions evaluate to true.none
- Checks that none of the supplied expressions evaluates to true.
They all accept any amount of arguments, or no arguments at all. If a function is passed, it will be run and its value will be evaluated. Return value is always a boolean.
All functions other than one
will short circuit when realizing the condition is not met.
Why use it
In most cases (other than one
) you can do just fine using Array.prototype.some
and Array.prototype.every
, some of these functions are used internally by Vest.
- You can use these functions as conditionals:
if (one(var1, var2, var3)) {
}
- You can use these functions to pause execution of some code after a condition is met
all(
validateInput1,
validateInput2,
validateInput3,
);
Installation
npm i anyone
yarn add anyone
Usage Examples
import { any, one, all, none } from 'anyone';
import any from 'anyone/any';
import one from 'anyone/one';
import none from 'anyone/none';
import all from 'anyone/all';
any(
someFunction,
1,
someVar,
);
any(
someFunction,
0,
someVar,
);
one(
someFunction,
0,
someVar,
);
none(
someFunction,
1,
someVar,
);
none(
someFunction,
0,
someVar,
);
all(
someFunction,
0,
someVar,
);
all(
someFunction,
1,
someVar,
);