0
# lodash._isiterateecall
1
2
Internal lodash utility function that determines whether provided arguments are from an iteratee call in the context of lodash operations. This function analyzes callback invocation patterns to enable lodash's method chaining and iteratee detection system.
3
4
## Package Information
5
6
- **Package Name**: lodash._isiterateecall
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash._isiterateecall`
10
11
## Core Imports
12
13
```javascript
14
const isIterateeCall = require('lodash._isiterateecall');
15
```
16
17
## Basic Usage
18
19
```javascript
20
const isIterateeCall = require('lodash._isiterateecall');
21
22
// Check if arguments match iteratee call pattern
23
const users = [{ name: 'Alice' }, { name: 'Bob' }];
24
25
// These would return true in an iteratee context:
26
// isIterateeCall(user, 0, users) => true (when called from array method)
27
// isIterateeCall(user, 'name', userObject) => true (when called from object method)
28
29
// Direct calls typically return false:
30
const result1 = isIterateeCall({ name: 'Alice' }, 0, users);
31
// => false (not from iteratee context)
32
33
const result2 = isIterateeCall('value', 'key', { key: 'value' });
34
// => true (matches object property pattern)
35
36
const result3 = isIterateeCall('different', 'key', { key: 'value' });
37
// => false (value doesn't match object[key])
38
```
39
40
## Capabilities
41
42
### Iteratee Call Detection
43
44
Determines whether three arguments represent a callback invocation pattern from lodash iteration methods like `map`, `filter`, and `forEach`.
45
46
```javascript { .api }
47
/**
48
* Checks if the provided arguments are from an iteratee call.
49
*
50
* @param {*} value - The potential iteratee value argument
51
* @param {*} index - The potential iteratee index or key argument
52
* @param {*} object - The potential iteratee object argument
53
* @returns {boolean} Returns true if the arguments are from an iteratee call, else false
54
*/
55
function isIterateeCall(value, index, object)
56
```
57
58
**Detection Logic:**
59
60
The function performs several validation checks:
61
62
1. **Object Validation**: Ensures the third argument is an object (not null/undefined)
63
2. **Index Type Checking**: Handles both numeric indices and string keys
64
3. **Array-like Detection**: For numeric indices, validates the object is array-like and index is valid
65
4. **Property Access**: For string keys, verifies the key exists in the object
66
5. **Value Matching**: Compares the value argument with `object[index]`, handling NaN cases correctly
67
68
**Usage Examples:**
69
70
```javascript
71
const isIterateeCall = require('lodash._isiterateecall');
72
73
// Array-like iteratee patterns
74
const arr = ['a', 'b', 'c'];
75
isIterateeCall('a', 0, arr); // => true
76
isIterateeCall('b', 1, arr); // => true
77
isIterateeCall('wrong', 0, arr); // => false
78
79
// Object iteratee patterns
80
const obj = { x: 10, y: 20 };
81
isIterateeCall(10, 'x', obj); // => true
82
isIterateeCall(20, 'y', obj); // => true
83
isIterateeCall(30, 'x', obj); // => false
84
85
// NaN handling
86
const nanObj = { prop: NaN };
87
isIterateeCall(NaN, 'prop', nanObj); // => true (special NaN comparison)
88
89
// Invalid cases
90
isIterateeCall('any', 'key', null); // => false (null object)
91
isIterateeCall('any', -1, arr); // => false (invalid index)
92
isIterateeCall('any', 'missing', obj); // => false (key doesn't exist)
93
```
94
95
**Edge Cases:**
96
97
- **NaN Values**: Uses special comparison logic (`value === value ? (value === other) : (other !== other)`) to correctly handle NaN comparisons
98
- **Type Coercion**: Numeric strings are converted to numbers for index validation
99
- **Array-like Objects**: Validates indices using length property and MAX_SAFE_INTEGER bounds
100
- **Non-objects**: Returns false immediately if the object parameter is null, undefined, or primitive
101
102
This function is essential for lodash's internal operation, enabling the library to distinguish between direct function calls and callback invocations from iteration methods, which is crucial for proper method chaining and iteratee behavior.