1.0.0 • Published 7 years ago
@lamansky/every v1.0.0
every
A better Array.prototype.every(). Supports iterables, whitelist testing, and more.
Installation
Requires Node.js 6.0.0 or above.
npm i @lamansky/everyAPI
The module exports a single function.
Parameters
- Bindable:
iter(iterable) - Optional:
test(function, array, or any): If a function is provided, iterated values will be evaluated on whethertestreturnstruewhen passed the value. If an array is provided, iterated values will be evaluated on whether they are contained in the array. If some other value is provided, iterated values will be evaluated on whether they strictly equaltest. Iftestis omitted, iterated values will be evaluated on whether they are truthy. - Optional: Object argument (or a value for
vacuously):vacuously(boolean): What to return ifiterdoesn’t iterate anything. Defaults totrue. Thiis is for consistency withArray.prototype.every(), which interprets any test on an empty array as being vacuously true.
Return Values
- If
iterdoesn’t iterate anything, returnsvacuouslyif set, otherwisetrue. - Otherwise, returns
trueif every one of the iterated values ofiterpassestest; otherwise returnsfalse.
Example
const every = require('@lamansky/every')
const arr = [1, 2, 3]
every(arr, n => n >= 1) // true
every(arr, [1, 2, 3, 4]) // true
every(arr, n => n > 1) // false
every(arr, 1) // false
every(arr, [1, 2]) // falseRelated
1.0.0
7 years ago