fast-equals 5.3.3-beta.1 → 5.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +128 -77
- package/dist/cjs/comparator.d.cts +58 -0
- package/dist/cjs/index.cjs +133 -156
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/{types/index.d.cts → index.d.cts} +21 -2
- package/{src/internalTypes.ts → dist/cjs/internalTypes.d.cts} +7 -43
- package/dist/cjs/{types/utils.d.cts → utils.d.cts} +7 -2
- package/dist/es/comparator.d.mts +58 -0
- package/dist/{esm/types → es}/index.d.mts +21 -2
- package/dist/{esm → es}/index.mjs +133 -156
- package/dist/es/index.mjs.map +1 -0
- package/dist/es/internalTypes.d.mts +174 -0
- package/dist/{esm/types → es}/utils.d.mts +7 -2
- package/dist/{min/types → umd}/comparator.d.ts +2 -2
- package/dist/{min/types → umd}/equals.d.ts +1 -1
- package/dist/umd/{types/index.d.ts → index.d.ts} +2 -2
- package/dist/umd/index.js +133 -156
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/{types/utils.d.ts → utils.d.ts} +1 -1
- package/index.d.ts +62 -68
- package/package.json +46 -54
- package/CHANGELOG.md +0 -364
- package/dist/cjs/types/comparator.d.cts +0 -26
- package/dist/cjs/types/internalTypes.d.cts +0 -157
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/types/comparator.d.mts +0 -26
- package/dist/esm/types/internalTypes.d.mts +0 -157
- package/dist/min/index.js +0 -1
- package/dist/min/types/index.d.ts +0 -47
- package/dist/min/types/utils.d.ts +0 -28
- package/dist/umd/types/comparator.d.ts +0 -26
- package/dist/umd/types/equals.d.ts +0 -54
- package/dist/umd/types/internalTypes.d.ts +0 -157
- package/src/comparator.ts +0 -376
- package/src/equals.ts +0 -355
- package/src/index.ts +0 -112
- package/src/utils.ts +0 -96
- package/dist/cjs/{types/equals.d.cts → equals.d.cts} +1 -1
- package/dist/{esm/types → es}/equals.d.mts +1 -1
- /package/dist/{min/types → umd}/internalTypes.d.ts +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const { getOwnPropertyNames, getOwnPropertySymbols } = Object;
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
3
|
+
const { hasOwnProperty } = Object.prototype;
|
|
3
4
|
/**
|
|
4
5
|
* Combine two comparators into a single comparators.
|
|
5
6
|
*/
|
|
@@ -18,15 +19,15 @@ function createIsCircular(areItemsEqual) {
|
|
|
18
19
|
if (!a || !b || typeof a !== 'object' || typeof b !== 'object') {
|
|
19
20
|
return areItemsEqual(a, b, state);
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const { cache } = state;
|
|
23
|
+
const cachedA = cache.get(a);
|
|
24
|
+
const cachedB = cache.get(b);
|
|
24
25
|
if (cachedA && cachedB) {
|
|
25
26
|
return cachedA === b && cachedB === a;
|
|
26
27
|
}
|
|
27
28
|
cache.set(a, b);
|
|
28
29
|
cache.set(b, a);
|
|
29
|
-
|
|
30
|
+
const result = areItemsEqual(a, b, state);
|
|
30
31
|
cache.delete(a);
|
|
31
32
|
cache.delete(b);
|
|
32
33
|
return result;
|
|
@@ -48,12 +49,9 @@ function getStrictProperties(object) {
|
|
|
48
49
|
/**
|
|
49
50
|
* Whether the object contains the property passed as an own property.
|
|
50
51
|
*/
|
|
51
|
-
|
|
52
|
+
const hasOwn =
|
|
52
53
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
53
|
-
Object.hasOwn ||
|
|
54
|
-
(function (object, property) {
|
|
55
|
-
return hasOwnProperty.call(object, property);
|
|
56
|
-
});
|
|
54
|
+
Object.hasOwn || ((object, property) => hasOwnProperty.call(object, property));
|
|
57
55
|
/**
|
|
58
56
|
* Whether the values passed are strictly equal or both NaN.
|
|
59
57
|
*/
|
|
@@ -61,15 +59,15 @@ function sameValueZeroEqual(a, b) {
|
|
|
61
59
|
return a === b || (!a && !b && a !== a && b !== b);
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const PREACT_VNODE = '__v';
|
|
63
|
+
const PREACT_OWNER = '__o';
|
|
64
|
+
const REACT_OWNER = '_owner';
|
|
65
|
+
const { getOwnPropertyDescriptor, keys } = Object;
|
|
68
66
|
/**
|
|
69
67
|
* Whether the arrays are equal in value.
|
|
70
68
|
*/
|
|
71
69
|
function areArraysEqual(a, b, state) {
|
|
72
|
-
|
|
70
|
+
let index = a.length;
|
|
73
71
|
if (b.length !== index) {
|
|
74
72
|
return false;
|
|
75
73
|
}
|
|
@@ -90,10 +88,7 @@ function areDatesEqual(a, b) {
|
|
|
90
88
|
* Whether the errors passed are equal in value.
|
|
91
89
|
*/
|
|
92
90
|
function areErrorsEqual(a, b) {
|
|
93
|
-
return
|
|
94
|
-
a.message === b.message &&
|
|
95
|
-
a.cause === b.cause &&
|
|
96
|
-
a.stack === b.stack);
|
|
91
|
+
return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
|
|
97
92
|
}
|
|
98
93
|
/**
|
|
99
94
|
* Whether the functions passed are equal in value.
|
|
@@ -105,26 +100,26 @@ function areFunctionsEqual(a, b) {
|
|
|
105
100
|
* Whether the `Map`s are equal in value.
|
|
106
101
|
*/
|
|
107
102
|
function areMapsEqual(a, b, state) {
|
|
108
|
-
|
|
103
|
+
const size = a.size;
|
|
109
104
|
if (size !== b.size) {
|
|
110
105
|
return false;
|
|
111
106
|
}
|
|
112
107
|
if (!size) {
|
|
113
108
|
return true;
|
|
114
109
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
const matchedIndices = new Array(size);
|
|
111
|
+
const aIterable = a.entries();
|
|
112
|
+
let aResult;
|
|
113
|
+
let bResult;
|
|
114
|
+
let index = 0;
|
|
120
115
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
121
116
|
while ((aResult = aIterable.next())) {
|
|
122
117
|
if (aResult.done) {
|
|
123
118
|
break;
|
|
124
119
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
const bIterable = b.entries();
|
|
121
|
+
let hasMatch = false;
|
|
122
|
+
let matchIndex = 0;
|
|
128
123
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
129
124
|
while ((bResult = bIterable.next())) {
|
|
130
125
|
if (bResult.done) {
|
|
@@ -134,10 +129,10 @@ function areMapsEqual(a, b, state) {
|
|
|
134
129
|
matchIndex++;
|
|
135
130
|
continue;
|
|
136
131
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state)
|
|
140
|
-
state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
|
|
132
|
+
const aEntry = aResult.value;
|
|
133
|
+
const bEntry = bResult.value;
|
|
134
|
+
if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state)
|
|
135
|
+
&& state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
|
|
141
136
|
hasMatch = matchedIndices[matchIndex] = true;
|
|
142
137
|
break;
|
|
143
138
|
}
|
|
@@ -153,13 +148,13 @@ function areMapsEqual(a, b, state) {
|
|
|
153
148
|
/**
|
|
154
149
|
* Whether the numbers are equal in value.
|
|
155
150
|
*/
|
|
156
|
-
|
|
151
|
+
const areNumbersEqual = sameValueZeroEqual;
|
|
157
152
|
/**
|
|
158
153
|
* Whether the objects are equal in value.
|
|
159
154
|
*/
|
|
160
155
|
function areObjectsEqual(a, b, state) {
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
const properties = keys(a);
|
|
157
|
+
let index = properties.length;
|
|
163
158
|
if (keys(b).length !== index) {
|
|
164
159
|
return false;
|
|
165
160
|
}
|
|
@@ -178,14 +173,14 @@ function areObjectsEqual(a, b, state) {
|
|
|
178
173
|
* Whether the objects are equal in value with strict property checking.
|
|
179
174
|
*/
|
|
180
175
|
function areObjectsEqualStrict(a, b, state) {
|
|
181
|
-
|
|
182
|
-
|
|
176
|
+
const properties = getStrictProperties(a);
|
|
177
|
+
let index = properties.length;
|
|
183
178
|
if (getStrictProperties(b).length !== index) {
|
|
184
179
|
return false;
|
|
185
180
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
181
|
+
let property;
|
|
182
|
+
let descriptorA;
|
|
183
|
+
let descriptorB;
|
|
189
184
|
// Decrementing `while` showed faster results than either incrementing or
|
|
190
185
|
// decrementing `for` loop and than an incrementing `while` loop. Declarative
|
|
191
186
|
// methods like `some` / `every` were not used to avoid incurring the garbage
|
|
@@ -197,12 +192,12 @@ function areObjectsEqualStrict(a, b, state) {
|
|
|
197
192
|
}
|
|
198
193
|
descriptorA = getOwnPropertyDescriptor(a, property);
|
|
199
194
|
descriptorB = getOwnPropertyDescriptor(b, property);
|
|
200
|
-
if ((descriptorA || descriptorB)
|
|
201
|
-
(!descriptorA
|
|
202
|
-
!descriptorB
|
|
203
|
-
descriptorA.configurable !== descriptorB.configurable
|
|
204
|
-
descriptorA.enumerable !== descriptorB.enumerable
|
|
205
|
-
descriptorA.writable !== descriptorB.writable)) {
|
|
195
|
+
if ((descriptorA || descriptorB)
|
|
196
|
+
&& (!descriptorA
|
|
197
|
+
|| !descriptorB
|
|
198
|
+
|| descriptorA.configurable !== descriptorB.configurable
|
|
199
|
+
|| descriptorA.enumerable !== descriptorB.enumerable
|
|
200
|
+
|| descriptorA.writable !== descriptorB.writable)) {
|
|
206
201
|
return false;
|
|
207
202
|
}
|
|
208
203
|
}
|
|
@@ -224,32 +219,32 @@ function areRegExpsEqual(a, b) {
|
|
|
224
219
|
* Whether the `Set`s are equal in value.
|
|
225
220
|
*/
|
|
226
221
|
function areSetsEqual(a, b, state) {
|
|
227
|
-
|
|
222
|
+
const size = a.size;
|
|
228
223
|
if (size !== b.size) {
|
|
229
224
|
return false;
|
|
230
225
|
}
|
|
231
226
|
if (!size) {
|
|
232
227
|
return true;
|
|
233
228
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
229
|
+
const matchedIndices = new Array(size);
|
|
230
|
+
const aIterable = a.values();
|
|
231
|
+
let aResult;
|
|
232
|
+
let bResult;
|
|
238
233
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
239
234
|
while ((aResult = aIterable.next())) {
|
|
240
235
|
if (aResult.done) {
|
|
241
236
|
break;
|
|
242
237
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
238
|
+
const bIterable = b.values();
|
|
239
|
+
let hasMatch = false;
|
|
240
|
+
let matchIndex = 0;
|
|
246
241
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
247
242
|
while ((bResult = bIterable.next())) {
|
|
248
243
|
if (bResult.done) {
|
|
249
244
|
break;
|
|
250
245
|
}
|
|
251
|
-
if (!matchedIndices[matchIndex]
|
|
252
|
-
state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
|
|
246
|
+
if (!matchedIndices[matchIndex]
|
|
247
|
+
&& state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
|
|
253
248
|
hasMatch = matchedIndices[matchIndex] = true;
|
|
254
249
|
break;
|
|
255
250
|
}
|
|
@@ -265,7 +260,7 @@ function areSetsEqual(a, b, state) {
|
|
|
265
260
|
* Whether the TypedArray instances are equal in value.
|
|
266
261
|
*/
|
|
267
262
|
function areTypedArraysEqual(a, b) {
|
|
268
|
-
|
|
263
|
+
let index = a.length;
|
|
269
264
|
if (b.length !== index) {
|
|
270
265
|
return false;
|
|
271
266
|
}
|
|
@@ -280,47 +275,44 @@ function areTypedArraysEqual(a, b) {
|
|
|
280
275
|
* Whether the URL instances are equal in value.
|
|
281
276
|
*/
|
|
282
277
|
function areUrlsEqual(a, b) {
|
|
283
|
-
return (a.hostname === b.hostname
|
|
284
|
-
a.pathname === b.pathname
|
|
285
|
-
a.protocol === b.protocol
|
|
286
|
-
a.port === b.port
|
|
287
|
-
a.hash === b.hash
|
|
288
|
-
a.username === b.username
|
|
289
|
-
a.password === b.password);
|
|
278
|
+
return (a.hostname === b.hostname
|
|
279
|
+
&& a.pathname === b.pathname
|
|
280
|
+
&& a.protocol === b.protocol
|
|
281
|
+
&& a.port === b.port
|
|
282
|
+
&& a.hash === b.hash
|
|
283
|
+
&& a.username === b.username
|
|
284
|
+
&& a.password === b.password);
|
|
290
285
|
}
|
|
291
286
|
function isPropertyEqual(a, b, state, property) {
|
|
292
|
-
if ((property === REACT_OWNER ||
|
|
293
|
-
|
|
294
|
-
property === PREACT_VNODE) &&
|
|
295
|
-
(a.$$typeof || b.$$typeof)) {
|
|
287
|
+
if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE)
|
|
288
|
+
&& (a.$$typeof || b.$$typeof)) {
|
|
296
289
|
return true;
|
|
297
290
|
}
|
|
298
|
-
return
|
|
299
|
-
state.equals(a[property], b[property], property, property, a, b, state));
|
|
291
|
+
return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
|
|
300
292
|
}
|
|
301
293
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
294
|
+
const ARGUMENTS_TAG = '[object Arguments]';
|
|
295
|
+
const BOOLEAN_TAG = '[object Boolean]';
|
|
296
|
+
const DATE_TAG = '[object Date]';
|
|
297
|
+
const ERROR_TAG = '[object Error]';
|
|
298
|
+
const MAP_TAG = '[object Map]';
|
|
299
|
+
const NUMBER_TAG = '[object Number]';
|
|
300
|
+
const OBJECT_TAG = '[object Object]';
|
|
301
|
+
const REG_EXP_TAG = '[object RegExp]';
|
|
302
|
+
const SET_TAG = '[object Set]';
|
|
303
|
+
const STRING_TAG = '[object String]';
|
|
304
|
+
const URL_TAG = '[object URL]';
|
|
305
|
+
const { isArray } = Array;
|
|
306
|
+
const isTypedArray =
|
|
307
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
308
|
+
typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' ? ArrayBuffer.isView : null;
|
|
309
|
+
const { assign } = Object;
|
|
310
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
311
|
+
const getTag = Object.prototype.toString.call.bind(Object.prototype.toString);
|
|
319
312
|
/**
|
|
320
313
|
* Create a comparator method based on the type-specific equality comparators passed.
|
|
321
314
|
*/
|
|
322
|
-
function createEqualityComparator(
|
|
323
|
-
var areArraysEqual = _a.areArraysEqual, areDatesEqual = _a.areDatesEqual, areErrorsEqual = _a.areErrorsEqual, areFunctionsEqual = _a.areFunctionsEqual, areMapsEqual = _a.areMapsEqual, areNumbersEqual = _a.areNumbersEqual, areObjectsEqual = _a.areObjectsEqual, arePrimitiveWrappersEqual = _a.arePrimitiveWrappersEqual, areRegExpsEqual = _a.areRegExpsEqual, areSetsEqual = _a.areSetsEqual, areTypedArraysEqual = _a.areTypedArraysEqual, areUrlsEqual = _a.areUrlsEqual, unknownTagComparators = _a.unknownTagComparators;
|
|
315
|
+
function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, unknownTagComparators, }) {
|
|
324
316
|
/**
|
|
325
317
|
* compare the value of the two objects and return true if they are equivalent in values
|
|
326
318
|
*/
|
|
@@ -334,7 +326,7 @@ function createEqualityComparator(_a) {
|
|
|
334
326
|
if (a == null || b == null) {
|
|
335
327
|
return false;
|
|
336
328
|
}
|
|
337
|
-
|
|
329
|
+
const type = typeof a;
|
|
338
330
|
if (type !== typeof b) {
|
|
339
331
|
return false;
|
|
340
332
|
}
|
|
@@ -348,7 +340,7 @@ function createEqualityComparator(_a) {
|
|
|
348
340
|
// If a primitive value that is not strictly equal, it must be unequal.
|
|
349
341
|
return false;
|
|
350
342
|
}
|
|
351
|
-
|
|
343
|
+
const constructor = a.constructor;
|
|
352
344
|
// Checks are listed in order of commonality of use-case:
|
|
353
345
|
// 1. Common complex object types (plain object, array)
|
|
354
346
|
// 2. Common data values (date, regexp)
|
|
@@ -375,7 +367,7 @@ function createEqualityComparator(_a) {
|
|
|
375
367
|
}
|
|
376
368
|
// `isTypedArray()` works on all possible TypedArray classes, so we can avoid
|
|
377
369
|
// capturing the string tag or comparing against all possible constructors.
|
|
378
|
-
if (isTypedArray
|
|
370
|
+
if (isTypedArray != null && isTypedArray(a)) {
|
|
379
371
|
return areTypedArraysEqual(a, b, state);
|
|
380
372
|
}
|
|
381
373
|
// Try to fast-path equality checks for other complex object types in the
|
|
@@ -397,7 +389,7 @@ function createEqualityComparator(_a) {
|
|
|
397
389
|
}
|
|
398
390
|
// Since this is a custom object, capture the string tag to determing its type.
|
|
399
391
|
// This is reasonably performant in modern environments like v8 and SpiderMonkey.
|
|
400
|
-
|
|
392
|
+
const tag = getTag(a);
|
|
401
393
|
if (tag === DATE_TAG) {
|
|
402
394
|
return areDatesEqual(a, b, state);
|
|
403
395
|
}
|
|
@@ -416,9 +408,7 @@ function createEqualityComparator(_a) {
|
|
|
416
408
|
// The exception for value comparison is custom `Promise`-like class instances. These should
|
|
417
409
|
// be treated the same as standard `Promise` objects, which means strict equality, and if
|
|
418
410
|
// it reaches this point then that strict equality comparison has already failed.
|
|
419
|
-
return
|
|
420
|
-
typeof b.then !== 'function' &&
|
|
421
|
-
areObjectsEqual(a, b, state));
|
|
411
|
+
return typeof a.then !== 'function' && typeof b.then !== 'function' && areObjectsEqual(a, b, state);
|
|
422
412
|
}
|
|
423
413
|
// If a URL tag, it should be tested explicitly. Like RegExp, the properties are not
|
|
424
414
|
// enumerable, and therefore will give false positives if tested like a standard object.
|
|
@@ -441,9 +431,9 @@ function createEqualityComparator(_a) {
|
|
|
441
431
|
return arePrimitiveWrappersEqual(a, b, state);
|
|
442
432
|
}
|
|
443
433
|
if (unknownTagComparators) {
|
|
444
|
-
|
|
434
|
+
let unknownTagComparator = unknownTagComparators[tag];
|
|
445
435
|
if (!unknownTagComparator) {
|
|
446
|
-
|
|
436
|
+
const shortTag = getShortTag(a);
|
|
447
437
|
if (shortTag) {
|
|
448
438
|
unknownTagComparator = unknownTagComparators[shortTag];
|
|
449
439
|
}
|
|
@@ -471,30 +461,19 @@ function createEqualityComparator(_a) {
|
|
|
471
461
|
/**
|
|
472
462
|
* Create the configuration object used for building comparators.
|
|
473
463
|
*/
|
|
474
|
-
function createEqualityComparatorConfig(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
areArraysEqual: strict
|
|
478
|
-
? areObjectsEqualStrict
|
|
479
|
-
: areArraysEqual,
|
|
464
|
+
function createEqualityComparatorConfig({ circular, createCustomConfig, strict, }) {
|
|
465
|
+
let config = {
|
|
466
|
+
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
480
467
|
areDatesEqual: areDatesEqual,
|
|
481
468
|
areErrorsEqual: areErrorsEqual,
|
|
482
469
|
areFunctionsEqual: areFunctionsEqual,
|
|
483
|
-
areMapsEqual: strict
|
|
484
|
-
? combineComparators(areMapsEqual, areObjectsEqualStrict)
|
|
485
|
-
: areMapsEqual,
|
|
470
|
+
areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
|
|
486
471
|
areNumbersEqual: areNumbersEqual,
|
|
487
|
-
areObjectsEqual: strict
|
|
488
|
-
? areObjectsEqualStrict
|
|
489
|
-
: areObjectsEqual,
|
|
472
|
+
areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
|
|
490
473
|
arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
|
|
491
474
|
areRegExpsEqual: areRegExpsEqual,
|
|
492
|
-
areSetsEqual: strict
|
|
493
|
-
|
|
494
|
-
: areSetsEqual,
|
|
495
|
-
areTypedArraysEqual: strict
|
|
496
|
-
? areObjectsEqualStrict
|
|
497
|
-
: areTypedArraysEqual,
|
|
475
|
+
areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
|
|
476
|
+
areTypedArraysEqual: strict ? areObjectsEqualStrict : areTypedArraysEqual,
|
|
498
477
|
areUrlsEqual: areUrlsEqual,
|
|
499
478
|
unknownTagComparators: undefined,
|
|
500
479
|
};
|
|
@@ -502,15 +481,15 @@ function createEqualityComparatorConfig(_a) {
|
|
|
502
481
|
config = assign({}, config, createCustomConfig(config));
|
|
503
482
|
}
|
|
504
483
|
if (circular) {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
484
|
+
const areArraysEqual = createIsCircular(config.areArraysEqual);
|
|
485
|
+
const areMapsEqual = createIsCircular(config.areMapsEqual);
|
|
486
|
+
const areObjectsEqual = createIsCircular(config.areObjectsEqual);
|
|
487
|
+
const areSetsEqual = createIsCircular(config.areSetsEqual);
|
|
509
488
|
config = assign({}, config, {
|
|
510
|
-
areArraysEqual
|
|
511
|
-
areMapsEqual
|
|
512
|
-
areObjectsEqual
|
|
513
|
-
areSetsEqual
|
|
489
|
+
areArraysEqual,
|
|
490
|
+
areMapsEqual,
|
|
491
|
+
areObjectsEqual,
|
|
492
|
+
areSetsEqual,
|
|
514
493
|
});
|
|
515
494
|
}
|
|
516
495
|
return config;
|
|
@@ -527,16 +506,15 @@ function createInternalEqualityComparator(compare) {
|
|
|
527
506
|
/**
|
|
528
507
|
* Create the `isEqual` function used by the consuming application.
|
|
529
508
|
*/
|
|
530
|
-
function createIsEqual(
|
|
531
|
-
var circular = _a.circular, comparator = _a.comparator, createState = _a.createState, equals = _a.equals, strict = _a.strict;
|
|
509
|
+
function createIsEqual({ circular, comparator, createState, equals, strict }) {
|
|
532
510
|
if (createState) {
|
|
533
511
|
return function isEqual(a, b) {
|
|
534
|
-
|
|
512
|
+
const { cache = circular ? new WeakMap() : undefined, meta } = createState();
|
|
535
513
|
return comparator(a, b, {
|
|
536
|
-
cache
|
|
537
|
-
equals
|
|
538
|
-
meta
|
|
539
|
-
strict
|
|
514
|
+
cache,
|
|
515
|
+
equals,
|
|
516
|
+
meta,
|
|
517
|
+
strict,
|
|
540
518
|
});
|
|
541
519
|
};
|
|
542
520
|
}
|
|
@@ -544,17 +522,17 @@ function createIsEqual(_a) {
|
|
|
544
522
|
return function isEqual(a, b) {
|
|
545
523
|
return comparator(a, b, {
|
|
546
524
|
cache: new WeakMap(),
|
|
547
|
-
equals
|
|
525
|
+
equals,
|
|
548
526
|
meta: undefined,
|
|
549
|
-
strict
|
|
527
|
+
strict,
|
|
550
528
|
});
|
|
551
529
|
};
|
|
552
530
|
}
|
|
553
|
-
|
|
531
|
+
const state = {
|
|
554
532
|
cache: undefined,
|
|
555
|
-
equals
|
|
533
|
+
equals,
|
|
556
534
|
meta: undefined,
|
|
557
|
-
strict
|
|
535
|
+
strict,
|
|
558
536
|
};
|
|
559
537
|
return function isEqual(a, b) {
|
|
560
538
|
return comparator(a, b, state);
|
|
@@ -564,50 +542,50 @@ function createIsEqual(_a) {
|
|
|
564
542
|
/**
|
|
565
543
|
* Whether the items passed are deeply-equal in value.
|
|
566
544
|
*/
|
|
567
|
-
|
|
545
|
+
const deepEqual = createCustomEqual();
|
|
568
546
|
/**
|
|
569
547
|
* Whether the items passed are deeply-equal in value based on strict comparison.
|
|
570
548
|
*/
|
|
571
|
-
|
|
549
|
+
const strictDeepEqual = createCustomEqual({ strict: true });
|
|
572
550
|
/**
|
|
573
551
|
* Whether the items passed are deeply-equal in value, including circular references.
|
|
574
552
|
*/
|
|
575
|
-
|
|
553
|
+
const circularDeepEqual = createCustomEqual({ circular: true });
|
|
576
554
|
/**
|
|
577
555
|
* Whether the items passed are deeply-equal in value, including circular references,
|
|
578
556
|
* based on strict comparison.
|
|
579
557
|
*/
|
|
580
|
-
|
|
558
|
+
const strictCircularDeepEqual = createCustomEqual({
|
|
581
559
|
circular: true,
|
|
582
560
|
strict: true,
|
|
583
561
|
});
|
|
584
562
|
/**
|
|
585
563
|
* Whether the items passed are shallowly-equal in value.
|
|
586
564
|
*/
|
|
587
|
-
|
|
588
|
-
createInternalComparator:
|
|
565
|
+
const shallowEqual = createCustomEqual({
|
|
566
|
+
createInternalComparator: () => sameValueZeroEqual,
|
|
589
567
|
});
|
|
590
568
|
/**
|
|
591
569
|
* Whether the items passed are shallowly-equal in value based on strict comparison
|
|
592
570
|
*/
|
|
593
|
-
|
|
571
|
+
const strictShallowEqual = createCustomEqual({
|
|
594
572
|
strict: true,
|
|
595
|
-
createInternalComparator:
|
|
573
|
+
createInternalComparator: () => sameValueZeroEqual,
|
|
596
574
|
});
|
|
597
575
|
/**
|
|
598
576
|
* Whether the items passed are shallowly-equal in value, including circular references.
|
|
599
577
|
*/
|
|
600
|
-
|
|
578
|
+
const circularShallowEqual = createCustomEqual({
|
|
601
579
|
circular: true,
|
|
602
|
-
createInternalComparator:
|
|
580
|
+
createInternalComparator: () => sameValueZeroEqual,
|
|
603
581
|
});
|
|
604
582
|
/**
|
|
605
583
|
* Whether the items passed are shallowly-equal in value, including circular references,
|
|
606
584
|
* based on strict comparison.
|
|
607
585
|
*/
|
|
608
|
-
|
|
586
|
+
const strictCircularShallowEqual = createCustomEqual({
|
|
609
587
|
circular: true,
|
|
610
|
-
createInternalComparator:
|
|
588
|
+
createInternalComparator: () => sameValueZeroEqual,
|
|
611
589
|
strict: true,
|
|
612
590
|
});
|
|
613
591
|
/**
|
|
@@ -618,15 +596,14 @@ var strictCircularShallowEqual = createCustomEqual({
|
|
|
618
596
|
* support for legacy environments that do not support expected features like
|
|
619
597
|
* `RegExp.prototype.flags` out of the box.
|
|
620
598
|
*/
|
|
621
|
-
function createCustomEqual(options) {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
var equals = createCustomInternalComparator
|
|
599
|
+
function createCustomEqual(options = {}) {
|
|
600
|
+
const { circular = false, createInternalComparator: createCustomInternalComparator, createState, strict = false, } = options;
|
|
601
|
+
const config = createEqualityComparatorConfig(options);
|
|
602
|
+
const comparator = createEqualityComparator(config);
|
|
603
|
+
const equals = createCustomInternalComparator
|
|
627
604
|
? createCustomInternalComparator(comparator)
|
|
628
605
|
: createInternalEqualityComparator(comparator);
|
|
629
|
-
return createIsEqual({ circular
|
|
606
|
+
return createIsEqual({ circular, comparator, createState, equals, strict });
|
|
630
607
|
}
|
|
631
608
|
|
|
632
609
|
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictShallowEqual };
|