fast-equals 6.0.4 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -69
- package/dist/cjs/index.cjs +60 -29
- package/dist/cjs/index.d.cts +12 -0
- package/dist/es/index.d.mts +12 -0
- package/dist/es/index.mjs +60 -29
- package/index.d.ts +12 -0
- package/package.json +1 -1
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.
|
|
4
|
+
various use-cases. It has no dependencies, and is ~2.46kB when minified and gzipped.
|
|
5
5
|
|
|
6
6
|
The following types are handled out-of-the-box:
|
|
7
7
|
|
|
@@ -17,8 +17,8 @@ The following types are handled out-of-the-box:
|
|
|
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
|
|
|
20
|
-
Methods are available for deep, shallow, [`SameValue`](
|
|
21
|
-
[`SameValueZero`](
|
|
20
|
+
Methods are available for deep, shallow, [`SameValue`](https://262.ecma-international.org/7.0/#sec-samevalue),
|
|
21
|
+
[`SameValueZero`](https://262.ecma-international.org/7.0/#sec-samevaluezero), or
|
|
22
22
|
[strict equality](https://262.ecma-international.org/7.0/#sec-strict-equality-comparison) comparison. In addition, you
|
|
23
23
|
can opt into support for circular objects, or performing a "strict" comparison with unconventional property definition,
|
|
24
24
|
or both. You can also customize any specific type comparison based on your application's use-cases.
|
|
@@ -47,6 +47,7 @@ If you are having any problems, want to request a new feature, or have any quest
|
|
|
47
47
|
- [strictCircularDeepEqual](#strictcirculardeepequal)
|
|
48
48
|
- [strictCircularShallowEqual](#strictcircularshallowequal)
|
|
49
49
|
- [createCustomEqual](#createcustomequal)
|
|
50
|
+
- [strictNullPrototypeComparison](#strictnullprototypecomparison)
|
|
50
51
|
- [getUnsupportedCustomComparator](#getunsupportedcustomcomparator)
|
|
51
52
|
- [Recipes](#recipes)
|
|
52
53
|
- [Benchmarks](#benchmarks)
|
|
@@ -79,7 +80,7 @@ console.log(deepEqual(objectA, objectB)); // true
|
|
|
79
80
|
#### Comparing `Map`s
|
|
80
81
|
|
|
81
82
|
`Map` objects support complex keys (objects, Arrays, etc.), however
|
|
82
|
-
[the spec for key lookups in `Map` are based on `
|
|
83
|
+
[the spec for key lookups in `Map` are based on `SameValueZero`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#key_equality).
|
|
83
84
|
If the spec were followed for comparison, the following would always be `false`:
|
|
84
85
|
|
|
85
86
|
```ts
|
|
@@ -113,8 +114,8 @@ console.log(shallowEqual(objectA, objectC)); // false
|
|
|
113
114
|
|
|
114
115
|
### sameValueEqual
|
|
115
116
|
|
|
116
|
-
Performs a [`SameValue`](
|
|
117
|
-
|
|
117
|
+
Performs a [`SameValue`](https://262.ecma-international.org/7.0/#sec-samevalue) comparison on the two objects passed and
|
|
118
|
+
returns a boolean representing the value equivalency of the objects. In simple terms, this means:
|
|
118
119
|
|
|
119
120
|
- `+0` and `-0` are not equal
|
|
120
121
|
- `NaN` is equal to `NaN`
|
|
@@ -140,15 +141,15 @@ _**NOTE**: In environments that support
|
|
|
140
141
|
|
|
141
142
|
### sameValueZeroEqual
|
|
142
143
|
|
|
143
|
-
Performs a [`SameValueZero`](
|
|
144
|
-
|
|
144
|
+
Performs a [`SameValueZero`](https://262.ecma-international.org/7.0/#sec-samevaluezero) comparison on the two objects
|
|
145
|
+
passed and returns a boolean representing the value equivalency of the objects. In simple terms, this means:
|
|
145
146
|
|
|
146
147
|
- `+0` and `-0` are equal
|
|
147
148
|
- `NaN` is equal to `NaN`
|
|
148
149
|
- All other items are based on referential equality (`a === b`)
|
|
149
150
|
|
|
150
151
|
```ts
|
|
151
|
-
import {
|
|
152
|
+
import { sameValueZeroEqual } from 'fast-equals';
|
|
152
153
|
|
|
153
154
|
const mainObject = { foo: NaN, bar: 'baz' };
|
|
154
155
|
|
|
@@ -156,9 +157,9 @@ const objectA = 'baz';
|
|
|
156
157
|
const objectB = NaN;
|
|
157
158
|
const objectC = { foo: NaN, bar: 'baz' };
|
|
158
159
|
|
|
159
|
-
console.log(
|
|
160
|
-
console.log(
|
|
161
|
-
console.log(
|
|
160
|
+
console.log(sameValueZeroEqual(mainObject.bar, objectA)); // true
|
|
161
|
+
console.log(sameValueZeroEqual(mainObject.foo, objectB)); // true
|
|
162
|
+
console.log(sameValueZeroEqual(mainObject, objectC)); // false
|
|
162
163
|
```
|
|
163
164
|
|
|
164
165
|
### strictEqual
|
|
@@ -180,9 +181,9 @@ const objectA = 'baz';
|
|
|
180
181
|
const objectB = NaN;
|
|
181
182
|
const objectC = { foo: NaN, bar: 'baz' };
|
|
182
183
|
|
|
183
|
-
console.log(
|
|
184
|
-
console.log(
|
|
185
|
-
console.log(
|
|
184
|
+
console.log(strictEqual(mainObject.bar, objectA)); // true
|
|
185
|
+
console.log(strictEqual(mainObject.foo, objectB)); // false
|
|
186
|
+
console.log(strictEqual(mainObject, objectC)); // false
|
|
186
187
|
```
|
|
187
188
|
|
|
188
189
|
_**NOTE**: This is mainly a convenience function, such as needing a default functional equality comparator. Naturally,
|
|
@@ -213,7 +214,7 @@ Just as with `deepEqual`, [both keys and values are compared for deep equality](
|
|
|
213
214
|
|
|
214
215
|
### circularShallowEqual
|
|
215
216
|
|
|
216
|
-
Performs the same comparison as `
|
|
217
|
+
Performs the same comparison as `shallowEqual` but supports circular objects. It is slower than `shallowEqual`, so only
|
|
217
218
|
use if you know circular objects are present.
|
|
218
219
|
|
|
219
220
|
```ts
|
|
@@ -227,7 +228,7 @@ console.log(circularShallowEqual(array, [array])); // false
|
|
|
227
228
|
|
|
228
229
|
### strictDeepEqual
|
|
229
230
|
|
|
230
|
-
Performs the same comparison as `deepEqual` but performs a strict comparison of the objects.
|
|
231
|
+
Performs the same comparison as `deepEqual` but performs a strict comparison of the objects. This includes:
|
|
231
232
|
|
|
232
233
|
- Checking symbol properties
|
|
233
234
|
- Checking non-enumerable properties in object comparisons
|
|
@@ -242,13 +243,13 @@ const otherArray = [{ foo: 'bar' }];
|
|
|
242
243
|
array.bar = 'baz';
|
|
243
244
|
otherArray.bar = 'baz';
|
|
244
245
|
|
|
245
|
-
console.log(strictDeepEqual(array, otherArray)); // true
|
|
246
|
-
console.log(strictDeepEqual(array, [{ foo: 'bar' }])); // false
|
|
246
|
+
console.log(strictDeepEqual(array, otherArray)); // true
|
|
247
|
+
console.log(strictDeepEqual(array, [{ foo: 'bar' }])); // false
|
|
247
248
|
```
|
|
248
249
|
|
|
249
250
|
### strictShallowEqual
|
|
250
251
|
|
|
251
|
-
Performs the same comparison as `shallowEqual` but performs a strict comparison of the objects.
|
|
252
|
+
Performs the same comparison as `shallowEqual` but performs a strict comparison of the objects. This includes:
|
|
252
253
|
|
|
253
254
|
- Checking non-enumerable properties in object comparisons
|
|
254
255
|
- Checking full descriptor of properties on the object to match
|
|
@@ -262,13 +263,13 @@ const otherArray = ['foo'];
|
|
|
262
263
|
array.bar = 'baz';
|
|
263
264
|
otherArray.bar = 'baz';
|
|
264
265
|
|
|
265
|
-
console.log(
|
|
266
|
-
console.log(
|
|
266
|
+
console.log(strictShallowEqual(array, otherArray)); // true
|
|
267
|
+
console.log(strictShallowEqual(array, ['foo'])); // false
|
|
267
268
|
```
|
|
268
269
|
|
|
269
270
|
### strictCircularDeepEqual
|
|
270
271
|
|
|
271
|
-
Performs the same comparison as `circularDeepEqual` but performs a strict comparison of the objects.
|
|
272
|
+
Performs the same comparison as `circularDeepEqual` but performs a strict comparison of the objects. This includes:
|
|
272
273
|
|
|
273
274
|
- Checking `Symbol` properties on the object
|
|
274
275
|
- Checking non-enumerable properties in object comparisons
|
|
@@ -302,14 +303,13 @@ Object.defineProperty(second, 'bar', {
|
|
|
302
303
|
value: 'baz',
|
|
303
304
|
});
|
|
304
305
|
|
|
305
|
-
console.log(
|
|
306
|
-
console.log(
|
|
306
|
+
console.log(strictCircularDeepEqual(first, second)); // true
|
|
307
|
+
console.log(strictCircularDeepEqual(first, new Circular('foo'))); // false
|
|
307
308
|
```
|
|
308
309
|
|
|
309
310
|
### strictCircularShallowEqual
|
|
310
311
|
|
|
311
|
-
Performs the same comparison as `circularShallowEqual` but performs a strict comparison of the objects.
|
|
312
|
-
includes:
|
|
312
|
+
Performs the same comparison as `circularShallowEqual` but performs a strict comparison of the objects. This includes:
|
|
313
313
|
|
|
314
314
|
- Checking non-enumerable properties in object comparisons
|
|
315
315
|
- Checking full descriptor of properties on the object to match
|
|
@@ -321,13 +321,13 @@ const array = ['foo'];
|
|
|
321
321
|
const otherArray = ['foo'];
|
|
322
322
|
|
|
323
323
|
array.push(array);
|
|
324
|
-
otherArray.push(
|
|
324
|
+
otherArray.push(array); // Shallow comparison requires the same nested reference.
|
|
325
325
|
|
|
326
326
|
array.bar = 'baz';
|
|
327
327
|
otherArray.bar = 'baz';
|
|
328
328
|
|
|
329
|
-
console.log(
|
|
330
|
-
console.log(
|
|
329
|
+
console.log(strictCircularShallowEqual(array, otherArray)); // true
|
|
330
|
+
console.log(strictCircularShallowEqual(array, ['foo', array])); // false
|
|
331
331
|
```
|
|
332
332
|
|
|
333
333
|
### createCustomEqual
|
|
@@ -360,7 +360,9 @@ interface ComparatorConfig<Meta> {
|
|
|
360
360
|
areSetsEqual: EqualityComparator<Meta>;
|
|
361
361
|
areTypedArraysEqual: EqualityComparator<Meta>;
|
|
362
362
|
areUrlsEqual: EqualityComparator<Meta>;
|
|
363
|
-
getUnsupportedCustomComparator:
|
|
363
|
+
getUnsupportedCustomComparator:
|
|
364
|
+
(<Type>(a: Type, b: Type, state: State<Meta>, tag: string) => EqualityComparator<Meta> | undefined) | undefined;
|
|
365
|
+
strictNullPrototypeComparison?: boolean;
|
|
364
366
|
}
|
|
365
367
|
|
|
366
368
|
function createCustomEqual<Meta>(options: {
|
|
@@ -371,6 +373,7 @@ function createCustomEqual<Meta>(options: {
|
|
|
371
373
|
) => (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
372
374
|
createState?: () => { cache?: Cache; meta?: Meta };
|
|
373
375
|
strict?: boolean;
|
|
376
|
+
strictNullPrototypeComparison?: boolean;
|
|
374
377
|
}): <A, B>(a: A, b: B) => boolean;
|
|
375
378
|
```
|
|
376
379
|
|
|
@@ -383,11 +386,29 @@ _**NOTE**: `Map` implementations compare equality for both keys and value. When
|
|
|
383
386
|
equality of the keys, the iteration index is provided as both `indexOrKeyA` and `indexOrKeyB` to help use-cases where
|
|
384
387
|
ordering of keys matters to equality._
|
|
385
388
|
|
|
389
|
+
#### strictNullPrototypeComparison
|
|
390
|
+
|
|
391
|
+
Defaults to `true`, which keeps a null-prototype object (`Object.create(null)`) unequal to an otherwise identical plain
|
|
392
|
+
object. Set it to `false` to compare the two as dictionaries, for values such as
|
|
393
|
+
[ProseMirror node attributes](https://prosemirror.net/docs/ref/#model.Node.attrs) or `Object.groupBy` results.
|
|
394
|
+
|
|
395
|
+
```ts
|
|
396
|
+
const equal = createCustomEqual({ strictNullPrototypeComparison: false });
|
|
397
|
+
const attrs = Object.assign(Object.create(null), { aspectRatio: 16 / 9 });
|
|
398
|
+
|
|
399
|
+
equal(attrs, { ...attrs }); // true
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
This is the only exception to the constructor check: a null-prototype object remains unequal to arrays, `Map`s, dates,
|
|
403
|
+
and other built-ins, and distinct class constructors remain unequal to each other. It applies to nested values and can
|
|
404
|
+
be combined with `circular`, `strict`, and custom comparators.
|
|
405
|
+
|
|
386
406
|
#### getUnsupportedCustomComparator
|
|
387
407
|
|
|
388
|
-
If you want to compare objects
|
|
389
|
-
|
|
390
|
-
|
|
408
|
+
If you want to compare objects whose tag is not handled out-of-the-box (such as a custom `Symbol.toStringTag` or a
|
|
409
|
+
`WeakMap`), you can provide a `getUnsupportedCustomComparator` method. It receives both values, the comparison state,
|
|
410
|
+
and the tag, and returns the comparator to use for them. Returning `undefined` treats the values as unequal. See
|
|
411
|
+
[this recipe](./recipes/special-objects.md) for an example.
|
|
391
412
|
|
|
392
413
|
#### Recipes
|
|
393
414
|
|
|
@@ -396,16 +417,15 @@ to the problem you are solving, they can offer guidance of how to structure your
|
|
|
396
417
|
|
|
397
418
|
- [Legacy environment support for `RegExp` comparators](./recipes/legacy-regexp-support.md)
|
|
398
419
|
- [Explicit property check](./recipes/explicit-property-check.md)
|
|
399
|
-
- [Using `meta` in comparison](./recipes
|
|
420
|
+
- [Using `meta` in comparison](./recipes/using-meta-in-comparison.md)
|
|
400
421
|
- [Comparing non-standard properties](./recipes/non-standard-properties.md)
|
|
401
|
-
- [Strict property descriptor comparison](./recipes/strict-property-descriptor-check.md)
|
|
402
422
|
- [Legacy environment support for circular equal comparators](./recipes/legacy-circular-equal-support.md)
|
|
403
423
|
- [Custom comparator support](./recipes/special-objects.md)
|
|
404
424
|
|
|
405
425
|
## Benchmarks
|
|
406
426
|
|
|
407
427
|
All benchmarks were performed on an i9-11900H Ubuntu Linux 24.04 laptop with 64GB of memory using NodeJS version
|
|
408
|
-
`24.
|
|
428
|
+
`24.15.0`, and are based on averages of running comparisons based deep equality on the following object types:
|
|
409
429
|
|
|
410
430
|
- Primitives (`String`, `Number`, `null`, `undefined`)
|
|
411
431
|
- `Function`
|
|
@@ -421,74 +441,74 @@ Testing mixed objects equal...
|
|
|
421
441
|
┌────────────────────────────────────────┬────────────────┐
|
|
422
442
|
│ Name │ Ops / sec │
|
|
423
443
|
├────────────────────────────────────────┼────────────────┤
|
|
424
|
-
│ fast-equals (passed) │
|
|
444
|
+
│ fast-equals (passed) │ 1522774.1567 │
|
|
425
445
|
├────────────────────────────────────────┼────────────────┤
|
|
426
|
-
│ fast-
|
|
446
|
+
│ react-fast-compare (passed) │ 1285289.880042 │
|
|
427
447
|
├────────────────────────────────────────┼────────────────┤
|
|
428
|
-
│
|
|
448
|
+
│ fast-deep-equal (passed) │ 1285105.414715 │
|
|
429
449
|
├────────────────────────────────────────┼────────────────┤
|
|
430
|
-
│ shallow-equal-fuzzy (passed) │
|
|
450
|
+
│ shallow-equal-fuzzy (passed) │ 1248325.039481 │
|
|
431
451
|
├────────────────────────────────────────┼────────────────┤
|
|
432
|
-
│ nano-equal (failed) │
|
|
452
|
+
│ nano-equal (failed) │ 962152.688616 │
|
|
433
453
|
├────────────────────────────────────────┼────────────────┤
|
|
434
|
-
│ fast-equals (circular) (passed) │
|
|
454
|
+
│ fast-equals (circular) (passed) │ 800100.693495 │
|
|
435
455
|
├────────────────────────────────────────┼────────────────┤
|
|
436
|
-
│ dequal/lite (passed) │
|
|
456
|
+
│ dequal/lite (passed) │ 778011.650869 │
|
|
437
457
|
├────────────────────────────────────────┼────────────────┤
|
|
438
|
-
│ dequal (passed) │
|
|
458
|
+
│ dequal (passed) │ 770187.208947 │
|
|
439
459
|
├────────────────────────────────────────┼────────────────┤
|
|
440
|
-
│ underscore.isEqual (passed) │
|
|
460
|
+
│ underscore.isEqual (passed) │ 449433.41171 │
|
|
441
461
|
├────────────────────────────────────────┼────────────────┤
|
|
442
|
-
│ assert.deepStrictEqual (passed) │
|
|
462
|
+
│ assert.deepStrictEqual (passed) │ 442249.829162 │
|
|
443
463
|
├────────────────────────────────────────┼────────────────┤
|
|
444
|
-
│ es-toolkit (passed) │
|
|
464
|
+
│ es-toolkit (passed) │ 355943.82757 │
|
|
445
465
|
├────────────────────────────────────────┼────────────────┤
|
|
446
|
-
│ fast-equals (strict) (passed) │
|
|
466
|
+
│ fast-equals (strict) (passed) │ 307931.96677 │
|
|
447
467
|
├────────────────────────────────────────┼────────────────┤
|
|
448
|
-
│ lodash.isEqual (passed) │
|
|
468
|
+
│ lodash.isEqual (passed) │ 294660.269815 │
|
|
449
469
|
├────────────────────────────────────────┼────────────────┤
|
|
450
|
-
│ fast-equals (strict circular) (passed) │
|
|
470
|
+
│ fast-equals (strict circular) (passed) │ 252760.794458 │
|
|
451
471
|
├────────────────────────────────────────┼────────────────┤
|
|
452
|
-
│ deep-eql (passed) │
|
|
472
|
+
│ deep-eql (passed) │ 166131.383227 │
|
|
453
473
|
├────────────────────────────────────────┼────────────────┤
|
|
454
|
-
│ deep-equal (passed) │
|
|
474
|
+
│ deep-equal (passed) │ 970.944208 │
|
|
455
475
|
└────────────────────────────────────────┴────────────────┘
|
|
456
476
|
|
|
457
477
|
Testing mixed objects not equal...
|
|
458
478
|
┌────────────────────────────────────────┬────────────────┐
|
|
459
479
|
│ Name │ Ops / sec │
|
|
460
480
|
├────────────────────────────────────────┼────────────────┤
|
|
461
|
-
│ fast-equals (passed) │
|
|
481
|
+
│ fast-equals (passed) │ 5122472.769802 │
|
|
462
482
|
├────────────────────────────────────────┼────────────────┤
|
|
463
|
-
│ fast-
|
|
483
|
+
│ fast-deep-equal (passed) │ 3520297.242957 │
|
|
464
484
|
├────────────────────────────────────────┼────────────────┤
|
|
465
|
-
│ fast-
|
|
485
|
+
│ fast-equals (circular) (passed) │ 3485912.9348 │
|
|
466
486
|
├────────────────────────────────────────┼────────────────┤
|
|
467
|
-
│ react-fast-compare (passed) │
|
|
487
|
+
│ react-fast-compare (passed) │ 3414203.488651 │
|
|
468
488
|
├────────────────────────────────────────┼────────────────┤
|
|
469
|
-
│ fast-equals (strict) (passed) │
|
|
489
|
+
│ fast-equals (strict) (passed) │ 3038182.032793 │
|
|
470
490
|
├────────────────────────────────────────┼────────────────┤
|
|
471
|
-
│ fast-equals (strict circular) (passed) │
|
|
491
|
+
│ fast-equals (strict circular) (passed) │ 2344879.08551 │
|
|
472
492
|
├────────────────────────────────────────┼────────────────┤
|
|
473
|
-
│ dequal/lite (passed) │
|
|
493
|
+
│ dequal/lite (passed) │ 1340883.333611 │
|
|
474
494
|
├────────────────────────────────────────┼────────────────┤
|
|
475
|
-
│ dequal (passed) │
|
|
495
|
+
│ dequal (passed) │ 1311832.728093 │
|
|
476
496
|
├────────────────────────────────────────┼────────────────┤
|
|
477
|
-
│ shallow-equal-fuzzy (failed) │
|
|
497
|
+
│ shallow-equal-fuzzy (failed) │ 1249967.301358 │
|
|
478
498
|
├────────────────────────────────────────┼────────────────┤
|
|
479
|
-
│ nano-equal (passed) │
|
|
499
|
+
│ nano-equal (passed) │ 1096529.56672 │
|
|
480
500
|
├────────────────────────────────────────┼────────────────┤
|
|
481
|
-
│ underscore.isEqual (passed) │
|
|
501
|
+
│ underscore.isEqual (passed) │ 660524.165237 │
|
|
482
502
|
├────────────────────────────────────────┼────────────────┤
|
|
483
|
-
│ lodash.isEqual (passed) │
|
|
503
|
+
│ lodash.isEqual (passed) │ 385500.174796 │
|
|
484
504
|
├────────────────────────────────────────┼────────────────┤
|
|
485
|
-
│ es-toolkit (passed) │
|
|
505
|
+
│ es-toolkit (passed) │ 365617.977684 │
|
|
486
506
|
├────────────────────────────────────────┼────────────────┤
|
|
487
|
-
│ deep-eql (passed) │
|
|
507
|
+
│ deep-eql (passed) │ 186388.440331 │
|
|
488
508
|
├────────────────────────────────────────┼────────────────┤
|
|
489
|
-
│ assert.deepStrictEqual (passed) │
|
|
509
|
+
│ assert.deepStrictEqual (passed) │ 21060.162935 │
|
|
490
510
|
├────────────────────────────────────────┼────────────────┤
|
|
491
|
-
│ deep-equal (passed) │
|
|
511
|
+
│ deep-equal (passed) │ 3819.218852 │
|
|
492
512
|
└────────────────────────────────────────┴────────────────┘
|
|
493
513
|
```
|
|
494
514
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { getOwnPropertyNames, getOwnPropertySymbols } = Object;
|
|
4
|
-
const { hasOwnProperty } = Object.prototype;
|
|
4
|
+
const { hasOwnProperty, toString: toString$1 } = Object.prototype;
|
|
5
|
+
const OBJECT_TAG = '[object Object]';
|
|
5
6
|
/**
|
|
6
7
|
* Combine two comparators into a single comparators.
|
|
7
8
|
*/
|
|
@@ -50,14 +51,31 @@ function getStrictProperties(object) {
|
|
|
50
51
|
const hasOwn =
|
|
51
52
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
52
53
|
Object.hasOwn || ((object, property) => hasOwnProperty.call(object, property));
|
|
54
|
+
/**
|
|
55
|
+
* Whether a null-prototype object is being compared with a plain object. Only one side can be
|
|
56
|
+
* null-prototype when the constructors differ. The other side must be a plain object by
|
|
57
|
+
* constructor, or by tag when it comes from another realm.
|
|
58
|
+
*/
|
|
59
|
+
function isNullPrototypeComparable(a, b) {
|
|
60
|
+
const aConstructor = a.constructor;
|
|
61
|
+
const bConstructor = b.constructor;
|
|
62
|
+
if (aConstructor == null) {
|
|
63
|
+
return bConstructor === Object || toString$1.call(b) === OBJECT_TAG;
|
|
64
|
+
}
|
|
65
|
+
if (bConstructor == null) {
|
|
66
|
+
return aConstructor === Object || toString$1.call(a) === OBJECT_TAG;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
53
70
|
|
|
54
71
|
const PREACT_VNODE = '__v';
|
|
55
72
|
const PREACT_OWNER = '__o';
|
|
56
73
|
const REACT_OWNER = '_owner';
|
|
57
|
-
// `Float16Array` is recent enough that it cannot be referenced unguarded, and capturing its
|
|
58
|
-
// availability once keeps that detail out of the comparison itself.
|
|
59
|
-
const HAS_FLOAT_16_ARRAY = typeof Float16Array !== 'undefined';
|
|
60
74
|
const { getOwnPropertyDescriptor, keys } = Object;
|
|
75
|
+
/**
|
|
76
|
+
* Identify the element type of TypedArrays across realms and subclasses.
|
|
77
|
+
*/
|
|
78
|
+
const getTypedArrayTag = getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
|
|
61
79
|
/**
|
|
62
80
|
* Whether the values passed are equal based on a [SameValue](https://262.ecma-international.org/7.0/#sec-samevalue) basis.
|
|
63
81
|
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`) or both are `NaN`.
|
|
@@ -309,7 +327,8 @@ function areTypedArraysEqual(a, b) {
|
|
|
309
327
|
// Only float-backed views can hold `NaN`, and the additional check needed to treat it as equal
|
|
310
328
|
// to itself measurably slows the loop, so integer views keep the plain comparison. This is
|
|
311
329
|
// hoisted out of the loop so the cost is paid once per call rather than once per element.
|
|
312
|
-
|
|
330
|
+
const tag = getTypedArrayTag.call(a);
|
|
331
|
+
if (tag === 'Float64Array' || tag === 'Float32Array' || tag === 'Float16Array') {
|
|
313
332
|
while (index-- > 0) {
|
|
314
333
|
// `NaN` is the only value not equal to itself, and it is treated as equal here to match
|
|
315
334
|
// the SameValueZero semantics used for every other numeric comparison in the library.
|
|
@@ -378,13 +397,42 @@ function isPropertyEqual(a, b, state, property) {
|
|
|
378
397
|
return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
|
|
379
398
|
}
|
|
380
399
|
|
|
381
|
-
const toString = Object.prototype
|
|
400
|
+
const { toString } = Object.prototype;
|
|
382
401
|
/**
|
|
383
402
|
* Create a comparator method based on the type-specific equality comparators passed.
|
|
384
403
|
*/
|
|
385
404
|
function createEqualityComparator(config) {
|
|
386
405
|
const supportedComparatorMap = createSupportedComparatorMap(config);
|
|
387
|
-
const { areArraysEqual, areDatesEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, areRegExpsEqual, areSetsEqual, getUnsupportedCustomComparator, } = config;
|
|
406
|
+
const { areArraysEqual, areDatesEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, areRegExpsEqual, areSetsEqual, getUnsupportedCustomComparator, strictNullPrototypeComparison, } = config;
|
|
407
|
+
/**
|
|
408
|
+
* Whether the custom objects are equal in value, based on their string tag. If not matching any tags
|
|
409
|
+
* that require a specific type of comparison, then we hard-code false because the only thing remaining
|
|
410
|
+
* is strict equality, which has already been compared. This is for a few reasons:
|
|
411
|
+
* - Certain types that cannot be introspected (e.g., `WeakMap`). For these types, this is the only
|
|
412
|
+
* comparison that can be made.
|
|
413
|
+
* - For types that can be introspected but do not have an objective definition of what
|
|
414
|
+
* equality is (`Error`, etc.), the subjective decision is to be conservative and strictly compare.
|
|
415
|
+
* In all cases, these decisions should be reevaluated based on changes to the language and
|
|
416
|
+
* common development practices.
|
|
417
|
+
*
|
|
418
|
+
* Capturing the tag is reasonably performant in modern environments like v8 and SpiderMonkey. This is
|
|
419
|
+
* kept out of the main comparator so that it stays within the engine's bytecode budget for inlining.
|
|
420
|
+
* See [#207](https://github.com/planttheidea/fast-equals/pull/207) for more details.
|
|
421
|
+
*/
|
|
422
|
+
const areTaggedObjectsEqual = getUnsupportedCustomComparator
|
|
423
|
+
? function areTaggedObjectsEqual(a, b, state) {
|
|
424
|
+
const tag = toString.call(a);
|
|
425
|
+
const supportedComparator = supportedComparatorMap[tag];
|
|
426
|
+
if (supportedComparator) {
|
|
427
|
+
return supportedComparator(a, b, state);
|
|
428
|
+
}
|
|
429
|
+
const unsupportedCustomComparator = getUnsupportedCustomComparator(a, b, state, tag);
|
|
430
|
+
return unsupportedCustomComparator ? unsupportedCustomComparator(a, b, state) : false;
|
|
431
|
+
}
|
|
432
|
+
: function areTaggedObjectsEqual(a, b, state) {
|
|
433
|
+
const supportedComparator = supportedComparatorMap[toString.call(a)];
|
|
434
|
+
return supportedComparator ? supportedComparator(a, b, state) : false;
|
|
435
|
+
};
|
|
388
436
|
/**
|
|
389
437
|
* compare the value of the two objects and return true if they are equivalent in values
|
|
390
438
|
*/
|
|
@@ -424,7 +472,7 @@ function createEqualityComparator(config) {
|
|
|
424
472
|
// Constructors should match, otherwise there is potential for false positives
|
|
425
473
|
// between class and subclass or custom object and POJO.
|
|
426
474
|
if (constructor !== b.constructor) {
|
|
427
|
-
return false;
|
|
475
|
+
return strictNullPrototypeComparison ? false : isNullPrototypeComparable(a, b) && areObjectsEqual(a, b, state);
|
|
428
476
|
}
|
|
429
477
|
// Try to fast-path equality checks for other complex object types in the
|
|
430
478
|
// same realm to avoid capturing the string tag. Strict equality is used
|
|
@@ -463,32 +511,14 @@ function createEqualityComparator(config) {
|
|
|
463
511
|
if (Array.isArray(a)) {
|
|
464
512
|
return areArraysEqual(a, b, state);
|
|
465
513
|
}
|
|
466
|
-
// Since this is a custom object,
|
|
467
|
-
|
|
468
|
-
const tag = toString.call(a);
|
|
469
|
-
const supportedComparator = supportedComparatorMap[tag];
|
|
470
|
-
if (supportedComparator) {
|
|
471
|
-
return supportedComparator(a, b, state);
|
|
472
|
-
}
|
|
473
|
-
const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, state, tag);
|
|
474
|
-
if (unsupportedCustomComparator) {
|
|
475
|
-
return unsupportedCustomComparator(a, b, state);
|
|
476
|
-
}
|
|
477
|
-
// If not matching any tags that require a specific type of comparison, then we hard-code false because
|
|
478
|
-
// the only thing remaining is strict equality, which has already been compared. This is for a few reasons:
|
|
479
|
-
// - Certain types that cannot be introspected (e.g., `WeakMap`). For these types, this is the only
|
|
480
|
-
// comparison that can be made.
|
|
481
|
-
// - For types that can be introspected but do not have an objective definition of what
|
|
482
|
-
// equality is (`Error`, etc.), the subjective decision is to be conservative and strictly compare.
|
|
483
|
-
// In all cases, these decisions should be reevaluated based on changes to the language and
|
|
484
|
-
// common development practices.
|
|
485
|
-
return false;
|
|
514
|
+
// Since this is a custom object, use the string tag to determine its type.
|
|
515
|
+
return areTaggedObjectsEqual(a, b, state);
|
|
486
516
|
};
|
|
487
517
|
}
|
|
488
518
|
/**
|
|
489
519
|
* Create the configuration object used for building comparators.
|
|
490
520
|
*/
|
|
491
|
-
function createEqualityComparatorConfig({ circular, createCustomConfig, strict, }) {
|
|
521
|
+
function createEqualityComparatorConfig({ circular, createCustomConfig, strict, strictNullPrototypeComparison = true, }) {
|
|
492
522
|
let config = {
|
|
493
523
|
areArrayBuffersEqual,
|
|
494
524
|
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
@@ -513,6 +543,7 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
513
543
|
: areTypedArraysEqual,
|
|
514
544
|
areUrlsEqual: areUrlsEqual,
|
|
515
545
|
getUnsupportedCustomComparator: undefined,
|
|
546
|
+
strictNullPrototypeComparison,
|
|
516
547
|
};
|
|
517
548
|
if (createCustomConfig) {
|
|
518
549
|
config = Object.assign({}, config, createCustomConfig(config));
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -94,6 +94,12 @@ interface ComparatorConfig<Meta> {
|
|
|
94
94
|
* Get a custom comparator based on the objects passed.
|
|
95
95
|
*/
|
|
96
96
|
getUnsupportedCustomComparator: ((a: any, b: any, state: State<Meta>, tag: string) => EqualityComparator<Meta> | undefined) | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Whether a null-prototype object (`Object.create(null)`) is unequal to an otherwise identical
|
|
99
|
+
* plain object. Defaults to `true`; when `false`, the two are compared as dictionaries.
|
|
100
|
+
* Constructor checks for all other types are unaffected.
|
|
101
|
+
*/
|
|
102
|
+
strictNullPrototypeComparison?: boolean;
|
|
97
103
|
}
|
|
98
104
|
type EqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
99
105
|
type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
@@ -138,6 +144,12 @@ interface CustomEqualCreatorOptions<Meta> {
|
|
|
138
144
|
* with equal shape of descriptors.
|
|
139
145
|
*/
|
|
140
146
|
strict?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Whether a null-prototype object (`Object.create(null)`) is unequal to an otherwise identical
|
|
149
|
+
* plain object. Defaults to `true`; when `false`, the two are compared as dictionaries.
|
|
150
|
+
* Constructor checks for all other types are unaffected.
|
|
151
|
+
*/
|
|
152
|
+
strictNullPrototypeComparison?: boolean;
|
|
141
153
|
}
|
|
142
154
|
|
|
143
155
|
/**
|
package/dist/es/index.d.mts
CHANGED
|
@@ -94,6 +94,12 @@ interface ComparatorConfig<Meta> {
|
|
|
94
94
|
* Get a custom comparator based on the objects passed.
|
|
95
95
|
*/
|
|
96
96
|
getUnsupportedCustomComparator: ((a: any, b: any, state: State<Meta>, tag: string) => EqualityComparator<Meta> | undefined) | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Whether a null-prototype object (`Object.create(null)`) is unequal to an otherwise identical
|
|
99
|
+
* plain object. Defaults to `true`; when `false`, the two are compared as dictionaries.
|
|
100
|
+
* Constructor checks for all other types are unaffected.
|
|
101
|
+
*/
|
|
102
|
+
strictNullPrototypeComparison?: boolean;
|
|
97
103
|
}
|
|
98
104
|
type EqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
99
105
|
type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
@@ -138,6 +144,12 @@ interface CustomEqualCreatorOptions<Meta> {
|
|
|
138
144
|
* with equal shape of descriptors.
|
|
139
145
|
*/
|
|
140
146
|
strict?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Whether a null-prototype object (`Object.create(null)`) is unequal to an otherwise identical
|
|
149
|
+
* plain object. Defaults to `true`; when `false`, the two are compared as dictionaries.
|
|
150
|
+
* Constructor checks for all other types are unaffected.
|
|
151
|
+
*/
|
|
152
|
+
strictNullPrototypeComparison?: boolean;
|
|
141
153
|
}
|
|
142
154
|
|
|
143
155
|
/**
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { getOwnPropertyNames, getOwnPropertySymbols } = Object;
|
|
2
|
-
const { hasOwnProperty } = Object.prototype;
|
|
2
|
+
const { hasOwnProperty, toString: toString$1 } = Object.prototype;
|
|
3
|
+
const OBJECT_TAG = '[object Object]';
|
|
3
4
|
/**
|
|
4
5
|
* Combine two comparators into a single comparators.
|
|
5
6
|
*/
|
|
@@ -48,14 +49,31 @@ function getStrictProperties(object) {
|
|
|
48
49
|
const hasOwn =
|
|
49
50
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
50
51
|
Object.hasOwn || ((object, property) => hasOwnProperty.call(object, property));
|
|
52
|
+
/**
|
|
53
|
+
* Whether a null-prototype object is being compared with a plain object. Only one side can be
|
|
54
|
+
* null-prototype when the constructors differ. The other side must be a plain object by
|
|
55
|
+
* constructor, or by tag when it comes from another realm.
|
|
56
|
+
*/
|
|
57
|
+
function isNullPrototypeComparable(a, b) {
|
|
58
|
+
const aConstructor = a.constructor;
|
|
59
|
+
const bConstructor = b.constructor;
|
|
60
|
+
if (aConstructor == null) {
|
|
61
|
+
return bConstructor === Object || toString$1.call(b) === OBJECT_TAG;
|
|
62
|
+
}
|
|
63
|
+
if (bConstructor == null) {
|
|
64
|
+
return aConstructor === Object || toString$1.call(a) === OBJECT_TAG;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
51
68
|
|
|
52
69
|
const PREACT_VNODE = '__v';
|
|
53
70
|
const PREACT_OWNER = '__o';
|
|
54
71
|
const REACT_OWNER = '_owner';
|
|
55
|
-
// `Float16Array` is recent enough that it cannot be referenced unguarded, and capturing its
|
|
56
|
-
// availability once keeps that detail out of the comparison itself.
|
|
57
|
-
const HAS_FLOAT_16_ARRAY = typeof Float16Array !== 'undefined';
|
|
58
72
|
const { getOwnPropertyDescriptor, keys } = Object;
|
|
73
|
+
/**
|
|
74
|
+
* Identify the element type of TypedArrays across realms and subclasses.
|
|
75
|
+
*/
|
|
76
|
+
const getTypedArrayTag = getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
|
|
59
77
|
/**
|
|
60
78
|
* Whether the values passed are equal based on a [SameValue](https://262.ecma-international.org/7.0/#sec-samevalue) basis.
|
|
61
79
|
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`) or both are `NaN`.
|
|
@@ -307,7 +325,8 @@ function areTypedArraysEqual(a, b) {
|
|
|
307
325
|
// Only float-backed views can hold `NaN`, and the additional check needed to treat it as equal
|
|
308
326
|
// to itself measurably slows the loop, so integer views keep the plain comparison. This is
|
|
309
327
|
// hoisted out of the loop so the cost is paid once per call rather than once per element.
|
|
310
|
-
|
|
328
|
+
const tag = getTypedArrayTag.call(a);
|
|
329
|
+
if (tag === 'Float64Array' || tag === 'Float32Array' || tag === 'Float16Array') {
|
|
311
330
|
while (index-- > 0) {
|
|
312
331
|
// `NaN` is the only value not equal to itself, and it is treated as equal here to match
|
|
313
332
|
// the SameValueZero semantics used for every other numeric comparison in the library.
|
|
@@ -376,13 +395,42 @@ function isPropertyEqual(a, b, state, property) {
|
|
|
376
395
|
return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
|
|
377
396
|
}
|
|
378
397
|
|
|
379
|
-
const toString = Object.prototype
|
|
398
|
+
const { toString } = Object.prototype;
|
|
380
399
|
/**
|
|
381
400
|
* Create a comparator method based on the type-specific equality comparators passed.
|
|
382
401
|
*/
|
|
383
402
|
function createEqualityComparator(config) {
|
|
384
403
|
const supportedComparatorMap = createSupportedComparatorMap(config);
|
|
385
|
-
const { areArraysEqual, areDatesEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, areRegExpsEqual, areSetsEqual, getUnsupportedCustomComparator, } = config;
|
|
404
|
+
const { areArraysEqual, areDatesEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, areRegExpsEqual, areSetsEqual, getUnsupportedCustomComparator, strictNullPrototypeComparison, } = config;
|
|
405
|
+
/**
|
|
406
|
+
* Whether the custom objects are equal in value, based on their string tag. If not matching any tags
|
|
407
|
+
* that require a specific type of comparison, then we hard-code false because the only thing remaining
|
|
408
|
+
* is strict equality, which has already been compared. This is for a few reasons:
|
|
409
|
+
* - Certain types that cannot be introspected (e.g., `WeakMap`). For these types, this is the only
|
|
410
|
+
* comparison that can be made.
|
|
411
|
+
* - For types that can be introspected but do not have an objective definition of what
|
|
412
|
+
* equality is (`Error`, etc.), the subjective decision is to be conservative and strictly compare.
|
|
413
|
+
* In all cases, these decisions should be reevaluated based on changes to the language and
|
|
414
|
+
* common development practices.
|
|
415
|
+
*
|
|
416
|
+
* Capturing the tag is reasonably performant in modern environments like v8 and SpiderMonkey. This is
|
|
417
|
+
* kept out of the main comparator so that it stays within the engine's bytecode budget for inlining.
|
|
418
|
+
* See [#207](https://github.com/planttheidea/fast-equals/pull/207) for more details.
|
|
419
|
+
*/
|
|
420
|
+
const areTaggedObjectsEqual = getUnsupportedCustomComparator
|
|
421
|
+
? function areTaggedObjectsEqual(a, b, state) {
|
|
422
|
+
const tag = toString.call(a);
|
|
423
|
+
const supportedComparator = supportedComparatorMap[tag];
|
|
424
|
+
if (supportedComparator) {
|
|
425
|
+
return supportedComparator(a, b, state);
|
|
426
|
+
}
|
|
427
|
+
const unsupportedCustomComparator = getUnsupportedCustomComparator(a, b, state, tag);
|
|
428
|
+
return unsupportedCustomComparator ? unsupportedCustomComparator(a, b, state) : false;
|
|
429
|
+
}
|
|
430
|
+
: function areTaggedObjectsEqual(a, b, state) {
|
|
431
|
+
const supportedComparator = supportedComparatorMap[toString.call(a)];
|
|
432
|
+
return supportedComparator ? supportedComparator(a, b, state) : false;
|
|
433
|
+
};
|
|
386
434
|
/**
|
|
387
435
|
* compare the value of the two objects and return true if they are equivalent in values
|
|
388
436
|
*/
|
|
@@ -422,7 +470,7 @@ function createEqualityComparator(config) {
|
|
|
422
470
|
// Constructors should match, otherwise there is potential for false positives
|
|
423
471
|
// between class and subclass or custom object and POJO.
|
|
424
472
|
if (constructor !== b.constructor) {
|
|
425
|
-
return false;
|
|
473
|
+
return strictNullPrototypeComparison ? false : isNullPrototypeComparable(a, b) && areObjectsEqual(a, b, state);
|
|
426
474
|
}
|
|
427
475
|
// Try to fast-path equality checks for other complex object types in the
|
|
428
476
|
// same realm to avoid capturing the string tag. Strict equality is used
|
|
@@ -461,32 +509,14 @@ function createEqualityComparator(config) {
|
|
|
461
509
|
if (Array.isArray(a)) {
|
|
462
510
|
return areArraysEqual(a, b, state);
|
|
463
511
|
}
|
|
464
|
-
// Since this is a custom object,
|
|
465
|
-
|
|
466
|
-
const tag = toString.call(a);
|
|
467
|
-
const supportedComparator = supportedComparatorMap[tag];
|
|
468
|
-
if (supportedComparator) {
|
|
469
|
-
return supportedComparator(a, b, state);
|
|
470
|
-
}
|
|
471
|
-
const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, state, tag);
|
|
472
|
-
if (unsupportedCustomComparator) {
|
|
473
|
-
return unsupportedCustomComparator(a, b, state);
|
|
474
|
-
}
|
|
475
|
-
// If not matching any tags that require a specific type of comparison, then we hard-code false because
|
|
476
|
-
// the only thing remaining is strict equality, which has already been compared. This is for a few reasons:
|
|
477
|
-
// - Certain types that cannot be introspected (e.g., `WeakMap`). For these types, this is the only
|
|
478
|
-
// comparison that can be made.
|
|
479
|
-
// - For types that can be introspected but do not have an objective definition of what
|
|
480
|
-
// equality is (`Error`, etc.), the subjective decision is to be conservative and strictly compare.
|
|
481
|
-
// In all cases, these decisions should be reevaluated based on changes to the language and
|
|
482
|
-
// common development practices.
|
|
483
|
-
return false;
|
|
512
|
+
// Since this is a custom object, use the string tag to determine its type.
|
|
513
|
+
return areTaggedObjectsEqual(a, b, state);
|
|
484
514
|
};
|
|
485
515
|
}
|
|
486
516
|
/**
|
|
487
517
|
* Create the configuration object used for building comparators.
|
|
488
518
|
*/
|
|
489
|
-
function createEqualityComparatorConfig({ circular, createCustomConfig, strict, }) {
|
|
519
|
+
function createEqualityComparatorConfig({ circular, createCustomConfig, strict, strictNullPrototypeComparison = true, }) {
|
|
490
520
|
let config = {
|
|
491
521
|
areArrayBuffersEqual,
|
|
492
522
|
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
@@ -511,6 +541,7 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
511
541
|
: areTypedArraysEqual,
|
|
512
542
|
areUrlsEqual: areUrlsEqual,
|
|
513
543
|
getUnsupportedCustomComparator: undefined,
|
|
544
|
+
strictNullPrototypeComparison,
|
|
514
545
|
};
|
|
515
546
|
if (createCustomConfig) {
|
|
516
547
|
config = Object.assign({}, config, createCustomConfig(config));
|
package/index.d.ts
CHANGED
|
@@ -94,6 +94,12 @@ interface ComparatorConfig<Meta> {
|
|
|
94
94
|
* Get a custom comparator based on the objects passed.
|
|
95
95
|
*/
|
|
96
96
|
getUnsupportedCustomComparator: ((a: any, b: any, state: State<Meta>, tag: string) => EqualityComparator<Meta> | undefined) | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Whether a null-prototype object (`Object.create(null)`) is unequal to an otherwise identical
|
|
99
|
+
* plain object. Defaults to `true`; when `false`, the two are compared as dictionaries.
|
|
100
|
+
* Constructor checks for all other types are unaffected.
|
|
101
|
+
*/
|
|
102
|
+
strictNullPrototypeComparison?: boolean;
|
|
97
103
|
}
|
|
98
104
|
type EqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
99
105
|
type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
@@ -138,6 +144,12 @@ interface CustomEqualCreatorOptions<Meta> {
|
|
|
138
144
|
* with equal shape of descriptors.
|
|
139
145
|
*/
|
|
140
146
|
strict?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Whether a null-prototype object (`Object.create(null)`) is unequal to an otherwise identical
|
|
149
|
+
* plain object. Defaults to `true`; when `false`, the two are compared as dictionaries.
|
|
150
|
+
* Constructor checks for all other types are unaffected.
|
|
151
|
+
*/
|
|
152
|
+
strictNullPrototypeComparison?: boolean;
|
|
141
153
|
}
|
|
142
154
|
|
|
143
155
|
/**
|
package/package.json
CHANGED