@lamansky/every

A better Array.prototype.every(). Supports iterables, whitelist testing, and more.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
00May 23, 2018May 23, 2018Minified + gzip package size for @lamansky/every in KB

Readme

every

A better Array.prototype.every(). Supports iterables, whitelist testing, and more.

Installation

Requires Node.js 6.0.0 or above.

npm i @lamansky/every

API

The module exports a single function.

Parameters

  1. Bindable: iter (iterable)
  2. Optional: test (function, array, or any): If a function is provided, iterated values will be evaluated on whether test returns true when 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 equal test. If test is omitted, iterated values will be evaluated on whether they are truthy.
  3. Optional: Object argument (or a value for vacuously):
    • vacuously (boolean): What to return if iter doesn’t iterate anything. Defaults to true. Thiis is for consistency with Array.prototype.every(), which interprets any test on an empty array as being vacuously true.

Return Values

  • If iter doesn’t iterate anything, returns vacuously if set, otherwise true.
  • Otherwise, returns true if every one of the iterated values of iter passes test; otherwise returns false.

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]) // false

Related

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.