fast-equals 6.0.0-rc.1 → 6.0.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 +83 -84
- package/dist/cjs/index.cjs +20 -16
- package/dist/cjs/index.d.cts +34 -39
- package/dist/es/index.d.mts +34 -39
- package/dist/es/index.mjs +20 -17
- package/index.d.ts +34 -39
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
> fast-equals
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<img src="https://img.shields.io/badge/license-MIT-blue.svg"/>
|
|
6
|
-
|
|
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.
|
|
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 ~2kB when minified and gzipped.
|
|
10
5
|
|
|
11
6
|
The following types are handled out-of-the-box:
|
|
12
7
|
|
|
@@ -16,36 +11,43 @@ The following types are handled out-of-the-box:
|
|
|
16
11
|
- `Date` objects
|
|
17
12
|
- `RegExp` objects
|
|
18
13
|
- `Map` / `Set` iterables
|
|
19
|
-
- `Promise` objects
|
|
14
|
+
- `Promise` objects and then-ables
|
|
20
15
|
- Primitive wrappers (`new Boolean()` / `new Number()` / `new String()`)
|
|
21
16
|
- Custom class instances, including subclasses of native classes
|
|
22
17
|
|
|
23
|
-
Methods are available for deep, shallow,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
- [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
- [
|
|
48
|
-
- [
|
|
18
|
+
Methods are available for deep, shallow, [`SameValue`](http://ecma-international.org/ecma-262/7.0/#sec-samevalue),
|
|
19
|
+
[`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero), or
|
|
20
|
+
[strict equality](https://262.ecma-international.org/7.0/#sec-strict-equality-comparison) comparison. In addition, you
|
|
21
|
+
can opt into support for circular objects, or performing a "strict" comparison with unconventional property definition,
|
|
22
|
+
or both. You can also customize any specific type comparison based on your application's use-cases.
|
|
23
|
+
|
|
24
|
+
By default, npm should resolve the correct build of the package based on your consumption (ESM vs CommonJS). However, if
|
|
25
|
+
you want to force use of a specific build, they can be located here:
|
|
26
|
+
|
|
27
|
+
- ESM => `fast-equals/dist/es/index.mjs`
|
|
28
|
+
- CommonJS => `fast-equals/dist/cjs/index.cjs`
|
|
29
|
+
|
|
30
|
+
If you are having any problems, want to request a new feature, or have any questions,
|
|
31
|
+
[please file an issue](https://github.com/planttheidea/fast-equals/issues).
|
|
32
|
+
|
|
33
|
+
- [Usage](#usage)
|
|
34
|
+
- [Available methods](#available-methods)
|
|
35
|
+
- [deepEqual](#deepequal)
|
|
36
|
+
- [Comparing `Map`s](#comparing-maps)
|
|
37
|
+
- [shallowEqual](#shallowequal)
|
|
38
|
+
- [sameValueEqual](#samevalueequal)
|
|
39
|
+
- [sameValueZeroEqual](#samevaluezeroequal)
|
|
40
|
+
- [strictEqual](#strictequal)
|
|
41
|
+
- [circularDeepEqual](#circulardeepequal)
|
|
42
|
+
- [circularShallowEqual](#circularshallowequal)
|
|
43
|
+
- [strictDeepEqual](#strictdeepequal)
|
|
44
|
+
- [strictShallowEqual](#strictshallowequal)
|
|
45
|
+
- [strictCircularDeepEqual](#strictcirculardeepequal)
|
|
46
|
+
- [strictCircularShallowEqual](#strictcircularshallowequal)
|
|
47
|
+
- [createCustomEqual](#createcustomequal)
|
|
48
|
+
- [getUnsupportedCustomComparator](#getunsupportedcustomcomparator)
|
|
49
|
+
- [Recipes](#recipes)
|
|
50
|
+
- [Benchmarks](#benchmarks)
|
|
49
51
|
|
|
50
52
|
## Usage
|
|
51
53
|
|
|
@@ -55,19 +57,6 @@ import { deepEqual } from 'fast-equals';
|
|
|
55
57
|
console.log(deepEqual({ foo: 'bar' }, { foo: 'bar' })); // true
|
|
56
58
|
```
|
|
57
59
|
|
|
58
|
-
### Specific builds
|
|
59
|
-
|
|
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:
|
|
62
|
-
|
|
63
|
-
- ESM => `fast-equals/dist/esm/index.mjs`
|
|
64
|
-
- CommonJS => `fast-equals/dist/cjs/index.cjs`
|
|
65
|
-
- UMD => `fast-equals/dist/umd/index.js`
|
|
66
|
-
- Minified UMD => `fast-equals/dist/min/index.js`
|
|
67
|
-
|
|
68
|
-
If you are having issues loading a specific build type,
|
|
69
|
-
[please file an issue](https://github.com/planttheidea/fast-equals/issues).
|
|
70
|
-
|
|
71
60
|
## Available methods
|
|
72
61
|
|
|
73
62
|
### deepEqual
|
|
@@ -99,7 +88,7 @@ deepEqual(mapA, mapB);
|
|
|
99
88
|
```
|
|
100
89
|
|
|
101
90
|
To support true deep equality of all contents, `fast-equals` will perform a deep equality comparison for key and value
|
|
102
|
-
|
|
91
|
+
pairs. Therefore, the above would be `true`.
|
|
103
92
|
|
|
104
93
|
### shallowEqual
|
|
105
94
|
|
|
@@ -143,9 +132,9 @@ console.log(sameValueEqual(mainObject.foo, objectB)); // true
|
|
|
143
132
|
console.log(sameValueEqual(mainObject, objectC)); // false
|
|
144
133
|
```
|
|
145
134
|
|
|
146
|
-
**NOTE**: In environments that support
|
|
135
|
+
_**NOTE**: In environments that support
|
|
147
136
|
[`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is),
|
|
148
|
-
`sameValueEqual` is just a re-export of that method.
|
|
137
|
+
`sameValueEqual` is just a re-export of that method._
|
|
149
138
|
|
|
150
139
|
### sameValueZeroEqual
|
|
151
140
|
|
|
@@ -170,6 +159,33 @@ console.log(sameValueEqual(mainObject.foo, objectB)); // true
|
|
|
170
159
|
console.log(sameValueEqual(mainObject, objectC)); // false
|
|
171
160
|
```
|
|
172
161
|
|
|
162
|
+
### strictEqual
|
|
163
|
+
|
|
164
|
+
Performs a [Strict Equality](https://262.ecma-international.org/7.0/#sec-strict-equality-comparison) comparison on the
|
|
165
|
+
two objects passed and returns a boolean representing the referential equality of the objects. In simple terms, this
|
|
166
|
+
means:
|
|
167
|
+
|
|
168
|
+
- `+0` and `-0` are equal
|
|
169
|
+
- `NaN` is not equal to `NaN`
|
|
170
|
+
- All other items are based on referential equality (`a === b`)
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { strictEqual } from 'fast-equals';
|
|
174
|
+
|
|
175
|
+
const mainObject = { foo: NaN, bar: 'baz' };
|
|
176
|
+
|
|
177
|
+
const objectA = 'baz';
|
|
178
|
+
const objectB = NaN;
|
|
179
|
+
const objectC = { foo: NaN, bar: 'baz' };
|
|
180
|
+
|
|
181
|
+
console.log(sameValueEqual(mainObject.bar, objectA)); // true
|
|
182
|
+
console.log(sameValueEqual(mainObject.foo, objectB)); // false
|
|
183
|
+
console.log(sameValueEqual(mainObject, objectC)); // false
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
_**NOTE**: This is mainly a convenience function, such as needing a default functional equality comparator. Naturally,
|
|
187
|
+
it is faster to simply compare `a === b`. :)_
|
|
188
|
+
|
|
173
189
|
### circularDeepEqual
|
|
174
190
|
|
|
175
191
|
Performs the same comparison as `deepEqual` but supports circular objects. It is slower than `deepEqual`, so only use if
|
|
@@ -328,21 +344,21 @@ interface Cache<Key extends object, Value> {
|
|
|
328
344
|
}
|
|
329
345
|
|
|
330
346
|
interface ComparatorConfig<Meta> {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
areDataViewsEqual:
|
|
334
|
-
areDatesEqual:
|
|
335
|
-
areErrorsEqual:
|
|
336
|
-
areFunctionsEqual:
|
|
337
|
-
areMapsEqual:
|
|
338
|
-
areNumbersEqual:
|
|
339
|
-
areObjectsEqual:
|
|
340
|
-
arePrimitiveWrappersEqual:
|
|
341
|
-
areRegExpsEqual:
|
|
342
|
-
areSetsEqual:
|
|
343
|
-
areTypedArraysEqual:
|
|
344
|
-
areUrlsEqual:
|
|
345
|
-
getUnsupportedCustomComparator: <Type>(a: Type, b: Type, tag: string) =>
|
|
347
|
+
areArrayBuffersEqual: EqualityComparator<Meta>;
|
|
348
|
+
areArraysEqual: EqualityComparator<Meta>;
|
|
349
|
+
areDataViewsEqual: EqualityComparator<Meta>;
|
|
350
|
+
areDatesEqual: EqualityComparator<Meta>;
|
|
351
|
+
areErrorsEqual: EqualityComparator<Meta>;
|
|
352
|
+
areFunctionsEqual: EqualityComparator<Meta>;
|
|
353
|
+
areMapsEqual: EqualityComparator<Meta>;
|
|
354
|
+
areNumbersEqual: EqualityComparator<Meta>;
|
|
355
|
+
areObjectsEqual: EqualityComparator<Meta>;
|
|
356
|
+
arePrimitiveWrappersEqual: EqualityComparator<Meta>;
|
|
357
|
+
areRegExpsEqual: EqualityComparator<Meta>;
|
|
358
|
+
areSetsEqual: EqualityComparator<Meta>;
|
|
359
|
+
areTypedArraysEqual: EqualityComparator<Meta>;
|
|
360
|
+
areUrlsEqual: EqualityComparator<Meta>;
|
|
361
|
+
getUnsupportedCustomComparator: <Type>(a: Type, b: Type, state: State<Meta>, tag: string) => EqualityComparator<Meta>;
|
|
346
362
|
}
|
|
347
363
|
|
|
348
364
|
function createCustomEqual<Meta>(options: {
|
|
@@ -381,7 +397,7 @@ to the problem you are solving, they can offer guidance of how to structure your
|
|
|
381
397
|
- [Using `meta` in comparison](./recipes//using-meta-in-comparison.md)
|
|
382
398
|
- [Comparing non-standard properties](./recipes/non-standard-properties.md)
|
|
383
399
|
- [Strict property descriptor comparison](./recipes/strict-property-descriptor-check.md)
|
|
384
|
-
- [Legacy environment support for
|
|
400
|
+
- [Legacy environment support for circular equal comparators](./recipes/legacy-circular-equal-support.md)
|
|
385
401
|
- [Custom comparator support](./recipes/special-objects.md)
|
|
386
402
|
|
|
387
403
|
## Benchmarks
|
|
@@ -491,20 +507,3 @@ All of these have the potential of inflating the respective library's numbers in
|
|
|
491
507
|
the closest apples-to-apples comparison I could create of a reasonable sample size. It should be noted that `react`
|
|
492
508
|
elements can be circular objects, however simple elements are not; I kept the `react` comparison very basic to allow it
|
|
493
509
|
to be included.
|
|
494
|
-
|
|
495
|
-
## Development
|
|
496
|
-
|
|
497
|
-
Standard practice, clone the repo and `npm i` to get the dependencies. The following npm scripts are available:
|
|
498
|
-
|
|
499
|
-
- benchmark => run benchmark tests against other equality libraries
|
|
500
|
-
- build => build `main`, `module`, and `browser` distributables with `rollup`
|
|
501
|
-
- clean => run `rimraf` on the `dist` folder
|
|
502
|
-
- dev => start `vite` playground App
|
|
503
|
-
- dist => run `build`
|
|
504
|
-
- lint => run ESLint on all files in `src` folder (also runs on `dev` script)
|
|
505
|
-
- lint:fix => run `lint` script, but with auto-fixer
|
|
506
|
-
- prepublish:compile => run `lint`, `test:coverage`, `transpile:lib`, `transpile:es`, and `dist` scripts
|
|
507
|
-
- start => run `dev`
|
|
508
|
-
- test => run AVA with NODE_ENV=test on all files in `test` folder
|
|
509
|
-
- test:coverage => run same script as `test` with code coverage calculation via `nyc`
|
|
510
|
-
- test:watch => run same script as `test` but keep persistent watcher
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -75,6 +75,18 @@ Object.is
|
|
|
75
75
|
function sameValueZeroEqual(a, b) {
|
|
76
76
|
return a === b || (a !== a && b !== b);
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Whether the values passed are equal based on a
|
|
80
|
+
* [Strict Equality Comparison](https://262.ecma-international.org/7.0/#sec-strict-equality-comparison) basis.
|
|
81
|
+
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`).
|
|
82
|
+
*
|
|
83
|
+
* @note
|
|
84
|
+
* This is mainly available as a convenience function, such as being a default when a function to determine equality between
|
|
85
|
+
* two objects is used.
|
|
86
|
+
*/
|
|
87
|
+
function strictEqual(a, b) {
|
|
88
|
+
return a === b;
|
|
89
|
+
}
|
|
78
90
|
/**
|
|
79
91
|
* Whether the array buffers are equal in value.
|
|
80
92
|
*/
|
|
@@ -115,12 +127,6 @@ function areDatesEqual(a, b) {
|
|
|
115
127
|
function areErrorsEqual(a, b) {
|
|
116
128
|
return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
|
|
117
129
|
}
|
|
118
|
-
/**
|
|
119
|
-
* Whether the functions passed are equal in value.
|
|
120
|
-
*/
|
|
121
|
-
function areFunctionsEqual(a, b) {
|
|
122
|
-
return a === b;
|
|
123
|
-
}
|
|
124
130
|
/**
|
|
125
131
|
* Whether the `Map`s are equal in value.
|
|
126
132
|
*/
|
|
@@ -170,10 +176,6 @@ function areMapsEqual(a, b, state) {
|
|
|
170
176
|
}
|
|
171
177
|
return true;
|
|
172
178
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Whether the numbers are equal in value.
|
|
175
|
-
*/
|
|
176
|
-
const areNumbersEqual = sameValueEqual;
|
|
177
179
|
/**
|
|
178
180
|
* Whether the objects are equal in value.
|
|
179
181
|
*/
|
|
@@ -368,8 +370,8 @@ function createEqualityComparator(config) {
|
|
|
368
370
|
// Try to fast-path equality checks for other complex object types in the
|
|
369
371
|
// same realm to avoid capturing the string tag. Strict equality is used
|
|
370
372
|
// instead of `instanceof` because it is more performant for the common
|
|
371
|
-
// use-case. If someone is
|
|
372
|
-
// with the string tag comparison.
|
|
373
|
+
// use-case. If someone is creating a subclass from a native class, it will be
|
|
374
|
+
// handled with the string tag comparison.
|
|
373
375
|
if (constructor === Object) {
|
|
374
376
|
return areObjectsEqual(a, b, state);
|
|
375
377
|
}
|
|
@@ -398,14 +400,14 @@ function createEqualityComparator(config) {
|
|
|
398
400
|
if (Array.isArray(a)) {
|
|
399
401
|
return areArraysEqual(a, b, state);
|
|
400
402
|
}
|
|
401
|
-
// Since this is a custom object, capture the string tag to
|
|
403
|
+
// Since this is a custom object, capture the string tag to determining its type.
|
|
402
404
|
// This is reasonably performant in modern environments like v8 and SpiderMonkey.
|
|
403
405
|
const tag = toString.call(a);
|
|
404
406
|
const supportedComparator = supportedComparatorMap[tag];
|
|
405
407
|
if (supportedComparator) {
|
|
406
408
|
return supportedComparator(a, b, state);
|
|
407
409
|
}
|
|
408
|
-
const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, tag);
|
|
410
|
+
const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, state, tag);
|
|
409
411
|
if (unsupportedCustomComparator) {
|
|
410
412
|
return unsupportedCustomComparator(a, b, state);
|
|
411
413
|
}
|
|
@@ -430,9 +432,9 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
430
432
|
areDataViewsEqual,
|
|
431
433
|
areDatesEqual: areDatesEqual,
|
|
432
434
|
areErrorsEqual: areErrorsEqual,
|
|
433
|
-
areFunctionsEqual:
|
|
435
|
+
areFunctionsEqual: strictEqual,
|
|
434
436
|
areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
|
|
435
|
-
areNumbersEqual:
|
|
437
|
+
areNumbersEqual: sameValueEqual,
|
|
436
438
|
areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
|
|
437
439
|
arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
|
|
438
440
|
areRegExpsEqual: areRegExpsEqual,
|
|
@@ -512,6 +514,7 @@ function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, ar
|
|
|
512
514
|
'[object Arguments]': areObjectsEqual,
|
|
513
515
|
'[object Array]': areArraysEqual,
|
|
514
516
|
'[object ArrayBuffer]': areArrayBuffersEqual,
|
|
517
|
+
'[object AsyncGeneratorFunction]': areFunctionsEqual,
|
|
515
518
|
'[object BigInt]': areNumbersEqual,
|
|
516
519
|
'[object BigInt64Array]': areTypedArraysEqual,
|
|
517
520
|
'[object BigUint64Array]': areTypedArraysEqual,
|
|
@@ -626,4 +629,5 @@ exports.shallowEqual = shallowEqual;
|
|
|
626
629
|
exports.strictCircularDeepEqual = strictCircularDeepEqual;
|
|
627
630
|
exports.strictCircularShallowEqual = strictCircularShallowEqual;
|
|
628
631
|
exports.strictDeepEqual = strictDeepEqual;
|
|
632
|
+
exports.strictEqual = strictEqual;
|
|
629
633
|
exports.strictShallowEqual = strictShallowEqual;
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -27,92 +27,75 @@ interface State<Meta> {
|
|
|
27
27
|
*/
|
|
28
28
|
readonly strict: boolean;
|
|
29
29
|
}
|
|
30
|
-
interface CircularState<Meta> extends State<Meta> {
|
|
31
|
-
readonly cache: Cache<any, any>;
|
|
32
|
-
}
|
|
33
|
-
interface DefaultState<Meta> extends State<Meta> {
|
|
34
|
-
readonly cache: undefined;
|
|
35
|
-
}
|
|
36
|
-
interface Dictionary<Value = any> {
|
|
37
|
-
[key: string | symbol]: Value;
|
|
38
|
-
$$typeof?: any;
|
|
39
|
-
}
|
|
40
30
|
interface ComparatorConfig<Meta> {
|
|
41
31
|
/**
|
|
42
32
|
* Whether the array buffers passed are equal in value. In strict mode, this includes
|
|
43
33
|
* additional properties added to the array.
|
|
44
34
|
*/
|
|
45
|
-
areArrayBuffersEqual:
|
|
35
|
+
areArrayBuffersEqual: EqualityComparator<Meta>;
|
|
46
36
|
/**
|
|
47
37
|
* Whether the arrays passed are equal in value. In strict mode, this includes
|
|
48
38
|
* additional properties added to the array.
|
|
49
39
|
*/
|
|
50
|
-
areArraysEqual:
|
|
40
|
+
areArraysEqual: EqualityComparator<Meta>;
|
|
51
41
|
/**
|
|
52
42
|
* Whether the data views passed are equal in value.
|
|
53
43
|
*/
|
|
54
|
-
areDataViewsEqual:
|
|
44
|
+
areDataViewsEqual: EqualityComparator<Meta>;
|
|
55
45
|
/**
|
|
56
46
|
* Whether the dates passed are equal in value.
|
|
57
47
|
*/
|
|
58
|
-
areDatesEqual:
|
|
48
|
+
areDatesEqual: EqualityComparator<Meta>;
|
|
59
49
|
/**
|
|
60
50
|
* Whether the errors passed are equal in value.
|
|
61
51
|
*/
|
|
62
|
-
areErrorsEqual:
|
|
52
|
+
areErrorsEqual: EqualityComparator<Meta>;
|
|
63
53
|
/**
|
|
64
54
|
* Whether the functions passed are equal in value.
|
|
65
55
|
*/
|
|
66
|
-
areFunctionsEqual:
|
|
56
|
+
areFunctionsEqual: EqualityComparator<Meta>;
|
|
67
57
|
/**
|
|
68
58
|
* Whether the maps passed are equal in value. In strict mode, this includes
|
|
69
59
|
* additional properties added to the map.
|
|
70
60
|
*/
|
|
71
|
-
areMapsEqual:
|
|
61
|
+
areMapsEqual: EqualityComparator<Meta>;
|
|
72
62
|
/**
|
|
73
63
|
* Whether the numbers passed are equal in value.
|
|
74
64
|
*/
|
|
75
|
-
areNumbersEqual:
|
|
65
|
+
areNumbersEqual: EqualityComparator<Meta>;
|
|
76
66
|
/**
|
|
77
67
|
* Whether the objects passed are equal in value. In strict mode, this includes
|
|
78
68
|
* non-enumerable properties added to the map, as well as symbol properties.
|
|
79
69
|
*/
|
|
80
|
-
areObjectsEqual:
|
|
70
|
+
areObjectsEqual: EqualityComparator<Meta>;
|
|
81
71
|
/**
|
|
82
72
|
* Whether the primitive wrappers passed are equal in value.
|
|
83
73
|
*/
|
|
84
|
-
arePrimitiveWrappersEqual:
|
|
74
|
+
arePrimitiveWrappersEqual: EqualityComparator<Meta>;
|
|
85
75
|
/**
|
|
86
76
|
* Whether the regexps passed are equal in value.
|
|
87
77
|
*/
|
|
88
|
-
areRegExpsEqual:
|
|
78
|
+
areRegExpsEqual: EqualityComparator<Meta>;
|
|
89
79
|
/**
|
|
90
80
|
* Whether the sets passed are equal in value. In strict mode, this includes
|
|
91
81
|
* additional properties added to the set.
|
|
92
82
|
*/
|
|
93
|
-
areSetsEqual:
|
|
83
|
+
areSetsEqual: EqualityComparator<Meta>;
|
|
94
84
|
/**
|
|
95
85
|
* Whether the typed arrays passed are equal in value. In strict mode, this includes
|
|
96
86
|
* additional properties added to the typed array.
|
|
97
87
|
*/
|
|
98
|
-
areTypedArraysEqual:
|
|
88
|
+
areTypedArraysEqual: EqualityComparator<Meta>;
|
|
99
89
|
/**
|
|
100
90
|
* Whether the URLs passed are equal in value.
|
|
101
91
|
*/
|
|
102
|
-
areUrlsEqual:
|
|
92
|
+
areUrlsEqual: EqualityComparator<Meta>;
|
|
103
93
|
/**
|
|
104
94
|
* Get a custom comparator based on the objects passed.
|
|
105
95
|
*/
|
|
106
|
-
getUnsupportedCustomComparator: ((a: any, b: any, tag: string) =>
|
|
96
|
+
getUnsupportedCustomComparator: ((a: any, b: any, state: State<Meta>, tag: string) => EqualityComparator<Meta> | undefined) | undefined;
|
|
107
97
|
}
|
|
108
|
-
type
|
|
109
|
-
type CreateState<Meta> = () => {
|
|
110
|
-
cache?: Cache<any, any> | undefined;
|
|
111
|
-
meta?: Meta;
|
|
112
|
-
};
|
|
113
|
-
type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;
|
|
114
|
-
type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
115
|
-
type EqualityComparatorCreator<Meta> = (fn: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
|
|
98
|
+
type EqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
116
99
|
type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
117
100
|
type PrimitiveWrapper = Boolean | Number | String;
|
|
118
101
|
/**
|
|
@@ -120,7 +103,6 @@ type PrimitiveWrapper = Boolean | Number | String;
|
|
|
120
103
|
* classes.
|
|
121
104
|
*/
|
|
122
105
|
type TypedArray = BigInt64Array | BigUint64Array | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray;
|
|
123
|
-
type TypeEqualityComparator<Type, Meta = undefined> = (a: Type, b: Type, state: State<Meta>) => boolean;
|
|
124
106
|
interface CustomEqualCreatorOptions<Meta> {
|
|
125
107
|
/**
|
|
126
108
|
* Whether circular references should be supported. It causes the
|
|
@@ -131,9 +113,9 @@ interface CustomEqualCreatorOptions<Meta> {
|
|
|
131
113
|
/**
|
|
132
114
|
* Create a custom configuration of type-specific equality comparators.
|
|
133
115
|
* This receives the default configuration, which allows either replacement
|
|
134
|
-
* or
|
|
116
|
+
* or a superset of the default methods.
|
|
135
117
|
*/
|
|
136
|
-
createCustomConfig?:
|
|
118
|
+
createCustomConfig?: (config: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
|
|
137
119
|
/**
|
|
138
120
|
* Create a custom internal comparator, which is used as an override to the
|
|
139
121
|
* default entry point for nested value equality comparisons. This is often
|
|
@@ -146,7 +128,10 @@ interface CustomEqualCreatorOptions<Meta> {
|
|
|
146
128
|
* Create a custom `state` object passed between the methods. This allows for
|
|
147
129
|
* custom `cache` and/or `meta` values to be used.
|
|
148
130
|
*/
|
|
149
|
-
createState?:
|
|
131
|
+
createState?: () => {
|
|
132
|
+
cache?: Cache<any, any> | undefined;
|
|
133
|
+
meta?: Meta;
|
|
134
|
+
};
|
|
150
135
|
/**
|
|
151
136
|
* Whether the equality comparison is strict, meaning it matches
|
|
152
137
|
* all properties (including symbols and non-enumerable properties)
|
|
@@ -170,6 +155,16 @@ declare const sameValueEqual: (value1: any, value2: any) => boolean;
|
|
|
170
155
|
* are either positive or negative zero.
|
|
171
156
|
*/
|
|
172
157
|
declare function sameValueZeroEqual(a: any, b: any): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Whether the values passed are equal based on a
|
|
160
|
+
* [Strict Equality Comparison](https://262.ecma-international.org/7.0/#sec-strict-equality-comparison) basis.
|
|
161
|
+
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`).
|
|
162
|
+
*
|
|
163
|
+
* @note
|
|
164
|
+
* This is mainly available as a convenience function, such as being a default when a function to determine equality between
|
|
165
|
+
* two objects is used.
|
|
166
|
+
*/
|
|
167
|
+
declare function strictEqual(a: any, b: any): boolean;
|
|
173
168
|
|
|
174
169
|
/**
|
|
175
170
|
* Whether the items passed are deeply-equal in value.
|
|
@@ -215,5 +210,5 @@ declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
|
215
210
|
*/
|
|
216
211
|
declare function createCustomEqual<Meta = undefined>(options?: CustomEqualCreatorOptions<Meta>): <A, B>(a: A, b: B) => boolean;
|
|
217
212
|
|
|
218
|
-
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictShallowEqual };
|
|
219
|
-
export type {
|
|
213
|
+
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictEqual, strictShallowEqual };
|
|
214
|
+
export type { Cache, ComparatorConfig, CustomEqualCreatorOptions, EqualityComparator, InternalEqualityComparator, PrimitiveWrapper, State, TypedArray };
|
package/dist/es/index.d.mts
CHANGED
|
@@ -27,92 +27,75 @@ interface State<Meta> {
|
|
|
27
27
|
*/
|
|
28
28
|
readonly strict: boolean;
|
|
29
29
|
}
|
|
30
|
-
interface CircularState<Meta> extends State<Meta> {
|
|
31
|
-
readonly cache: Cache<any, any>;
|
|
32
|
-
}
|
|
33
|
-
interface DefaultState<Meta> extends State<Meta> {
|
|
34
|
-
readonly cache: undefined;
|
|
35
|
-
}
|
|
36
|
-
interface Dictionary<Value = any> {
|
|
37
|
-
[key: string | symbol]: Value;
|
|
38
|
-
$$typeof?: any;
|
|
39
|
-
}
|
|
40
30
|
interface ComparatorConfig<Meta> {
|
|
41
31
|
/**
|
|
42
32
|
* Whether the array buffers passed are equal in value. In strict mode, this includes
|
|
43
33
|
* additional properties added to the array.
|
|
44
34
|
*/
|
|
45
|
-
areArrayBuffersEqual:
|
|
35
|
+
areArrayBuffersEqual: EqualityComparator<Meta>;
|
|
46
36
|
/**
|
|
47
37
|
* Whether the arrays passed are equal in value. In strict mode, this includes
|
|
48
38
|
* additional properties added to the array.
|
|
49
39
|
*/
|
|
50
|
-
areArraysEqual:
|
|
40
|
+
areArraysEqual: EqualityComparator<Meta>;
|
|
51
41
|
/**
|
|
52
42
|
* Whether the data views passed are equal in value.
|
|
53
43
|
*/
|
|
54
|
-
areDataViewsEqual:
|
|
44
|
+
areDataViewsEqual: EqualityComparator<Meta>;
|
|
55
45
|
/**
|
|
56
46
|
* Whether the dates passed are equal in value.
|
|
57
47
|
*/
|
|
58
|
-
areDatesEqual:
|
|
48
|
+
areDatesEqual: EqualityComparator<Meta>;
|
|
59
49
|
/**
|
|
60
50
|
* Whether the errors passed are equal in value.
|
|
61
51
|
*/
|
|
62
|
-
areErrorsEqual:
|
|
52
|
+
areErrorsEqual: EqualityComparator<Meta>;
|
|
63
53
|
/**
|
|
64
54
|
* Whether the functions passed are equal in value.
|
|
65
55
|
*/
|
|
66
|
-
areFunctionsEqual:
|
|
56
|
+
areFunctionsEqual: EqualityComparator<Meta>;
|
|
67
57
|
/**
|
|
68
58
|
* Whether the maps passed are equal in value. In strict mode, this includes
|
|
69
59
|
* additional properties added to the map.
|
|
70
60
|
*/
|
|
71
|
-
areMapsEqual:
|
|
61
|
+
areMapsEqual: EqualityComparator<Meta>;
|
|
72
62
|
/**
|
|
73
63
|
* Whether the numbers passed are equal in value.
|
|
74
64
|
*/
|
|
75
|
-
areNumbersEqual:
|
|
65
|
+
areNumbersEqual: EqualityComparator<Meta>;
|
|
76
66
|
/**
|
|
77
67
|
* Whether the objects passed are equal in value. In strict mode, this includes
|
|
78
68
|
* non-enumerable properties added to the map, as well as symbol properties.
|
|
79
69
|
*/
|
|
80
|
-
areObjectsEqual:
|
|
70
|
+
areObjectsEqual: EqualityComparator<Meta>;
|
|
81
71
|
/**
|
|
82
72
|
* Whether the primitive wrappers passed are equal in value.
|
|
83
73
|
*/
|
|
84
|
-
arePrimitiveWrappersEqual:
|
|
74
|
+
arePrimitiveWrappersEqual: EqualityComparator<Meta>;
|
|
85
75
|
/**
|
|
86
76
|
* Whether the regexps passed are equal in value.
|
|
87
77
|
*/
|
|
88
|
-
areRegExpsEqual:
|
|
78
|
+
areRegExpsEqual: EqualityComparator<Meta>;
|
|
89
79
|
/**
|
|
90
80
|
* Whether the sets passed are equal in value. In strict mode, this includes
|
|
91
81
|
* additional properties added to the set.
|
|
92
82
|
*/
|
|
93
|
-
areSetsEqual:
|
|
83
|
+
areSetsEqual: EqualityComparator<Meta>;
|
|
94
84
|
/**
|
|
95
85
|
* Whether the typed arrays passed are equal in value. In strict mode, this includes
|
|
96
86
|
* additional properties added to the typed array.
|
|
97
87
|
*/
|
|
98
|
-
areTypedArraysEqual:
|
|
88
|
+
areTypedArraysEqual: EqualityComparator<Meta>;
|
|
99
89
|
/**
|
|
100
90
|
* Whether the URLs passed are equal in value.
|
|
101
91
|
*/
|
|
102
|
-
areUrlsEqual:
|
|
92
|
+
areUrlsEqual: EqualityComparator<Meta>;
|
|
103
93
|
/**
|
|
104
94
|
* Get a custom comparator based on the objects passed.
|
|
105
95
|
*/
|
|
106
|
-
getUnsupportedCustomComparator: ((a: any, b: any, tag: string) =>
|
|
96
|
+
getUnsupportedCustomComparator: ((a: any, b: any, state: State<Meta>, tag: string) => EqualityComparator<Meta> | undefined) | undefined;
|
|
107
97
|
}
|
|
108
|
-
type
|
|
109
|
-
type CreateState<Meta> = () => {
|
|
110
|
-
cache?: Cache<any, any> | undefined;
|
|
111
|
-
meta?: Meta;
|
|
112
|
-
};
|
|
113
|
-
type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;
|
|
114
|
-
type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
115
|
-
type EqualityComparatorCreator<Meta> = (fn: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
|
|
98
|
+
type EqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
116
99
|
type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
117
100
|
type PrimitiveWrapper = Boolean | Number | String;
|
|
118
101
|
/**
|
|
@@ -120,7 +103,6 @@ type PrimitiveWrapper = Boolean | Number | String;
|
|
|
120
103
|
* classes.
|
|
121
104
|
*/
|
|
122
105
|
type TypedArray = BigInt64Array | BigUint64Array | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray;
|
|
123
|
-
type TypeEqualityComparator<Type, Meta = undefined> = (a: Type, b: Type, state: State<Meta>) => boolean;
|
|
124
106
|
interface CustomEqualCreatorOptions<Meta> {
|
|
125
107
|
/**
|
|
126
108
|
* Whether circular references should be supported. It causes the
|
|
@@ -131,9 +113,9 @@ interface CustomEqualCreatorOptions<Meta> {
|
|
|
131
113
|
/**
|
|
132
114
|
* Create a custom configuration of type-specific equality comparators.
|
|
133
115
|
* This receives the default configuration, which allows either replacement
|
|
134
|
-
* or
|
|
116
|
+
* or a superset of the default methods.
|
|
135
117
|
*/
|
|
136
|
-
createCustomConfig?:
|
|
118
|
+
createCustomConfig?: (config: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
|
|
137
119
|
/**
|
|
138
120
|
* Create a custom internal comparator, which is used as an override to the
|
|
139
121
|
* default entry point for nested value equality comparisons. This is often
|
|
@@ -146,7 +128,10 @@ interface CustomEqualCreatorOptions<Meta> {
|
|
|
146
128
|
* Create a custom `state` object passed between the methods. This allows for
|
|
147
129
|
* custom `cache` and/or `meta` values to be used.
|
|
148
130
|
*/
|
|
149
|
-
createState?:
|
|
131
|
+
createState?: () => {
|
|
132
|
+
cache?: Cache<any, any> | undefined;
|
|
133
|
+
meta?: Meta;
|
|
134
|
+
};
|
|
150
135
|
/**
|
|
151
136
|
* Whether the equality comparison is strict, meaning it matches
|
|
152
137
|
* all properties (including symbols and non-enumerable properties)
|
|
@@ -170,6 +155,16 @@ declare const sameValueEqual: (value1: any, value2: any) => boolean;
|
|
|
170
155
|
* are either positive or negative zero.
|
|
171
156
|
*/
|
|
172
157
|
declare function sameValueZeroEqual(a: any, b: any): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Whether the values passed are equal based on a
|
|
160
|
+
* [Strict Equality Comparison](https://262.ecma-international.org/7.0/#sec-strict-equality-comparison) basis.
|
|
161
|
+
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`).
|
|
162
|
+
*
|
|
163
|
+
* @note
|
|
164
|
+
* This is mainly available as a convenience function, such as being a default when a function to determine equality between
|
|
165
|
+
* two objects is used.
|
|
166
|
+
*/
|
|
167
|
+
declare function strictEqual(a: any, b: any): boolean;
|
|
173
168
|
|
|
174
169
|
/**
|
|
175
170
|
* Whether the items passed are deeply-equal in value.
|
|
@@ -215,5 +210,5 @@ declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
|
215
210
|
*/
|
|
216
211
|
declare function createCustomEqual<Meta = undefined>(options?: CustomEqualCreatorOptions<Meta>): <A, B>(a: A, b: B) => boolean;
|
|
217
212
|
|
|
218
|
-
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictShallowEqual };
|
|
219
|
-
export type {
|
|
213
|
+
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictEqual, strictShallowEqual };
|
|
214
|
+
export type { Cache, ComparatorConfig, CustomEqualCreatorOptions, EqualityComparator, InternalEqualityComparator, PrimitiveWrapper, State, TypedArray };
|
package/dist/es/index.mjs
CHANGED
|
@@ -73,6 +73,18 @@ Object.is
|
|
|
73
73
|
function sameValueZeroEqual(a, b) {
|
|
74
74
|
return a === b || (a !== a && b !== b);
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Whether the values passed are equal based on a
|
|
78
|
+
* [Strict Equality Comparison](https://262.ecma-international.org/7.0/#sec-strict-equality-comparison) basis.
|
|
79
|
+
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`).
|
|
80
|
+
*
|
|
81
|
+
* @note
|
|
82
|
+
* This is mainly available as a convenience function, such as being a default when a function to determine equality between
|
|
83
|
+
* two objects is used.
|
|
84
|
+
*/
|
|
85
|
+
function strictEqual(a, b) {
|
|
86
|
+
return a === b;
|
|
87
|
+
}
|
|
76
88
|
/**
|
|
77
89
|
* Whether the array buffers are equal in value.
|
|
78
90
|
*/
|
|
@@ -113,12 +125,6 @@ function areDatesEqual(a, b) {
|
|
|
113
125
|
function areErrorsEqual(a, b) {
|
|
114
126
|
return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
|
|
115
127
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Whether the functions passed are equal in value.
|
|
118
|
-
*/
|
|
119
|
-
function areFunctionsEqual(a, b) {
|
|
120
|
-
return a === b;
|
|
121
|
-
}
|
|
122
128
|
/**
|
|
123
129
|
* Whether the `Map`s are equal in value.
|
|
124
130
|
*/
|
|
@@ -168,10 +174,6 @@ function areMapsEqual(a, b, state) {
|
|
|
168
174
|
}
|
|
169
175
|
return true;
|
|
170
176
|
}
|
|
171
|
-
/**
|
|
172
|
-
* Whether the numbers are equal in value.
|
|
173
|
-
*/
|
|
174
|
-
const areNumbersEqual = sameValueEqual;
|
|
175
177
|
/**
|
|
176
178
|
* Whether the objects are equal in value.
|
|
177
179
|
*/
|
|
@@ -366,8 +368,8 @@ function createEqualityComparator(config) {
|
|
|
366
368
|
// Try to fast-path equality checks for other complex object types in the
|
|
367
369
|
// same realm to avoid capturing the string tag. Strict equality is used
|
|
368
370
|
// instead of `instanceof` because it is more performant for the common
|
|
369
|
-
// use-case. If someone is
|
|
370
|
-
// with the string tag comparison.
|
|
371
|
+
// use-case. If someone is creating a subclass from a native class, it will be
|
|
372
|
+
// handled with the string tag comparison.
|
|
371
373
|
if (constructor === Object) {
|
|
372
374
|
return areObjectsEqual(a, b, state);
|
|
373
375
|
}
|
|
@@ -396,14 +398,14 @@ function createEqualityComparator(config) {
|
|
|
396
398
|
if (Array.isArray(a)) {
|
|
397
399
|
return areArraysEqual(a, b, state);
|
|
398
400
|
}
|
|
399
|
-
// Since this is a custom object, capture the string tag to
|
|
401
|
+
// Since this is a custom object, capture the string tag to determining its type.
|
|
400
402
|
// This is reasonably performant in modern environments like v8 and SpiderMonkey.
|
|
401
403
|
const tag = toString.call(a);
|
|
402
404
|
const supportedComparator = supportedComparatorMap[tag];
|
|
403
405
|
if (supportedComparator) {
|
|
404
406
|
return supportedComparator(a, b, state);
|
|
405
407
|
}
|
|
406
|
-
const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, tag);
|
|
408
|
+
const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, state, tag);
|
|
407
409
|
if (unsupportedCustomComparator) {
|
|
408
410
|
return unsupportedCustomComparator(a, b, state);
|
|
409
411
|
}
|
|
@@ -428,9 +430,9 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
428
430
|
areDataViewsEqual,
|
|
429
431
|
areDatesEqual: areDatesEqual,
|
|
430
432
|
areErrorsEqual: areErrorsEqual,
|
|
431
|
-
areFunctionsEqual:
|
|
433
|
+
areFunctionsEqual: strictEqual,
|
|
432
434
|
areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
|
|
433
|
-
areNumbersEqual:
|
|
435
|
+
areNumbersEqual: sameValueEqual,
|
|
434
436
|
areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
|
|
435
437
|
arePrimitiveWrappersEqual: arePrimitiveWrappersEqual,
|
|
436
438
|
areRegExpsEqual: areRegExpsEqual,
|
|
@@ -510,6 +512,7 @@ function createSupportedComparatorMap({ areArrayBuffersEqual, areArraysEqual, ar
|
|
|
510
512
|
'[object Arguments]': areObjectsEqual,
|
|
511
513
|
'[object Array]': areArraysEqual,
|
|
512
514
|
'[object ArrayBuffer]': areArrayBuffersEqual,
|
|
515
|
+
'[object AsyncGeneratorFunction]': areFunctionsEqual,
|
|
513
516
|
'[object BigInt]': areNumbersEqual,
|
|
514
517
|
'[object BigInt64Array]': areTypedArraysEqual,
|
|
515
518
|
'[object BigUint64Array]': areTypedArraysEqual,
|
|
@@ -614,4 +617,4 @@ function createCustomEqual(options = {}) {
|
|
|
614
617
|
return createIsEqual({ circular, comparator, createState, equals, strict });
|
|
615
618
|
}
|
|
616
619
|
|
|
617
|
-
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictShallowEqual };
|
|
620
|
+
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictEqual, strictShallowEqual };
|
package/index.d.ts
CHANGED
|
@@ -27,92 +27,75 @@ interface State<Meta> {
|
|
|
27
27
|
*/
|
|
28
28
|
readonly strict: boolean;
|
|
29
29
|
}
|
|
30
|
-
interface CircularState<Meta> extends State<Meta> {
|
|
31
|
-
readonly cache: Cache<any, any>;
|
|
32
|
-
}
|
|
33
|
-
interface DefaultState<Meta> extends State<Meta> {
|
|
34
|
-
readonly cache: undefined;
|
|
35
|
-
}
|
|
36
|
-
interface Dictionary<Value = any> {
|
|
37
|
-
[key: string | symbol]: Value;
|
|
38
|
-
$$typeof?: any;
|
|
39
|
-
}
|
|
40
30
|
interface ComparatorConfig<Meta> {
|
|
41
31
|
/**
|
|
42
32
|
* Whether the array buffers passed are equal in value. In strict mode, this includes
|
|
43
33
|
* additional properties added to the array.
|
|
44
34
|
*/
|
|
45
|
-
areArrayBuffersEqual:
|
|
35
|
+
areArrayBuffersEqual: EqualityComparator<Meta>;
|
|
46
36
|
/**
|
|
47
37
|
* Whether the arrays passed are equal in value. In strict mode, this includes
|
|
48
38
|
* additional properties added to the array.
|
|
49
39
|
*/
|
|
50
|
-
areArraysEqual:
|
|
40
|
+
areArraysEqual: EqualityComparator<Meta>;
|
|
51
41
|
/**
|
|
52
42
|
* Whether the data views passed are equal in value.
|
|
53
43
|
*/
|
|
54
|
-
areDataViewsEqual:
|
|
44
|
+
areDataViewsEqual: EqualityComparator<Meta>;
|
|
55
45
|
/**
|
|
56
46
|
* Whether the dates passed are equal in value.
|
|
57
47
|
*/
|
|
58
|
-
areDatesEqual:
|
|
48
|
+
areDatesEqual: EqualityComparator<Meta>;
|
|
59
49
|
/**
|
|
60
50
|
* Whether the errors passed are equal in value.
|
|
61
51
|
*/
|
|
62
|
-
areErrorsEqual:
|
|
52
|
+
areErrorsEqual: EqualityComparator<Meta>;
|
|
63
53
|
/**
|
|
64
54
|
* Whether the functions passed are equal in value.
|
|
65
55
|
*/
|
|
66
|
-
areFunctionsEqual:
|
|
56
|
+
areFunctionsEqual: EqualityComparator<Meta>;
|
|
67
57
|
/**
|
|
68
58
|
* Whether the maps passed are equal in value. In strict mode, this includes
|
|
69
59
|
* additional properties added to the map.
|
|
70
60
|
*/
|
|
71
|
-
areMapsEqual:
|
|
61
|
+
areMapsEqual: EqualityComparator<Meta>;
|
|
72
62
|
/**
|
|
73
63
|
* Whether the numbers passed are equal in value.
|
|
74
64
|
*/
|
|
75
|
-
areNumbersEqual:
|
|
65
|
+
areNumbersEqual: EqualityComparator<Meta>;
|
|
76
66
|
/**
|
|
77
67
|
* Whether the objects passed are equal in value. In strict mode, this includes
|
|
78
68
|
* non-enumerable properties added to the map, as well as symbol properties.
|
|
79
69
|
*/
|
|
80
|
-
areObjectsEqual:
|
|
70
|
+
areObjectsEqual: EqualityComparator<Meta>;
|
|
81
71
|
/**
|
|
82
72
|
* Whether the primitive wrappers passed are equal in value.
|
|
83
73
|
*/
|
|
84
|
-
arePrimitiveWrappersEqual:
|
|
74
|
+
arePrimitiveWrappersEqual: EqualityComparator<Meta>;
|
|
85
75
|
/**
|
|
86
76
|
* Whether the regexps passed are equal in value.
|
|
87
77
|
*/
|
|
88
|
-
areRegExpsEqual:
|
|
78
|
+
areRegExpsEqual: EqualityComparator<Meta>;
|
|
89
79
|
/**
|
|
90
80
|
* Whether the sets passed are equal in value. In strict mode, this includes
|
|
91
81
|
* additional properties added to the set.
|
|
92
82
|
*/
|
|
93
|
-
areSetsEqual:
|
|
83
|
+
areSetsEqual: EqualityComparator<Meta>;
|
|
94
84
|
/**
|
|
95
85
|
* Whether the typed arrays passed are equal in value. In strict mode, this includes
|
|
96
86
|
* additional properties added to the typed array.
|
|
97
87
|
*/
|
|
98
|
-
areTypedArraysEqual:
|
|
88
|
+
areTypedArraysEqual: EqualityComparator<Meta>;
|
|
99
89
|
/**
|
|
100
90
|
* Whether the URLs passed are equal in value.
|
|
101
91
|
*/
|
|
102
|
-
areUrlsEqual:
|
|
92
|
+
areUrlsEqual: EqualityComparator<Meta>;
|
|
103
93
|
/**
|
|
104
94
|
* Get a custom comparator based on the objects passed.
|
|
105
95
|
*/
|
|
106
|
-
getUnsupportedCustomComparator: ((a: any, b: any, tag: string) =>
|
|
96
|
+
getUnsupportedCustomComparator: ((a: any, b: any, state: State<Meta>, tag: string) => EqualityComparator<Meta> | undefined) | undefined;
|
|
107
97
|
}
|
|
108
|
-
type
|
|
109
|
-
type CreateState<Meta> = () => {
|
|
110
|
-
cache?: Cache<any, any> | undefined;
|
|
111
|
-
meta?: Meta;
|
|
112
|
-
};
|
|
113
|
-
type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;
|
|
114
|
-
type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
115
|
-
type EqualityComparatorCreator<Meta> = (fn: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
|
|
98
|
+
type EqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
116
99
|
type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
117
100
|
type PrimitiveWrapper = Boolean | Number | String;
|
|
118
101
|
/**
|
|
@@ -120,7 +103,6 @@ type PrimitiveWrapper = Boolean | Number | String;
|
|
|
120
103
|
* classes.
|
|
121
104
|
*/
|
|
122
105
|
type TypedArray = BigInt64Array | BigUint64Array | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray;
|
|
123
|
-
type TypeEqualityComparator<Type, Meta = undefined> = (a: Type, b: Type, state: State<Meta>) => boolean;
|
|
124
106
|
interface CustomEqualCreatorOptions<Meta> {
|
|
125
107
|
/**
|
|
126
108
|
* Whether circular references should be supported. It causes the
|
|
@@ -131,9 +113,9 @@ interface CustomEqualCreatorOptions<Meta> {
|
|
|
131
113
|
/**
|
|
132
114
|
* Create a custom configuration of type-specific equality comparators.
|
|
133
115
|
* This receives the default configuration, which allows either replacement
|
|
134
|
-
* or
|
|
116
|
+
* or a superset of the default methods.
|
|
135
117
|
*/
|
|
136
|
-
createCustomConfig?:
|
|
118
|
+
createCustomConfig?: (config: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
|
|
137
119
|
/**
|
|
138
120
|
* Create a custom internal comparator, which is used as an override to the
|
|
139
121
|
* default entry point for nested value equality comparisons. This is often
|
|
@@ -146,7 +128,10 @@ interface CustomEqualCreatorOptions<Meta> {
|
|
|
146
128
|
* Create a custom `state` object passed between the methods. This allows for
|
|
147
129
|
* custom `cache` and/or `meta` values to be used.
|
|
148
130
|
*/
|
|
149
|
-
createState?:
|
|
131
|
+
createState?: () => {
|
|
132
|
+
cache?: Cache<any, any> | undefined;
|
|
133
|
+
meta?: Meta;
|
|
134
|
+
};
|
|
150
135
|
/**
|
|
151
136
|
* Whether the equality comparison is strict, meaning it matches
|
|
152
137
|
* all properties (including symbols and non-enumerable properties)
|
|
@@ -170,6 +155,16 @@ declare const sameValueEqual: (value1: any, value2: any) => boolean;
|
|
|
170
155
|
* are either positive or negative zero.
|
|
171
156
|
*/
|
|
172
157
|
declare function sameValueZeroEqual(a: any, b: any): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Whether the values passed are equal based on a
|
|
160
|
+
* [Strict Equality Comparison](https://262.ecma-international.org/7.0/#sec-strict-equality-comparison) basis.
|
|
161
|
+
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`).
|
|
162
|
+
*
|
|
163
|
+
* @note
|
|
164
|
+
* This is mainly available as a convenience function, such as being a default when a function to determine equality between
|
|
165
|
+
* two objects is used.
|
|
166
|
+
*/
|
|
167
|
+
declare function strictEqual(a: any, b: any): boolean;
|
|
173
168
|
|
|
174
169
|
/**
|
|
175
170
|
* Whether the items passed are deeply-equal in value.
|
|
@@ -215,5 +210,5 @@ declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
|
215
210
|
*/
|
|
216
211
|
declare function createCustomEqual<Meta = undefined>(options?: CustomEqualCreatorOptions<Meta>): <A, B>(a: A, b: B) => boolean;
|
|
217
212
|
|
|
218
|
-
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictShallowEqual };
|
|
219
|
-
export type {
|
|
213
|
+
export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictEqual, strictShallowEqual };
|
|
214
|
+
export type { Cache, ComparatorConfig, CustomEqualCreatorOptions, EqualityComparator, InternalEqualityComparator, PrimitiveWrapper, State, TypedArray };
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"bugs": {
|
|
8
8
|
"url": "https://github.com/planttheidea/fast-equals/issues"
|
|
9
9
|
},
|
|
10
|
-
"description": "A blazing
|
|
10
|
+
"description": "A blazing-fast equality comparison utility for a variety of use-cases",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@planttheidea/build-tools": "^2.0.0",
|
|
13
13
|
"@types/lodash": "^4.17.21",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@types/react-dom": "^19.2.3",
|
|
18
18
|
"@typescript-eslint/eslint-plugin": "^8.50.0",
|
|
19
19
|
"@typescript-eslint/parser": "^8.50.0",
|
|
20
|
-
"@vitest/coverage-v8": "^4.0.
|
|
20
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
21
21
|
"cli-table3": "^0.6.5",
|
|
22
22
|
"decircularize": "^1.0.0",
|
|
23
23
|
"deep-eql": "^5.0.2",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"typescript-eslint": "^8.50.0",
|
|
43
43
|
"underscore": "^1.13.7",
|
|
44
44
|
"vite": "^7.3.0",
|
|
45
|
-
"vitest": "^4.0.
|
|
45
|
+
"vitest": "^4.0.16"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=6.0.0"
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
"sideEffects": false,
|
|
110
110
|
"type": "module",
|
|
111
111
|
"types": "./index.d.ts",
|
|
112
|
-
"version": "6.0.0
|
|
112
|
+
"version": "6.0.0"
|
|
113
113
|
}
|