fast-equals 6.3.0 → 6.4.1

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 CHANGED
@@ -13,7 +13,7 @@ The following types are handled out-of-the-box:
13
13
  - `Map` / `Set` iterables
14
14
  - `Promise` objects and then-ables
15
15
  - `Error` objects, including subclasses and their own properties
16
- - `URL` objects
16
+ - `URL` / `URLSearchParams` objects
17
17
  - Primitive wrappers (`new Boolean()` / `new Number()` / `new String()`, and boxed `BigInt`)
18
18
  - Custom class instances, including subclasses of native classes
19
19
 
@@ -235,8 +235,8 @@ Performs the same comparison as `deepEqual` but performs a strict comparison of
235
235
  - Checking full descriptor of properties on the object to match
236
236
  - Checking non-index properties on arrays
237
237
  - Checking non-key properties on `Map` / `Set` objects
238
- - Checking own properties on objects that hold their value internally (`Date`, `RegExp`, `URL`, primitive wrappers,
239
- `ArrayBuffer`, `DataView` and `TypedArray` objects), including `lastIndex` on `RegExp` objects
238
+ - Checking own properties on objects that hold their value internally (`Date`, `RegExp`, `URL`, `URLSearchParams`,
239
+ primitive wrappers, `ArrayBuffer`, `DataView` and `TypedArray` objects), including `lastIndex` on `RegExp` objects
240
240
 
241
241
  ```ts
242
242
  const array = [{ foo: 'bar' }];
@@ -267,8 +267,8 @@ Performs the same comparison as `shallowEqual` but performs a strict comparison
267
267
  - Checking full descriptor of properties on the object to match
268
268
  - Checking non-index properties on arrays
269
269
  - Checking non-key properties on `Map` / `Set` objects
270
- - Checking own properties on objects that hold their value internally (`Date`, `RegExp`, `URL`, primitive wrappers,
271
- `ArrayBuffer`, `DataView` and `TypedArray` objects), including `lastIndex` on `RegExp` objects
270
+ - Checking own properties on objects that hold their value internally (`Date`, `RegExp`, `URL`, `URLSearchParams`,
271
+ primitive wrappers, `ArrayBuffer`, `DataView` and `TypedArray` objects), including `lastIndex` on `RegExp` objects
272
272
 
273
273
  ```ts
274
274
  const array = ['foo'];
@@ -290,8 +290,8 @@ Performs the same comparison as `circularDeepEqual` but performs a strict compar
290
290
  - Checking full descriptor of properties on the object to match
291
291
  - Checking non-index properties on arrays
292
292
  - Checking non-key properties on `Map` / `Set` objects
293
- - Checking own properties on objects that hold their value internally (`Date`, `RegExp`, `URL`, primitive wrappers,
294
- `ArrayBuffer`, `DataView` and `TypedArray` objects), including `lastIndex` on `RegExp` objects
293
+ - Checking own properties on objects that hold their value internally (`Date`, `RegExp`, `URL`, `URLSearchParams`,
294
+ primitive wrappers, `ArrayBuffer`, `DataView` and `TypedArray` objects), including `lastIndex` on `RegExp` objects
295
295
 
296
296
  ```ts
297
297
  function Circular(value) {
@@ -331,8 +331,8 @@ Performs the same comparison as `circularShallowEqual` but performs a strict com
331
331
  - Checking full descriptor of properties on the object to match
332
332
  - Checking non-index properties on arrays
333
333
  - Checking non-key properties on `Map` / `Set` objects
334
- - Checking own properties on objects that hold their value internally (`Date`, `RegExp`, `URL`, primitive wrappers,
335
- `ArrayBuffer`, `DataView` and `TypedArray` objects), including `lastIndex` on `RegExp` objects
334
+ - Checking own properties on objects that hold their value internally (`Date`, `RegExp`, `URL`, `URLSearchParams`,
335
+ primitive wrappers, `ArrayBuffer`, `DataView` and `TypedArray` objects), including `lastIndex` on `RegExp` objects
336
336
 
337
337
  ```ts
338
338
  const array = ['foo'];
