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.00
# Lodash Every
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: lodash.every
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash.every`
10
11
## Core Imports
12
13
```javascript
14
var every = require('lodash.every');
15
```
16
17
For ES modules:
18
19
```javascript
20
import every from 'lodash.every';
21
```
22
23
## Basic Usage
24
25
```javascript
26
var every = require('lodash.every');
27
28
// Using function predicate
29
every([true, 1, null, 'yes'], Boolean);
30
// => false
31
32
// Using object matching
33
var users = [
34
{ 'user': 'barney', 'active': false },
35
{ 'user': 'fred', 'active': false }
36
];
37
38
every(users, { 'user': 'barney', 'active': false });
39
// => false
40
```
41
42
## Capabilities
43
44
### Collection Validation
45
46
Checks if a predicate returns truthy for all elements in a collection. Supports multiple predicate styles for flexible usage patterns.
47
48
```javascript { .api }
49
/**
50
* Checks if predicate returns truthy for all elements of collection.
51
* Alias: all
52
* @param {Array|Object|string} collection - The collection to iterate over
53
* @param {Function|Object|string} [predicate=_.identity] - The function invoked per iteration
54
* @param {*} [thisArg] - The this binding of predicate
55
* @returns {boolean} Returns true if all elements pass the predicate check, else false
56
*/
57
function every(collection, predicate, thisArg) {}
58
```
59
60
**Predicate Types:**
61
62
1. **Function Predicate**: Custom function receiving `(value, index|key, collection)`
63
2. **Property Name**: String property name for `_.property` style callback
64
3. **Property Matching**: Property name with value for `_.matchesProperty` style callback
65
4. **Object Matching**: Object for `_.matches` style callback
66
67
**Usage Examples:**
68
69
```javascript
70
var every = require('lodash.every');
71
72
// Function predicate - check if all values are truthy when passed to Boolean
73
every([true, 1, null, 'yes'], Boolean);
74
// => false (null is falsy)
75
76
// Object matching - check if all users match the given object properties
77
var users = [
78
{ 'user': 'barney', 'active': false },
79
{ 'user': 'fred', 'active': false }
80
];
81
every(users, { 'active': false });
82
// => true (all users have active: false)
83
84
every(users, { 'user': 'barney', 'active': false });
85
// => false (only one user matches completely)
86
87
// Property matching - check if all users have matching property value
88
every(users, 'active', false);
89
// => true (all users have active property equal to false)
90
91
// Property checking - check if all users have truthy property value
92
every(users, 'active');
93
// => false (all users have falsy active property)
94
95
// Custom function with access to value, index, and collection
96
every([2, 4, 6], function(value, index, collection) {
97
return value % 2 === 0;
98
});
99
// => true (all numbers are even)
100
101
// Works with objects too
102
every({ a: 1, b: 2, c: 3 }, function(value) {
103
return value > 0;
104
});
105
// => true (all values are positive)
106
107
// Works with strings
108
every('hello', function(char) {
109
return char !== 'x';
110
});
111
// => true (no character is 'x')
112
```
113
114
**Edge Cases:**
115
116
```javascript
117
// Empty collections return true
118
every([], Boolean);
119
// => true
120
121
every({}, function() { return false; });
122
// => true
123
124
// Single element collections
125
every([true], Boolean);
126
// => true
127
128
every([false], Boolean);
129
// => false
130
```