fast-equals 6.2.1 → 6.3.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
 
@@ -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`, primitive wrappers,
239
+ `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`, primitive wrappers,
271
+ `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`, primitive wrappers,
294
+ `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`, primitive wrappers,
335
+ `ArrayBuffer`, `DataView` and `TypedArray` objects), including `lastIndex` on `RegExp` objects
322
336
 
323
337
  ```ts
324
338
  const array = ['foo'];
@@ -428,8 +442,8 @@ to the problem you are solving, they can offer guidance of how to structure your
428
442
 
429
443
  ## Benchmarks
430
444
 
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:
445
+ All benchmarks were performed on an i9-11900H Manjaro Linux laptop with 64GB of memory using NodeJS version `26.13.0`,
446
+ and are based on averages of running comparisons based deep equality on the following object types:
433
447
 
434
448
  - Primitives (`String`, `Number`, `null`, `undefined`)
435
449
  - `Function`
@@ -445,74 +459,74 @@ Testing mixed objects equal...
445
459
  ┌────────────────────────────────────────┬────────────────┐
446
460
  │ Name │ Ops / sec │
447
461
  ├────────────────────────────────────────┼────────────────┤
448
- │ fast-equals (passed) │ 1763109.81851 │
462
+ │ fast-equals (passed) │ 1731598.023836 │
449
463
  ├────────────────────────────────────────┼────────────────┤
450
- │ fast-deep-equal (passed) │ 1297247.799465 │
464
+ │ fast-deep-equal (passed) │ 1309307.899547 │
451
465
  ├────────────────────────────────────────┼────────────────┤
452
- │ react-fast-compare (passed) │ 1271146.258704 │
466
+ │ react-fast-compare (passed) │ 1292046.683991 │
453
467
  ├────────────────────────────────────────┼────────────────┤
454
- │ shallow-equal-fuzzy (passed) │ 1235115.693854 │
468
+ │ shallow-equal-fuzzy (passed) │ 1226265.458405 │
455
469
  ├────────────────────────────────────────┼────────────────┤
456
- │ nano-equal (failed) │ 964815.367752 │
470
+ │ nano-equal (failed) │ 963157.128972 │
457
471
  ├────────────────────────────────────────┼────────────────┤
458
- │ fast-equals (circular) (passed) │ 834232.686567 │
472
+ │ fast-equals (circular) (passed) │ 909479.445346 │
459
473
  ├────────────────────────────────────────┼────────────────┤
460
- │ dequal (passed) │ 759417.072806 │
474
+ │ dequal/lite (passed) │ 778122.31992 │
461
475
  ├────────────────────────────────────────┼────────────────┤
462
- │ dequal/lite (passed) │ 751901.517376 │
476
+ │ dequal (passed) │ 760245.363659 │
463
477
  ├────────────────────────────────────────┼────────────────┤
464
- │ underscore.isEqual (passed) │ 447789.934941 │
478
+ │ underscore.isEqual (passed) │ 445304.799867 │
465
479
  ├────────────────────────────────────────┼────────────────┤
466
- │ assert.deepStrictEqual (passed) │ 433256.455121 │
480
+ │ assert.deepStrictEqual (passed) │ 438737.156408 │
467
481
  ├────────────────────────────────────────┼────────────────┤
468
- │ es-toolkit (passed) │ 343382.909087 │
482
+ │ es-toolkit (passed) │ 382792.590707 │
469
483
  ├────────────────────────────────────────┼────────────────┤
470
- │ fast-equals (strict) (passed) │ 294211.792998 │
484
+ │ lodash.isEqual (passed) │ 290229.549964 │
471
485
  ├────────────────────────────────────────┼────────────────┤
472
- │ lodash.isEqual (passed) │ 290477.460766 │
486
+ │ fast-equals (strict) (passed) │ 279185.538603 │
473
487
  ├────────────────────────────────────────┼────────────────┤
474
- │ fast-equals (strict circular) (passed) │ 232110.748904 │
488
+ │ fast-equals (strict circular) (passed) │ 238470.634046 │
475
489
  ├────────────────────────────────────────┼────────────────┤
476
- │ deep-eql (passed) │ 161408.4511 │
490
+ │ deep-eql (passed) │ 172670.983717 │
477
491
  ├────────────────────────────────────────┼────────────────┤
478
- │ deep-equal (passed) │ 951.279346 │
492
+ │ deep-equal (passed) │ 1357.008406 │
479
493
  └────────────────────────────────────────┴────────────────┘
