or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--every

The modern build of lodash's _.every method for checking if a predicate returns truthy for all elements of a collection.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.every@3.2.x

To install, run

npx @tessl/cli install tessl/npm-lodash--every@3.2.0

index.mddocs/

Lodash Every

Lodash 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.

Package Information

  • Package Name: lodash.every
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.every

Core Imports

var every = require('lodash.every');

For ES modules:

import every from 'lodash.every';

Basic Usage

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 });
// => false

Capabilities

Collection Validation

Checks 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:

  1. Function Predicate: Custom function receiving (value, index|key, collection)
  2. Property Name: String property name for _.property style callback
  3. Property Matching: Property name with value for _.matchesProperty style callback
  4. Object Matching: Object for _.matches style callback

Usage 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