fast-equals 6.1.0 → 6.2.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 +4 -0
- package/dist/cjs/index.cjs +11 -5
- package/dist/cjs/index.d.cts +2 -1
- package/dist/es/index.d.mts +2 -1
- package/dist/es/index.mjs +11 -5
- package/index.d.ts +2 -1
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -235,6 +235,7 @@ Performs the same comparison as `deepEqual` but performs a strict comparison of
|
|
|
235
235
|
- Checking full descriptor of properties on the object to match
|
|
236
236
|
- Checking non-index properties on arrays
|
|
237
237
|
- Checking non-key properties on `Map` / `Set` objects
|
|
238
|
+
- Checking own properties on `Date` objects
|
|
238
239
|
|
|
239
240
|
```ts
|
|
240
241
|
const array = [{ foo: 'bar' }];
|
|
@@ -255,6 +256,7 @@ Performs the same comparison as `shallowEqual` but performs a strict comparison
|
|
|
255
256
|
- Checking full descriptor of properties on the object to match
|
|
256
257
|
- Checking non-index properties on arrays
|
|
257
258
|
- Checking non-key properties on `Map` / `Set` objects
|
|
259
|
+
- Checking own properties on `Date` objects
|
|
258
260
|
|
|
259
261
|
```ts
|
|
260
262
|
const array = ['foo'];
|
|
@@ -276,6 +278,7 @@ Performs the same comparison as `circularDeepEqual` but performs a strict compar
|
|
|
276
278
|
- Checking full descriptor of properties on the object to match
|
|
277
279
|
- Checking non-index properties on arrays
|
|
278
280
|
- Checking non-key properties on `Map` / `Set` objects
|
|
281
|
+
- Checking own properties on `Date` objects
|
|
279
282
|
|
|
280
283
|
```ts
|
|
281
284
|
function Circular(value) {
|
|
@@ -315,6 +318,7 @@ Performs the same comparison as `circularShallowEqual` but performs a strict com
|
|
|
315
318
|
- Checking full descriptor of properties on the object to match
|
|
316
319
|
- Checking non-index properties on arrays
|
|
317
320
|
- Checking non-key properties on `Map` / `Set` objects
|
|
321
|
+
- Checking own properties on `Date` objects
|
|
318
322
|
|
|
319
323
|
```ts
|
|
320
324
|
const array = ['foo'];
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -71,10 +71,11 @@ function isNullPrototypeComparable(a, b) {
|
|
|
71
71
|
const PREACT_VNODE = '__v';
|
|
72
72
|
const PREACT_OWNER = '__o';
|
|
73
73
|
const REACT_OWNER = '_owner';
|
|
74
|
-
// `Float16Array` is recent enough that it cannot be referenced unguarded, and capturing its
|
|
75
|
-
// availability once keeps that detail out of the comparison itself.
|
|
76
|
-
const HAS_FLOAT_16_ARRAY = typeof Float16Array !== 'undefined';
|
|
77
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;
|
|
78
79
|
/**
|
|
79
80
|
* Whether the values passed are equal based on a [SameValue](https://262.ecma-international.org/7.0/#sec-samevalue) basis.
|
|
80
81
|
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`) or both are `NaN`.
|
|
@@ -326,7 +327,8 @@ function areTypedArraysEqual(a, b) {
|
|
|
326
327
|
// Only float-backed views can hold `NaN`, and the additional check needed to treat it as equal
|
|
327
328
|
// to itself measurably slows the loop, so integer views keep the plain comparison. This is
|
|
328
329
|
// hoisted out of the loop so the cost is paid once per call rather than once per element.
|
|
329
|
-
|
|
330
|
+
const tag = getTypedArrayTag.call(a);
|
|
331
|
+
if (tag === 'Float64Array' || tag === 'Float32Array' || tag === 'Float16Array') {
|
|
330
332
|
while (index-- > 0) {
|
|
331
333
|
// `NaN` is the only value not equal to itself, and it is treated as equal here to match
|
|
332
334
|
// the SameValueZero semantics used for every other numeric comparison in the library.
|
|
@@ -521,7 +523,9 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
521
523
|
areArrayBuffersEqual,
|
|
522
524
|
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
523
525
|
areDataViewsEqual,
|
|
524
|
-
areDatesEqual:
|
|
526
|
+
areDatesEqual: strict
|
|
527
|
+
? combineComparators(areDatesEqual, areObjectsEqualStrict)
|
|
528
|
+
: areDatesEqual,
|
|
525
529
|
// `Error` subclasses routinely carry their own enumerable properties (`status`, `code`, ...),
|
|
526
530
|
// which the error comparator alone does not see, so it is composed with the object comparator.
|
|
527
531
|
// `name` / `message` / `stack` are own but not enumerable, which is why errors need a
|
|
@@ -548,6 +552,7 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
548
552
|
}
|
|
549
553
|
if (circular) {
|
|
550
554
|
const areArraysEqual = createIsCircular(config.areArraysEqual);
|
|
555
|
+
const areDatesEqual = strict ? createIsCircular(config.areDatesEqual) : config.areDatesEqual;
|
|
551
556
|
// Errors are included because comparing `cause` and own properties by value means an error
|
|
552
557
|
// that references itself would otherwise recurse without bound.
|
|
553
558
|
const areErrorsEqual = createIsCircular(config.areErrorsEqual);
|
|
@@ -556,6 +561,7 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
556
561
|
const areSetsEqual = createIsCircular(config.areSetsEqual);
|
|
557
562
|
config = Object.assign({}, config, {
|
|
558
563
|
areArraysEqual,
|
|
564
|
+
areDatesEqual,
|
|
559
565
|
areErrorsEqual,
|
|
560
566
|
areMapsEqual,
|
|
561
567
|
areObjectsEqual,
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -43,7 +43,8 @@ interface ComparatorConfig<Meta> {
|
|
|
43
43
|
*/
|
|
44
44
|
areDataViewsEqual: EqualityComparator<Meta>;
|
|
45
45
|
/**
|
|
46
|
-
* Whether the dates passed are equal in value.
|
|
46
|
+
* Whether the dates passed are equal in value. In strict mode, this includes
|
|
47
|
+
* additional properties added to the date.
|
|
47
48
|
*/
|
|
48
49
|
areDatesEqual: EqualityComparator<Meta>;
|
|
49
50
|
/**
|
package/dist/es/index.d.mts
CHANGED
|
@@ -43,7 +43,8 @@ interface ComparatorConfig<Meta> {
|
|
|
43
43
|
*/
|
|
44
44
|
areDataViewsEqual: EqualityComparator<Meta>;
|
|
45
45
|
/**
|
|
46
|
-
* Whether the dates passed are equal in value.
|
|
46
|
+
* Whether the dates passed are equal in value. In strict mode, this includes
|
|
47
|
+
* additional properties added to the date.
|
|
47
48
|
*/
|
|
48
49
|
areDatesEqual: EqualityComparator<Meta>;
|
|
49
50
|
/**
|
package/dist/es/index.mjs
CHANGED
|
@@ -69,10 +69,11 @@ function isNullPrototypeComparable(a, b) {
|
|
|
69
69
|
const PREACT_VNODE = '__v';
|
|
70
70
|
const PREACT_OWNER = '__o';
|
|
71
71
|
const REACT_OWNER = '_owner';
|
|
72
|
-
// `Float16Array` is recent enough that it cannot be referenced unguarded, and capturing its
|
|
73
|
-
// availability once keeps that detail out of the comparison itself.
|
|
74
|
-
const HAS_FLOAT_16_ARRAY = typeof Float16Array !== 'undefined';
|
|
75
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;
|
|
76
77
|
/**
|
|
77
78
|
* Whether the values passed are equal based on a [SameValue](https://262.ecma-international.org/7.0/#sec-samevalue) basis.
|
|
78
79
|
* Simplified, this maps to if the two values are referentially equal to one another (`a === b`) or both are `NaN`.
|
|
@@ -324,7 +325,8 @@ function areTypedArraysEqual(a, b) {
|
|
|
324
325
|
// Only float-backed views can hold `NaN`, and the additional check needed to treat it as equal
|
|
325
326
|
// to itself measurably slows the loop, so integer views keep the plain comparison. This is
|
|
326
327
|
// hoisted out of the loop so the cost is paid once per call rather than once per element.
|
|
327
|
-
|
|
328
|
+
const tag = getTypedArrayTag.call(a);
|
|
329
|
+
if (tag === 'Float64Array' || tag === 'Float32Array' || tag === 'Float16Array') {
|
|
328
330
|
while (index-- > 0) {
|
|
329
331
|
// `NaN` is the only value not equal to itself, and it is treated as equal here to match
|
|
330
332
|
// the SameValueZero semantics used for every other numeric comparison in the library.
|
|
@@ -519,7 +521,9 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
519
521
|
areArrayBuffersEqual,
|
|
520
522
|
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
521
523
|
areDataViewsEqual,
|
|
522
|
-
areDatesEqual:
|
|
524
|
+
areDatesEqual: strict
|
|
525
|
+
? combineComparators(areDatesEqual, areObjectsEqualStrict)
|
|
526
|
+
: areDatesEqual,
|
|
523
527
|
// `Error` subclasses routinely carry their own enumerable properties (`status`, `code`, ...),
|
|
524
528
|
// which the error comparator alone does not see, so it is composed with the object comparator.
|
|
525
529
|
// `name` / `message` / `stack` are own but not enumerable, which is why errors need a
|
|
@@ -546,6 +550,7 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
546
550
|
}
|
|
547
551
|
if (circular) {
|
|
548
552
|
const areArraysEqual = createIsCircular(config.areArraysEqual);
|
|
553
|
+
const areDatesEqual = strict ? createIsCircular(config.areDatesEqual) : config.areDatesEqual;
|
|
549
554
|
// Errors are included because comparing `cause` and own properties by value means an error
|
|
550
555
|
// that references itself would otherwise recurse without bound.
|
|
551
556
|
const areErrorsEqual = createIsCircular(config.areErrorsEqual);
|
|
@@ -554,6 +559,7 @@ function createEqualityComparatorConfig({ circular, createCustomConfig, strict,
|
|
|
554
559
|
const areSetsEqual = createIsCircular(config.areSetsEqual);
|
|
555
560
|
config = Object.assign({}, config, {
|
|
556
561
|
areArraysEqual,
|
|
562
|
+
areDatesEqual,
|
|
557
563
|
areErrorsEqual,
|
|
558
564
|
areMapsEqual,
|
|
559
565
|
areObjectsEqual,
|
package/index.d.ts
CHANGED
|
@@ -43,7 +43,8 @@ interface ComparatorConfig<Meta> {
|
|
|
43
43
|
*/
|
|
44
44
|
areDataViewsEqual: EqualityComparator<Meta>;
|
|
45
45
|
/**
|
|
46
|
-
* Whether the dates passed are equal in value.
|
|
46
|
+
* Whether the dates passed are equal in value. In strict mode, this includes
|
|
47
|
+
* additional properties added to the date.
|
|
47
48
|
*/
|
|
48
49
|
areDatesEqual: EqualityComparator<Meta>;
|
|
49
50
|
/**
|
package/package.json
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@planttheidea/build-tools": "^2.0.8",
|
|
13
13
|
"@types/lodash": "^4.17.25",
|
|
14
|
-
"@types/node": "^24.
|
|
14
|
+
"@types/node": "^24.19.1",
|
|
15
15
|
"@types/ramda": "^0.32.0",
|
|
16
|
-
"@types/react": "^19.
|
|
17
|
-
"@types/react-dom": "^19.
|
|
18
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
19
|
-
"@typescript-eslint/parser": "^8.
|
|
16
|
+
"@types/react": "^19.3.0",
|
|
17
|
+
"@types/react-dom": "^19.3.0",
|
|
18
|
+
"@typescript-eslint/eslint-plugin": "^8.71.1",
|
|
19
|
+
"@typescript-eslint/parser": "^8.71.1",
|
|
20
20
|
"@vitest/coverage-v8": "^4.1.11",
|
|
21
21
|
"cli-table3": "^0.6.5",
|
|
22
22
|
"decircularize": "^1.0.0",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"fast-glob": "^3.3.3",
|
|
32
32
|
"lodash": "^4.18.1",
|
|
33
33
|
"nano-equal": "^2.0.2",
|
|
34
|
-
"prettier": "^3.9.
|
|
35
|
-
"react": "^19.
|
|
36
|
-
"react-dom": "^19.
|
|
34
|
+
"prettier": "^3.9.9",
|
|
35
|
+
"react": "^19.3.0",
|
|
36
|
+
"react-dom": "^19.3.0",
|
|
37
37
|
"react-fast-compare": "^3.2.2",
|
|
38
|
-
"release-it": "^21.
|
|
39
|
-
"rollup": "^4.
|
|
38
|
+
"release-it": "^21.1.1",
|
|
39
|
+
"rollup": "^4.64.3",
|
|
40
40
|
"shallow-equal-fuzzy": "^0.0.2",
|
|
41
|
-
"tinybench": "^6.1
|
|
41
|
+
"tinybench": "^6.2.1",
|
|
42
42
|
"typescript": "^6.0.3",
|
|
43
|
-
"typescript-eslint": "^8.
|
|
43
|
+
"typescript-eslint": "^8.71.1",
|
|
44
44
|
"underscore": "^1.13.8",
|
|
45
|
-
"vite": "^8.
|
|
45
|
+
"vite": "^8.3.4",
|
|
46
46
|
"vitest": "^4.1.11"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"sideEffects": false,
|
|
111
111
|
"type": "module",
|
|
112
112
|
"types": "./index.d.ts",
|
|
113
|
-
"version": "6.
|
|
113
|
+
"version": "6.2.0"
|
|
114
114
|
}
|