The modern build of lodash's _.every method for checking if a predicate returns truthy for all elements of a collection.
npx @tessl/cli install tessl/npm-lodash--every@3.2.0Lodash Every provides the modular build of lodash's _.every method as a standalone Node.js module. It checks if a predicate returns truthy for all elements of a collection, supporting various callback styles including function predicates, property names, and object matching.
npm install lodash.everyvar every = require('lodash.every');For ES modules:
import every from 'lodash.every';var every = require('lodash.every');
// Using function predicate
every([true, 1, null, 'yes'], Boolean);
// => false
// Using object matching
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false }
];
every(users, { 'user': 'barney', 'active': false });
// => falseChecks if a predicate returns truthy for all elements in a collection. Supports multiple predicate styles for flexible usage patterns.
/**
* Checks if predicate returns truthy for all elements of collection.
* Alias: all
* @param {Array|Object|string} collection - The collection to iterate over
* @param {Function|Object|string} [predicate=_.identity] - The function invoked per iteration
* @param {*} [thisArg] - The this binding of predicate
* @returns {boolean} Returns true if all elements pass the predicate check, else false
*/
function every(collection, predicate, thisArg) {}Predicate Types:
(value, index|key, collection)_.property style callback_.matchesProperty style callback_.matches style callbackUsage Examples:
var every = require('lodash.every');
// Function predicate - check if all values are truthy when passed to Boolean
every([true, 1, null, 'yes'], Boolean);
// => false (null is falsy)
// Object matching - check if all users match the given object properties
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false }
];
every(users, { 'active': false });
// => true (all users have active: false)
every(users, { 'user': 'barney', 'active': false });
// => false (only one user matches completely)
// Property matching - check if all users have matching property value
every(users, 'active', false);
// => true (all users have active property equal to false)
// Property checking - check if all users have truthy property value
every(users, 'active');
// => false (all users have falsy active property)
// Custom function with access to value, index, and collection
every([2, 4, 6], function(value, index, collection) {
return value % 2 === 0;
});
// => true (all numbers are even)
// Works with objects too
every({ a: 1, b: 2, c: 3 }, function(value) {
return value > 0;
});
// => true (all values are positive)
// Works with strings
every('hello', function(char) {
return char !== 'x';
});
// => true (no character is 'x')Edge Cases:
// Empty collections return true
every([], Boolean);
// => true
every({}, function() { return false; });
// => true
// Single element collections
every([true], Boolean);
// => true
every([false], Boolean);
// => false