480
494
 
481
495
  Testing mixed objects not equal...
482
496
  ┌────────────────────────────────────────┬────────────────┐
483
497
  │ Name │ Ops / sec │
484
498
  ├────────────────────────────────────────┼────────────────┤
485
- │ fast-equals (passed) │ 5402008.064431 │
499
+ │ fast-equals (passed) │ 5076106.125712 │
486
500
  ├────────────────────────────────────────┼────────────────┤
487
- │ fast-equals (circular) (passed) │ 3687783.563818 │
501
+ │ fast-equals (circular) (passed) │ 3544911.437592 │
488
502
  ├────────────────────────────────────────┼────────────────┤
489
- │ fast-deep-equal (passed) │ 3479884.479164 │
503
+ │ fast-deep-equal (passed) │ 3433830.73191 │
490
504
  ├────────────────────────────────────────┼────────────────┤
491
- │ react-fast-compare (passed) │ 3356141.586592 │
505
+ │ react-fast-compare (passed) │ 3246695.251508 │
492
506
  ├────────────────────────────────────────┼────────────────┤
493
- │ fast-equals (strict) (passed) │ 2927133.435788 │
507
+ │ fast-equals (strict) (passed) │ 1584702.069444 │
494
508
  ├────────────────────────────────────────┼────────────────┤
495
- │ fast-equals (strict circular) (passed) │ 1566187.833636 │
509
+ │ dequal/lite (passed) │ 1393178.232807 │
496
510
  ├────────────────────────────────────────┼────────────────┤
497
- │ dequal/lite (passed) │ 1316031.262808 │
511
+ │ dequal (passed) │ 1370661.947753 │
498
512
  ├────────────────────────────────────────┼────────────────┤
499
- │ dequal (passed) │ 1298255.762153 │
513
+ │ fast-equals (strict circular) (passed) │ 1336500.602356 │
500
514
  ├────────────────────────────────────────┼────────────────┤
501
- │ shallow-equal-fuzzy (failed) │ 1219217.578795 │
515
+ │ shallow-equal-fuzzy (failed) │ 1219389.24268 │
502
516
  ├────────────────────────────────────────┼────────────────┤
503
- │ nano-equal (passed) │ 1074115.593615 │
517
+ │ nano-equal (passed) │ 1088061.461684 │
504
518
  ├────────────────────────────────────────┼────────────────┤
505
- │ underscore.isEqual (passed) │ 659016.868085 │
519
+ │ underscore.isEqual (passed) │ 661655.436986 │
506
520
  ├────────────────────────────────────────┼────────────────┤
507
- │ lodash.isEqual (passed) │ 374944.853605 │
521
+ │ es-toolkit (passed) │ 401295.827671 │
508
522
  ├────────────────────────────────────────┼────────────────┤
509
- │ es-toolkit (passed) │ 355882.255615 │
523
+ │ lodash.isEqual (passed) │ 377347.276362 │
510
524
  ├────────────────────────────────────────┼────────────────┤
511
- │ deep-eql (passed) │ 182235.73069 │
525
+ │ deep-eql (passed) │ 199704.751472 │
512
526
  ├────────────────────────────────────────┼────────────────┤
513
- │ assert.deepStrictEqual (passed) │ 20975.582116 │
527
+ │ assert.deepStrictEqual (passed) │ 25504.609914 │
514
528
  ├────────────────────────────────────────┼────────────────┤
515
- │ deep-equal (passed) │ 3760.574487 │
529
+ │ deep-equal (passed) │ 5996.790087 │
516
530
  └────────────────────────────────────────┴────────────────┘
