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