fast-equals 5.3.3 → 5.4.0
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 +60 -0
- package/dist/cjs/{types/equals.d.cts → equals.d.cts} +8 -0
- package/dist/cjs/index.cjs +171 -162
- 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} +18 -50
- package/dist/cjs/{types/utils.d.cts → utils.d.cts} +7 -2
- package/dist/es/comparator.d.mts +60 -0
- package/dist/{esm/types → es}/equals.d.mts +8 -0
- package/dist/{esm/types → es}/index.d.mts +21 -2
- package/dist/{esm → es}/index.mjs +171 -162
- package/dist/es/index.mjs.map +1 -0
- package/dist/es/internalTypes.d.mts +178 -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 +8 -0
- package/dist/umd/index.js +171 -162
- package/dist/umd/index.js.map +1 -1
- package/dist/{min/types → umd}/internalTypes.d.ts +10 -8
- package/index.d.ts +73 -75
- package/package.json +45 -48
- 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/{min/types → umd}/index.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,21 @@ 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;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the array buffers are equal in value.
|
|
70
|
+
*/
|
|
71
|
+
function areArrayBuffersEqual(a, b) {
|
|
72
|
+
return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
|
|
73
|
+
}
|
|
70
74
|
/**
|
|
71
75
|
* Whether the arrays are equal in value.
|
|
72
76
|
*/
|
|
73
77
|
function areArraysEqual(a, b, state) {
|
|
74
|
-
|
|
78
|
+
let index = a.length;
|
|
75
79
|
if (b.length !== index) {
|
|
76
80
|
return false;
|
|
77
81
|
}
|
|
@@ -82,6 +86,13 @@ function areArraysEqual(a, b, state) {
|
|
|
82
86
|
}
|
|
83
87
|
return true;
|
|
84
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Whether the dataviews are equal in value.
|
|
91
|
+
*/
|
|
92
|
+
function areDataViewsEqual(a, b) {
|
|
93
|
+
return (a.byteLength === b.byteLength
|
|
94
|
+
&& areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength)));
|
|
95
|
+
}
|
|
85
96
|
/**
|
|
86
97
|
* Whether the dates passed are equal in value.
|
|
87
98
|
*/
|
|
@@ -92,10 +103,7 @@ function areDatesEqual(a, b) {
|
|
|
92
103
|
* Whether the errors passed are equal in value.
|
|
93
104
|
*/
|
|
94
105
|
function areErrorsEqual(a, b) {
|
|
95
|
-
return
|
|
96
|
-
a.message === b.message &&
|
|
97
|
-
a.cause === b.cause &&
|
|
98
|
-
a.stack === b.stack);
|
|
106
|
+
return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
|
|
99
107
|
}
|
|
100
108
|
/**
|
|
101
109
|
* Whether the functions passed are equal in value.
|
|
@@ -107,26 +115,26 @@ function areFunctionsEqual(a, b) {
|
|
|
107
115
|
* Whether the `Map`s are equal in value.
|
|
108
116
|
*/
|
|
109
117
|
function areMapsEqual(a, b, state) {
|
|
110
|
-
|
|
118
|
+
const size = a.size;
|
|
111
119
|
if (size !== b.size) {
|
|
112
120
|
return false;
|
|
113
121
|
}
|
|
114
122
|
if (!size) {
|
|
115
123
|
return true;
|
|
116
124
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
const matchedIndices = new Array(size);
|
|
126
|
+
const aIterable = a.entries();
|
|
127
|
+
let aResult;
|
|
128
|
+
let bResult;
|
|
129
|
+
let index = 0;
|
|
122
130
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
123
131
|
while ((aResult = aIterable.next())) {
|
|
124
132
|
if (aResult.done) {
|
|
125
133
|
break;
|
|
126
134
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
const bIterable = b.entries();
|
|
136
|
+
let hasMatch = false;
|
|
137
|
+
let matchIndex = 0;
|
|
130
138
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
131
139
|
while ((bResult = bIterable.next())) {
|
|
132
140
|
if (bResult.done) {
|
|
@@ -136,10 +144,10 @@ function areMapsEqual(a, b, state) {
|
|
|
136
144
|
matchIndex++;
|
|
137
145
|
continue;
|
|
138
146
|
}
|
|
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)) {
|
|
147
|
+
const aEntry = aResult.value;
|
|
148
|
+
const bEntry = bResult.value;
|
|
149
|
+
if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state)
|
|
150
|
+
&& state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
|
|
143
151
|
hasMatch = matchedIndices[matchIndex] = true;
|
|
144
152
|
break;
|
|
145
153
|
}
|
|
@@ -155,13 +163,13 @@ function areMapsEqual(a, b, state) {
|
|
|
155
163
|
/**
|
|
156
164
|
* Whether the numbers are equal in value.
|
|
157
165
|
*/
|
|
158
|
-
|
|
166
|
+
const areNumbersEqual = sameValueZeroEqual;
|
|
159
167
|
/**
|
|
160
168
|
* Whether the objects are equal in value.
|
|
161
169
|
*/
|
|
162
170
|
function areObjectsEqual(a, b, state) {
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
const properties = keys(a);
|
|
172
|
+
let index = properties.length;
|
|
165
173
|
if (keys(b).length !== index) {
|
|
166
174
|
return false;
|
|
167
175
|
}
|
|
@@ -180,14 +188,14 @@ function areObjectsEqual(a, b, state) {
|
|
|
180
188
|
* Whether the objects are equal in value with strict property checking.
|
|
181
189
|
*/
|
|
182
190
|
function areObjectsEqualStrict(a, b, state) {
|
|
183
|
-
|
|
184
|
-
|
|
191
|
+
const properties = getStrictProperties(a);
|
|
192
|
+
let index = properties.length;
|
|
185
193
|
if (getStrictProperties(b).length !== index) {
|
|
186
194
|
return false;
|
|
187
195
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
196
|
+
let property;
|
|
197
|
+
let descriptorA;
|
|
198
|
+
let descriptorB;
|
|
191
199
|
// Decrementing `while` showed faster results than either incrementing or
|
|
192
200
|
// decrementing `for` loop and than an incrementing `while` loop. Declarative
|
|
193
201
|
// methods like `some` / `every` were not used to avoid incurring the garbage
|
|
@@ -199,12 +207,12 @@ function areObjectsEqualStrict(a, b, state) {
|
|
|
199
207
|
}
|
|
200
208
|
descriptorA = getOwnPropertyDescriptor(a, property);
|
|
201
209
|
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)) {
|
|
210
|
+
if ((descriptorA || descriptorB)
|
|
211
|
+
&& (!descriptorA
|
|
212
|
+
|| !descriptorB
|
|
213
|
+
|| descriptorA.configurable !== descriptorB.configurable
|
|
214
|
+
|| descriptorA.enumerable !== descriptorB.enumerable
|
|
215
|
+
|| descriptorA.writable !== descriptorB.writable)) {
|
|
208
216
|
return false;
|
|
209
217
|
}
|
|
210
218
|
}
|
|
@@ -226,32 +234,32 @@ function areRegExpsEqual(a, b) {
|
|
|
226
234
|
* Whether the `Set`s are equal in value.
|
|
227
235
|
*/
|
|
228
236
|
function areSetsEqual(a, b, state) {
|
|
229
|
-
|
|
237
|
+
const size = a.size;
|
|
230
238
|
if (size !== b.size) {
|
|
231
239
|
return false;
|
|
232
240
|
}
|
|
233
241
|
if (!size) {
|
|
234
242
|
return true;
|
|
235
243
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
244
|
+
const matchedIndices = new Array(size);
|
|
245
|
+
const aIterable = a.values();
|
|
246
|
+
let aResult;
|
|
247
|
+
let bResult;
|
|
240
248
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
241
249
|
while ((aResult = aIterable.next())) {
|
|
242
250
|
if (aResult.done) {
|
|
243
251
|
break;
|
|
244
252
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
253
|
+
const bIterable = b.values();
|
|
254
|
+
let hasMatch = false;
|
|
255
|
+
let matchIndex = 0;
|
|
248
256
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
249
257
|
while ((bResult = bIterable.next())) {
|
|
250
258
|
if (bResult.done) {
|
|
251
259
|
break;
|
|
252
260
|
}
|
|
253
|
-
if (!matchedIndices[matchIndex]
|
|
254
|
-
state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
|
|
261
|
+
if (!matchedIndices[matchIndex]
|
|
262
|
+
&& state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
|
|
255
263
|
hasMatch = matchedIndices[matchIndex] = true;
|
|
256
264
|
break;
|
|
257
265
|
}
|
|
@@ -267,8 +275,8 @@ function areSetsEqual(a, b, state) {
|
|
|
267
275
|
* Whether the TypedArray instances are equal in value.
|
|
268
276
|
*/
|
|
269
277
|
function areTypedArraysEqual(a, b) {
|
|
270
|
-
|
|
271
|
-
if (b.
|
|
278
|
+
let index = a.byteLength;
|
|
279
|
+
if (b.byteLength !== index || a.byteOffset !== b.byteOffset) {
|
|
272
280
|
return false;
|
|
273
281
|
}
|
|
274
282
|
while (index-- > 0) {
|
|
@@ -282,47 +290,55 @@ function areTypedArraysEqual(a, b) {
|
|
|
282
290
|
* Whether the URL instances are equal in value.
|
|
283
291
|
*/
|
|
284
292
|
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);
|
|
293
|
+
return (a.hostname === b.hostname
|
|
294
|
+
&& a.pathname === b.pathname
|
|
295
|
+
&& a.protocol === b.protocol
|
|
296
|
+
&& a.port === b.port
|
|
297
|
+
&& a.hash === b.hash
|
|
298
|
+
&& a.username === b.username
|
|
299
|
+
&& a.password === b.password);
|
|
292
300
|
}
|
|
293
301
|
function isPropertyEqual(a, b, state, property) {
|
|
294
|
-
if ((property === REACT_OWNER ||
|
|
295
|
-
|
|
296
|
-
property === PREACT_VNODE) &&
|
|
297
|
-
(a.$$typeof || b.$$typeof)) {
|
|
302
|
+
if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE)
|
|
303
|
+
&& (a.$$typeof || b.$$typeof)) {
|
|
298
304
|
return true;
|
|
299
305
|
}
|
|
300
|
-
return
|
|
301
|
-
state.equals(a[property], b[property], property, property, a, b, state));
|
|
306
|
+
return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
|
|
302
307
|
}
|
|
303
308
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
:
|
|
319
|
-
|
|
320
|
-
|
|
309
|
+
const ARRAY_BUFFER_TAG = '[object ArrayBuffer]';
|
|
310
|
+
const ARGUMENTS_TAG = '[object Arguments]';
|
|
311
|
+
const BOOLEAN_TAG = '[object Boolean]';
|
|
312
|
+
const DATA_VIEW_TAG = '[object DataView]';
|
|
313
|
+
const DATE_TAG = '[object Date]';
|
|
314
|
+
const ERROR_TAG = '[object Error]';
|
|
315
|
+
const MAP_TAG = '[object Map]';
|
|
316
|
+
const NUMBER_TAG = '[object Number]';
|
|
317
|
+
const OBJECT_TAG = '[object Object]';
|
|
318
|
+
const REG_EXP_TAG = '[object RegExp]';
|
|
319
|
+
const SET_TAG = '[object Set]';
|
|
320
|
+
const STRING_TAG = '[object String]';
|
|
321
|
+
const TYPED_ARRAY_TAGS = {
|
|
322
|
+
'[object Int8Array]': true,
|
|
323
|
+
'[object Uint8Array]': true,
|
|
324
|
+
'[object Uint8ClampedArray]': true,
|
|
325
|
+
'[object Int16Array]': true,
|
|
326
|
+
'[object Uint16Array]': true,
|
|
327
|
+
'[object Int32Array]': true,
|
|
328
|
+
'[object Uint32Array]': true,
|
|
329
|
+
'[object Float16Array]': true,
|
|
330
|
+
'[object Float32Array]': true,
|
|
331
|
+
'[object Float64Array]': true,
|
|
332
|
+
'[object BigInt64Array]': true,
|
|
333
|
+
'[object BigUint64Array]': true,
|
|
334
|
+
};
|
|
335
|
+
const URL_TAG = '[object URL]';
|
|
336
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
337
|
+
const toString = Object.prototype.toString;
|
|
321
338
|
/**
|
|
322
339
|
* Create a comparator method based on the type-specific equality comparators passed.
|
|
323
340
|
*/
|
|
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;
|
|
341
|
+
function createEqualityComparator({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, unknownTagComparators, }) {
|
|
326
342
|
/**
|
|
327
343
|
* compare the value of the two objects and return true if they are equivalent in values
|
|
328
344
|
*/
|
|
@@ -336,7 +352,7 @@ function createEqualityComparator(_a) {
|
|
|
336
352
|
if (a == null || b == null) {
|
|
337
353
|
return false;
|
|
338
354
|
}
|
|
339
|
-
|
|
355
|
+
const type = typeof a;
|
|
340
356
|
if (type !== typeof b) {
|
|
341
357
|
return false;
|
|
342
358
|
}
|
|
@@ -350,7 +366,7 @@ function createEqualityComparator(_a) {
|
|
|
350
366
|
// If a primitive value that is not strictly equal, it must be unequal.
|
|
351
367
|
return false;
|
|
352
368
|
}
|
|
353
|
-
|
|
369
|
+
const constructor = a.constructor;
|
|
354
370
|
// Checks are listed in order of commonality of use-case:
|
|
355
371
|
// 1. Common complex object types (plain object, array)
|
|
356
372
|
// 2. Common data values (date, regexp)
|
|
@@ -372,14 +388,9 @@ function createEqualityComparator(_a) {
|
|
|
372
388
|
}
|
|
373
389
|
// `isArray()` works on subclasses and is cross-realm, so we can avoid capturing
|
|
374
390
|
// the string tag or doing an `instanceof` check.
|
|
375
|
-
if (isArray(a)) {
|
|
391
|
+
if (Array.isArray(a)) {
|
|
376
392
|
return areArraysEqual(a, b, state);
|
|
377
393
|
}
|
|
378
|
-
// `isTypedArray()` works on all possible TypedArray classes, so we can avoid
|
|
379
|
-
// capturing the string tag or comparing against all possible constructors.
|
|
380
|
-
if (isTypedArray != null && isTypedArray(a)) {
|
|
381
|
-
return areTypedArraysEqual(a, b, state);
|
|
382
|
-
}
|
|
383
394
|
// Try to fast-path equality checks for other complex object types in the
|
|
384
395
|
// same realm to avoid capturing the string tag. Strict equality is used
|
|
385
396
|
// instead of `instanceof` because it is more performant for the common
|
|
@@ -399,7 +410,7 @@ function createEqualityComparator(_a) {
|
|
|
399
410
|
}
|
|
400
411
|
// Since this is a custom object, capture the string tag to determing its type.
|
|
401
412
|
// This is reasonably performant in modern environments like v8 and SpiderMonkey.
|
|
402
|
-
|
|
413
|
+
const tag = toString.call(a);
|
|
403
414
|
if (tag === DATE_TAG) {
|
|
404
415
|
return areDatesEqual(a, b, state);
|
|
405
416
|
}
|
|
@@ -418,9 +429,7 @@ function createEqualityComparator(_a) {
|
|
|
418
429
|
// The exception for value comparison is custom `Promise`-like class instances. These should
|
|
419
430
|
// be treated the same as standard `Promise` objects, which means strict equality, and if
|
|
420
431
|
// it reaches this point then that strict equality comparison has already failed.
|
|
421
|
-
return
|
|
422
|
-
typeof b.then !== 'function' &&
|
|
423
|
-
areObjectsEqual(a, b, state));
|
|
432
|
+
return typeof a.then !== 'function' && typeof b.then !== 'function' && areObjectsEqual(a, b, state);
|
|
424
433
|
}
|
|
425
434
|
// If a URL tag, it should be tested explicitly. Like RegExp, the properties are not
|
|
426
435
|
// enumerable, and therefore will give false positives if tested like a standard object.
|
|
@@ -436,6 +445,15 @@ function createEqualityComparator(_a) {
|
|
|
436
445
|
if (tag === ARGUMENTS_TAG) {
|
|
437
446
|
return areObjectsEqual(a, b, state);
|
|
438
447
|
}
|
|
448
|
+
if (TYPED_ARRAY_TAGS[tag]) {
|
|
449
|
+
return areTypedArraysEqual(a, b, state);
|
|
450
|
+
}
|
|
451
|
+
if (tag === ARRAY_BUFFER_TAG) {
|
|
452
|
+
return areArrayBuffersEqual(a, b, state);
|
|
453
|
+
}
|
|
454
|
+
if (tag === DATA_VIEW_TAG) {
|
|
455
|
+
return areDataViewsEqual(a, b, state);
|
|
456
|
+
}
|
|
439
457
|
// As the penultimate fallback, check if the values passed are primitive wrappers. This
|
|
440
458
|
// is very rare in modern JS, which is why it is deprioritized compared to all other object
|
|
441
459
|
// types.
|
|
@@ -443,9 +461,9 @@ function createEqualityComparator(_a) {
|
|
|
443
461
|
return arePrimitiveWrappersEqual(a, b, state);
|
|
444
462
|
}
|
|
445
463
|
if (unknownTagComparators) {
|
|
446
|
-
|
|
464
|
+
let unknownTagComparator = unknownTagComparators[tag];
|
|
447
465
|
if (!unknownTagComparator) {
|
|
448
|
-
|
|
466
|
+
const shortTag = getShortTag(a);
|
|
449
467
|
if (shortTag) {
|
|
450
468
|
unknownTagComparator = unknownTagComparators[shortTag];
|
|
451
469
|
}
|
|
@@ -473,46 +491,39 @@ function createEqualityComparator(_a) {
|
|
|
473
491
|
/**
|
|
474
492
|
* Create the configuration object used for building comparators.
|
|
475
493
|
*/
|
|
476
|
-
function createEqualityComparatorConfig(
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
areArraysEqual: strict
|
|
480
|
-
|
|
481
|
-
: areArraysEqual,
|
|
494
|
+
function createEqualityComparatorConfig({ circular, createCustomConfig, strict, }) {
|
|
495
|
+
let config = {
|
|
496
|
+
areArrayBuffersEqual,
|
|
497
|
+
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
498
|
+
areDataViewsEqual,
|
|
482
499
|
areDatesEqual: areDatesEqual,
|
|
483
500
|
areErrorsEqual: areErrorsEqual,
|
|
484
501
|
areFunctionsEqual: areFunctionsEqual,
|
|
485
|
-
areMapsEqual: strict
|
|
486
|
-
? combineComparators(areMapsEqual, areObjectsEqualStrict)
|
|
487
|
-
: areMapsEqual,
|
|
502
|
+
areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
|
|
488
503
|
areNumbersEqual: areNumbersEqual,
|
|
489
|
-
areObjectsEqual: strict
|
|
490
|
-
? areObjectsEqualStrict
|
|
491
|
-
: areObjectsEqual,
|
|
504
|
+
areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
|
|
492
505
|
arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
|
|
493
506
|
areRegExpsEqual: areRegExpsEqual,
|
|
494
|
-
areSetsEqual: strict
|
|
495
|
-
? combineComparators(areSetsEqual, areObjectsEqualStrict)
|
|
496
|
-
: areSetsEqual,
|
|
507
|
+
areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
|
|
497
508
|
areTypedArraysEqual: strict
|
|
498
|
-
? areObjectsEqualStrict
|
|
509
|
+
? combineComparators(areTypedArraysEqual, areObjectsEqualStrict)
|
|
499
510
|
: areTypedArraysEqual,
|
|
500
511
|
areUrlsEqual: areUrlsEqual,
|
|
501
512
|
unknownTagComparators: undefined,
|
|
502
513
|
};
|
|
503
514
|
if (createCustomConfig) {
|
|
504
|
-
config = assign({}, config, createCustomConfig(config));
|
|
515
|
+
config = Object.assign({}, config, createCustomConfig(config));
|
|
505
516
|
}
|
|
506
517
|
if (circular) {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
config = assign({}, config, {
|
|
512
|
-
areArraysEqual
|
|
513
|
-
areMapsEqual
|
|
514
|
-
areObjectsEqual
|
|
515
|
-
areSetsEqual
|
|
518
|
+
const areArraysEqual = createIsCircular(config.areArraysEqual);
|
|
519
|
+
const areMapsEqual = createIsCircular(config.areMapsEqual);
|
|
520
|
+
const areObjectsEqual = createIsCircular(config.areObjectsEqual);
|
|
521
|
+
const areSetsEqual = createIsCircular(config.areSetsEqual);
|
|
522
|
+
config = Object.assign({}, config, {
|
|
523
|
+
areArraysEqual,
|
|
524
|
+
areMapsEqual,
|
|
525
|
+
areObjectsEqual,
|
|
526
|
+
areSetsEqual,
|
|
516
527
|
});
|
|
517
528
|
}
|
|
518
529
|
return config;
|
|
@@ -529,16 +540,15 @@ function createInternalEqualityComparator(compare) {
|
|
|
529
540
|
/**
|
|
530
541
|
* Create the `isEqual` function used by the consuming application.
|
|
531
542
|
*/
|
|
532
|
-
function createIsEqual(
|
|
533
|
-
var circular = _a.circular, comparator = _a.comparator, createState = _a.createState, equals = _a.equals, strict = _a.strict;
|
|
543
|
+
function createIsEqual({ circular, comparator, createState, equals, strict }) {
|
|
534
544
|
if (createState) {
|
|
535
545
|
return function isEqual(a, b) {
|
|
536
|
-
|
|
546
|
+
const { cache = circular ? new WeakMap() : undefined, meta } = createState();
|
|
537
547
|
return comparator(a, b, {
|
|
538
|
-
cache
|
|
539
|
-
equals
|
|
540
|
-
meta
|
|
541
|
-
strict
|
|
548
|
+
cache,
|
|
549
|
+
equals,
|
|
550
|
+
meta,
|
|
551
|
+
strict,
|
|
542
552
|
});
|
|
543
553
|
};
|
|
544
554
|
}
|
|
@@ -546,17 +556,17 @@ function createIsEqual(_a) {
|
|
|
546
556
|
return function isEqual(a, b) {
|
|
547
557
|
return comparator(a, b, {
|
|
548
558
|
cache: new WeakMap(),
|
|
549
|
-
equals
|
|
559
|
+
equals,
|
|
550
560
|
meta: undefined,
|
|
551
|
-
strict
|
|
561
|
+
strict,
|
|
552
562
|
});
|
|
553
563
|
};
|
|
554
564
|
}
|
|
555
|
-
|
|
565
|
+
const state = {
|
|
556
566
|
cache: undefined,
|
|
557
|
-
equals
|
|
567
|
+
equals,
|
|
558
568
|
meta: undefined,
|
|
559
|
-
strict
|
|
569
|
+
strict,
|
|
560
570
|
};
|
|
561
571
|
return function isEqual(a, b) {
|
|
562
572
|
return comparator(a, b, state);
|
|
@@ -566,50 +576,50 @@ function createIsEqual(_a) {
|
|
|
566
576
|
/**
|
|
567
577
|
* Whether the items passed are deeply-equal in value.
|
|
568
578
|
*/
|
|
569
|
-
|
|
579
|
+
const deepEqual = createCustomEqual();
|
|
570
580
|
/**
|
|
571
581
|
* Whether the items passed are deeply-equal in value based on strict comparison.
|
|
572
582
|
*/
|
|
573
|
-
|
|
583
|
+
const strictDeepEqual = createCustomEqual({ strict: true });
|
|
574
584
|
/**
|
|
575
585
|
* Whether the items passed are deeply-equal in value, including circular references.
|
|
576
586
|
*/
|
|
577
|
-
|
|
587
|
+
const circularDeepEqual = createCustomEqual({ circular: true });
|
|
578
588
|
/**
|
|
579
589
|
* Whether the items passed are deeply-equal in value, including circular references,
|
|
580
590
|
* based on strict comparison.
|
|
581
591
|
*/
|
|
582
|
-
|
|
592
|
+
const strictCircularDeepEqual = createCustomEqual({
|
|
583
593
|
circular: true,
|
|
584
594
|
strict: true,
|
|
585
595
|
});
|
|
586
596
|
/**
|
|
587
597
|
* Whether the items passed are shallowly-equal in value.
|
|
588
598
|
*/
|
|
589
|
-
|
|
590
|
-
createInternalComparator:
|
|
599
|
+
const shallowEqual = createCustomEqual({
|
|
600
|
+
createInternalComparator: () => sameValueZeroEqual,
|
|
591
601
|
});
|
|
592
602
|
/**
|
|
593
603
|
* Whether the items passed are shallowly-equal in value based on strict comparison
|
|
594
604
|
*/
|
|
595
|
-
|
|
605
|
+
const strictShallowEqual = createCustomEqual({
|
|
596
606
|
strict: true,
|
|
597
|
-
createInternalComparator:
|
|
607
|
+
createInternalComparator: () => sameValueZeroEqual,
|
|
598
608
|
});
|
|
599
609
|
/**
|
|
600
610
|
* Whether the items passed are shallowly-equal in value, including circular references.
|
|
601
611
|
*/
|
|
602
|
-
|
|
612
|
+
const circularShallowEqual = createCustomEqual({
|
|
603
613
|
circular: true,
|
|
604
|
-
createInternalComparator:
|
|
614
|
+
createInternalComparator: () => sameValueZeroEqual,
|
|
605
615
|
});
|
|
606
616
|
/**
|
|
607
617
|
* Whether the items passed are shallowly-equal in value, including circular references,
|
|
608
618
|
* based on strict comparison.
|
|
609
619
|
*/
|
|
610
|
-
|
|
620
|
+
const strictCircularShallowEqual = createCustomEqual({
|
|
611
621
|
circular: true,
|
|
612
|
-
createInternalComparator:
|
|
622
|
+
createInternalComparator: () => sameValueZeroEqual,
|
|
613
623
|
strict: true,
|
|
614
624
|
});
|
|
615
625
|
/**
|
|
@@ -620,15 +630,14 @@ var strictCircularShallowEqual = createCustomEqual({
|
|
|
620
630
|
* support for legacy environments that do not support expected features like
|
|
621
631
|
* `RegExp.prototype.flags` out of the box.
|
|
622
632
|
*/
|
|
623
|
-
function createCustomEqual(options) {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
var equals = createCustomInternalComparator
|
|
633
|
+
function createCustomEqual(options = {}) {
|
|
634
|
+
const { circular = false, createInternalComparator: createCustomInternalComparator, createState, strict = false, } = options;
|
|
635
|
+
const config = createEqualityComparatorConfig(options);
|
|
636
|
+
const comparator = createEqualityComparator(config);
|
|
637
|
+
const equals = createCustomInternalComparator
|
|
629
638
|
? createCustomInternalComparator(comparator)
|
|
630
639
|
: createInternalEqualityComparator(comparator);
|
|
631
|
-
return createIsEqual({ circular
|
|
640
|
+
return createIsEqual({ circular, comparator, createState, equals, strict });
|
|
632
641
|
}
|
|
633
642
|
|
|
634
643
|
exports.circularDeepEqual = circularDeepEqual;
|