517
531
  ```
518
532
 
@@ -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
  *
@@ -428,12 +540,25 @@ function areSetsEqual(a, b, state) {
428
540
  }
429
541
  return true;
430
542
  }
543
+ /**
544
+ * Whether the `Set`s are equal in value with strict property checking.
545
+ *
546
+ * @note
547
+ * See `areMapsEqualStrict` for why the own properties are compared without additional tracking.
548
+ */
549
+ function areSetsEqualStrict(a, b, state) {
550
+ return areSetsEqual(a, b, state) && areObjectsEqualStrict(a, b, state);
551
+ }
431
552
  /**
432
553
  * Whether the TypedArray instances are equal in value.
433
554
  */
434
555
  function areTypedArraysEqual(a, b) {
435
556
  let index = a.length;
436
- if (b.length !== index || a.byteOffset !== b.byteOffset) {
557
+ // `byteOffset` is where the view starts in its buffer, not part of its value: two views holding
558
+ // the same elements are equal wherever they sit, the same as `DataView` and `ArrayBuffer`
559
+ // comparisons. Node.js `Buffer`s are views into a shared pool at varying offsets, so checking it
560
+ // would make equal `Buffer`s compare unequal.
561
+ if (b.length !== index) {
437
562
  return false;
438
563
  }
439
564
  // Only float-backed views can hold `NaN`, and the additional check needed to treat it as equal
@@ -466,11 +591,7 @@ function areTypedArraysEqual(a, b) {
466
591
  * (including symbols) are compared with strict property checking.
467
592
  */
468
593
  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));
594
+ return areTypedArraysEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, a.length, a.length);
474
595
  }
475
596
  /**
476
597
  * Whether the URL instances are equal in value.
@@ -490,6 +611,12 @@ function areUrlsEqual(a, b) {
490
611
  && a.hash === b.hash
491
612
  && areSearchParamsEqual(a.searchParams, b.searchParams));
492
613
  }
614
+ /**
615
+ * Whether the URL instances are equal in value with strict property checking.
616
+ */
617
+ function areUrlsEqualStrict(a, b, state) {
618
+ return areUrlsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
619
+ }
493
620
 
494
621
  const { toString } = Object.prototype;
495
622
  /**
@@ -613,27 +740,30 @@ function createEqualityComparator(config) {
613
740
  * Create the configuration object used for building comparators.
614
741
  */
615
742
  function createEqualityComparatorConfig({ circular, createCustomConfig, strict, strictNullPrototypeComparison = true, }) {
743
+ // In strict mode, every type compares its own properties in addition to its value, because any
744
+ // object can have properties assigned to it (`date.foo = 'bar'`). For types that hold their value
745
+ // internally (`Date`, `RegExp`, TypedArrays, etc.), only the properties after the intrinsic ones
746
+ // are compared, and circular references among them are tracked by the comparator itself (see
747
+ // `areOwnPropertiesEqualStrict`).
616
748
  let config = {
617
- areArrayBuffersEqual,
749
+ areArrayBuffersEqual: strict ? areArrayBuffersEqualStrict : areArrayBuffersEqual,
618
750
  areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
619
- areDataViewsEqual,
620
- areDatesEqual: strict
621
- ? combineComparators(areDatesEqual, areObjectsEqualStrict)
622
- : areDatesEqual,
751
+ areDataViewsEqual: strict ? areDataViewsEqualStrict : areDataViewsEqual,
752
+ areDatesEqual: strict ? areDatesEqualStrict : areDatesEqual,
623
753
  // `name` / `message` / `stack` / `cause` / `errors` are not enumerable (unless assigned), which is why
624
754
  // errors need a comparator of their own rather than being treated as plain objects. Each variant also
625
755
  // compares the own properties that `Error` subclasses routinely carry (`status`, `code`, ...):
626
756
  // enumerable ones in loose mode, and all of them (via `areObjectsEqualStrict`) in strict mode.
627
757
  areErrorsEqual: strict ? areErrorsEqualStrict : areErrorsEqual,
628
758
  areFunctionsEqual: strictEqual,
629
- areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
759
+ areMapsEqual: strict ? areMapsEqualStrict : areMapsEqual,
630
760
  areNumbersEqual: sameValueEqual,
631
761
  areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
632
- arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
633
- areRegExpsEqual: areRegExpsEqual,
634
- areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
762
+ arePrimitiveWrappersEqual: strict ? arePrimitiveWrappersEqualStrict : arePrimitiveWrappersEqual,
763
+ areRegExpsEqual: strict ? areRegExpsEqualStrict : areRegExpsEqual,
764
+ areSetsEqual: strict ? areSetsEqualStrict : areSetsEqual,
635
765
  areTypedArraysEqual: strict ? areTypedArraysEqualStrict : areTypedArraysEqual,
636
- areUrlsEqual: areUrlsEqual,
766
+ areUrlsEqual: strict ? areUrlsEqualStrict : areUrlsEqual,
637
767
  getUnsupportedCustomComparator: undefined,
638
768
  strictNullPrototypeComparison,
639
769
  };
@@ -641,21 +771,16 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
641
771
  config = Object.assign({}, config, createCustomConfig(config));
642
772
  }
643
773
  if (circular) {
644
- const areArraysEqual = createIsCircular(config.areArraysEqual);
645
- const areDatesEqual = strict ? createIsCircular(config.areDatesEqual) : config.areDatesEqual;
774
+ // Only containers are wrapped, since they always compare nested values. Types that hold their
775
+ // value internally only do so for own properties in strict mode, and track those themselves.
646
776
  // Errors are included because comparing `cause` and own properties by value means an error
647
777
  // 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
778
  config = Object.assign({}, config, {
653
- areArraysEqual,
654
- areDatesEqual,
655
- areErrorsEqual,
656
- areMapsEqual,
657
- areObjectsEqual,
658
- areSetsEqual,
779
+ areArraysEqual: createIsCircular(config.areArraysEqual),
780
+ areErrorsEqual: createIsCircular(config.areErrorsEqual),
781
+ areMapsEqual: createIsCircular(config.areMapsEqual),
782
+ areObjectsEqual: createIsCircular(config.areObjectsEqual),
783
+ areSetsEqual: createIsCircular(config.areSetsEqual),
659
784
  });
660
785
  }
661
786
  return config;
@@ -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,8 @@ interface ComparatorConfig<Meta> {
88
91
  */
89
92
  areTypedArraysEqual: EqualityComparator<Meta>;
90
93
  /**
91
- * Whether the URLs passed are equal in value.
94
+ * Whether the URLs passed are equal in value. In strict mode, this includes
95
+ * additional properties added to the URL.
92
96
  */
93
97
  areUrlsEqual: EqualityComparator<Meta>;
94
98
  /**
@@ -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,8 @@ interface ComparatorConfig<Meta> {
88
91
  */
89
92
  areTypedArraysEqual: EqualityComparator<Meta>;
90
93
  /**
91
- * Whether the URLs passed are equal in value.
94
+ * Whether the URLs passed are equal in value. In strict mode, this includes
95
+ * additional properties added to the URL.
92
96
  */
93
97
  areUrlsEqual: EqualityComparator<Meta>;
94
98
  /**
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
  *
@@ -426,12 +538,25 @@ function areSetsEqual(a, b, state) {
426
538
  }
427
539
  return true;
428
540
  }
541
+ /**
542
+ * Whether the `Set`s are equal in value with strict property checking.
543
+ *
544
+ * @note
545
+ * See `areMapsEqualStrict` for why the own properties are compared without additional tracking.
546
+ */
547
+ function areSetsEqualStrict(a, b, state) {
548
+ return areSetsEqual(a, b, state) && areObjectsEqualStrict(a, b, state);
549
+ }
429
550
  /**
430
551
  * Whether the TypedArray instances are equal in value.
431
552
  */
432
553
  function areTypedArraysEqual(a, b) {
433
554
  let index = a.length;
434
- if (b.length !== index || a.byteOffset !== b.byteOffset) {
555
+ // `byteOffset` is where the view starts in its buffer, not part of its value: two views holding
556
+ // the same elements are equal wherever they sit, the same as `DataView` and `ArrayBuffer`
557
+ // comparisons. Node.js `Buffer`s are views into a shared pool at varying offsets, so checking it
558
+ // would make equal `Buffer`s compare unequal.
559
+ if (b.length !== index) {
435
560
  return false;
436
561
  }
437
562
  // Only float-backed views can hold `NaN`, and the additional check needed to treat it as equal
@@ -464,11 +589,7 @@ function areTypedArraysEqual(a, b) {
464
589
  * (including symbols) are compared with strict property checking.
465
590
  */
466
591
  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));
592
+ return areTypedArraysEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, a.length, a.length);
472
593
  }
473
594
  /**
474
595
  * Whether the URL instances are equal in value.
@@ -488,6 +609,12 @@ function areUrlsEqual(a, b) {
488
609
  && a.hash === b.hash
489
610
  && areSearchParamsEqual(a.searchParams, b.searchParams));
490
611
  }
612
+ /**
613
+ * Whether the URL instances are equal in value with strict property checking.
614
+ */
615
+ function areUrlsEqualStrict(a, b, state) {
616
+ return areUrlsEqual(a, b) && areOwnPropertiesEqualStrict(a, b, state, 0, 0);
617
+ }
491
618
 
492
619
  const { toString } = Object.prototype;
493
620
  /**
@@ -611,27 +738,30 @@ function createEqualityComparator(config) {
611
738
  * Create the configuration object used for building comparators.
612
739
  */
613
740
  function createEqualityComparatorConfig({ circular, createCustomConfig, strict, strictNullPrototypeComparison = true, }) {
741
+ // In strict mode, every type compares its own properties in addition to its value, because any
742
+ // object can have properties assigned to it (`date.foo = 'bar'`). For types that hold their value
743
+ // internally (`Date`, `RegExp`, TypedArrays, etc.), only the properties after the intrinsic ones
744
+ // are compared, and circular references among them are tracked by the comparator itself (see
745
+ // `areOwnPropertiesEqualStrict`).
614
746
  let config = {
615
- areArrayBuffersEqual,
747
+ areArrayBuffersEqual: strict ? areArrayBuffersEqualStrict : areArrayBuffersEqual,
616
748
  areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
617
- areDataViewsEqual,
618
- areDatesEqual: strict
619
- ? combineComparators(areDatesEqual, areObjectsEqualStrict)
620
- : areDatesEqual,
749
+ areDataViewsEqual: strict ? areDataViewsEqualStrict : areDataViewsEqual,
750
+ areDatesEqual: strict ? areDatesEqualStrict : areDatesEqual,
621
751
  // `name` / `message` / `stack` / `cause` / `errors` are not enumerable (unless assigned), which is why
622
752
  // errors need a comparator of their own rather than being treated as plain objects. Each variant also
623
753
  // compares the own properties that `Error` subclasses routinely carry (`status`, `code`, ...):
624
754
  // enumerable ones in loose mode, and all of them (via `areObjectsEqualStrict`) in strict mode.
625
755
  areErrorsEqual: strict ? areErrorsEqualStrict : areErrorsEqual,
626
756
  areFunctionsEqual: strictEqual,
627
- areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
757
+ areMapsEqual: strict ? areMapsEqualStrict : areMapsEqual,
628
758
  areNumbersEqual: sameValueEqual,
629
759
  areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
630
- arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
631
- areRegExpsEqual: areRegExpsEqual,
632
- areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
760
+ arePrimitiveWrappersEqual: strict ? arePrimitiveWrappersEqualStrict : arePrimitiveWrappersEqual,
761
+ areRegExpsEqual: strict ? areRegExpsEqualStrict : areRegExpsEqual,
762
+ areSetsEqual: strict ? areSetsEqualStrict : areSetsEqual,
633
763
  areTypedArraysEqual: strict ? areTypedArraysEqualStrict : areTypedArraysEqual,
634
- areUrlsEqual: areUrlsEqual,
764
+ areUrlsEqual: strict ? areUrlsEqualStrict : areUrlsEqual,
635
765
  getUnsupportedCustomComparator: undefined,
636
766
  strictNullPrototypeComparison,
637
767
  };
@@ -639,21 +769,16 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
639
769
  config = Object.assign({}, config, createCustomConfig(config));
640
770
  }
641
771
  if (circular) {
642
- const areArraysEqual = createIsCircular(config.areArraysEqual);
643
- const areDatesEqual = strict ? createIsCircular(config.areDatesEqual) : config.areDatesEqual;
772
+ // Only containers are wrapped, since they always compare nested values. Types that hold their
773
+ // value internally only do so for own properties in strict mode, and track those themselves.
644
774
  // Errors are included because comparing `cause` and own properties by value means an error
645
775
  // 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
776
  config = Object.assign({}, config, {
651
- areArraysEqual,
652
- areDatesEqual,
653
- areErrorsEqual,
654
- areMapsEqual,
655
- areObjectsEqual,
656
- areSetsEqual,
777
+ areArraysEqual: createIsCircular(config.areArraysEqual),
778
+ areErrorsEqual: createIsCircular(config.areErrorsEqual),
779
+ areMapsEqual: createIsCircular(config.areMapsEqual),
780
+ areObjectsEqual: createIsCircular(config.areObjectsEqual),
781
+ areSetsEqual: createIsCircular(config.areSetsEqual),
657
782
  });
658
783
  }
659
784
  return config;
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,8 @@ interface ComparatorConfig<Meta> {
88
91
  */
89
92
  areTypedArraysEqual: EqualityComparator<Meta>;
90
93
  /**
91
- * Whether the URLs passed are equal in value.
94
+ * Whether the URLs passed are equal in value. In strict mode, this includes
95
+ * additional properties added to the URL.
92
96
  */
93
97
  areUrlsEqual: EqualityComparator<Meta>;
94
98
  /**
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.1"
113
+ "version": "6.3.0"
114
114
  }