fast-equals 5.3.4 → 6.0.0-beta.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/README.md +32 -32
- package/dist/cjs/comparator.d.cts +2 -0
- package/dist/cjs/equals.d.cts +8 -0
- package/dist/cjs/index.cjs +51 -20
- package/dist/cjs/internalTypes.d.cts +11 -7
- package/dist/es/comparator.d.mts +2 -0
- package/dist/es/equals.d.mts +8 -0
- package/dist/es/index.mjs +51 -20
- package/dist/es/internalTypes.d.mts +11 -7
- package/index.d.ts +11 -7
- package/package.json +4 -10
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/es/index.mjs.map +0 -1
- package/dist/umd/comparator.d.ts +0 -26
- package/dist/umd/equals.d.ts +0 -54
- package/dist/umd/index.d.ts +0 -47
- package/dist/umd/index.js +0 -627
- package/dist/umd/index.js.map +0 -1
- package/dist/umd/internalTypes.d.ts +0 -157
- package/dist/umd/utils.d.ts +0 -28
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ The following types are handled out-of-the-box:
|
|
|
12
12
|
|
|
13
13
|
- Plain objects (including `react` elements and `Arguments`)
|
|
14
14
|
- Arrays
|
|
15
|
-
-
|
|
15
|
+
- `ArrayBuffer` / `TypedArray` / `DataView` instances
|
|
16
16
|
- `Date` objects
|
|
17
17
|
- `RegExp` objects
|
|
18
18
|
- `Map` / `Set` iterables
|
|
@@ -369,70 +369,70 @@ Testing mixed objects equal...
|
|
|
369
369
|
┌────────────────────────────────────────┬────────────────┐
|
|
370
370
|
│ Name │ Ops / sec │
|
|
371
371
|
├────────────────────────────────────────┼────────────────┤
|
|
372
|
-
│ fast-equals (passed) │
|
|
372
|
+
│ fast-equals (passed) │ 1416193.769468 │
|
|
373
373
|
├────────────────────────────────────────┼────────────────┤
|
|
374
|
-
│ fast-deep-equal (passed) │
|
|
374
|
+
│ fast-deep-equal (passed) │ 1284824.583215 │
|
|
375
375
|
├────────────────────────────────────────┼────────────────┤
|
|
376
|
-
│ react-fast-compare (passed) │
|
|
376
|
+
│ react-fast-compare (passed) │ 1246947.505444 │
|
|
377
377
|
├────────────────────────────────────────┼────────────────┤
|
|
378
|
-
│ shallow-equal-fuzzy (passed) │
|
|
378
|
+
│ shallow-equal-fuzzy (passed) │ 1238082.379207 │
|
|
379
379
|
├────────────────────────────────────────┼────────────────┤
|
|
380
|
-
│ nano-equal (failed) │
|
|
380
|
+
│ nano-equal (failed) │ 946782.33704 │
|
|
381
381
|
├────────────────────────────────────────┼────────────────┤
|
|
382
|
-
│ dequal/lite (passed) │
|
|
382
|
+
│ dequal/lite (passed) │ 758213.632866 │
|
|
383
383
|
├────────────────────────────────────────┼────────────────┤
|
|
384
|
-
│ dequal (passed) │
|
|
384
|
+
│ dequal (passed) │ 756789.655029 │
|
|
385
385
|
├────────────────────────────────────────┼────────────────┤
|
|
386
|
-
│ fast-equals (circular) (passed) │
|
|
386
|
+
│ fast-equals (circular) (passed) │ 726093.253185 │
|
|
387
387
|
├────────────────────────────────────────┼────────────────┤
|
|
388
|
-
│ underscore.isEqual (passed) │
|
|
388
|
+
│ underscore.isEqual (passed) │ 489748.701783 │
|
|
389
389
|
├────────────────────────────────────────┼────────────────┤
|
|
390
|
-
│ assert.deepStrictEqual (passed) │
|
|
390
|
+
│ assert.deepStrictEqual (passed) │ 453761.890107 │
|
|
391
391
|
├────────────────────────────────────────┼────────────────┤
|
|
392
|
-
│ lodash.isEqual (passed) │
|
|
392
|
+
│ lodash.isEqual (passed) │ 288264.867811 │
|
|
393
393
|
├────────────────────────────────────────┼────────────────┤
|
|
394
|
-
│ fast-equals (strict) (passed) │
|
|
394
|
+
│ fast-equals (strict) (passed) │ 217221.619705 │
|
|
395
395
|
├────────────────────────────────────────┼────────────────┤
|
|
396
|
-
│ fast-equals (strict circular) (passed) │
|
|
396
|
+
│ fast-equals (strict circular) (passed) │ 186916.942934 │
|
|
397
397
|
├────────────────────────────────────────┼────────────────┤
|
|
398
|
-
│ deep-eql (passed) │
|
|
398
|
+
│ deep-eql (passed) │ 162487.877883 │
|
|
399
399
|
├────────────────────────────────────────┼────────────────┤
|
|
400
|
-
│ deep-equal (passed) │
|
|
401
|
-
|
|
400
|
+
│ deep-equal (passed) │ 916.680714 │
|
|
401
|
+
└────────────────────────────────────────┴────────────────┘
|
|
402
402
|
|
|
403
403
|
Testing mixed objects not equal...
|
|
404
404
|
┌────────────────────────────────────────┬────────────────┐
|
|
405
405
|
│ Name │ Ops / sec │
|
|
406
406
|
├────────────────────────────────────────┼────────────────┤
|
|
407
|
-
│ fast-equals (passed) │
|
|
407
|
+
│ fast-equals (passed) │ 4687012.640614 │
|
|
408
408
|
├────────────────────────────────────────┼────────────────┤
|
|
409
|
-
│ fast-deep-equal (passed) │
|
|
409
|
+
│ fast-deep-equal (passed) │ 3418170.156109 │
|
|
410
410
|
├────────────────────────────────────────┼────────────────┤
|
|
411
|
-
│ react-fast-compare (passed) │
|
|
411
|
+
│ react-fast-compare (passed) │ 3283516.669966 │
|
|
412
412
|
├────────────────────────────────────────┼────────────────┤
|
|
413
|
-
│ fast-equals (circular) (passed) │
|
|
413
|
+
│ fast-equals (circular) (passed) │ 3268062.099602 │
|
|
414
414
|
├────────────────────────────────────────┼────────────────┤
|
|
415
|
-
│ fast-equals (strict) (passed) │
|
|
415
|
+
│ fast-equals (strict) (passed) │ 1747578.66456 │
|
|
416
416
|
├────────────────────────────────────────┼────────────────┤
|
|
417
|
-
│ fast-equals (strict circular) (passed) │
|
|
417
|
+
│ fast-equals (strict circular) (passed) │ 1477873.624956 │
|
|
418
418
|
├────────────────────────────────────────┼────────────────┤
|
|
419
|
-
│ dequal/lite (passed) │
|
|
419
|
+
│ dequal/lite (passed) │ 1335397.839502 │
|
|
420
420
|
├────────────────────────────────────────┼────────────────┤
|
|
421
|
-
│ dequal (passed) │
|
|
421
|
+
│ dequal (passed) │ 1319426.71146 │
|
|
422
422
|
├────────────────────────────────────────┼────────────────┤
|
|
423
|
-
│ shallow-equal-fuzzy (failed) │
|
|
423
|
+
│ shallow-equal-fuzzy (failed) │ 1237432.986615 │
|
|
424
424
|
├────────────────────────────────────────┼────────────────┤
|
|
425
|
-
│ nano-equal (passed) │
|
|
425
|
+
│ nano-equal (passed) │ 1064383.319776 │
|
|
426
426
|
├────────────────────────────────────────┼────────────────┤
|
|
427
|
-
│ underscore.isEqual (passed) │
|
|
427
|
+
│ underscore.isEqual (passed) │ 920462.516736 │
|
|
428
428
|
├────────────────────────────────────────┼────────────────┤
|
|
429
|
-
│ lodash.isEqual (passed) │
|
|
429
|
+
│ lodash.isEqual (passed) │ 379370.998021 │
|
|
430
430
|
├────────────────────────────────────────┼────────────────┤
|
|
431
|
-
│ deep-eql (passed) │
|
|
431
|
+
│ deep-eql (passed) │ 184111.383127 │
|
|
432
432
|
├────────────────────────────────────────┼────────────────┤
|
|
433
|
-
│ assert.deepStrictEqual (passed) │
|
|
433
|
+
│ assert.deepStrictEqual (passed) │ 20775.59065 │
|
|
434
434
|
├────────────────────────────────────────┼────────────────┤
|
|
435
|
-
│ deep-equal (passed) │
|
|
435
|
+
│ deep-equal (passed) │ 3678.51009 │
|
|
436
436
|
└────────────────────────────────────────┴────────────────┘
|
|
437
437
|
```
|
|
438
438
|
|
|
@@ -16,7 +16,9 @@ interface CreateIsEqualOptions<Meta> {
|
|
|
16
16
|
* Create a comparator method based on the type-specific equality comparators passed.
|
|
17
17
|
*/
|
|
18
18
|
export declare function createEqualityComparator<Meta>({
|
|
19
|
+
areArrayBuffersEqual,
|
|
19
20
|
areArraysEqual,
|
|
21
|
+
areDataViewsEqual,
|
|
20
22
|
areDatesEqual,
|
|
21
23
|
areErrorsEqual,
|
|
22
24
|
areFunctionsEqual,
|
package/dist/cjs/equals.d.cts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { Dictionary, PrimitiveWrapper, State, TypedArray } from './internalTypes.d.cts';
|
|
2
2
|
import type { sameValueZeroEqual } from './utils.d.cts';
|
|
3
|
+
/**
|
|
4
|
+
* Whether the array buffers are equal in value.
|
|
5
|
+
*/
|
|
6
|
+
export declare function areArrayBuffersEqual(a: ArrayBuffer, b: ArrayBuffer): boolean;
|
|
3
7
|
/**
|
|
4
8
|
* Whether the arrays are equal in value.
|
|
5
9
|
*/
|
|
6
10
|
export declare function areArraysEqual(a: any[], b: any[], state: State<any>): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the dataviews are equal in value.
|
|
13
|
+
*/
|
|
14
|
+
export declare function areDataViewsEqual(a: DataView, b: DataView): boolean;
|
|
7
15
|
/**
|
|
8
16
|
* Whether the dates passed are equal in value.
|
|
9
17
|
*/
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -65,6 +65,12 @@ const PREACT_VNODE = '__v';
|
|
|
65
65
|
const PREACT_OWNER = '__o';
|
|
66
66
|
const REACT_OWNER = '_owner';
|
|
67
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
|
+
}
|
|
68
74
|
/**
|
|
69
75
|
* Whether the arrays are equal in value.
|
|
70
76
|
*/
|
|
@@ -80,6 +86,13 @@ function areArraysEqual(a, b, state) {
|
|
|
80
86
|
}
|
|
81
87
|
return true;
|
|
82
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
|
+
}
|
|
83
96
|
/**
|
|
84
97
|
* Whether the dates passed are equal in value.
|
|
85
98
|
*/
|
|
@@ -262,8 +275,8 @@ function areSetsEqual(a, b, state) {
|
|
|
262
275
|
* Whether the TypedArray instances are equal in value.
|
|
263
276
|
*/
|
|
264
277
|
function areTypedArraysEqual(a, b) {
|
|
265
|
-
let index = a.
|
|
266
|
-
if (b.
|
|
278
|
+
let index = a.byteLength;
|
|
279
|
+
if (b.byteLength !== index || a.byteOffset !== b.byteOffset) {
|
|
267
280
|
return false;
|
|
268
281
|
}
|
|
269
282
|
while (index-- > 0) {
|
|
@@ -293,8 +306,10 @@ function isPropertyEqual(a, b, state, property) {
|
|
|
293
306
|
return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
|
|
294
307
|
}
|
|
295
308
|
|
|
309
|
+
const ARRAY_BUFFER_TAG = '[object ArrayBuffer]';
|
|
296
310
|
const ARGUMENTS_TAG = '[object Arguments]';
|
|
297
311
|
const BOOLEAN_TAG = '[object Boolean]';
|
|
312
|
+
const DATA_VIEW_TAG = '[object DataView]';
|
|
298
313
|
const DATE_TAG = '[object Date]';
|
|
299
314
|
const ERROR_TAG = '[object Error]';
|
|
300
315
|
const MAP_TAG = '[object Map]';
|
|
@@ -303,18 +318,27 @@ const OBJECT_TAG = '[object Object]';
|
|
|
303
318
|
const REG_EXP_TAG = '[object RegExp]';
|
|
304
319
|
const SET_TAG = '[object Set]';
|
|
305
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
|
+
};
|
|
306
335
|
const URL_TAG = '[object URL]';
|
|
307
|
-
const { isArray } = Array;
|
|
308
|
-
const isTypedArray =
|
|
309
336
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
310
|
-
|
|
311
|
-
const { assign } = Object;
|
|
312
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
313
|
-
const getTag = Object.prototype.toString.call.bind(Object.prototype.toString);
|
|
337
|
+
const toString = Object.prototype.toString;
|
|
314
338
|
/**
|
|
315
339
|
* Create a comparator method based on the type-specific equality comparators passed.
|
|
316
340
|
*/
|
|
317
|
-
function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, unknownTagComparators, }) {
|
|
341
|
+
function createEqualityComparator({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, unknownTagComparators, }) {
|
|
318
342
|
/**
|
|
319
343
|
* compare the value of the two objects and return true if they are equivalent in values
|
|
320
344
|
*/
|
|
@@ -364,14 +388,9 @@ function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqua
|
|
|
364
388
|
}
|
|
365
389
|
// `isArray()` works on subclasses and is cross-realm, so we can avoid capturing
|
|
366
390
|
// the string tag or doing an `instanceof` check.
|
|
367
|
-
if (isArray(a)) {
|
|
391
|
+
if (Array.isArray(a)) {
|
|
368
392
|
return areArraysEqual(a, b, state);
|
|
369
393
|
}
|
|
370
|
-
// `isTypedArray()` works on all possible TypedArray classes, so we can avoid
|
|
371
|
-
// capturing the string tag or comparing against all possible constructors.
|
|
372
|
-
if (isTypedArray != null && isTypedArray(a)) {
|
|
373
|
-
return areTypedArraysEqual(a, b, state);
|
|
374
|
-
}
|
|
375
394
|
// Try to fast-path equality checks for other complex object types in the
|
|
376
395
|
// same realm to avoid capturing the string tag. Strict equality is used
|
|
377
396
|
// instead of `instanceof` because it is more performant for the common
|
|
@@ -391,7 +410,7 @@ function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqua
|
|
|
391
410
|
}
|
|
392
411
|
// Since this is a custom object, capture the string tag to determing its type.
|
|
393
412
|
// This is reasonably performant in modern environments like v8 and SpiderMonkey.
|
|
394
|
-
const tag =
|
|
413
|
+
const tag = toString.call(a);
|
|
395
414
|
if (tag === DATE_TAG) {
|
|
396
415
|
return areDatesEqual(a, b, state);
|
|
397
416
|
}
|
|
@@ -426,6 +445,15 @@ function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqua
|
|
|
426
445
|
if (tag === ARGUMENTS_TAG) {
|
|
427
446
|
return areObjectsEqual(a, b, state);
|
|
428
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
|
+
}
|
|
429
457
|
// As the penultimate fallback, check if the values passed are primitive wrappers. This
|
|
430
458
|
// is very rare in modern JS, which is why it is deprioritized compared to all other object
|
|
431
459
|
// types.
|
|
@@ -465,7 +493,9 @@ function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqua
|
|
|
465
493
|
*/
|
|
466
494
|
function createEqualityComparatorConfig({ circular, createCustomConfig, strict, }) {
|
|
467
495
|
let config = {
|
|
496
|
+
areArrayBuffersEqual,
|
|
468
497
|
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
498
|
+
areDataViewsEqual,
|
|
469
499
|
areDatesEqual: areDatesEqual,
|
|
470
500
|
areErrorsEqual: areErrorsEqual,
|
|
471
501
|
areFunctionsEqual: areFunctionsEqual,
|
|
@@ -475,19 +505,21 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
475
505
|
arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
|
|
476
506
|
areRegExpsEqual: areRegExpsEqual,
|
|
477
507
|
areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
|
|
478
|
-
areTypedArraysEqual: strict
|
|
508
|
+
areTypedArraysEqual: strict
|
|
509
|
+
? combineComparators(areTypedArraysEqual, areObjectsEqualStrict)
|
|
510
|
+
: areTypedArraysEqual,
|
|
479
511
|
areUrlsEqual: areUrlsEqual,
|
|
480
512
|
unknownTagComparators: undefined,
|
|
481
513
|
};
|
|
482
514
|
if (createCustomConfig) {
|
|
483
|
-
config = assign({}, config, createCustomConfig(config));
|
|
515
|
+
config = Object.assign({}, config, createCustomConfig(config));
|
|
484
516
|
}
|
|
485
517
|
if (circular) {
|
|
486
518
|
const areArraysEqual = createIsCircular(config.areArraysEqual);
|
|
487
519
|
const areMapsEqual = createIsCircular(config.areMapsEqual);
|
|
488
520
|
const areObjectsEqual = createIsCircular(config.areObjectsEqual);
|
|
489
521
|
const areSetsEqual = createIsCircular(config.areSetsEqual);
|
|
490
|
-
config = assign({}, config, {
|
|
522
|
+
config = Object.assign({}, config, {
|
|
491
523
|
areArraysEqual,
|
|
492
524
|
areMapsEqual,
|
|
493
525
|
areObjectsEqual,
|
|
@@ -618,4 +650,3 @@ exports.strictCircularDeepEqual = strictCircularDeepEqual;
|
|
|
618
650
|
exports.strictCircularShallowEqual = strictCircularShallowEqual;
|
|
619
651
|
exports.strictDeepEqual = strictDeepEqual;
|
|
620
652
|
exports.strictShallowEqual = strictShallowEqual;
|
|
621
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -38,11 +38,20 @@ export interface Dictionary<Value = any> {
|
|
|
38
38
|
$$typeof?: any;
|
|
39
39
|
}
|
|
40
40
|
export interface ComparatorConfig<Meta> {
|
|
41
|
+
/**
|
|
42
|
+
* Whether the array buffers passed are equal in value. In strict mode, this includes
|
|
43
|
+
* additional properties added to the array.
|
|
44
|
+
*/
|
|
45
|
+
areArrayBuffersEqual: TypeEqualityComparator<any, Meta>;
|
|
41
46
|
/**
|
|
42
47
|
* Whether the arrays passed are equal in value. In strict mode, this includes
|
|
43
48
|
* additional properties added to the array.
|
|
44
49
|
*/
|
|
45
50
|
areArraysEqual: TypeEqualityComparator<any, Meta>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the data views passed are equal in value.
|
|
53
|
+
*/
|
|
54
|
+
areDataViewsEqual: TypeEqualityComparator<any, Meta>;
|
|
46
55
|
/**
|
|
47
56
|
* Whether the dates passed are equal in value.
|
|
48
57
|
*/
|
|
@@ -120,15 +129,10 @@ export type PrimitiveWrapper = Boolean | Number | String;
|
|
|
120
129
|
/**
|
|
121
130
|
* Type which encompasses possible instances of TypedArray
|
|
122
131
|
* classes.
|
|
123
|
-
*
|
|
124
|
-
* **NOTE**: This does not include `BigInt64Array` and
|
|
125
|
-
* `BitUint64Array` because those are part of ES2020 and
|
|
126
|
-
* not supported by certain TS configurations. If using
|
|
127
|
-
* either in `areTypedArraysEqual`, you can cast the
|
|
128
|
-
* instance as `TypedArray` and it will work as expected,
|
|
129
|
-
* because runtime checks will still work for those classes.
|
|
130
132
|
*/
|
|
131
133
|
export type TypedArray =
|
|
134
|
+
| BigInt64Array
|
|
135
|
+
| BigUint64Array
|
|
132
136
|
| Float32Array
|
|
133
137
|
| Float64Array
|
|
134
138
|
| Int8Array
|
package/dist/es/comparator.d.mts
CHANGED
|
@@ -16,7 +16,9 @@ interface CreateIsEqualOptions<Meta> {
|
|
|
16
16
|
* Create a comparator method based on the type-specific equality comparators passed.
|
|
17
17
|
*/
|
|
18
18
|
export declare function createEqualityComparator<Meta>({
|
|
19
|
+
areArrayBuffersEqual,
|
|
19
20
|
areArraysEqual,
|
|
21
|
+
areDataViewsEqual,
|
|
20
22
|
areDatesEqual,
|
|
21
23
|
areErrorsEqual,
|
|
22
24
|
areFunctionsEqual,
|
package/dist/es/equals.d.mts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { Dictionary, PrimitiveWrapper, State, TypedArray } from './internalTypes.d.mts';
|
|
2
2
|
import type { sameValueZeroEqual } from './utils.d.mts';
|
|
3
|
+
/**
|
|
4
|
+
* Whether the array buffers are equal in value.
|
|
5
|
+
*/
|
|
6
|
+
export declare function areArrayBuffersEqual(a: ArrayBuffer, b: ArrayBuffer): boolean;
|
|
3
7
|
/**
|
|
4
8
|
* Whether the arrays are equal in value.
|
|
5
9
|
*/
|
|
6
10
|
export declare function areArraysEqual(a: any[], b: any[], state: State<any>): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the dataviews are equal in value.
|
|
13
|
+
*/
|
|
14
|
+
export declare function areDataViewsEqual(a: DataView, b: DataView): boolean;
|
|
7
15
|
/**
|
|
8
16
|
* Whether the dates passed are equal in value.
|
|
9
17
|
*/
|
package/dist/es/index.mjs
CHANGED
|
@@ -63,6 +63,12 @@ const PREACT_VNODE = '__v';
|
|
|
63
63
|
const PREACT_OWNER = '__o';
|
|
64
64
|
const REACT_OWNER = '_owner';
|
|
65
65
|
const { getOwnPropertyDescriptor, keys } = Object;
|
|
66
|
+
/**
|
|
67
|
+
* Whether the array buffers are equal in value.
|
|
68
|
+
*/
|
|
69
|
+
function areArrayBuffersEqual(a, b) {
|
|
70
|
+
return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
|
|
71
|
+
}
|
|
66
72
|
/**
|
|
67
73
|
* Whether the arrays are equal in value.
|
|
68
74
|
*/
|
|
@@ -78,6 +84,13 @@ function areArraysEqual(a, b, state) {
|
|
|
78
84
|
}
|
|
79
85
|
return true;
|
|
80
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Whether the dataviews are equal in value.
|
|
89
|
+
*/
|
|
90
|
+
function areDataViewsEqual(a, b) {
|
|
91
|
+
return (a.byteLength === b.byteLength
|
|
92
|
+
&& areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength)));
|
|
93
|
+
}
|
|
81
94
|
/**
|
|
82
95
|
* Whether the dates passed are equal in value.
|
|
83
96
|
*/
|
|
@@ -260,8 +273,8 @@ function areSetsEqual(a, b, state) {
|
|
|
260
273
|
* Whether the TypedArray instances are equal in value.
|
|
261
274
|
*/
|
|
262
275
|
function areTypedArraysEqual(a, b) {
|
|
263
|
-
let index = a.
|
|
264
|
-
if (b.
|
|
276
|
+
let index = a.byteLength;
|
|
277
|
+
if (b.byteLength !== index || a.byteOffset !== b.byteOffset) {
|
|
265
278
|
return false;
|
|
266
279
|
}
|
|
267
280
|
while (index-- > 0) {
|
|
@@ -291,8 +304,10 @@ function isPropertyEqual(a, b, state, property) {
|
|
|
291
304
|
return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
|
|
292
305
|
}
|
|
293
306
|
|
|
307
|
+
const ARRAY_BUFFER_TAG = '[object ArrayBuffer]';
|
|
294
308
|
const ARGUMENTS_TAG = '[object Arguments]';
|
|
295
309
|
const BOOLEAN_TAG = '[object Boolean]';
|
|
310
|
+
const DATA_VIEW_TAG = '[object DataView]';
|
|
296
311
|
const DATE_TAG = '[object Date]';
|
|
297
312
|
const ERROR_TAG = '[object Error]';
|
|
298
313
|
const MAP_TAG = '[object Map]';
|
|
@@ -301,18 +316,27 @@ const OBJECT_TAG = '[object Object]';
|
|
|
301
316
|
const REG_EXP_TAG = '[object RegExp]';
|
|
302
317
|
const SET_TAG = '[object Set]';
|
|
303
318
|
const STRING_TAG = '[object String]';
|
|
319
|
+
const TYPED_ARRAY_TAGS = {
|
|
320
|
+
'[object Int8Array]': true,
|
|
321
|
+
'[object Uint8Array]': true,
|
|
322
|
+
'[object Uint8ClampedArray]': true,
|
|
323
|
+
'[object Int16Array]': true,
|
|
324
|
+
'[object Uint16Array]': true,
|
|
325
|
+
'[object Int32Array]': true,
|
|
326
|
+
'[object Uint32Array]': true,
|
|
327
|
+
'[object Float16Array]': true,
|
|
328
|
+
'[object Float32Array]': true,
|
|
329
|
+
'[object Float64Array]': true,
|
|
330
|
+
'[object BigInt64Array]': true,
|
|
331
|
+
'[object BigUint64Array]': true,
|
|
332
|
+
};
|
|
304
333
|
const URL_TAG = '[object URL]';
|
|
305
|
-
const { isArray } = Array;
|
|
306
|
-
const isTypedArray =
|
|
307
334
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
308
|
-
|
|
309
|
-
const { assign } = Object;
|
|
310
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
311
|
-
const getTag = Object.prototype.toString.call.bind(Object.prototype.toString);
|
|
335
|
+
const toString = Object.prototype.toString;
|
|
312
336
|
/**
|
|
313
337
|
* Create a comparator method based on the type-specific equality comparators passed.
|
|
314
338
|
*/
|
|
315
|
-
function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, unknownTagComparators, }) {
|
|
339
|
+
function createEqualityComparator({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, unknownTagComparators, }) {
|
|
316
340
|
/**
|
|
317
341
|
* compare the value of the two objects and return true if they are equivalent in values
|
|
318
342
|
*/
|
|
@@ -362,14 +386,9 @@ function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqua
|
|
|
362
386
|
}
|
|
363
387
|
// `isArray()` works on subclasses and is cross-realm, so we can avoid capturing
|
|
364
388
|
// the string tag or doing an `instanceof` check.
|
|
365
|
-
if (isArray(a)) {
|
|
389
|
+
if (Array.isArray(a)) {
|
|
366
390
|
return areArraysEqual(a, b, state);
|
|
367
391
|
}
|
|
368
|
-
// `isTypedArray()` works on all possible TypedArray classes, so we can avoid
|
|
369
|
-
// capturing the string tag or comparing against all possible constructors.
|
|
370
|
-
if (isTypedArray != null && isTypedArray(a)) {
|
|
371
|
-
return areTypedArraysEqual(a, b, state);
|
|
372
|
-
}
|
|
373
392
|
// Try to fast-path equality checks for other complex object types in the
|
|
374
393
|
// same realm to avoid capturing the string tag. Strict equality is used
|
|
375
394
|
// instead of `instanceof` because it is more performant for the common
|
|
@@ -389,7 +408,7 @@ function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqua
|
|
|
389
408
|
}
|
|
390
409
|
// Since this is a custom object, capture the string tag to determing its type.
|
|
391
410
|
// This is reasonably performant in modern environments like v8 and SpiderMonkey.
|
|
392
|
-
const tag =
|
|
411
|
+
const tag = toString.call(a);
|
|
393
412
|
if (tag === DATE_TAG) {
|
|
394
413
|
return areDatesEqual(a, b, state);
|
|
395
414
|
}
|
|
@@ -424,6 +443,15 @@ function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqua
|
|
|
424
443
|
if (tag === ARGUMENTS_TAG) {
|
|
425
444
|
return areObjectsEqual(a, b, state);
|
|
426
445
|
}
|
|
446
|
+
if (TYPED_ARRAY_TAGS[tag]) {
|
|
447
|
+
return areTypedArraysEqual(a, b, state);
|
|
448
|
+
}
|
|
449
|
+
if (tag === ARRAY_BUFFER_TAG) {
|
|
450
|
+
return areArrayBuffersEqual(a, b, state);
|
|
451
|
+
}
|
|
452
|
+
if (tag === DATA_VIEW_TAG) {
|
|
453
|
+
return areDataViewsEqual(a, b, state);
|
|
454
|
+
}
|
|
427
455
|
// As the penultimate fallback, check if the values passed are primitive wrappers. This
|
|
428
456
|
// is very rare in modern JS, which is why it is deprioritized compared to all other object
|
|
429
457
|
// types.
|
|
@@ -463,7 +491,9 @@ function createEqualityComparator({ areArraysEqual, areDatesEqual, areErrorsEqua
|
|
|
463
491
|
*/
|
|
464
492
|
function createEqualityComparatorConfig({ circular, createCustomConfig, strict, }) {
|
|
465
493
|
let config = {
|
|
494
|
+
areArrayBuffersEqual,
|
|
466
495
|
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
496
|
+
areDataViewsEqual,
|
|
467
497
|
areDatesEqual: areDatesEqual,
|
|
468
498
|
areErrorsEqual: areErrorsEqual,
|
|
469
499
|
areFunctionsEqual: areFunctionsEqual,
|
|
@@ -473,19 +503,21 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
473
503
|
arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
|
|
474
504
|
areRegExpsEqual: areRegExpsEqual,
|
|
475
505
|
areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
|
|
476
|
-
areTypedArraysEqual: strict
|
|
506
|
+
areTypedArraysEqual: strict
|
|
507
|
+
? combineComparators(areTypedArraysEqual, areObjectsEqualStrict)
|
|
508
|
+
: areTypedArraysEqual,
|
|
477
509
|
areUrlsEqual: areUrlsEqual,
|
|
478
510
|
unknownTagComparators: undefined,
|
|
479
511
|
};
|
|
480
512
|
if (createCustomConfig) {
|
|
481
|
-
config = assign({}, config, createCustomConfig(config));
|
|
513
|
+
config = Object.assign({}, config, createCustomConfig(config));
|
|
482
514
|
}
|
|
483
515
|
if (circular) {
|
|
484
516
|
const areArraysEqual = createIsCircular(config.areArraysEqual);
|
|
485
517
|
const areMapsEqual = createIsCircular(config.areMapsEqual);
|
|
486
518
|
const areObjectsEqual = createIsCircular(config.areObjectsEqual);
|
|
487
519
|
const areSetsEqual = createIsCircular(config.areSetsEqual);
|
|
488
|
-
config = assign({}, config, {
|
|
520
|
+
config = Object.assign({}, config, {
|
|
489
521
|
areArraysEqual,
|
|
490
522
|
areMapsEqual,
|
|
491
523
|
areObjectsEqual,
|
|
@@ -607,4 +639,3 @@ function createCustomEqual(options = {}) {
|
|
|
607
639
|
}
|
|
608
640
|
|
|
609
641
|
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictShallowEqual };
|
|
610
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -38,11 +38,20 @@ export interface Dictionary<Value = any> {
|
|
|
38
38
|
$$typeof?: any;
|
|
39
39
|
}
|
|
40
40
|
export interface ComparatorConfig<Meta> {
|
|
41
|
+
/**
|
|
42
|
+
* Whether the array buffers passed are equal in value. In strict mode, this includes
|
|
43
|
+
* additional properties added to the array.
|
|
44
|
+
*/
|
|
45
|
+
areArrayBuffersEqual: TypeEqualityComparator<any, Meta>;
|
|
41
46
|
/**
|
|
42
47
|
* Whether the arrays passed are equal in value. In strict mode, this includes
|
|
43
48
|
* additional properties added to the array.
|
|
44
49
|
*/
|
|
45
50
|
areArraysEqual: TypeEqualityComparator<any, Meta>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the data views passed are equal in value.
|
|
53
|
+
*/
|
|
54
|
+
areDataViewsEqual: TypeEqualityComparator<any, Meta>;
|
|
46
55
|
/**
|
|
47
56
|
* Whether the dates passed are equal in value.
|
|
48
57
|
*/
|
|
@@ -120,15 +129,10 @@ export type PrimitiveWrapper = Boolean | Number | String;
|
|
|
120
129
|
/**
|
|
121
130
|
* Type which encompasses possible instances of TypedArray
|
|
122
131
|
* classes.
|
|
123
|
-
*
|
|
124
|
-
* **NOTE**: This does not include `BigInt64Array` and
|
|
125
|
-
* `BitUint64Array` because those are part of ES2020 and
|
|
126
|
-
* not supported by certain TS configurations. If using
|
|
127
|
-
* either in `areTypedArraysEqual`, you can cast the
|
|
128
|
-
* instance as `TypedArray` and it will work as expected,
|
|
129
|
-
* because runtime checks will still work for those classes.
|
|
130
132
|
*/
|
|
131
133
|
export type TypedArray =
|
|
134
|
+
| BigInt64Array
|
|
135
|
+
| BigUint64Array
|
|
132
136
|
| Float32Array
|
|
133
137
|
| Float64Array
|
|
134
138
|
| Int8Array
|
package/index.d.ts
CHANGED
|
@@ -38,11 +38,20 @@ interface Dictionary<Value = any> {
|
|
|
38
38
|
$$typeof?: any;
|
|
39
39
|
}
|
|
40
40
|
interface ComparatorConfig<Meta> {
|
|
41
|
+
/**
|
|
42
|
+
* Whether the array buffers passed are equal in value. In strict mode, this includes
|
|
43
|
+
* additional properties added to the array.
|
|
44
|
+
*/
|
|
45
|
+
areArrayBuffersEqual: TypeEqualityComparator<any, Meta>;
|
|
41
46
|
/**
|
|
42
47
|
* Whether the arrays passed are equal in value. In strict mode, this includes
|
|
43
48
|
* additional properties added to the array.
|
|
44
49
|
*/
|
|
45
50
|
areArraysEqual: TypeEqualityComparator<any, Meta>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the data views passed are equal in value.
|
|
53
|
+
*/
|
|
54
|
+
areDataViewsEqual: TypeEqualityComparator<any, Meta>;
|
|
46
55
|
/**
|
|
47
56
|
* Whether the dates passed are equal in value.
|
|
48
57
|
*/
|
|
@@ -120,15 +129,10 @@ type PrimitiveWrapper = Boolean | Number | String;
|
|
|
120
129
|
/**
|
|
121
130
|
* Type which encompasses possible instances of TypedArray
|
|
122
131
|
* classes.
|
|
123
|
-
*
|
|
124
|
-
* **NOTE**: This does not include `BigInt64Array` and
|
|
125
|
-
* `BitUint64Array` because those are part of ES2020 and
|
|
126
|
-
* not supported by certain TS configurations. If using
|
|
127
|
-
* either in `areTypedArraysEqual`, you can cast the
|
|
128
|
-
* instance as `TypedArray` and it will work as expected,
|
|
129
|
-
* because runtime checks will still work for those classes.
|
|
130
132
|
*/
|
|
131
133
|
type TypedArray =
|
|
134
|
+
| BigInt64Array
|
|
135
|
+
| BigUint64Array
|
|
132
136
|
| Float32Array
|
|
133
137
|
| Float64Array
|
|
134
138
|
| Int8Array
|