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