fast-equals 6.2.2 → 6.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  > fast-equals
2
2
 
3
3
  Perform [blazing fast](#benchmarks) equality comparisons between two objects, while also allowing for flexibility for
4
- various use-cases. It has no dependencies, and is ~2.65kB when minified and gzipped.
4
+ various use-cases. It has no dependencies, and is ~2.90kB when minified and gzipped.
5
5
 
6
6
  The following types are handled out-of-the-box:
7
7
 
@@ -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,7 +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 `Date` 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
239
240
 
240
241
  ```ts
241
242
  const array = [{ foo: 'bar' }];
@@ -248,6 +249,16 @@ console.log(strictDeepEqual(array, otherArray)); // true
248
249
  console.log(strictDeepEqual(array, [{ foo: 'bar' }])); // false
249
250
  ```
250
251
 
252
+ _**NOTE**: Any object can have properties assigned to it, including objects whose value is held internally
253
+ (`date.foo = 'bar'`), so strict comparisons check those own properties in addition to the value itself. Properties that
254
+ are part of the value (the elements of a `TypedArray`, the characters of a `String` wrapper) are not compared twice, but
255
+ listing an object's own properties still has a cost. It is most noticeable for:_
256
+
257
+ - _`RegExp` objects, which always have an own `lastIndex` property, so their own properties are always listed and
258
+ compared_
259
+ - _`String` wrappers, whose characters are each an own property, so listing their own properties grows with the length
260
+ of the string_
261
+
251
262
  ### strictShallowEqual
252
263
 
253
264
  Performs the same comparison as `shallowEqual` but performs a strict comparison of the objects. This includes:
@@ -256,7 +267,8 @@ Performs the same comparison as `shallowEqual` but performs a strict comparison
256
267
  - Checking full descriptor of properties on the object to match
257
268
  - Checking non-index properties on arrays
258
269
  - Checking non-key properties on `Map` / `Set` objects
259
- - Checking own properties on `Date` 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
260
272
 
261
273
  ```ts
262
274
  const array = ['foo'];
@@ -278,7 +290,8 @@ Performs the same comparison as `circularDeepEqual` but performs a strict compar
278
290
  - Checking full descriptor of properties on the object to match
279
291
  - Checking non-index properties on arrays
280
292
  - Checking non-key properties on `Map` / `Set` objects
281
- - Checking own properties on `Date` 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
282
295
 
283
296
  ```ts
284
297
  function Circular(value) {
@@ -318,7 +331,8 @@ Performs the same comparison as `circularShallowEqual` but performs a strict com
318
331
  - Checking full descriptor of properties on the object to match
319
332
  - Checking non-index properties on arrays
320
333
  - Checking non-key properties on `Map` / `Set` objects
321
- - Checking own properties on `Date` 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
322
336
 
323
337
  ```ts
324
338
  const array = ['foo'];
@@ -363,6 +377,7 @@ interface ComparatorConfig<Meta> {
363
377
  areRegExpsEqual: EqualityComparator<Meta>;
364
378
  areSetsEqual: EqualityComparator<Meta>;
365
379
  areTypedArraysEqual: EqualityComparator<Meta>;
380
+ areUrlSearchParamsEqual: EqualityComparator<Meta>;
366
381
  areUrlsEqual: EqualityComparator<Meta>;
367
382
  getUnsupportedCustomComparator:
368
383
  (<Type>(a: Type, b: Type, state: State<Meta>, tag: string) => EqualityComparator<Meta> | undefined) | undefined;
@@ -428,8 +443,8 @@ to the problem you are solving, they can offer guidance of how to structure your
428
443
 
429
444
  ## Benchmarks
430
445
 
431
- All benchmarks were performed on an i9-11900H Ubuntu Linux 24.04 laptop with 64GB of memory using NodeJS version
432
- `24.15.0`, and are based on averages of running comparisons based deep equality on the following object types:
446
+ All benchmarks were performed on an i9-11900H Manjaro Linux laptop with 64GB of memory using NodeJS version `26.13.0`,
447
+ and are based on averages of running comparisons based deep equality on the following object types:
433
448
 
434
449
  - Primitives (`String`, `Number`, `null`, `undefined`)
435
450
  - `Function`
@@ -445,74 +460,74 @@ Testing mixed objects equal...
445
460
  ┌────────────────────────────────────────┬────────────────┐
446
461
  │ Name │ Ops / sec │
447
462
  ├────────────────────────────────────────┼────────────────┤
448
- │ fast-equals (passed) │ 1763109.81851 │
463
+ │ fast-equals (passed) │ 1731598.023836 │
449
464
  ├────────────────────────────────────────┼────────────────┤
450
- │ fast-deep-equal (passed) │ 1297247.799465 │
465
+ │ fast-deep-equal (passed) │ 1309307.899547 │
451
466
  ├────────────────────────────────────────┼────────────────┤
452
- │ react-fast-compare (passed) │ 1271146.258704 │
467
+ │ react-fast-compare (passed) │ 1292046.683991 │
453
468
  ├────────────────────────────────────────┼────────────────┤
454
- │ shallow-equal-fuzzy (passed) │ 1235115.693854 │
469
+ │ shallow-equal-fuzzy (passed) │ 1226265.458405 │
455
470
  ├────────────────────────────────────────┼────────────────┤
456
- │ nano-equal (failed) │ 964815.367752 │
471
+ │ nano-equal (failed) │ 963157.128972 │
457
472
  ├────────────────────────────────────────┼────────────────┤
458
- │ fast-equals (circular) (passed) │ 834232.686567 │
473
+ │ fast-equals (circular) (passed) │ 909479.445346 │
459
474
  ├────────────────────────────────────────┼────────────────┤
460
- │ dequal (passed) │ 759417.072806 │
475
+ │ dequal/lite (passed) │ 778122.31992 │
461
476
  ├────────────────────────────────────────┼────────────────┤
462
- │ dequal/lite (passed) │ 751901.517376 │
477
+ │ dequal (passed) │ 760245.363659 │
463
478
  ├────────────────────────────────────────┼────────────────┤
464
- │ underscore.isEqual (passed) │ 447789.934941 │
479
+ │ underscore.isEqual (passed) │ 445304.799867 │
465
480
  ├────────────────────────────────────────┼────────────────┤
466
- │ assert.deepStrictEqual (passed) │ 433256.455121 │
481
+ │ assert.deepStrictEqual (passed) │ 438737.156408 │
467
482
  ├────────────────────────────────────────┼────────────────┤
468
- │ es-toolkit (passed) │ 343382.909087 │
483
+ │ es-toolkit (passed) │ 382792.590707 │
469
484
  ├────────────────────────────────────────┼────────────────┤
470
- │ fast-equals (strict) (passed) │ 294211.792998 │
485
+ │ lodash.isEqual (passed) │ 290229.549964 │
471
486
  ├────────────────────────────────────────┼────────────────┤
472
- │ lodash.isEqual (passed) │ 290477.460766 │
487
+ │ fast-equals (strict) (passed) │ 279185.538603 │
473
488
  ├────────────────────────────────────────┼────────────────┤
474
- │ fast-equals (strict circular) (passed) │ 232110.748904 │
489
+ │ fast-equals (strict circular) (passed) │ 238470.634046 │
475
490
  ├────────────────────────────────────────┼────────────────┤
476
- │ deep-eql (passed) │ 161408.4511 │
491
+ │ deep-eql (passed) │ 172670.983717 │
477
492
  ├────────────────────────────────────────┼────────────────┤
478
- │ deep-equal (passed) │ 951.279346 │
493
+ │ deep-equal (passed) │ 1357.008406 │
479
494
  └────────────────────────────────────────┴────────────────┘
480
495
 
481
496
  Testing mixed objects not equal...
482
497
  ┌────────────────────────────────────────┬────────────────┐
483
498
  │ Name │ Ops / sec │
484
499
  ├────────────────────────────────────────┼────────────────┤
485
- │ fast-equals (passed) │ 5402008.064431 │
500
+ │ fast-equals (passed) │ 5076106.125712 │
486
501
  ├────────────────────────────────────────┼────────────────┤
487
- │ fast-equals (circular) (passed) │ 3687783.563818 │
502
+ │ fast-equals (circular) (passed) │ 3544911.437592 │
488
503
  ├────────────────────────────────────────┼────────────────┤
489
- │ fast-deep-equal (passed) │ 3479884.479164 │
504
+ │ fast-deep-equal (passed) │ 3433830.73191 │
490
505
  ├────────────────────────────────────────┼────────────────┤
491
- │ react-fast-compare (passed) │ 3356141.586592 │
506
+ │ react-fast-compare (passed) │ 3246695.251508 │
492
507
  ├────────────────────────────────────────┼────────────────┤
493
- │ fast-equals (strict) (passed) │ 2927133.435788 │
508
+ │ fast-equals (strict) (passed) │ 1584702.069444 │
494
509
  ├────────────────────────────────────────┼────────────────┤
495
- │ fast-equals (strict circular) (passed) │ 1566187.833636 │
510
+ │ dequal/lite (passed) │ 1393178.232807 │
496
511
  ├────────────────────────────────────────┼────────────────┤
497
- │ dequal/lite (passed) │ 1316031.262808 │
512
+ │ dequal (passed) │ 1370661.947753 │
498
513
  ├────────────────────────────────────────┼────────────────┤
499
- │ dequal (passed) │ 1298255.762153 │
514
+ │ fast-equals (strict circular) (passed) │ 1336500.602356 │
500
515
  ├────────────────────────────────────────┼────────────────┤
501
- │ shallow-equal-fuzzy (failed) │ 1219217.578795 │
516
+ │ shallow-equal-fuzzy (failed) │ 1219389.24268 │
502
517
  ├────────────────────────────────────────┼────────────────┤
503
- │ nano-equal (passed) │ 1074115.593615 │
518
+ │ nano-equal (passed) │ 1088061.461684 │
504
519
  ├────────────────────────────────────────┼────────────────┤
505
- │ underscore.isEqual (passed) │ 659016.868085 │
520
+ │ underscore.isEqual (passed) │ 661655.436986 │
506
521
  ├────────────────────────────────────────┼────────────────┤
507
- │ lodash.isEqual (passed) │ 374944.853605 │
522
+ │ es-toolkit (passed) │ 401295.827671 │
508
523
  ├────────────────────────────────────────┼────────────────┤
509
- │ es-toolkit (passed) │ 355882.255615 │
524
+ │ lodash.isEqual (passed) │ 377347.276362 │
510
525
  ├────────────────────────────────────────┼────────────────┤
511
- │ deep-eql (passed) │ 182235.73069 │
526
+ │ deep-eql (passed) │ 199704.751472 │
512
527
  ├────────────────────────────────────────┼────────────────┤
513
- │ assert.deepStrictEqual (passed) │ 20975.582116 │
528
+ │ assert.deepStrictEqual (passed) │ 25504.609914 │
514
529
  ├────────────────────────────────────────┼────────────────┤
515
- │ deep-equal (passed) │ 3760.574487 │
530
+ │ deep-equal (passed) │ 5996.790087 │
516
531
  └────────────────────────────────────────┴────────────────┘
517
532
  ```
518
533
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols } = Object;
3
+ const { getOwnPropertyDescriptor: getOwnPropertyDescriptor$1, getOwnPropertyNames, getOwnPropertySymbols } = Object;
4
4
  const { hasOwnProperty, toString: toString$1 } = Object.prototype;
5
5
  const OBJECT_TAG = '[object Object]';
6
6
  /**
@@ -22,8 +22,8 @@ function areStrictPropertiesEqual(a, b, state, properties, end) {
22
22
  && (!hasOwn(b, property) || !state.equals(a[property], b[property], property, property, a, b, state))) {
23
23
  return false;
24
24
  }
25
- descriptorA = getOwnPropertyDescriptor(a, property);
26
- descriptorB = getOwnPropertyDescriptor(b, property);
25
+ descriptorA = getOwnPropertyDescriptor$1(a, property);
26
+ descriptorB = getOwnPropertyDescriptor$1(b, property);
27
27
  if ((descriptorA || descriptorB)
28
28
  && (!descriptorA
29
29
  || !descriptorB
@@ -36,12 +36,43 @@ function areStrictPropertiesEqual(a, b, state, properties, end) {
36
36
  return true;
37
37
  }
38
38
  /**
39
- * Combine two comparators into a single comparators.
40
- */
41
- function combineComparators(comparatorA, comparatorB) {
42
- return function isEqual(a, b, state) {
43
- return comparatorA(a, b, state) && comparatorB(a, b, state);
44
- };
39
+ * Whether the own properties of objects whose value is compared by other means (`Date`, `RegExp`,
40
+ * TypedArrays, primitive wrappers, etc.) are equal with strict property checking. Own properties
41
+ * before `start` are intrinsic to the type and already covered by the value comparison, so only the
42
+ * ones after them are compared. When `intrinsic` properties have been compared by the caller but are
43
+ * not guaranteed to be listed first (`RegExp`'s `lastIndex`), objects with only those return early,
44
+ * and otherwise every property from `start` is compared.
45
+ *
46
+ * @note
47
+ * These objects rarely have own properties beyond their intrinsic ones, so that case returns before
48
+ * any circular tracking is done. When they do, the properties can reference the object itself, so
49
+ * the pair is tracked in the cache (when present) here rather than by wrapping the comparator with
50
+ * `createIsCircular`. This keeps the cost of tracking off the common case.
51
+ */
52
+ function areOwnPropertiesEqualStrict(a, b, state, start, intrinsic) {
53
+ const properties = getOwnKeys(a);
54
+ const length = properties.length;
55
+ if (getOwnKeys(b).length !== length) {
56
+ return false;
57
+ }
58
+ if (length === intrinsic) {
59
+ return true;
60
+ }
61
+ const cache = state.cache;
62
+ if (!cache) {
63
+ return areStrictPropertiesEqual(a, b, state, properties, start);
64
+ }
65
+ const cachedA = cache.get(a);
66
+ const cachedB = cache.get(b);
67
+ if (cachedA && cachedB) {
68
+ return cachedA === b && cachedB === a;
69
+ }
70
+ cache.set(a, b);
71
+ cache.set(b, a);
72
+ const result = areStrictPropertiesEqual(a, b, state, properties, start);
73
+ cache.delete(a);
74
+ cache.delete(b);
75
+ return result;
45
76
  }
46
77
  /**
47
78
  * Wrap the provided `areItemsEqual` method to manage the circular state, allowing
@@ -80,7 +111,14 @@ function getStrictProperties(object) {
80
111
  /**
81
112
  * Identify the element type of TypedArrays across realms and subclasses.
82
113
  */
83
- const getTypedArrayTag = getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
114
+ const getTypedArrayTag = getOwnPropertyDescriptor$1(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
115
+ /**
116
+ * Get all own properties of the object, both strings and symbols, in the same order as
117
+ * `getStrictProperties`. `Reflect.ownKeys` is used when available because it is faster for objects
118
+ * like `Date` / `RegExp` / TypedArrays in V8. It is slower for plain objects without symbols, which
119
+ * is why `getStrictProperties` is still used directly for those.
120
+ */
121
+ const getOwnKeys = (typeof Reflect !== 'undefined' && Reflect.ownKeys) || getStrictProperties;
84
122
  /**
85
123
  * Whether the object contains the property passed as an own property.
86
124
  */
@@ -132,8 +170,9 @@ function sortSearchParams(serialized) {
132
170
  * scanning the other object's keys. Measured in V8: scanning wins up to 50 keys and loses from 100.
133
171
  */
134
172
  const MAX_SCANNED_PROPERTIES = 64;
135
- const { keys } = Object;
173
+ const { getOwnPropertyDescriptor, keys } = Object;
136
174
  const { propertyIsEnumerable } = Object.prototype;
175
+ const { valueOf: stringValueOf } = String.prototype;
137
176
  /**
138
177
  * Whether the values passed are equal based on a [SameValue](https://262.ecma-international.org/7.0/#sec-samevalue) basis.
139
178
  * Simplified, this maps to if the two values are referentially equal to one another (`a === b`) or both are `NaN`.
@@ -174,6 +213,12 @@ function strictEqual(a, b) {
174
213
  function areArrayBuffersEqual(a, b) {
175
214
  return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
176
215
  }
216
+ /**
217
+ * Whether the array buffers are equal in value with strict property checking.
218
+ */
219
+ function areArrayBuffersEqualStrict(a, b, state) {
220
+ return areArrayBuffersEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
221
+ }
177
222
  /**
178
223
  * Whether the arrays are equal in value.
179
224
  */
@@ -196,12 +241,24 @@ function areDataViewsEqual(a, b) {
196
241
  return (a.byteLength === b.byteLength
197
242
  && areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength)));
198
243
  }
244
+ /**
245
+ * Whether the dataviews are equal in value with strict property checking.
246
+ */
247
+ function areDataViewsEqualStrict(a, b, state) {
248
+ return areDataViewsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
249
+ }
199
250
  /**
200
251
  * Whether the dates passed are equal in value.
201
252
  */
202
253
  function areDatesEqual(a, b) {
203
254
  return sameValueEqual(a.getTime(), b.getTime());
204
255
  }
256
+ /**
257
+ * Whether the dates passed are equal in value with strict property checking.
258
+ */
259
+ function areDatesEqualStrict(a, b, state) {
260
+ return areDatesEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
261
+ }
205
262
  /**
206
263
  * Whether the errors passed are equal in value.
207
264
  *
@@ -319,6 +376,16 @@ function areMapsEqual(a, b, state) {
319
376
  }
320
377
  return true;
321
378
  }
379
+ /**
380
+ * Whether the `Map`s are equal in value with strict property checking.
381
+ *
382
+ * @note
383
+ * The entries can be circular, so this is wrapped with `createIsCircular` in circular mode like
384
+ * other containers, and the own properties are compared without additional tracking.
385
+ */
386
+ function areMapsEqualStrict(a, b, state) {
387
+ return areMapsEqual(a, b, state) && areObjectsEqualStrict(a, b, state);
388
+ }
322
389
  /**
323
390
  * Whether the objects are equal in value.
324
391
  */
@@ -366,12 +433,57 @@ function areObjectsEqualStrict(a, b, state) {
366
433
  function arePrimitiveWrappersEqual(a, b) {
367
434
  return sameValueEqual(a.valueOf(), b.valueOf());
368
435
  }
436
+ /**
437
+ * Whether the primitive wrappers passed are equal in value with strict property checking.
438
+ *
439
+ * @note
440
+ * A `String` wrapper's characters are own index properties, listed first and in order, followed
441
+ * by `length`. They are covered by the value comparison, so they are skipped, but only when the
442
+ * value comes from the native `valueOf`. Otherwise (overridden or cross-realm `valueOf`) the value
443
+ * may not reflect the characters, so they are compared as properties.
444
+ */
445
+ function arePrimitiveWrappersEqualStrict(a, b, state) {
446
+ const value = a.valueOf();
447
+ if (!sameValueEqual(value, b.valueOf())) {
448
+ return false;
449
+ }
450
+ // `length` follows the characters, so a native `String` wrapper without other own properties has one more.
451
+ return typeof value === 'string' && a.valueOf === stringValueOf && b.valueOf === stringValueOf
452
+ ? areOwnPropertiesEqualStrict(a, b, state, value.length, value.length + 1)
453
+ : areOwnPropertiesEqualStrict(a, b, state, 0, 0);
454
+ }
369
455
  /**
370
456
  * Whether the regexps passed are equal in value.
371
457
  */
372
458
  function areRegExpsEqual(a, b) {
373
459
  return a.source === b.source && a.flags === b.flags;
374
460
  }
461
+ /**
462
+ * Whether the regexps passed are equal in value with strict property checking.
463
+ *
464
+ * @note
465
+ * `lastIndex` is an own property that every regexp has, and usually the only one. It is compared
466
+ * directly so that the common case avoids the full property comparison. If it differs in identity or
467
+ * writability, or there are other own properties, every own property is compared (including
468
+ * `lastIndex`, since index properties may be listed before it).
469
+ */
470
+ function areRegExpsEqualStrict(a, b, state) {
471
+ if (!areRegExpsEqual(a, b)) {
472
+ return false;
473
+ }
474
+ // Environments that predate (or polyfill around) `lastIndex` being an own property may not have
475
+ // it, in which case there is nothing to shortcut and every own property is compared.
476
+ const descriptorA = getOwnPropertyDescriptor(a, 'lastIndex');
477
+ const descriptorB = getOwnPropertyDescriptor(b, 'lastIndex');
478
+ return areOwnPropertiesEqualStrict(a, b, state, 0, descriptorA
479
+ && descriptorB
480
+ && a.lastIndex === b.lastIndex
481
+ && descriptorA.configurable === descriptorB.configurable
482
+ && descriptorA.enumerable === descriptorB.enumerable
483
+ && descriptorA.writable === descriptorB.writable
484
+ ? 1
485
+ : 0);
486
+ }
375
487
  /**
376
488
  * Whether the search params passed are equal in value.
377
489
  *
@@ -380,13 +492,19 @@ function areRegExpsEqual(a, b) {
380
492
  * compared. Repeated keys are, so this is a comparison of multisets rather than of sets:
381
493
  * `a=1&a=2` is equal to `a=2&a=1`, but not to `a=1&a=1`.
382
494
  */
383
- function areSearchParamsEqual(a, b) {
495
+ function areUrlSearchParamsEqual(a, b) {
384
496
  const serializedA = a.toString();
385
497
  const serializedB = b.toString();
386
498
  // Identical serializations are equal under any ordering, and this is by far the common case, so
387
499
  // it is worth checking before sorting anything.
388
500
  return serializedA === serializedB || sortSearchParams(serializedA) === sortSearchParams(serializedB);
389
501
  }
502
+ /**
503
+ * Whether the search params passed are equal in value with strict property checking.
504
+ */
505
+ function areUrlSearchParamsEqualStrict(a, b, state) {
506
+ return areUrlSearchParamsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
507
+ }
390
508
  /**
391
509
  * Whether the `Set`s are equal in value.
392
510
  */
@@ -428,12 +546,25 @@ function areSetsEqual(a, b, state) {
428
546
  }
429
547
  return true;
430
548
  }
549
+ /**
550
+ * Whether the `Set`s are equal in value with strict property checking.
551
+ *
552
+ * @note
553
+ * See `areMapsEqualStrict` for why the own properties are compared without additional tracking.
554
+ */
555
+ function areSetsEqualStrict(a, b, state) {
556
+ return areSetsEqual(a, b, state) && areObjectsEqualStrict(a, b, state);
557
+ }
431
558
  /**
432
559
  * Whether the TypedArray instances are equal in value.
433
560
  */
434
561
  function areTypedArraysEqual(a, b) {
435
562
  let index = a.length;
436
- if (b.length !== index || a.byteOffset !== b.byteOffset) {
563
+ // `byteOffset` is where the view starts in its buffer, not part of its value: two views holding
564
+ // the same elements are equal wherever they sit, the same as `DataView` and `ArrayBuffer`
565
+ // comparisons. Node.js `Buffer`s are views into a shared pool at varying offsets, so checking it
566
+ // would make equal `Buffer`s compare unequal.
567
+ if (b.length !== index) {
437
568
  return false;
438
569
  }
439
570
  // Only float-backed views can hold `NaN`, and the additional check needed to treat it as equal
@@ -466,11 +597,7 @@ function areTypedArraysEqual(a, b) {
466
597
  * (including symbols) are compared with strict property checking.
467
598
  */
468
599
  function areTypedArraysEqualStrict(a, b, state) {
469
- if (!areTypedArraysEqual(a, b)) {
470
- return false;
471
- }
472
- const properties = getStrictProperties(a);
473
- return (getStrictProperties(b).length === properties.length && areStrictPropertiesEqual(a, b, state, properties, a.length));
600
+ return areTypedArraysEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, a.length, a.length);
474
601
  }
475
602
  /**
476
603
  * Whether the URL instances are equal in value.
@@ -488,7 +615,13 @@ function areUrlsEqual(a, b) {
488
615
  && a.host === b.host
489
616
  && a.pathname === b.pathname
490
617
  && a.hash === b.hash
491
- && areSearchParamsEqual(a.searchParams, b.searchParams));
618
+ && areUrlSearchParamsEqual(a.searchParams, b.searchParams));
619
+ }
620
+ /**
621
+ * Whether the URL instances are equal in value with strict property checking.
622
+ */
623
+ function areUrlsEqualStrict(a, b, state) {
624
+ return areUrlsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
492
625
  }
493
626
 
494
627
  const { toString } = Object.prototype;
@@ -613,27 +746,31 @@ function createEqualityComparator(config) {
613
746
  * Create the configuration object used for building comparators.
614
747
  */
615
748
  function createEqualityComparatorConfig({ circular, createCustomConfig, strict, strictNullPrototypeComparison = true, }) {
749
+ // In strict mode, every type compares its own properties in addition to its value, because any
750
+ // object can have properties assigned to it (`date.foo = 'bar'`). For types that hold their value
751
+ // internally (`Date`, `RegExp`, TypedArrays, etc.), only the properties after the intrinsic ones
752
+ // are compared, and circular references among them are tracked by the comparator itself (see
753
+ // `areOwnPropertiesEqualStrict`).
616
754
  let config = {
617
- areArrayBuffersEqual,
755
+ areArrayBuffersEqual: strict ? areArrayBuffersEqualStrict : areArrayBuffersEqual,
618
756
  areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
619
- areDataViewsEqual,
620
- areDatesEqual: strict
621
- ? combineComparators(areDatesEqual, areObjectsEqualStrict)
622
- : areDatesEqual,
757
+ areDataViewsEqual: strict ? areDataViewsEqualStrict : areDataViewsEqual,
758
+ areDatesEqual: strict ? areDatesEqualStrict : areDatesEqual,
623
759
  // `name` / `message` / `stack` / `cause` / `errors` are not enumerable (unless assigned), which is why
624
760
  // errors need a comparator of their own rather than being treated as plain objects. Each variant also
625
761
  // compares the own properties that `Error` subclasses routinely carry (`status`, `code`, ...):
626
762
  // enumerable ones in loose mode, and all of them (via `areObjectsEqualStrict`) in strict mode.
627
763
  areErrorsEqual: strict ? areErrorsEqualStrict : areErrorsEqual,
628
764
  areFunctionsEqual: strictEqual,
629
- areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
765
+ areMapsEqual: strict ? areMapsEqualStrict : areMapsEqual,
630
766
  areNumbersEqual: sameValueEqual,
631
767
  areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
632
- arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
633
- areRegExpsEqual: areRegExpsEqual,
634
- areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
768
+ arePrimitiveWrappersEqual: strict ? arePrimitiveWrappersEqualStrict : arePrimitiveWrappersEqual,
769
+ areRegExpsEqual: strict ? areRegExpsEqualStrict : areRegExpsEqual,
770
+ areSetsEqual: strict ? areSetsEqualStrict : areSetsEqual,
635
771
  areTypedArraysEqual: strict ? areTypedArraysEqualStrict : areTypedArraysEqual,
636
- areUrlsEqual: areUrlsEqual,
772
+ areUrlSearchParamsEqual: strict ? areUrlSearchParamsEqualStrict : areUrlSearchParamsEqual,
773
+ areUrlsEqual: strict ? areUrlsEqualStrict : areUrlsEqual,
637
774
  getUnsupportedCustomComparator: undefined,
638
775
  strictNullPrototypeComparison,
639
776
  };
@@ -641,23 +778,16 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
641
778
  config = Object.assign({}, config, createCustomConfig(config));
642
779
  }
643
780
  if (circular) {
644
- const areArraysEqual = createIsCircular(config.areArraysEqual);
645
- const areDatesEqual = strict ? createIsCircular(config.areDatesEqual) : config.areDatesEqual;
781
+ // Only containers are wrapped, since they always compare nested values. Types that hold their
782
+ // value internally only do so for own properties in strict mode, and track those themselves.
646
783
  // Errors are included because comparing `cause` and own properties by value means an error
647
784
  // that references itself would otherwise recurse without bound.
648
- const areErrorsEqual = createIsCircular(config.areErrorsEqual);
649
- const areMapsEqual = createIsCircular(config.areMapsEqual);
650
- const areObjectsEqual = createIsCircular(config.areObjectsEqual);
651
- const areSetsEqual = createIsCircular(config.areSetsEqual);
652
- const areTypedArraysEqual = strict ? createIsCircular(config.areTypedArraysEqual) : config.areTypedArraysEqual;
653
785
  config = Object.assign({}, config, {
654
- areArraysEqual,
655
- areDatesEqual,
656
- areErrorsEqual,
657
- areMapsEqual,
658
- areObjectsEqual,
659
- areSetsEqual,
660
- areTypedArraysEqual,
786
+ areArraysEqual: createIsCircular(config.areArraysEqual),
787
+ areErrorsEqual: createIsCircular(config.areErrorsEqual),
788
+ areMapsEqual: createIsCircular(config.areMapsEqual),
789
+ areObjectsEqual: createIsCircular(config.areObjectsEqual),
790
+ areSetsEqual: createIsCircular(config.areSetsEqual),
661
791
  });
662
792
  }
663
793
  return config;
@@ -709,7 +839,7 @@ function createIsEqual({ circular, comparator, createState, equals, strict }) {
709
839
  /**
710
840
  * Create a map of `toString()` values to their respective handlers for `tag`-based lookups.
711
841
  */
712
- function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, }) {
842
+ function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlSearchParamsEqual, areUrlsEqual, }) {
713
843
  return {
714
844
  '[object Arguments]': areObjectsEqual,
715
845
  '[object Array]': areArraysEqual,
@@ -745,6 +875,7 @@ function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, ar
745
875
  '[object Set]': areSetsEqual,
746
876
  '[object String]': arePrimitiveWrappersEqual,
747
877
  '[object URL]': areUrlsEqual,
878
+ '[object URLSearchParams]': areUrlSearchParamsEqual,
748
879
  '[object Uint8Array]': areTypedArraysEqual,
749
880
  '[object Uint8ClampedArray]': areTypedArraysEqual,
750
881
  '[object Uint16Array]': areTypedArraysEqual,
@@ -30,7 +30,7 @@ interface State<Meta> {
30
30
  interface ComparatorConfig<Meta> {
31
31
  /**
32
32
  * Whether the array buffers passed are equal in value. In strict mode, this includes
33
- * additional properties added to the array.
33
+ * additional properties added to the array buffer.
34
34
  */
35
35
  areArrayBuffersEqual: EqualityComparator<Meta>;
36
36
  /**
@@ -39,7 +39,8 @@ interface ComparatorConfig<Meta> {
39
39
  */
40
40
  areArraysEqual: EqualityComparator<Meta>;
41
41
  /**
42
- * Whether the data views passed are equal in value.
42
+ * Whether the data views passed are equal in value. In strict mode, this includes
43
+ * additional properties added to the data view.
43
44
  */
44
45
  areDataViewsEqual: EqualityComparator<Meta>;
45
46
  /**
@@ -70,11 +71,13 @@ interface ComparatorConfig<Meta> {
70
71
  */
71
72
  areObjectsEqual: EqualityComparator<Meta>;
72
73
  /**
73
- * Whether the primitive wrappers passed are equal in value.
74
+ * Whether the primitive wrappers passed are equal in value. In strict mode, this includes
75
+ * additional properties added to the wrapper.
74
76
  */
75
77
  arePrimitiveWrappersEqual: EqualityComparator<Meta>;
76
78
  /**
77
- * Whether the regexps passed are equal in value.
79
+ * Whether the regexps passed are equal in value. In strict mode, this includes `lastIndex`
80
+ * and additional properties added to the regexp.
78
81
  */
79
82
  areRegExpsEqual: EqualityComparator<Meta>;
80
83
  /**
@@ -88,7 +91,13 @@ interface ComparatorConfig<Meta> {
88
91
  */
89
92
  areTypedArraysEqual: EqualityComparator<Meta>;
90
93
  /**
91
- * Whether the URLs passed are equal in value.
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>;
98
+ /**
99
+ * Whether the URLs passed are equal in value. In strict mode, this includes
100
+ * additional properties added to the URL.
92
101
  */
93
102
  areUrlsEqual: EqualityComparator<Meta>;
94
103
  /**
@@ -30,7 +30,7 @@ interface State<Meta> {
30
30
  interface ComparatorConfig<Meta> {
31
31
  /**
32
32
  * Whether the array buffers passed are equal in value. In strict mode, this includes
33
- * additional properties added to the array.
33
+ * additional properties added to the array buffer.
34
34
  */
35
35
  areArrayBuffersEqual: EqualityComparator<Meta>;
36
36
  /**
@@ -39,7 +39,8 @@ interface ComparatorConfig<Meta> {
39
39
  */
40
40
  areArraysEqual: EqualityComparator<Meta>;
41
41
  /**
42
- * Whether the data views passed are equal in value.
42
+ * Whether the data views passed are equal in value. In strict mode, this includes
43
+ * additional properties added to the data view.
43
44
  */
44
45
  areDataViewsEqual: EqualityComparator<Meta>;
45
46
  /**
@@ -70,11 +71,13 @@ interface ComparatorConfig<Meta> {
70
71
  */
71
72
  areObjectsEqual: EqualityComparator<Meta>;
72
73
  /**
73
- * Whether the primitive wrappers passed are equal in value.
74
+ * Whether the primitive wrappers passed are equal in value. In strict mode, this includes
75
+ * additional properties added to the wrapper.
74
76
  */
75
77
  arePrimitiveWrappersEqual: EqualityComparator<Meta>;
76
78
  /**
77
- * Whether the regexps passed are equal in value.
79
+ * Whether the regexps passed are equal in value. In strict mode, this includes `lastIndex`
80
+ * and additional properties added to the regexp.
78
81
  */
79
82
  areRegExpsEqual: EqualityComparator<Meta>;
80
83
  /**
@@ -88,7 +91,13 @@ interface ComparatorConfig<Meta> {
88
91
  */
89
92
  areTypedArraysEqual: EqualityComparator<Meta>;
90
93
  /**
91
- * Whether the URLs passed are equal in value.
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>;
98
+ /**
99
+ * Whether the URLs passed are equal in value. In strict mode, this includes
100
+ * additional properties added to the URL.
92
101
  */
93
102
  areUrlsEqual: EqualityComparator<Meta>;
94
103
  /**
package/dist/es/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const { getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols } = Object;
1
+ const { getOwnPropertyDescriptor: getOwnPropertyDescriptor$1, getOwnPropertyNames, getOwnPropertySymbols } = Object;
2
2
  const { hasOwnProperty, toString: toString$1 } = Object.prototype;
3
3
  const OBJECT_TAG = '[object Object]';
4
4
  /**
@@ -20,8 +20,8 @@ function areStrictPropertiesEqual(a, b, state, properties, end) {
20
20
  && (!hasOwn(b, property) || !state.equals(a[property], b[property], property, property, a, b, state))) {
21
21
  return false;
22
22
  }
23
- descriptorA = getOwnPropertyDescriptor(a, property);
24
- descriptorB = getOwnPropertyDescriptor(b, property);
23
+ descriptorA = getOwnPropertyDescriptor$1(a, property);
24
+ descriptorB = getOwnPropertyDescriptor$1(b, property);
25
25
  if ((descriptorA || descriptorB)
26
26
  && (!descriptorA
27
27
  || !descriptorB
@@ -34,12 +34,43 @@ function areStrictPropertiesEqual(a, b, state, properties, end) {
34
34
  return true;
35
35
  }
36
36
  /**
37
- * Combine two comparators into a single comparators.
38
- */
39
- function combineComparators(comparatorA, comparatorB) {
40
- return function isEqual(a, b, state) {
41
- return comparatorA(a, b, state) && comparatorB(a, b, state);
42
- };
37
+ * Whether the own properties of objects whose value is compared by other means (`Date`, `RegExp`,
38
+ * TypedArrays, primitive wrappers, etc.) are equal with strict property checking. Own properties
39
+ * before `start` are intrinsic to the type and already covered by the value comparison, so only the
40
+ * ones after them are compared. When `intrinsic` properties have been compared by the caller but are
41
+ * not guaranteed to be listed first (`RegExp`'s `lastIndex`), objects with only those return early,
42
+ * and otherwise every property from `start` is compared.
43
+ *
44
+ * @note
45
+ * These objects rarely have own properties beyond their intrinsic ones, so that case returns before
46
+ * any circular tracking is done. When they do, the properties can reference the object itself, so
47
+ * the pair is tracked in the cache (when present) here rather than by wrapping the comparator with
48
+ * `createIsCircular`. This keeps the cost of tracking off the common case.
49
+ */
50
+ function areOwnPropertiesEqualStrict(a, b, state, start, intrinsic) {
51
+ const properties = getOwnKeys(a);
52
+ const length = properties.length;
53
+ if (getOwnKeys(b).length !== length) {
54
+ return false;
55
+ }
56
+ if (length === intrinsic) {
57
+ return true;
58
+ }
59
+ const cache = state.cache;
60
+ if (!cache) {
61
+ return areStrictPropertiesEqual(a, b, state, properties, start);
62
+ }
63
+ const cachedA = cache.get(a);
64
+ const cachedB = cache.get(b);
65
+ if (cachedA && cachedB) {
66
+ return cachedA === b && cachedB === a;
67
+ }
68
+ cache.set(a, b);
69
+ cache.set(b, a);
70
+ const result = areStrictPropertiesEqual(a, b, state, properties, start);
71
+ cache.delete(a);
72
+ cache.delete(b);
73
+ return result;
43
74
  }
44
75
  /**
45
76
  * Wrap the provided `areItemsEqual` method to manage the circular state, allowing
@@ -78,7 +109,14 @@ function getStrictProperties(object) {
78
109
  /**
79
110
  * Identify the element type of TypedArrays across realms and subclasses.
80
111
  */
81
- const getTypedArrayTag = getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
112
+ const getTypedArrayTag = getOwnPropertyDescriptor$1(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
113
+ /**
114
+ * Get all own properties of the object, both strings and symbols, in the same order as
115
+ * `getStrictProperties`. `Reflect.ownKeys` is used when available because it is faster for objects
116
+ * like `Date` / `RegExp` / TypedArrays in V8. It is slower for plain objects without symbols, which
117
+ * is why `getStrictProperties` is still used directly for those.
118
+ */
119
+ const getOwnKeys = (typeof Reflect !== 'undefined' && Reflect.ownKeys) || getStrictProperties;
82
120
  /**
83
121
  * Whether the object contains the property passed as an own property.
84
122
  */
@@ -130,8 +168,9 @@ function sortSearchParams(serialized) {
130
168
  * scanning the other object's keys. Measured in V8: scanning wins up to 50 keys and loses from 100.
131
169
  */
132
170
  const MAX_SCANNED_PROPERTIES = 64;
133
- const { keys } = Object;
171
+ const { getOwnPropertyDescriptor, keys } = Object;
134
172
  const { propertyIsEnumerable } = Object.prototype;
173
+ const { valueOf: stringValueOf } = String.prototype;
135
174
  /**
136
175
  * Whether the values passed are equal based on a [SameValue](https://262.ecma-international.org/7.0/#sec-samevalue) basis.
137
176
  * Simplified, this maps to if the two values are referentially equal to one another (`a === b`) or both are `NaN`.
@@ -172,6 +211,12 @@ function strictEqual(a, b) {
172
211
  function areArrayBuffersEqual(a, b) {
173
212
  return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
174
213
  }
214
+ /**
215
+ * Whether the array buffers are equal in value with strict property checking.
216
+ */
217
+ function areArrayBuffersEqualStrict(a, b, state) {
218
+ return areArrayBuffersEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
219
+ }
175
220
  /**
176
221
  * Whether the arrays are equal in value.
177
222
  */
@@ -194,12 +239,24 @@ function areDataViewsEqual(a, b) {
194
239
  return (a.byteLength === b.byteLength
195
240
  && areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength)));
196
241
  }
242
+ /**
243
+ * Whether the dataviews are equal in value with strict property checking.
244
+ */
245
+ function areDataViewsEqualStrict(a, b, state) {
246
+ return areDataViewsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
247
+ }
197
248
  /**
198
249
  * Whether the dates passed are equal in value.
199
250
  */
200
251
  function areDatesEqual(a, b) {
201
252
  return sameValueEqual(a.getTime(), b.getTime());
202
253
  }
254
+ /**
255
+ * Whether the dates passed are equal in value with strict property checking.
256
+ */
257
+ function areDatesEqualStrict(a, b, state) {
258
+ return areDatesEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
259
+ }
203
260
  /**
204
261
  * Whether the errors passed are equal in value.
205
262
  *
@@ -317,6 +374,16 @@ function areMapsEqual(a, b, state) {
317
374
  }
318
375
  return true;
319
376
  }
377
+ /**
378
+ * Whether the `Map`s are equal in value with strict property checking.
379
+ *
380
+ * @note
381
+ * The entries can be circular, so this is wrapped with `createIsCircular` in circular mode like
382
+ * other containers, and the own properties are compared without additional tracking.
383
+ */
384
+ function areMapsEqualStrict(a, b, state) {
385
+ return areMapsEqual(a, b, state) && areObjectsEqualStrict(a, b, state);
386
+ }
320
387
  /**
321
388
  * Whether the objects are equal in value.
322
389
  */
@@ -364,12 +431,57 @@ function areObjectsEqualStrict(a, b, state) {
364
431
  function arePrimitiveWrappersEqual(a, b) {
365
432
  return sameValueEqual(a.valueOf(), b.valueOf());
366
433
  }
434
+ /**
435
+ * Whether the primitive wrappers passed are equal in value with strict property checking.
436
+ *
437
+ * @note
438
+ * A `String` wrapper's characters are own index properties, listed first and in order, followed
439
+ * by `length`. They are covered by the value comparison, so they are skipped, but only when the
440
+ * value comes from the native `valueOf`. Otherwise (overridden or cross-realm `valueOf`) the value
441
+ * may not reflect the characters, so they are compared as properties.
442
+ */
443
+ function arePrimitiveWrappersEqualStrict(a, b, state) {
444
+ const value = a.valueOf();
445
+ if (!sameValueEqual(value, b.valueOf())) {
446
+ return false;
447
+ }
448
+ // `length` follows the characters, so a native `String` wrapper without other own properties has one more.
449
+ return typeof value === 'string' && a.valueOf === stringValueOf && b.valueOf === stringValueOf
450
+ ? areOwnPropertiesEqualStrict(a, b, state, value.length, value.length + 1)
451
+ : areOwnPropertiesEqualStrict(a, b, state, 0, 0);
452
+ }
367
453
  /**
368
454
  * Whether the regexps passed are equal in value.
369
455
  */
370
456
  function areRegExpsEqual(a, b) {
371
457
  return a.source === b.source && a.flags === b.flags;
372
458
  }
459
+ /**
460
+ * Whether the regexps passed are equal in value with strict property checking.
461
+ *
462
+ * @note
463
+ * `lastIndex` is an own property that every regexp has, and usually the only one. It is compared
464
+ * directly so that the common case avoids the full property comparison. If it differs in identity or
465
+ * writability, or there are other own properties, every own property is compared (including
466
+ * `lastIndex`, since index properties may be listed before it).
467
+ */
468
+ function areRegExpsEqualStrict(a, b, state) {
469
+ if (!areRegExpsEqual(a, b)) {
470
+ return false;
471
+ }
472
+ // Environments that predate (or polyfill around) `lastIndex` being an own property may not have
473
+ // it, in which case there is nothing to shortcut and every own property is compared.
474
+ const descriptorA = getOwnPropertyDescriptor(a, 'lastIndex');
475
+ const descriptorB = getOwnPropertyDescriptor(b, 'lastIndex');
476
+ return areOwnPropertiesEqualStrict(a, b, state, 0, descriptorA
477
+ && descriptorB
478
+ && a.lastIndex === b.lastIndex
479
+ && descriptorA.configurable === descriptorB.configurable
480
+ && descriptorA.enumerable === descriptorB.enumerable
481
+ && descriptorA.writable === descriptorB.writable
482
+ ? 1
483
+ : 0);
484
+ }
373
485
  /**
374
486
  * Whether the search params passed are equal in value.
375
487
  *
@@ -378,13 +490,19 @@ function areRegExpsEqual(a, b) {
378
490
  * compared. Repeated keys are, so this is a comparison of multisets rather than of sets:
379
491
  * `a=1&a=2` is equal to `a=2&a=1`, but not to `a=1&a=1`.
380
492
  */
381
- function areSearchParamsEqual(a, b) {
493
+ function areUrlSearchParamsEqual(a, b) {
382
494
  const serializedA = a.toString();
383
495
  const serializedB = b.toString();
384
496
  // Identical serializations are equal under any ordering, and this is by far the common case, so
385
497
  // it is worth checking before sorting anything.
386
498
  return serializedA === serializedB || sortSearchParams(serializedA) === sortSearchParams(serializedB);
387
499
  }
500
+ /**
501
+ * Whether the search params passed are equal in value with strict property checking.
502
+ */
503
+ function areUrlSearchParamsEqualStrict(a, b, state) {
504
+ return areUrlSearchParamsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
505
+ }
388
506
  /**
389
507
  * Whether the `Set`s are equal in value.
390
508
  */
@@ -426,12 +544,25 @@ function areSetsEqual(a, b, state) {
426
544
  }
427
545
  return true;
428
546
  }
547
+ /**
548
+ * Whether the `Set`s are equal in value with strict property checking.
549
+ *
550
+ * @note
551
+ * See `areMapsEqualStrict` for why the own properties are compared without additional tracking.
552
+ */
553
+ function areSetsEqualStrict(a, b, state) {
554
+ return areSetsEqual(a, b, state) && areObjectsEqualStrict(a, b, state);
555
+ }
429
556
  /**
430
557
  * Whether the TypedArray instances are equal in value.
431
558
  */
432
559
  function areTypedArraysEqual(a, b) {
433
560
  let index = a.length;
434
- if (b.length !== index || a.byteOffset !== b.byteOffset) {
561
+ // `byteOffset` is where the view starts in its buffer, not part of its value: two views holding
562
+ // the same elements are equal wherever they sit, the same as `DataView` and `ArrayBuffer`
563
+ // comparisons. Node.js `Buffer`s are views into a shared pool at varying offsets, so checking it
564
+ // would make equal `Buffer`s compare unequal.
565
+ if (b.length !== index) {
435
566
  return false;
436
567
  }
437
568
  // Only float-backed views can hold `NaN`, and the additional check needed to treat it as equal
@@ -464,11 +595,7 @@ function areTypedArraysEqual(a, b) {
464
595
  * (including symbols) are compared with strict property checking.
465
596
  */
466
597
  function areTypedArraysEqualStrict(a, b, state) {
467
- if (!areTypedArraysEqual(a, b)) {
468
- return false;
469
- }
470
- const properties = getStrictProperties(a);
471
- return (getStrictProperties(b).length === properties.length && areStrictPropertiesEqual(a, b, state, properties, a.length));
598
+ return areTypedArraysEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, a.length, a.length);
472
599
  }
473
600
  /**
474
601
  * Whether the URL instances are equal in value.
@@ -486,7 +613,13 @@ function areUrlsEqual(a, b) {
486
613
  && a.host === b.host
487
614
  && a.pathname === b.pathname
488
615
  && a.hash === b.hash
489
- && areSearchParamsEqual(a.searchParams, b.searchParams));
616
+ && areUrlSearchParamsEqual(a.searchParams, b.searchParams));
617
+ }
618
+ /**
619
+ * Whether the URL instances are equal in value with strict property checking.
620
+ */
621
+ function areUrlsEqualStrict(a, b, state) {
622
+ return areUrlsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
490
623
  }
491
624
 
492
625
  const { toString } = Object.prototype;
@@ -611,27 +744,31 @@ function createEqualityComparator(config) {
611
744
  * Create the configuration object used for building comparators.
612
745
  */
613
746
  function createEqualityComparatorConfig({ circular, createCustomConfig, strict, strictNullPrototypeComparison = true, }) {
747
+ // In strict mode, every type compares its own properties in addition to its value, because any
748
+ // object can have properties assigned to it (`date.foo = 'bar'`). For types that hold their value
749
+ // internally (`Date`, `RegExp`, TypedArrays, etc.), only the properties after the intrinsic ones
750
+ // are compared, and circular references among them are tracked by the comparator itself (see
751
+ // `areOwnPropertiesEqualStrict`).
614
752
  let config = {
615
- areArrayBuffersEqual,
753
+ areArrayBuffersEqual: strict ? areArrayBuffersEqualStrict : areArrayBuffersEqual,
616
754
  areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
617
- areDataViewsEqual,
618
- areDatesEqual: strict
619
- ? combineComparators(areDatesEqual, areObjectsEqualStrict)
620
- : areDatesEqual,
755
+ areDataViewsEqual: strict ? areDataViewsEqualStrict : areDataViewsEqual,
756
+ areDatesEqual: strict ? areDatesEqualStrict : areDatesEqual,
621
757
  // `name` / `message` / `stack` / `cause` / `errors` are not enumerable (unless assigned), which is why
622
758
  // errors need a comparator of their own rather than being treated as plain objects. Each variant also
623
759
  // compares the own properties that `Error` subclasses routinely carry (`status`, `code`, ...):
624
760
  // enumerable ones in loose mode, and all of them (via `areObjectsEqualStrict`) in strict mode.
625
761
  areErrorsEqual: strict ? areErrorsEqualStrict : areErrorsEqual,
626
762
  areFunctionsEqual: strictEqual,
627
- areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
763
+ areMapsEqual: strict ? areMapsEqualStrict : areMapsEqual,
628
764
  areNumbersEqual: sameValueEqual,
629
765
  areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
630
- arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
631
- areRegExpsEqual: areRegExpsEqual,
632
- areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
766
+ arePrimitiveWrappersEqual: strict ? arePrimitiveWrappersEqualStrict : arePrimitiveWrappersEqual,
767
+ areRegExpsEqual: strict ? areRegExpsEqualStrict : areRegExpsEqual,
768
+ areSetsEqual: strict ? areSetsEqualStrict : areSetsEqual,
633
769
  areTypedArraysEqual: strict ? areTypedArraysEqualStrict : areTypedArraysEqual,
634
- areUrlsEqual: areUrlsEqual,
770
+ areUrlSearchParamsEqual: strict ? areUrlSearchParamsEqualStrict : areUrlSearchParamsEqual,
771
+ areUrlsEqual: strict ? areUrlsEqualStrict : areUrlsEqual,
635
772
  getUnsupportedCustomComparator: undefined,
636
773
  strictNullPrototypeComparison,
637
774
  };
@@ -639,23 +776,16 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
639
776
  config = Object.assign({}, config, createCustomConfig(config));
640
777
  }
641
778
  if (circular) {
642
- const areArraysEqual = createIsCircular(config.areArraysEqual);
643
- const areDatesEqual = strict ? createIsCircular(config.areDatesEqual) : config.areDatesEqual;
779
+ // Only containers are wrapped, since they always compare nested values. Types that hold their
780
+ // value internally only do so for own properties in strict mode, and track those themselves.
644
781
  // Errors are included because comparing `cause` and own properties by value means an error
645
782
  // that references itself would otherwise recurse without bound.
646
- const areErrorsEqual = createIsCircular(config.areErrorsEqual);
647
- const areMapsEqual = createIsCircular(config.areMapsEqual);
648
- const areObjectsEqual = createIsCircular(config.areObjectsEqual);
649
- const areSetsEqual = createIsCircular(config.areSetsEqual);
650
- const areTypedArraysEqual = strict ? createIsCircular(config.areTypedArraysEqual) : config.areTypedArraysEqual;
651
783
  config = Object.assign({}, config, {
652
- areArraysEqual,
653
- areDatesEqual,
654
- areErrorsEqual,
655
- areMapsEqual,
656
- areObjectsEqual,
657
- areSetsEqual,
658
- areTypedArraysEqual,
784
+ areArraysEqual: createIsCircular(config.areArraysEqual),
785
+ areErrorsEqual: createIsCircular(config.areErrorsEqual),
786
+ areMapsEqual: createIsCircular(config.areMapsEqual),
787
+ areObjectsEqual: createIsCircular(config.areObjectsEqual),
788
+ areSetsEqual: createIsCircular(config.areSetsEqual),
659
789
  });
660
790
  }
661
791
  return config;
@@ -707,7 +837,7 @@ function createIsEqual({ circular, comparator, createState, equals, strict }) {
707
837
  /**
708
838
  * Create a map of `toString()` values to their respective handlers for `tag`-based lookups.
709
839
  */
710
- function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, }) {
840
+ function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlSearchParamsEqual, areUrlsEqual, }) {
711
841
  return {
712
842
  '[object Arguments]': areObjectsEqual,
713
843
  '[object Array]': areArraysEqual,
@@ -743,6 +873,7 @@ function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, ar
743
873
  '[object Set]': areSetsEqual,
744
874
  '[object String]': arePrimitiveWrappersEqual,
745
875
  '[object URL]': areUrlsEqual,
876
+ '[object URLSearchParams]': areUrlSearchParamsEqual,
746
877
  '[object Uint8Array]': areTypedArraysEqual,
747
878
  '[object Uint8ClampedArray]': areTypedArraysEqual,
748
879
  '[object Uint16Array]': areTypedArraysEqual,
package/index.d.ts CHANGED
@@ -30,7 +30,7 @@ interface State<Meta> {
30
30
  interface ComparatorConfig<Meta> {
31
31
  /**
32
32
  * Whether the array buffers passed are equal in value. In strict mode, this includes
33
- * additional properties added to the array.
33
+ * additional properties added to the array buffer.
34
34
  */
35
35
  areArrayBuffersEqual: EqualityComparator<Meta>;
36
36
  /**
@@ -39,7 +39,8 @@ interface ComparatorConfig<Meta> {
39
39
  */
40
40
  areArraysEqual: EqualityComparator<Meta>;
41
41
  /**
42
- * Whether the data views passed are equal in value.
42
+ * Whether the data views passed are equal in value. In strict mode, this includes
43
+ * additional properties added to the data view.
43
44
  */
44
45
  areDataViewsEqual: EqualityComparator<Meta>;
45
46
  /**
@@ -70,11 +71,13 @@ interface ComparatorConfig<Meta> {
70
71
  */
71
72
  areObjectsEqual: EqualityComparator<Meta>;
72
73
  /**
73
- * Whether the primitive wrappers passed are equal in value.
74
+ * Whether the primitive wrappers passed are equal in value. In strict mode, this includes
75
+ * additional properties added to the wrapper.
74
76
  */
75
77
  arePrimitiveWrappersEqual: EqualityComparator<Meta>;
76
78
  /**
77
- * Whether the regexps passed are equal in value.
79
+ * Whether the regexps passed are equal in value. In strict mode, this includes `lastIndex`
80
+ * and additional properties added to the regexp.
78
81
  */
79
82
  areRegExpsEqual: EqualityComparator<Meta>;
80
83
  /**
@@ -88,7 +91,13 @@ interface ComparatorConfig<Meta> {
88
91
  */
89
92
  areTypedArraysEqual: EqualityComparator<Meta>;
90
93
  /**
91
- * Whether the URLs passed are equal in value.
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>;
98
+ /**
99
+ * Whether the URLs passed are equal in value. In strict mode, this includes
100
+ * additional properties added to the URL.
92
101
  */
93
102
  areUrlsEqual: EqualityComparator<Meta>;
94
103
  /**
package/package.json CHANGED
@@ -110,5 +110,5 @@
110
110
  "sideEffects": false,
111
111
  "type": "module",
112
112
  "types": "./index.d.ts",
113
- "version": "6.2.2"
113
+ "version": "6.4.0"
114
114
  }