0
# lodash._baseisequal
1
2
The internal lodash function `baseIsEqual` exported as a standalone module. Provides comprehensive deep equality comparison between JavaScript values with support for circular references, custom comparison functions, partial comparisons, and proper handling of complex data structures including arrays, objects, maps, sets, typed arrays, and special JavaScript values.
3
4
## Package Information
5
6
- **Package Name**: lodash._baseisequal
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash._baseisequal`
10
11
## Core Imports
12
13
```javascript
14
var baseIsEqual = require('lodash._baseisequal');
15
```
16
17
For ES modules:
18
19
```javascript
20
import baseIsEqual from 'lodash._baseisequal';
21
```
22
23
## Basic Usage
24
25
```javascript
26
var baseIsEqual = require('lodash._baseisequal');
27
28
// Basic deep equality comparison
29
var obj1 = { a: 1, b: { c: 2 } };
30
var obj2 = { a: 1, b: { c: 2 } };
31
var result = baseIsEqual(obj1, obj2);
32
// => true
33
34
// Arrays with same elements
35
var arr1 = [1, 2, [3, 4]];
36
var arr2 = [1, 2, [3, 4]];
37
baseIsEqual(arr1, arr2);
38
// => true
39
40
// Different objects
41
var obj3 = { a: 1, b: { c: 3 } };
42
baseIsEqual(obj1, obj3);
43
// => false
44
```
45
46
## Capabilities
47
48
### Deep Equality Comparison
49
50
Performs comprehensive deep equality comparison between two values with support for all JavaScript data types and edge cases.
51
52
```javascript { .api }
53
/**
54
* The base implementation of `_.isEqual` which supports partial comparisons
55
* and tracks traversed objects.
56
*
57
* @param {*} value The value to compare.
58
* @param {*} other The other value to compare.
59
* @param {Function} [customizer] The function to customize comparisons.
60
* @param {number} [bitmask] The bitmask flags (1=unordered, 2=partial).
61
* @param {Object} [stack] Tracks traversed objects for circular references.
62
* @returns {boolean} Returns `true` if values are equivalent, else `false`.
63
*/
64
baseIsEqual(value, other, customizer, bitmask, stack);
65
```
66
67
**Usage Examples:**
68
69
```javascript
70
var baseIsEqual = require('lodash._baseisequal');
71
72
// Custom comparison function
73
function customizer(objValue, othValue) {
74
if (typeof objValue === 'string' && typeof othValue === 'string') {
75
return objValue.toLowerCase() === othValue.toLowerCase();
76
}
77
}
78
79
baseIsEqual('Hello', 'HELLO', customizer);
80
// => true
81
82
// Partial comparison (bitmask = 2)
83
var object = { 'a': 1, 'b': 2 };
84
var source = { 'a': 1 };
85
baseIsEqual(object, source, null, 2);
86
// => true (partial match)
87
88
// Unordered array comparison (bitmask = 1)
89
var arr1 = [1, 2, 3];
90
var arr2 = [3, 1, 2];
91
baseIsEqual(arr1, arr2, null, 1);
92
// => true (order ignored)
93
```
94
95
## Supported Data Types
96
97
The function handles comprehensive comparison of:
98
99
- **Primitives**: `string`, `number`, `boolean`, `null`, `undefined`, `symbol`
100
- **Arrays**: Regular arrays and array-like objects
101
- **Objects**: Plain objects, including those with `null` prototype
102
- **Dates**: Compares by timestamp value
103
- **Regular Expressions**: Compares pattern and flags
104
- **Error Objects**: Compares `name` and `message` properties
105
- **Maps and Sets**: Deep comparison of entries/values
106
- **Typed Arrays**: `Int8Array`, `Uint8Array`, `Float32Array`, etc.
107
- **ArrayBuffer**: Compares byte contents
108
- **Arguments Objects**: Treated as arrays for comparison
109
- **Circular References**: Properly handles and detects circular object references
110
111
## Special Behaviors
112
113
### NaN Handling
114
```javascript
115
baseIsEqual(NaN, NaN);
116
// => true (treats NaN as equal to itself)
117
```
118
119
### Symbol Comparison
120
```javascript
121
var sym1 = Symbol('test');
122
var sym2 = Symbol('test');
123
baseIsEqual(sym1, sym2);
124
// => false (symbols are unique)
125
126
var sym3 = sym1;
127
baseIsEqual(sym1, sym3);
128
// => true (same symbol reference)
129
```
130
131
### Circular References
132
```javascript
133
var obj1 = { a: 1 };
134
obj1.circular = obj1;
135
136
var obj2 = { a: 1 };
137
obj2.circular = obj2;
138
139
baseIsEqual(obj1, obj2);
140
// => true (handles circular references properly)
141
```
142
143
### Lodash Wrapped Objects
144
```javascript
145
// Automatically unwraps lodash wrapped objects
146
var wrapped1 = _({ a: 1 });
147
var wrapped2 = _({ a: 1 });
148
baseIsEqual(wrapped1, wrapped2);
149
// => true (compares unwrapped values)
150
```
151
152
## Parameters
153
154
### value (*)
155
The primary value to compare. Can be any JavaScript value including primitives, objects, arrays, functions, etc.
156
157
### other (*)
158
The secondary value to compare against. Can be any JavaScript value.
159
160
### customizer (Function, optional)
161
Optional function to customize the comparison logic. Called with `(objValue, othValue, index|key, object, other, stack)` arguments.
162
163
**Return Values:**
164
- `true`: Values should be considered equal
165
- `false`: Values should be considered not equal
166
- `undefined`: Use default comparison logic
167
168
### bitmask (number, optional)
169
Bitwise flags to control comparison behavior:
170
171
- `1` (`UNORDERED_COMPARE_FLAG`): Ignore order in arrays and object properties
172
- `2` (`PARTIAL_COMPARE_FLAG`): Allow partial matching (source properties must exist in target)
173
- Can be combined: `3` enables both unordered and partial comparison
174
175
### stack (Object, optional)
176
Internal object used to track traversed objects and prevent infinite recursion with circular references. Automatically created if not provided.
177
178
## Returns
179
180
**boolean**: Returns `true` if the values are deeply equal according to the comparison rules, otherwise `false`.
181
182
## Dependencies
183
184
This module depends on:
185
- `lodash._root`: Provides environment detection and built-in references
186
- `lodash._stack`: Provides Stack data structure for tracking circular references
187
- `lodash.keys`: Provides object key enumeration functionality