fast-equals 5.3.3 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +128 -77
- package/dist/cjs/comparator.d.cts +60 -0
- package/dist/cjs/{types/equals.d.cts → equals.d.cts} +8 -0
- package/dist/cjs/index.cjs +171 -162
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/{types/index.d.cts → index.d.cts} +21 -2
- package/{src/internalTypes.ts → dist/cjs/internalTypes.d.cts} +18 -50
- package/dist/cjs/{types/utils.d.cts → utils.d.cts} +7 -2
- package/dist/es/comparator.d.mts +60 -0
- package/dist/{esm/types → es}/equals.d.mts +8 -0
- package/dist/{esm/types → es}/index.d.mts +21 -2
- package/dist/{esm → es}/index.mjs +171 -162
- package/dist/es/index.mjs.map +1 -0
- package/dist/es/internalTypes.d.mts +178 -0
- package/dist/{esm/types → es}/utils.d.mts +7 -2
- package/dist/{min/types → umd}/comparator.d.ts +2 -2
- package/dist/{min/types → umd}/equals.d.ts +8 -0
- package/dist/umd/index.js +171 -162
- package/dist/umd/index.js.map +1 -1
- package/dist/{min/types → umd}/internalTypes.d.ts +10 -8
- package/index.d.ts +73 -75
- package/package.json +45 -48
- package/CHANGELOG.md +0 -364
- package/dist/cjs/types/comparator.d.cts +0 -26
- package/dist/cjs/types/internalTypes.d.cts +0 -157
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/types/comparator.d.mts +0 -26
- package/dist/esm/types/internalTypes.d.mts +0 -157
- package/dist/min/index.js +0 -1
- package/dist/umd/types/comparator.d.ts +0 -26
- package/dist/umd/types/equals.d.ts +0 -54
- package/dist/umd/types/index.d.ts +0 -47
- package/dist/umd/types/internalTypes.d.ts +0 -157
- package/dist/umd/types/utils.d.ts +0 -28
- package/src/comparator.ts +0 -376
- package/src/equals.ts +0 -355
- package/src/index.ts +0 -112
- package/src/utils.ts +0 -96
- /package/dist/{min/types → umd}/index.d.ts +0 -0
- /package/dist/{min/types → umd}/utils.d.ts +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
<img src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg"/>
|
|
5
5
|
<img src="https://img.shields.io/badge/license-MIT-blue.svg"/>
|
|
6
6
|
|
|
7
|
-
Perform [blazing fast](#benchmarks) equality comparisons (either deep or shallow) on two objects passed, while also
|
|
7
|
+
Perform [blazing fast](#benchmarks) equality comparisons (either deep or shallow) on two objects passed, while also
|
|
8
|
+
maintaining a high degree of flexibility for various implementation use-cases. It has no dependencies, and is ~2kB when
|
|
9
|
+
minified and gzipped.
|
|
8
10
|
|
|
9
11
|
The following types are handled out-of-the-box:
|
|
10
12
|
|
|
11
13
|
- Plain objects (including `react` elements and `Arguments`)
|
|
12
14
|
- Arrays
|
|
13
|
-
-
|
|
15
|
+
- `ArrayBuffer` / `TypedArray` / `DataView` instances
|
|
14
16
|
- `Date` objects
|
|
15
17
|
- `RegExp` objects
|
|
16
18
|
- `Map` / `Set` iterables
|
|
@@ -18,7 +20,9 @@ The following types are handled out-of-the-box:
|
|
|
18
20
|
- Primitive wrappers (`new Boolean()` / `new Number()` / `new String()`)
|
|
19
21
|
- Custom class instances, including subclasses of native classes
|
|
20
22
|
|
|
21
|
-
Methods are available for deep, shallow, or referential equality comparison. In addition, you can opt into support for
|
|
23
|
+
Methods are available for deep, shallow, or referential equality comparison. In addition, you can opt into support for
|
|
24
|
+
circular objects, or performing a "strict" comparison with unconventional property definition, or both. You can also
|
|
25
|
+
customize any specific type comparison based on your application's use-cases.
|
|
22
26
|
|
|
23
27
|
## Table of contents
|
|
24
28
|
|
|
@@ -53,20 +57,23 @@ console.log(deepEqual({ foo: 'bar' }, { foo: 'bar' })); // true
|
|
|
53
57
|
|
|
54
58
|
### Specific builds
|
|
55
59
|
|
|
56
|
-
By default, npm should resolve the correct build of the package based on your consumption (ESM vs CommonJS). However, if
|
|
60
|
+
By default, npm should resolve the correct build of the package based on your consumption (ESM vs CommonJS). However, if
|
|
61
|
+
you want to force use of a specific build, they can be located here:
|
|
57
62
|
|
|
58
63
|
- ESM => `fast-equals/dist/esm/index.mjs`
|
|
59
64
|
- CommonJS => `fast-equals/dist/cjs/index.cjs`
|
|
60
65
|
- UMD => `fast-equals/dist/umd/index.js`
|
|
61
66
|
- Minified UMD => `fast-equals/dist/min/index.js`
|
|
62
67
|
|
|
63
|
-
If you are having issues loading a specific build type,
|
|
68
|
+
If you are having issues loading a specific build type,
|
|
69
|
+
[please file an issue](https://github.com/planttheidea/fast-equals/issues).
|
|
64
70
|
|
|
65
71
|
## Available methods
|
|
66
72
|
|
|
67
73
|
### deepEqual
|
|
68
74
|
|
|
69
|
-
Performs a deep equality comparison on the two objects passed and returns a boolean representing the value equivalency
|
|
75
|
+
Performs a deep equality comparison on the two objects passed and returns a boolean representing the value equivalency
|
|
76
|
+
of the objects.
|
|
70
77
|
|
|
71
78
|
```ts
|
|
72
79
|
import { deepEqual } from 'fast-equals';
|
|
@@ -80,7 +87,9 @@ console.log(deepEqual(objectA, objectB)); // true
|
|
|
80
87
|
|
|
81
88
|
#### Comparing `Map`s
|
|
82
89
|
|
|
83
|
-
`Map` objects support complex keys (objects, Arrays, etc.), however
|
|
90
|
+
`Map` objects support complex keys (objects, Arrays, etc.), however
|
|
91
|
+
[the spec for key lookups in `Map` are based on `SameZeroValue`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#key_equality).
|
|
92
|
+
If the spec were followed for comparison, the following would always be `false`:
|
|
84
93
|
|
|
85
94
|
```ts
|
|
86
95
|
const mapA = new Map([[{ foo: 'bar' }, { baz: 'quz' }]]);
|
|
@@ -89,11 +98,13 @@ const mapB = new Map([[{ foo: 'bar' }, { baz: 'quz' }]]);
|
|
|
89
98
|
deepEqual(mapA, mapB);
|
|
90
99
|
```
|
|
91
100
|
|
|
92
|
-
To support true deep equality of all contents, `fast-equals` will perform a deep equality comparison for key and value
|
|
101
|
+
To support true deep equality of all contents, `fast-equals` will perform a deep equality comparison for key and value
|
|
102
|
+
parirs. Therefore, the above would be `true`.
|
|
93
103
|
|
|
94
104
|
### shallowEqual
|
|
95
105
|
|
|
96
|
-
Performs a shallow equality comparison on the two objects passed and returns a boolean representing the value
|
|
106
|
+
Performs a shallow equality comparison on the two objects passed and returns a boolean representing the value
|
|
107
|
+
equivalency of the objects.
|
|
97
108
|
|
|
98
109
|
```ts
|
|
99
110
|
import { shallowEqual } from 'fast-equals';
|
|
@@ -111,7 +122,9 @@ console.log(shallowEqual(objectA, objectC)); // false
|
|
|
111
122
|
|
|
112
123
|
### sameValueZeroEqual
|
|
113
124
|
|
|
114
|
-
Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) comparison on the two
|
|
125
|
+
Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) comparison on the two
|
|
126
|
+
objects passed and returns a boolean representing the value equivalency of the objects. In simple terms, this means
|
|
127
|
+
either strictly equal or both `NaN`.
|
|
115
128
|
|
|
116
129
|
```ts
|
|
117
130
|
import { sameValueZeroEqual } from 'fast-equals';
|
|
@@ -129,7 +142,8 @@ console.log(sameValueZeroEqual(mainObject, objectC)); // false
|
|
|
129
142
|
|
|
130
143
|
### circularDeepEqual
|
|
131
144
|
|
|
132
|
-
Performs the same comparison as `deepEqual` but supports circular objects. It is slower than `deepEqual`, so only use if
|
|
145
|
+
Performs the same comparison as `deepEqual` but supports circular objects. It is slower than `deepEqual`, so only use if
|
|
146
|
+
you know circular objects are present.
|
|
133
147
|
|
|
134
148
|
```ts
|
|
135
149
|
function Circular(value) {
|
|
@@ -151,7 +165,8 @@ Just as with `deepEqual`, [both keys and values are compared for deep equality](
|
|
|
151
165
|
|
|
152
166
|
### circularShallowEqual
|
|
153
167
|
|
|
154
|
-
Performs the same comparison as `shallowequal` but supports circular objects. It is slower than `shallowEqual`, so only
|
|
168
|
+
Performs the same comparison as `shallowequal` but supports circular objects. It is slower than `shallowEqual`, so only
|
|
169
|
+
use if you know circular objects are present.
|
|
155
170
|
|
|
156
171
|
```ts
|
|
157
172
|
const array = ['foo'];
|
|
@@ -245,7 +260,8 @@ console.log(circularDeepEqual(first, new Circular('foo'))); // false
|
|
|
245
260
|
|
|
246
261
|
### strictCircularShallowEqual
|
|
247
262
|
|
|
248
|
-
Performs the same comparison as `circularShallowEqual` but performs a strict comparison of the objects. In this
|
|
263
|
+
Performs the same comparison as `circularShallowEqual` but performs a strict comparison of the objects. In this
|
|
264
|
+
includes:
|
|
249
265
|
|
|
250
266
|
- Checking non-enumerable properties in object comparisons
|
|
251
267
|
- Checking full descriptor of properties on the object to match
|
|
@@ -268,7 +284,9 @@ console.log(circularShallowEqual(array, ['foo', array])); // false
|
|
|
268
284
|
|
|
269
285
|
### createCustomEqual
|
|
270
286
|
|
|
271
|
-
Creates a custom equality comparator that will be used on nested values in the object. Unlike `deepEqual` and
|
|
287
|
+
Creates a custom equality comparator that will be used on nested values in the object. Unlike `deepEqual` and
|
|
288
|
+
`shallowEqual`, this is a factory method that receives the default options used internally, and allows you to override
|
|
289
|
+
the defaults as needed. This is generally for extreme edge-cases, or supporting legacy environments.
|
|
272
290
|
|
|
273
291
|
The signature is as follows:
|
|
274
292
|
|
|
@@ -286,10 +304,7 @@ interface ComparatorConfig<Meta> {
|
|
|
286
304
|
areFunctionsEqual: TypeEqualityComparator<(...args: any[]) => any, Meta>;
|
|
287
305
|
areMapsEqual: TypeEqualityComparator<Map<any, any>, Meta>;
|
|
288
306
|
areObjectsEqual: TypeEqualityComparator<Record<string, any>, Meta>;
|
|
289
|
-
arePrimitiveWrappersEqual: TypeEqualityComparator<
|
|
290
|
-
boolean | string | number,
|
|
291
|
-
Meta
|
|
292
|
-
>;
|
|
307
|
+
arePrimitiveWrappersEqual: TypeEqualityComparator<boolean | string | number, Meta>;
|
|
293
308
|
areRegExpsEqual: TypeEqualityComparator<RegExp, Meta>;
|
|
294
309
|
areSetsEqual: TypeEqualityComparator<Set<any>, Meta>;
|
|
295
310
|
areTypedArraysEqual: TypeEqualityComparator<TypedArray, Meta>;
|
|
@@ -299,36 +314,33 @@ interface ComparatorConfig<Meta> {
|
|
|
299
314
|
|
|
300
315
|
function createCustomEqual<Meta>(options: {
|
|
301
316
|
circular?: boolean;
|
|
302
|
-
createCustomConfig?: (
|
|
303
|
-
defaultConfig: ComparatorConfig<Meta>,
|
|
304
|
-
) => Partial<ComparatorConfig<Meta>>;
|
|
317
|
+
createCustomConfig?: (defaultConfig: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
|
|
305
318
|
createInternalComparator?: (
|
|
306
319
|
compare: <A, B>(a: A, b: B, state: State<Meta>) => boolean,
|
|
307
|
-
) => (
|
|
308
|
-
a: any,
|
|
309
|
-
b: any,
|
|
310
|
-
indexOrKeyA: any,
|
|
311
|
-
indexOrKeyB: any,
|
|
312
|
-
parentA: any,
|
|
313
|
-
parentB: any,
|
|
314
|
-
state: State<Meta>,
|
|
315
|
-
) => boolean;
|
|
320
|
+
) => (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
316
321
|
createState?: () => { cache?: Cache; meta?: Meta };
|
|
317
322
|
strict?: boolean;
|
|
318
323
|
}): <A, B>(a: A, b: B) => boolean;
|
|
319
324
|
```
|
|
320
325
|
|
|
321
|
-
Create a custom equality comparator. This allows complete control over building a bespoke equality method, in case your
|
|
326
|
+
Create a custom equality comparator. This allows complete control over building a bespoke equality method, in case your
|
|
327
|
+
use-case requires a higher degree of performance, legacy environment support, or any other non-standard usage. The
|
|
328
|
+
[recipes](#recipes) provide examples of use in different use-cases, but if you have a specific goal in mind and would
|
|
329
|
+
like assistance feel free to [file an issue](https://github.com/planttheidea/fast-equals/issues).
|
|
322
330
|
|
|
323
|
-
_**NOTE**: `Map` implementations compare equality for both keys and value. When using a custom comparator and comparing
|
|
331
|
+
_**NOTE**: `Map` implementations compare equality for both keys and value. When using a custom comparator and comparing
|
|
332
|
+
equality of the keys, the iteration index is provided as both `indexOrKeyA` and `indexOrKeyB` to help use-cases where
|
|
333
|
+
ordering of keys matters to equality._
|
|
324
334
|
|
|
325
335
|
#### unknownTagComparators
|
|
326
336
|
|
|
327
|
-
If you want to compare objects that have a custom `@@toStringTag`, you can provide a map of the custom tags you want to
|
|
337
|
+
If you want to compare objects that have a custom `@@toStringTag`, you can provide a map of the custom tags you want to
|
|
338
|
+
support via the `unknownTagComparators` option. See [this recipe]('./recipes/special-objects.md) for an example.
|
|
328
339
|
|
|
329
340
|
#### Recipes
|
|
330
341
|
|
|
331
|
-
Some recipes have been created to provide examples of use-cases for `createCustomEqual`. Even if not directly applicable
|
|
342
|
+
Some recipes have been created to provide examples of use-cases for `createCustomEqual`. Even if not directly applicable
|
|
343
|
+
to the problem you are solving, they can offer guidance of how to structure your solution.
|
|
332
344
|
|
|
333
345
|
- [Legacy environment support for `RegExp` comparators](./recipes/legacy-regexp-support.md)
|
|
334
346
|
- [Explicit property check](./recipes/explicit-property-check.md)
|
|
@@ -340,7 +352,8 @@ Some recipes have been created to provide examples of use-cases for `createCusto
|
|
|
340
352
|
|
|
341
353
|
## Benchmarks
|
|
342
354
|
|
|
343
|
-
All benchmarks were performed on an i9-11900H Ubuntu Linux 24.04 laptop with 64GB of memory using NodeJS version
|
|
355
|
+
All benchmarks were performed on an i9-11900H Ubuntu Linux 24.04 laptop with 64GB of memory using NodeJS version
|
|
356
|
+
`20.17.0`, and are based on averages of running comparisons based deep equality on the following object types:
|
|
344
357
|
|
|
345
358
|
- Primitives (`String`, `Number`, `null`, `undefined`)
|
|
346
359
|
- `Function`
|
|
@@ -353,60 +366,98 @@ All benchmarks were performed on an i9-11900H Ubuntu Linux 24.04 laptop with 64G
|
|
|
353
366
|
|
|
354
367
|
```bash
|
|
355
368
|
Testing mixed objects equal...
|
|
356
|
-
|
|
357
|
-
│
|
|
358
|
-
|
|
359
|
-
│
|
|
360
|
-
|
|
361
|
-
│
|
|
362
|
-
|
|
363
|
-
│
|
|
364
|
-
|
|
365
|
-
│
|
|
366
|
-
|
|
367
|
-
│
|
|
368
|
-
|
|
369
|
-
│
|
|
370
|
-
|
|
371
|
-
│
|
|
372
|
-
|
|
373
|
-
|
|
369
|
+
┌────────────────────────────────────────┬────────────────┐
|
|
370
|
+
│ Name │ Ops / sec │
|
|
371
|
+
├────────────────────────────────────────┼────────────────┤
|
|
372
|
+
│ fast-equals (passed) │ 1416193.769468 │
|
|
373
|
+
├────────────────────────────────────────┼────────────────┤
|
|
374
|
+
│ fast-deep-equal (passed) │ 1284824.583215 │
|
|
375
|
+
├────────────────────────────────────────┼────────────────┤
|
|
376
|
+
│ react-fast-compare (passed) │ 1246947.505444 │
|
|
377
|
+
├────────────────────────────────────────┼────────────────┤
|
|
378
|
+
│ shallow-equal-fuzzy (passed) │ 1238082.379207 │
|
|
379
|
+
├────────────────────────────────────────┼────────────────┤
|
|
380
|
+
│ nano-equal (failed) │ 946782.33704 │
|
|
381
|
+
├────────────────────────────────────────┼────────────────┤
|
|
382
|
+
│ dequal/lite (passed) │ 758213.632866 │
|
|
383
|
+
├────────────────────────────────────────┼────────────────┤
|
|
384
|
+
│ dequal (passed) │ 756789.655029 │
|
|
385
|
+
├────────────────────────────────────────┼────────────────┤
|
|
386
|
+
│ fast-equals (circular) (passed) │ 726093.253185 │
|
|
387
|
+
├────────────────────────────────────────┼────────────────┤
|
|
388
|
+
│ underscore.isEqual (passed) │ 489748.701783 │
|
|
389
|
+
├────────────────────────────────────────┼────────────────┤
|
|
390
|
+
│ assert.deepStrictEqual (passed) │ 453761.890107 │
|
|
391
|
+
├────────────────────────────────────────┼────────────────┤
|
|
392
|
+
│ lodash.isEqual (passed) │ 288264.867811 │
|
|
393
|
+
├────────────────────────────────────────┼────────────────┤
|
|
394
|
+
│ fast-equals (strict) (passed) │ 217221.619705 │
|
|
395
|
+
├────────────────────────────────────────┼────────────────┤
|
|
396
|
+
│ fast-equals (strict circular) (passed) │ 186916.942934 │
|
|
397
|
+
├────────────────────────────────────────┼────────────────┤
|
|
398
|
+
│ deep-eql (passed) │ 162487.877883 │
|
|
399
|
+
├────────────────────────────────────────┼────────────────┤
|
|
400
|
+
│ deep-equal (passed) │ 916.680714 │
|
|
401
|
+
└────────────────────────────────────────┴────────────────┘
|
|
374
402
|
|
|
375
403
|
Testing mixed objects not equal...
|
|
376
|
-
|
|
377
|
-
│
|
|
378
|
-
|
|
379
|
-
│
|
|
380
|
-
|
|
381
|
-
│
|
|
382
|
-
|
|
383
|
-
│
|
|
384
|
-
|
|
385
|
-
│
|
|
386
|
-
|
|
387
|
-
│
|
|
388
|
-
|
|
389
|
-
│
|
|
390
|
-
|
|
391
|
-
│
|
|
392
|
-
|
|
393
|
-
|
|
404
|
+
┌────────────────────────────────────────┬────────────────┐
|
|
405
|
+
│ Name │ Ops / sec │
|
|
406
|
+
├────────────────────────────────────────┼────────────────┤
|
|
407
|
+
│ fast-equals (passed) │ 4687012.640614 │
|
|
408
|
+
├────────────────────────────────────────┼────────────────┤
|
|
409
|
+
│ fast-deep-equal (passed) │ 3418170.156109 │
|
|
410
|
+
├────────────────────────────────────────┼────────────────┤
|
|
411
|
+
│ react-fast-compare (passed) │ 3283516.669966 │
|
|
412
|
+
├────────────────────────────────────────┼────────────────┤
|
|
413
|
+
│ fast-equals (circular) (passed) │ 3268062.099602 │
|
|
414
|
+
├────────────────────────────────────────┼────────────────┤
|
|
415
|
+
│ fast-equals (strict) (passed) │ 1747578.66456 │
|
|
416
|
+
├────────────────────────────────────────┼────────────────┤
|
|
417
|
+
│ fast-equals (strict circular) (passed) │ 1477873.624956 │
|
|
418
|
+
├────────────────────────────────────────┼────────────────┤
|
|
419
|
+
│ dequal/lite (passed) │ 1335397.839502 │
|
|
420
|
+
├────────────────────────────────────────┼────────────────┤
|
|
421
|
+
│ dequal (passed) │ 1319426.71146 │
|
|
422
|
+
├────────────────────────────────────────┼────────────────┤
|
|
423
|
+
│ shallow-equal-fuzzy (failed) │ 1237432.986615 │
|
|
424
|
+
├────────────────────────────────────────┼────────────────┤
|
|
425
|
+
│ nano-equal (passed) │ 1064383.319776 │
|
|
426
|
+
├────────────────────────────────────────┼────────────────┤
|
|
427
|
+
│ underscore.isEqual (passed) │ 920462.516736 │
|
|
428
|
+
├────────────────────────────────────────┼────────────────┤
|
|
429
|
+
│ lodash.isEqual (passed) │ 379370.998021 │
|
|
430
|
+
├────────────────────────────────────────┼────────────────┤
|
|
431
|
+
│ deep-eql (passed) │ 184111.383127 │
|
|
432
|
+
├────────────────────────────────────────┼────────────────┤
|
|
433
|
+
│ assert.deepStrictEqual (passed) │ 20775.59065 │
|
|
434
|
+
├────────────────────────────────────────┼────────────────┤
|
|
435
|
+
│ deep-equal (passed) │ 3678.51009 │
|
|
436
|
+
└────────────────────────────────────────┴────────────────┘
|
|
394
437
|
```
|
|
395
438
|
|
|
396
439
|
Caveats that impact the benchmark (and accuracy of comparison):
|
|
397
440
|
|
|
398
|
-
- `Map`s, `Promise`s, and `Set`s were excluded from the benchmark entirely because no library other than `deep-eql`
|
|
399
|
-
|
|
441
|
+
- `Map`s, `Promise`s, and `Set`s were excluded from the benchmark entirely because no library other than `deep-eql`
|
|
442
|
+
fully supported their comparison
|
|
443
|
+
- `fast-deep-equal`, `react-fast-compare` and `nano-equal` throw on objects with `null` as prototype
|
|
444
|
+
(`Object.create(null)`)
|
|
400
445
|
- `assert.deepStrictEqual` does not support `NaN` or `SameValueZero` equality for dates
|
|
401
446
|
- `deep-eql` does not support `SameValueZero` equality for zero equality (positive and negative zero are not equal)
|
|
402
|
-
- `deep-equal` does not support `NaN` and does not strictly compare object type, or date / regexp values, nor uses
|
|
447
|
+
- `deep-equal` does not support `NaN` and does not strictly compare object type, or date / regexp values, nor uses
|
|
448
|
+
`SameValueZero` equality for dates
|
|
403
449
|
- `fast-deep-equal` does not support `NaN` or `SameValueZero` equality for dates
|
|
404
|
-
- `nano-equal` does not strictly compare object property structure, array length, or object type, nor `SameValueZero`
|
|
405
|
-
|
|
450
|
+
- `nano-equal` does not strictly compare object property structure, array length, or object type, nor `SameValueZero`
|
|
451
|
+
equality for dates
|
|
452
|
+
- `react-fast-compare` does not support `NaN` or `SameValueZero` equality for dates, and does not compare `function`
|
|
453
|
+
equality
|
|
406
454
|
- `shallow-equal-fuzzy` does not strictly compare object type or regexp values, nor `SameValueZero` equality for dates
|
|
407
455
|
- `underscore.isEqual` does not support `SameValueZero` equality for primitives or dates
|
|
408
456
|
|
|
409
|
-
All of these have the potential of inflating the respective library's numbers in comparison to `fast-equals`, but it was
|
|
457
|
+
All of these have the potential of inflating the respective library's numbers in comparison to `fast-equals`, but it was
|
|
458
|
+
the closest apples-to-apples comparison I could create of a reasonable sample size. It should be noted that `react`
|
|
459
|
+
elements can be circular objects, however simple elements are not; I kept the `react` comparison very basic to allow it
|
|
460
|
+
to be included.
|
|
410
461
|
|
|
411
462
|
## Development
|
|
412
463
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ComparatorConfig,
|
|
3
|
+
CreateState,
|
|
4
|
+
CustomEqualCreatorOptions,
|
|
5
|
+
EqualityComparator,
|
|
6
|
+
InternalEqualityComparator,
|
|
7
|
+
} from './internalTypes.d.cts';
|
|
8
|
+
interface CreateIsEqualOptions<Meta> {
|
|
9
|
+
circular: boolean;
|
|
10
|
+
comparator: EqualityComparator<Meta>;
|
|
11
|
+
createState: CreateState<Meta> | undefined;
|
|
12
|
+
equals: InternalEqualityComparator<Meta>;
|
|
13
|
+
strict: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a comparator method based on the type-specific equality comparators passed.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createEqualityComparator<Meta>({
|
|
19
|
+
areArrayBuffersEqual,
|
|
20
|
+
areArraysEqual,
|
|
21
|
+
areDataViewsEqual,
|
|
22
|
+
areDatesEqual,
|
|
23
|
+
areErrorsEqual,
|
|
24
|
+
areFunctionsEqual,
|
|
25
|
+
areMapsEqual,
|
|
26
|
+
areNumbersEqual,
|
|
27
|
+
areObjectsEqual,
|
|
28
|
+
arePrimitiveWrappersEqual,
|
|
29
|
+
areRegExpsEqual,
|
|
30
|
+
areSetsEqual,
|
|
31
|
+
areTypedArraysEqual,
|
|
32
|
+
areUrlsEqual,
|
|
33
|
+
unknownTagComparators,
|
|
34
|
+
}: ComparatorConfig<Meta>): EqualityComparator<Meta>;
|
|
35
|
+
/**
|
|
36
|
+
* Create the configuration object used for building comparators.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createEqualityComparatorConfig<Meta>({
|
|
39
|
+
circular,
|
|
40
|
+
createCustomConfig,
|
|
41
|
+
strict,
|
|
42
|
+
}: CustomEqualCreatorOptions<Meta>): ComparatorConfig<Meta>;
|
|
43
|
+
/**
|
|
44
|
+
* Default equality comparator pass-through, used as the standard `isEqual` creator for
|
|
45
|
+
* use inside the built comparator.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createInternalEqualityComparator<Meta>(
|
|
48
|
+
compare: EqualityComparator<Meta>,
|
|
49
|
+
): InternalEqualityComparator<Meta>;
|
|
50
|
+
/**
|
|
51
|
+
* Create the `isEqual` function used by the consuming application.
|
|
52
|
+
*/
|
|
53
|
+
export declare function createIsEqual<Meta>({
|
|
54
|
+
circular,
|
|
55
|
+
comparator,
|
|
56
|
+
createState,
|
|
57
|
+
equals,
|
|
58
|
+
strict,
|
|
59
|
+
}: CreateIsEqualOptions<Meta>): <A, B>(a: A, b: B) => boolean;
|
|
60
|
+
export {};
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { Dictionary, PrimitiveWrapper, State, TypedArray } from './internalTypes.d.cts';
|
|
2
2
|
import type { sameValueZeroEqual } from './utils.d.cts';
|
|
3
|
+
/**
|
|
4
|
+
* Whether the array buffers are equal in value.
|
|
5
|
+
*/
|
|
6
|
+
export declare function areArrayBuffersEqual(a: ArrayBuffer, b: ArrayBuffer): boolean;
|
|
3
7
|
/**
|
|
4
8
|
* Whether the arrays are equal in value.
|
|
5
9
|
*/
|
|
6
10
|
export declare function areArraysEqual(a: any[], b: any[], state: State<any>): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the dataviews are equal in value.
|
|
13
|
+
*/
|
|
14
|
+
export declare function areDataViewsEqual(a: DataView, b: DataView): boolean;
|
|
7
15
|
/**
|
|
8
16
|
* Whether the dates passed are equal in value.
|
|
9
17
|
*/
|