@@ -377,6 +377,7 @@ interface ComparatorConfig<Meta> {
377
377
  areRegExpsEqual: EqualityComparator<Meta>;
378
378
  areSetsEqual: EqualityComparator<Meta>;
379
379
  areTypedArraysEqual: EqualityComparator<Meta>;
380
+ areUrlSearchParamsEqual: EqualityComparator<Meta>;
380
381
  areUrlsEqual: EqualityComparator<Meta>;
381
382
  getUnsupportedCustomComparator:
382
383
  (<Type>(a: Type, b: Type, state: State<Meta>, tag: string) => EqualityComparator<Meta> | undefined) | undefined;
@@ -459,74 +460,74 @@ Testing mixed objects equal...
459
460
  ┌────────────────────────────────────────┬────────────────┐
460
461
  │ Name │ Ops / sec │
461
462
  ├────────────────────────────────────────┼────────────────┤
462
- │ fast-equals (passed) │ 1731598.023836 │
463
+ │ fast-equals (passed) │ 1782450.451369 │
463
464
  ├────────────────────────────────────────┼────────────────┤
464
- │ fast-deep-equal (passed) │ 1309307.899547 │
465
+ │ fast-deep-equal (passed) │ 1318966.05525 │
465
466
  ├────────────────────────────────────────┼────────────────┤
466
- │ react-fast-compare (passed) │ 1292046.683991 │
467
+ │ react-fast-compare (passed) │ 1312506.681929 │
467
468
  ├────────────────────────────────────────┼────────────────┤
468
- │ shallow-equal-fuzzy (passed) │ 1226265.458405 │
469
+ │ shallow-equal-fuzzy (passed) │ 1278565.812104 │
469
470
  ├────────────────────────────────────────┼────────────────┤
470
- │ nano-equal (failed) │ 963157.128972 │
471
+ │ nano-equal (failed) │ 983769.888387 │
471
472
  ├────────────────────────────────────────┼────────────────┤
472
- │ fast-equals (circular) (passed) │ 909479.445346 │
473
+ │ fast-equals (circular) (passed) │ 907118.190745 │
473
474
  ├────────────────────────────────────────┼────────────────┤
474
- │ dequal/lite (passed) │ 778122.31992 │
475
+ │ dequal/lite (passed) │ 783946.658853 │
475
476
  ├────────────────────────────────────────┼────────────────┤
476
- │ dequal (passed) │ 760245.363659 │
477
+ │ dequal (passed) │ 765217.048928 │
477
478
  ├────────────────────────────────────────┼────────────────┤
478
- │ underscore.isEqual (passed) │ 445304.799867 │
479
+ │ underscore.isEqual (passed) │ 461845.668653 │
479
480
  ├────────────────────────────────────────┼────────────────┤
480
- │ assert.deepStrictEqual (passed) │ 438737.156408 │
481
+ │ assert.deepStrictEqual (passed) │ 440373.095029 │
481
482
  ├────────────────────────────────────────┼────────────────┤
482
- │ es-toolkit (passed) │ 382792.590707 │
483
+ │ es-toolkit (passed) │ 391305.456936 │
483
484
  ├────────────────────────────────────────┼────────────────┤
484
- │ lodash.isEqual (passed) │ 290229.549964 │
485
+ │ lodash.isEqual (passed) │ 290278.80479 │
485
486
  ├────────────────────────────────────────┼────────────────┤
486
- │ fast-equals (strict) (passed) │ 279185.538603 │
487
+ │ fast-equals (strict) (passed) │ 290096.328199 │
487
488
  ├────────────────────────────────────────┼────────────────┤
488
- │ fast-equals (strict circular) (passed) │ 238470.634046 │
489
+ │ fast-equals (strict circular) (passed) │ 246541.923525 │
489
490
  ├────────────────────────────────────────┼────────────────┤
490
- │ deep-eql (passed) │ 172670.983717 │
491
+ │ deep-eql (passed) │ 173208.792462 │
491
492
  ├────────────────────────────────────────┼────────────────┤
492
- │ deep-equal (passed) │ 1357.008406 │
493
+ │ deep-equal (passed) │ 1412.586981 │
493
494
  └────────────────────────────────────────┴────────────────┘
494
495
 
495
496
  Testing mixed objects not equal...
496
497
  ┌────────────────────────────────────────┬────────────────┐
497
498
  │ Name │ Ops / sec │
498
499
  ├────────────────────────────────────────┼────────────────┤
499
- │ fast-equals (passed) │ 5076106.125712 │
500
+ │ fast-equals (passed) │ 5488976.412437 │
500
501
  ├────────────────────────────────────────┼────────────────┤
501
- │ fast-equals (circular) (passed) │ 3544911.437592 │
502
+ │ fast-equals (circular) (passed) │ 3668925.717479 │
502
503
  ├────────────────────────────────────────┼────────────────┤
503
- │ fast-deep-equal (passed) │ 3433830.73191 │
504
+ │ fast-deep-equal (passed) │ 3552737.084766 │
504
505
  ├────────────────────────────────────────┼────────────────┤
505
- │ react-fast-compare (passed) │ 3246695.251508 │
506
+ │ react-fast-compare (passed) │ 3441428.035043 │
506
507
  ├────────────────────────────────────────┼────────────────┤
507
- │ fast-equals (strict) (passed) │ 1584702.069444 │
508
+ │ fast-equals (strict) (passed) │ 1668916.622434 │
508
509
  ├────────────────────────────────────────┼────────────────┤
509
- │ dequal/lite (passed) │ 1393178.232807 │
510
+ │ dequal/lite (passed) │ 1446091.459485 │
510
511
  ├────────────────────────────────────────┼────────────────┤
511
- │ dequal (passed) │ 1370661.947753 │
512
+ │ fast-equals (strict circular) (passed) │ 1410439.853116 │
512
513
  ├────────────────────────────────────────┼────────────────┤
513
- │ fast-equals (strict circular) (passed) │ 1336500.602356 │
514
+ │ dequal (passed) │ 1395740.020934 │
514
515
  ├────────────────────────────────────────┼────────────────┤
515
- │ shallow-equal-fuzzy (failed) │ 1219389.24268 │
516
+ │ shallow-equal-fuzzy (failed) │ 1285610.296881 │
516
517
  ├────────────────────────────────────────┼────────────────┤
517
- │ nano-equal (passed) │ 1088061.461684 │
518
+ │ nano-equal (passed) │ 1130229.996399 │
518
519
  ├────────────────────────────────────────┼────────────────┤
519
- │ underscore.isEqual (passed) │ 661655.436986 │
520
+ │ underscore.isEqual (passed) │ 682455.329594 │
520
521
  ├────────────────────────────────────────┼────────────────┤
521
- │ es-toolkit (passed) │ 401295.827671 │
522
+ │ es-toolkit (passed) │ 417584.470986 │
522
523
  ├────────────────────────────────────────┼────────────────┤
523
- │ lodash.isEqual (passed) │ 377347.276362 │
524
+ │ lodash.isEqual (passed) │ 385904.998549 │
524
525
  ├────────────────────────────────────────┼────────────────┤
525
- │ deep-eql (passed) │ 199704.751472 │
526
+ │ deep-eql (passed) │ 202212.291682 │
526
527
  ├────────────────────────────────────────┼────────────────┤
527
- │ assert.deepStrictEqual (passed) │ 25504.609914 │
528
+ │ assert.deepStrictEqual (passed) │ 25540.74079 │
528
529
  ├────────────────────────────────────────┼────────────────┤
529
- │ deep-equal (passed) │ 5996.790087 │
530
+ │ deep-equal (passed) │ 5867.29696 │
530
531
  └────────────────────────────────────────┴────────────────┘
531
532
  ```
532
533
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  const { getOwnPropertyDescriptor: getOwnPropertyDescriptor$1, getOwnPropertyNames, getOwnPropertySymbols } = Object;
4
4
  const { hasOwnProperty, toString: toString$1 } = Object.prototype;
5
- const OBJECT_TAG = '[object Object]';
6
5
  /**
7
6
  * Whether the own properties from `end` onward are equal with strict property checking, where the
8
7
  * caller has already verified that both objects have the same number of own properties.
@@ -134,10 +133,10 @@ function isNullPrototypeComparable(a, b) {
134
133
  const aConstructor = a.constructor;
135
134
  const bConstructor = b.constructor;
136
135
  if (aConstructor == null) {
137
- return bConstructor === Object || toString$1.call(b) === OBJECT_TAG;
136
+ return bConstructor === Object || toString$1.call(b) === '[object Object]';
138
137
  }
139
138
  if (bConstructor == null) {
140
- return aConstructor === Object || toString$1.call(a) === OBJECT_TAG;
139
+ return aConstructor === Object || toString$1.call(a) === '[object Object]';
141
140
  }
142
141
  return false;
143
142
  }
@@ -492,13 +491,19 @@ function areRegExpsEqualStrict(a, b, state) {
492
491
  * compared. Repeated keys are, so this is a comparison of multisets rather than of sets:
493
492
  * `a=1&a=2` is equal to `a=2&a=1`, but not to `a=1&a=1`.
494
493
  */
495
- function areSearchParamsEqual(a, b) {
494
+ function areUrlSearchParamsEqual(a, b) {
496
495
  const serializedA = a.toString();
497
496
  const serializedB = b.toString();
498
497
  // Identical serializations are equal under any ordering, and this is by far the common case, so
499
498
  // it is worth checking before sorting anything.
500
499
  return serializedA === serializedB || sortSearchParams(serializedA) === sortSearchParams(serializedB);
501
500
  }
501
+ /**
502
+ * Whether the search params passed are equal in value with strict property checking.
503
+ */
504
+ function areUrlSearchParamsEqualStrict(a, b, state) {
505
+ return areUrlSearchParamsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
506
+ }
502
507
  /**
503
508
  * Whether the `Set`s are equal in value.
504
509
  */
@@ -609,7 +614,7 @@ function areUrlsEqual(a, b) {
609
614
  && a.host === b.host
610
615
  && a.pathname === b.pathname
611
616
  && a.hash === b.hash
612
- && areSearchParamsEqual(a.searchParams, b.searchParams));
617
+ && areUrlSearchParamsEqual(a.searchParams, b.searchParams));
613
618
  }
614
619
  /**
615
620
  * Whether the URL instances are equal in value with strict property checking.
@@ -619,6 +624,7 @@ function areUrlsEqualStrict(a, b, state) {
619
624
  }
620
625
 
621
626
  const { toString } = Object.prototype;
627
+ const toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag;
622
628
  /**
623
629
  * Create a comparator method based on the type-specific equality comparators passed.
624
630
  */
@@ -636,22 +642,30 @@ function createEqualityComparator(config) {
636
642
  * In all cases, these decisions should be reevaluated based on changes to the language and
637
643
  * common development practices.
638
644
  *
645
+ * When `Symbol.toStringTag` is a non-empty string (TypedArrays, `ArrayBuffer`, `DataView`, `Map`, `URL`,
646
+ * etc.), `toString()` returns `[object ${stringTag}]` regardless of the object's type, so the comparator
647
+ * is looked up by the `Symbol.toStringTag` value directly. This avoids building (and then hashing) the
648
+ * full tag string for every comparison. Otherwise the tag depends on the built-in type, and is captured
649
+ * with `toString()` as before.
650
+ *
639
651
  * Capturing the tag is reasonably performant in modern environments like v8 and SpiderMonkey. This is
640
652
  * kept out of the main comparator so that it stays within the engine's bytecode budget for inlining.
641
653
  * See [#207](https://github.com/planttheidea/fast-equals/pull/207) for more details.
642
654
  */
643
655
  const areTaggedObjectsEqual = getUnsupportedCustomComparator
644
656
  ? function areTaggedObjectsEqual(a, b, state) {
645
- const tag = toString.call(a);
657
+ const stringTag = toStringTag && a[toStringTag];
658
+ const tag = stringTag && typeof stringTag === 'string' ? stringTag : toString.call(a);
646
659
  const supportedComparator = supportedComparatorMap[tag];
647
660
  if (supportedComparator) {
648
661
  return supportedComparator(a, b, state);
649
662
  }
650
- const unsupportedCustomComparator = getUnsupportedCustomComparator(a, b, state, tag);
663
+ const unsupportedCustomComparator = getUnsupportedCustomComparator(a, b, state, tag === stringTag ? toString.call(a) : tag);
651
664
  return unsupportedCustomComparator ? unsupportedCustomComparator(a, b, state) : false;
652
665
  }
653
666
  : function areTaggedObjectsEqual(a, b, state) {
654
- const supportedComparator = supportedComparatorMap[toString.call(a)];
667
+ const stringTag = toStringTag && a[toStringTag];
668
+ const supportedComparator = supportedComparatorMap[stringTag && typeof stringTag === 'string' ? stringTag : toString.call(a)];
655
669
  return supportedComparator ? supportedComparator(a, b, state) : false;
656
670
  };
657
671
  /**
@@ -763,6 +777,7 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
763
777
  areRegExpsEqual: strict ? areRegExpsEqualStrict : areRegExpsEqual,
764
778
  areSetsEqual: strict ? areSetsEqualStrict : areSetsEqual,
765
779
  areTypedArraysEqual: strict ? areTypedArraysEqualStrict : areTypedArraysEqual,
780
+ areUrlSearchParamsEqual: strict ? areUrlSearchParamsEqualStrict : areUrlSearchParamsEqual,
766
781
  areUrlsEqual: strict ? areUrlsEqualStrict : areUrlsEqual,
767
782
  getUnsupportedCustomComparator: undefined,
768
783
  strictNullPrototypeComparison,
@@ -830,49 +845,61 @@ function createIsEqual({ circular, comparator, createState, equals, strict }) {
830
845
  };
831
846
  }
832
847
  /**
833
- * Create a map of `toString()` values to their respective handlers for `tag`-based lookups.
834
- */
835
- function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, }) {
836
- return {
837
- '[object Arguments]': areObjectsEqual,
838
- '[object Array]': areArraysEqual,
839
- '[object ArrayBuffer]': areArrayBuffersEqual,
840
- '[object AsyncGeneratorFunction]': areFunctionsEqual,
841
- '[object BigInt]': arePrimitiveWrappersEqual,
842
- '[object BigInt64Array]': areTypedArraysEqual,
843
- '[object BigUint64Array]': areTypedArraysEqual,
844
- '[object Boolean]': arePrimitiveWrappersEqual,
845
- '[object DataView]': areDataViewsEqual,
846
- '[object Date]': areDatesEqual,
848
+ * Create a map of tags to their respective handlers for `tag`-based lookups. Each handler is keyed
849
+ * by both its `Symbol.toStringTag` value (`Map`) and its `toString()` value (`[object Map]`).
850
+ *
851
+ * @note
852
+ * The map has a `null` prototype, so a `Symbol.toStringTag` like `constructor` or `toString` cannot
853
+ * resolve to an inherited `Object.prototype` method.
854
+ */
855
+ function createSupportedComparatorMap(config) {
856
+ return [
857
+ ['Arguments', config.areObjectsEqual],
858
+ ['Array', config.areArraysEqual],
859
+ ['ArrayBuffer', config.areArrayBuffersEqual],
860
+ ['AsyncGeneratorFunction', config.areFunctionsEqual],
861
+ ['BigInt', config.arePrimitiveWrappersEqual],
862
+ ['BigInt64Array', config.areTypedArraysEqual],
863
+ ['BigUint64Array', config.areTypedArraysEqual],
864
+ ['Boolean', config.arePrimitiveWrappersEqual],
865
+ ['DataView', config.areDataViewsEqual],
866
+ ['Date', config.areDatesEqual],
847
867
  // If an error tag, it should be tested explicitly. Like RegExp, the properties are not
848
868
  // enumerable, and therefore will give false positives if tested like a standard object.
849
- '[object Error]': areErrorsEqual,
850
- '[object Float16Array]': areTypedArraysEqual,
851
- '[object Float32Array]': areTypedArraysEqual,
852
- '[object Float64Array]': areTypedArraysEqual,
853
- '[object Function]': areFunctionsEqual,
854
- '[object GeneratorFunction]': areFunctionsEqual,
855
- '[object Int8Array]': areTypedArraysEqual,
856
- '[object Int16Array]': areTypedArraysEqual,
857
- '[object Int32Array]': areTypedArraysEqual,
858
- '[object Map]': areMapsEqual,
859
- '[object Number]': arePrimitiveWrappersEqual,
860
- '[object Object]': (a, b, state) =>
861
- // The exception for value comparison is custom `Promise`-like class instances. These should
862
- // be treated the same as standard `Promise` objects, which means strict equality, and if
863
- // it reaches this point then that strict equality comparison has already failed.
864
- typeof a.then !== 'function' && typeof b.then !== 'function' && areObjectsEqual(a, b, state),
869
+ ['Error', config.areErrorsEqual],
870
+ ['Float16Array', config.areTypedArraysEqual],
871
+ ['Float32Array', config.areTypedArraysEqual],
872
+ ['Float64Array', config.areTypedArraysEqual],
873
+ ['Function', config.areFunctionsEqual],
874
+ ['GeneratorFunction', config.areFunctionsEqual],
875
+ ['Int8Array', config.areTypedArraysEqual],
876
+ ['Int16Array', config.areTypedArraysEqual],
877
+ ['Int32Array', config.areTypedArraysEqual],
878
+ ['Map', config.areMapsEqual],
879
+ ['Number', config.arePrimitiveWrappersEqual],
880
+ [
881
+ 'Object',
882
+ (a, b, state) =>
883
+ // The exception for value comparison is custom `Promise`-like class instances. These should
884
+ // be treated the same as standard `Promise` objects, which means strict equality, and if
885
+ // it reaches this point then that strict equality comparison has already failed.
886
+ typeof a.then !== 'function' && typeof b.then !== 'function' && config.areObjectsEqual(a, b, state),
887
+ ],
865
888
  // For RegExp, the properties are not enumerable, and therefore will give false positives if
866
889
  // tested like a standard object.
867
- '[object RegExp]': areRegExpsEqual,
868
- '[object Set]': areSetsEqual,
869
- '[object String]': arePrimitiveWrappersEqual,
870
- '[object URL]': areUrlsEqual,
871
- '[object Uint8Array]': areTypedArraysEqual,
872
- '[object Uint8ClampedArray]': areTypedArraysEqual,
873
- '[object Uint16Array]': areTypedArraysEqual,
874
- '[object Uint32Array]': areTypedArraysEqual,
875
- };
890
+ ['RegExp', config.areRegExpsEqual],
891
+ ['Set', config.areSetsEqual],
892
+ ['String', config.arePrimitiveWrappersEqual],
893
+ ['URL', config.areUrlsEqual],
894
+ ['URLSearchParams', config.areUrlSearchParamsEqual],
895
+ ['Uint8Array', config.areTypedArraysEqual],
896
+ ['Uint8ClampedArray', config.areTypedArraysEqual],
897
+ ['Uint16Array', config.areTypedArraysEqual],
898
+ ['Uint32Array', config.areTypedArraysEqual],
899
+ ].reduce((comparatorMap, [tag, comparator]) => {
900
+ comparatorMap[tag] = comparatorMap[`[object ${tag}]`] = comparator;
901
+ return comparatorMap;
902
+ }, Object.create(null));
876
903
  }
877
904
 
878
905
  /**
@@ -90,6 +90,11 @@ interface ComparatorConfig<Meta> {
90
90
  * additional properties added to the typed array.
91
91
  */
92
92
  areTypedArraysEqual: EqualityComparator<Meta>;
93
+ /**
94
+ * Whether the `URLSearchParams` passed are equal in value. In strict mode, this includes
95
+ * additional properties added to the `URLSearchParams`.
96
+ */
97
+ areUrlSearchParamsEqual: EqualityComparator<Meta>;
93
98
  /**
94
99
  * Whether the URLs passed are equal in value. In strict mode, this includes
95
100
  * additional properties added to the URL.
@@ -90,6 +90,11 @@ interface ComparatorConfig<Meta> {
90
90
  * additional properties added to the typed array.
91
91
  */
92
92
  areTypedArraysEqual: EqualityComparator<Meta>;
93
+ /**
94
+ * Whether the `URLSearchParams` passed are equal in value. In strict mode, this includes
95
+ * additional properties added to the `URLSearchParams`.
96
+ */
97
+ areUrlSearchParamsEqual: EqualityComparator<Meta>;
93
98
  /**
94
99
  * Whether the URLs passed are equal in value. In strict mode, this includes
95
100
  * additional properties added to the URL.
package/dist/es/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  const { getOwnPropertyDescriptor: getOwnPropertyDescriptor$1, getOwnPropertyNames, getOwnPropertySymbols } = Object;
2
2
  const { hasOwnProperty, toString: toString$1 } = Object.prototype;
3
- const OBJECT_TAG = '[object Object]';
4
3
  /**
5
4
  * Whether the own properties from `end` onward are equal with strict property checking, where the
6
5
  * caller has already verified that both objects have the same number of own properties.
@@ -132,10 +131,10 @@ function isNullPrototypeComparable(a, b) {
132
131
  const aConstructor = a.constructor;
133
132
  const bConstructor = b.constructor;
134
133
  if (aConstructor == null) {
135
- return bConstructor === Object || toString$1.call(b) === OBJECT_TAG;
134
+ return bConstructor === Object || toString$1.call(b) === '[object Object]';
136
135
  }
137
136
  if (bConstructor == null) {
138
- return aConstructor === Object || toString$1.call(a) === OBJECT_TAG;
137
+ return aConstructor === Object || toString$1.call(a) === '[object Object]';
139
138
  }
140
139
  return false;
141
140
  }
@@ -490,13 +489,19 @@ function areRegExpsEqualStrict(a, b, state) {
490
489
  * compared. Repeated keys are, so this is a comparison of multisets rather than of sets:
491
490
  * `a=1&a=2` is equal to `a=2&a=1`, but not to `a=1&a=1`.
492
491
  */
493
- function areSearchParamsEqual(a, b) {
492
+ function areUrlSearchParamsEqual(a, b) {
494
493
  const serializedA = a.toString();
495
494
  const serializedB = b.toString();
496
495
  // Identical serializations are equal under any ordering, and this is by far the common case, so
497
496
  // it is worth checking before sorting anything.
498
497
  return serializedA === serializedB || sortSearchParams(serializedA) === sortSearchParams(serializedB);
499
498
  }
499
+ /**
500
+ * Whether the search params passed are equal in value with strict property checking.
501
+ */
502
+ function areUrlSearchParamsEqualStrict(a, b, state) {
503
+ return areUrlSearchParamsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
504
+ }
500
505
  /**
501
506
  * Whether the `Set`s are equal in value.
502
507
  */
@@ -607,7 +612,7 @@ function areUrlsEqual(a, b) {
607
612
  && a.host === b.host
608
613
  && a.pathname === b.pathname
609
614
  && a.hash === b.hash
610
- && areSearchParamsEqual(a.searchParams, b.searchParams));
615
+ && areUrlSearchParamsEqual(a.searchParams, b.searchParams));
611
616
  }
612
617
  /**
613
618
  * Whether the URL instances are equal in value with strict property checking.
@@ -617,6 +622,7 @@ function areUrlsEqualStrict(a, b, state) {
617
622
  }
618
623
 
619
624
  const { toString } = Object.prototype;
625
+ const toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag;
620
626
  /**
621
627
  * Create a comparator method based on the type-specific equality comparators passed.
622
628
  */
@@ -634,22 +640,30 @@ function createEqualityComparator(config) {
634
640
  * In all cases, these decisions should be reevaluated based on changes to the language and
635
641
  * common development practices.
636
642
  *
643
+ * When `Symbol.toStringTag` is a non-empty string (TypedArrays, `ArrayBuffer`, `DataView`, `Map`, `URL`,
644
+ * etc.), `toString()` returns `[object ${stringTag}]` regardless of the object's type, so the comparator
645
+ * is looked up by the `Symbol.toStringTag` value directly. This avoids building (and then hashing) the
646
+ * full tag string for every comparison. Otherwise the tag depends on the built-in type, and is captured
647
+ * with `toString()` as before.
648
+ *
637
649
  * Capturing the tag is reasonably performant in modern environments like v8 and SpiderMonkey. This is
638
650
  * kept out of the main comparator so that it stays within the engine's bytecode budget for inlining.
639
651
  * See [#207](https://github.com/planttheidea/fast-equals/pull/207) for more details.
640
652
  */
641
653
  const areTaggedObjectsEqual = getUnsupportedCustomComparator
642
654
  ? function areTaggedObjectsEqual(a, b, state) {
643
- const tag = toString.call(a);
655
+ const stringTag = toStringTag && a[toStringTag];
656
+ const tag = stringTag && typeof stringTag === 'string' ? stringTag : toString.call(a);
644
657
  const supportedComparator = supportedComparatorMap[tag];
645
658
  if (supportedComparator) {
646
659
  return supportedComparator(a, b, state);
647
660
  }
648
- const unsupportedCustomComparator = getUnsupportedCustomComparator(a, b, state, tag);
661
+ const unsupportedCustomComparator = getUnsupportedCustomComparator(a, b, state, tag === stringTag ? toString.call(a) : tag);
649
662
  return unsupportedCustomComparator ? unsupportedCustomComparator(a, b, state) : false;
650
663
  }
651
664
  : function areTaggedObjectsEqual(a, b, state) {
652
- const supportedComparator = supportedComparatorMap[toString.call(a)];
665
+ const stringTag = toStringTag && a[toStringTag];
666
+ const supportedComparator = supportedComparatorMap[stringTag && typeof stringTag === 'string' ? stringTag : toString.call(a)];
653
667
  return supportedComparator ? supportedComparator(a, b, state) : false;
654
668
  };
655
669
  /**
@@ -761,6 +775,7 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
761
775
  areRegExpsEqual: strict ? areRegExpsEqualStrict : areRegExpsEqual,
762
776
  areSetsEqual: strict ? areSetsEqualStrict : areSetsEqual,
763
777
  areTypedArraysEqual: strict ? areTypedArraysEqualStrict : areTypedArraysEqual,
778
+ areUrlSearchParamsEqual: strict ? areUrlSearchParamsEqualStrict : areUrlSearchParamsEqual,
764
779
  areUrlsEqual: strict ? areUrlsEqualStrict : areUrlsEqual,
765
780
  getUnsupportedCustomComparator: undefined,
766
781
  strictNullPrototypeComparison,
@@ -828,49 +843,61 @@ function createIsEqual({ circular, comparator, createState, equals, strict }) {
828
843
  };
829
844
  }
830
845
  /**
831
- * Create a map of `toString()` values to their respective handlers for `tag`-based lookups.
832
- */
833
- function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, }) {
834
- return {
835
- '[object Arguments]': areObjectsEqual,
836
- '[object Array]': areArraysEqual,
837
- '[object ArrayBuffer]': areArrayBuffersEqual,
838
- '[object AsyncGeneratorFunction]': areFunctionsEqual,
839
- '[object BigInt]': arePrimitiveWrappersEqual,
840
- '[object BigInt64Array]': areTypedArraysEqual,
841
- '[object BigUint64Array]': areTypedArraysEqual,
842
- '[object Boolean]': arePrimitiveWrappersEqual,
843
- '[object DataView]': areDataViewsEqual,
844
- '[object Date]': areDatesEqual,
846
+ * Create a map of tags to their respective handlers for `tag`-based lookups. Each handler is keyed
847
+ * by both its `Symbol.toStringTag` value (`Map`) and its `toString()` value (`[object Map]`).
848
+ *
849
+ * @note
850
+ * The map has a `null` prototype, so a `Symbol.toStringTag` like `constructor` or `toString` cannot
851
+ * resolve to an inherited `Object.prototype` method.
852
+ */
853
+ function createSupportedComparatorMap(config) {
854
+ return [
855
+ ['Arguments', config.areObjectsEqual],
856
+ ['Array', config.areArraysEqual],
857
+ ['ArrayBuffer', config.areArrayBuffersEqual],
858
+ ['AsyncGeneratorFunction', config.areFunctionsEqual],
859
+ ['BigInt', config.arePrimitiveWrappersEqual],
860
+ ['BigInt64Array', config.areTypedArraysEqual],
861
+ ['BigUint64Array', config.areTypedArraysEqual],
862
+ ['Boolean', config.arePrimitiveWrappersEqual],
863
+ ['DataView', config.areDataViewsEqual],
864
+ ['Date', config.areDatesEqual],
845
865
  // If an error tag, it should be tested explicitly. Like RegExp, the properties are not
846
866
  // enumerable, and therefore will give false positives if tested like a standard object.
847
- '[object Error]': areErrorsEqual,
848
- '[object Float16Array]': areTypedArraysEqual,
849
- '[object Float32Array]': areTypedArraysEqual,
850
- '[object Float64Array]': areTypedArraysEqual,
851
- '[object Function]': areFunctionsEqual,
852
- '[object GeneratorFunction]': areFunctionsEqual,
853
- '[object Int8Array]': areTypedArraysEqual,
854
- '[object Int16Array]': areTypedArraysEqual,
855
- '[object Int32Array]': areTypedArraysEqual,
856
- '[object Map]': areMapsEqual,
857
- '[object Number]': arePrimitiveWrappersEqual,
858
- '[object Object]': (a, b, state) =>
859
- // The exception for value comparison is custom `Promise`-like class instances. These should
860
- // be treated the same as standard `Promise` objects, which means strict equality, and if
861
- // it reaches this point then that strict equality comparison has already failed.
862
- typeof a.then !== 'function' && typeof b.then !== 'function' && areObjectsEqual(a, b, state),
867
+ ['Error', config.areErrorsEqual],
868
+ ['Float16Array', config.areTypedArraysEqual],
869
+ ['Float32Array', config.areTypedArraysEqual],
870
+ ['Float64Array', config.areTypedArraysEqual],
871
+ ['Function', config.areFunctionsEqual],
872
+ ['GeneratorFunction', config.areFunctionsEqual],
873
+ ['Int8Array', config.areTypedArraysEqual],
874
+ ['Int16Array', config.areTypedArraysEqual],
875
+ ['Int32Array', config.areTypedArraysEqual],
876
+ ['Map', config.areMapsEqual],
877
+ ['Number', config.arePrimitiveWrappersEqual],
878
+ [
879
+ 'Object',
880
+ (a, b, state) =>
881
+ // The exception for value comparison is custom `Promise`-like class instances. These should
882
+ // be treated the same as standard `Promise` objects, which means strict equality, and if
883
+ // it reaches this point then that strict equality comparison has already failed.
884
+ typeof a.then !== 'function' && typeof b.then !== 'function' && config.areObjectsEqual(a, b, state),
885
+ ],
863
886
  // For RegExp, the properties are not enumerable, and therefore will give false positives if
864
887
  // tested like a standard object.
865
- '[object RegExp]': areRegExpsEqual,
866
- '[object Set]': areSetsEqual,
867
- '[object String]': arePrimitiveWrappersEqual,
868
- '[object URL]': areUrlsEqual,
869
- '[object Uint8Array]': areTypedArraysEqual,
870
- '[object Uint8ClampedArray]': areTypedArraysEqual,
871
- '[object Uint16Array]': areTypedArraysEqual,
872
- '[object Uint32Array]': areTypedArraysEqual,
873
- };
888
+ ['RegExp', config.areRegExpsEqual],
889
+ ['Set', config.areSetsEqual],
890
+ ['String', config.arePrimitiveWrappersEqual],
891
+ ['URL', config.areUrlsEqual],
892
+ ['URLSearchParams', config.areUrlSearchParamsEqual],
893
+ ['Uint8Array', config.areTypedArraysEqual],
894
+ ['Uint8ClampedArray', config.areTypedArraysEqual],
895
+ ['Uint16Array', config.areTypedArraysEqual],
896
+ ['Uint32Array', config.areTypedArraysEqual],
897
+ ].reduce((comparatorMap, [tag, comparator]) => {
898
+ comparatorMap[tag] = comparatorMap[`[object ${tag}]`] = comparator;
899
+ return comparatorMap;
900
+ }, Object.create(null));
874
901
  }
875
902
 
876
903
  /**
package/index.d.ts CHANGED
@@ -90,6 +90,11 @@ interface ComparatorConfig<Meta> {
90
90
  * additional properties added to the typed array.
91
91
  */
92
92
  areTypedArraysEqual: EqualityComparator<Meta>;
93
+ /**
94
+ * Whether the `URLSearchParams` passed are equal in value. In strict mode, this includes
95
+ * additional properties added to the `URLSearchParams`.
96
+ */
97
+ areUrlSearchParamsEqual: EqualityComparator<Meta>;
93
98
  /**
94
99
  * Whether the URLs passed are equal in value. In strict mode, this includes
95
100
  * additional properties added to the URL.
package/package.json CHANGED
@@ -10,20 +10,20 @@
10
10
  "description": "A blazing-fast equality comparison utility for a variety of use-cases",
11
11
  "devDependencies": {
12
12
  "@planttheidea/build-tools": "^2.0.8",
13
- "@types/lodash": "^4.17.25",
14
- "@types/node": "^24.19.1",
13
+ "@types/lodash": "^4.17.27",
14
+ "@types/node": "^24.19.2",
15
15
  "@types/ramda": "^0.32.0",
16
16
  "@types/react": "^19.3.0",
17
17
  "@types/react-dom": "^19.3.0",
18
- "@typescript-eslint/eslint-plugin": "^8.71.1",
19
- "@typescript-eslint/parser": "^8.71.1",
20
- "@vitest/coverage-v8": "^4.1.11",
18
+ "@typescript-eslint/eslint-plugin": "^8.73.0",
19
+ "@typescript-eslint/parser": "^8.73.0",
20
+ "@vitest/coverage-v8": "^5.1.1",
21
21
  "cli-table3": "^0.6.5",
22
22
  "decircularize": "^1.0.0",
23
23
  "deep-eql": "^5.0.2",
24
24
  "deep-equal": "^2.2.3",
25
25
  "dequal": "^2.0.3",
26
- "es-toolkit": "^1.52.0",
26
+ "es-toolkit": "^1.53.2",
27
27
  "eslint": "^9.39.5",
28
28
  "eslint-friendly-formatter": "^4.0.1",
29
29
  "eslint-plugin-import": "^2.32.0",
@@ -31,19 +31,19 @@
31
31
  "fast-glob": "^3.3.3",
32
32
  "lodash": "^4.18.1",
33
33
  "nano-equal": "^2.0.2",
34
- "prettier": "^3.9.9",
35
- "react": "^19.3.0",
36
- "react-dom": "^19.3.0",
37
- "react-fast-compare": "^3.2.2",
38
- "release-it": "^21.1.1",
39
- "rollup": "^4.64.3",
34
+ "prettier": "^3.10.1",
35
+ "react": "^19.3.1",
36
+ "react-dom": "^19.3.1",
37
+ "react-fast-compare": "^3.2.4",
38
+ "release-it": "^21.1.3",
39
+ "rollup": "^4.68.8",
40
40
  "shallow-equal-fuzzy": "^0.0.2",
41
- "tinybench": "^6.2.1",
41
+ "tinybench": "^6.2.4",
42
42
  "typescript": "^6.0.3",
43
- "typescript-eslint": "^8.71.1",
43
+ "typescript-eslint": "^8.73.0",
44
44
  "underscore": "^1.13.8",
45
- "vite": "^8.3.4",
46
- "vitest": "^4.1.11"
45
+ "vite": "^8.3.8",
46
+ "vitest": "^5.1.1"
47
47
  },
48
48
  "engines": {
49
49
  "node": ">=6.0.0"
@@ -79,6 +79,7 @@
79
79
  "main": "./dist/cjs/index.cjs",
80
80
  "module": "./dist/es/index.mjs",
81
81
  "name": "fast-equals",
82
+ "packageManager": "yarn@4.18.1",
82
83
  "publishConfig": {
83
84
  "access": "public"
84
85
  },
@@ -110,5 +111,5 @@
110
111
  "sideEffects": false,
111
112
  "type": "module",
112
113
  "types": "./index.d.ts",
113
- "version": "6.3.0"
114
+ "version": "6.4.1"
114
115
  }