fast-equals 4.0.0-beta.0 → 4.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/CHANGELOG.md +31 -0
- package/README.md +14 -129
- package/dist/fast-equals.cjs.js +5 -1
- package/dist/fast-equals.cjs.js.map +1 -1
- package/dist/fast-equals.esm.js +5 -1
- package/dist/fast-equals.esm.js.map +1 -1
- package/dist/fast-equals.js +5 -1
- package/dist/fast-equals.js.map +1 -1
- package/dist/fast-equals.min.js +1 -1
- package/dist/fast-equals.mjs +5 -1
- package/dist/fast-equals.mjs.map +1 -1
- package/package.json +3 -3
- package/recipes/explicit-property-check.md +28 -0
- package/recipes/legacy-circular-equal-support.md +66 -0
- package/recipes/legacy-regexp-support.md +26 -0
- package/recipes/non-standard-properties.md +34 -0
- package/recipes/strict-property-descriptor-check.md +42 -0
- package/recipes/using-meta-in-comparison.md +23 -0
- package/src/arrays.ts +1 -1
- package/src/comparator.ts +3 -3
- package/src/index.ts +9 -5
- package/src/maps.ts +1 -1
- package/src/objects.ts +1 -1
- package/src/sets.ts +1 -1
- package/src/utils.ts +9 -11
package/src/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type {
|
|
|
22
22
|
EqualityComparatorCreator,
|
|
23
23
|
InternalEqualityComparator,
|
|
24
24
|
NativeEqualityComparator,
|
|
25
|
+
TypeEqualityComparator,
|
|
25
26
|
} from './utils';
|
|
26
27
|
|
|
27
28
|
export type BaseCircularMeta = Pick<
|
|
@@ -105,7 +106,7 @@ export function circularShallowEqual<A, B>(a: A, b: B): boolean {
|
|
|
105
106
|
* support for legacy environments that do not support expected features like
|
|
106
107
|
* `RegExp.prototype.flags` out of the box.
|
|
107
108
|
*/
|
|
108
|
-
export function createCustomEqual<Meta>(
|
|
109
|
+
export function createCustomEqual<Meta = undefined>(
|
|
109
110
|
getComparatorOptions: GetComparatorOptions<Meta>,
|
|
110
111
|
): EqualityComparator<Meta> {
|
|
111
112
|
return createComparator<Meta>(
|
|
@@ -123,13 +124,16 @@ export function createCustomEqual<Meta>(
|
|
|
123
124
|
* support for legacy environments that do not support expected features like
|
|
124
125
|
* `WeakMap` out of the box.
|
|
125
126
|
*/
|
|
126
|
-
export function createCustomCircularEqual<
|
|
127
|
-
|
|
128
|
-
): EqualityComparator<Meta> {
|
|
129
|
-
|
|
127
|
+
export function createCustomCircularEqual<
|
|
128
|
+
Meta extends BaseCircularMeta = WeakMap<any, any>,
|
|
129
|
+
>(getComparatorOptions: GetComparatorOptions<Meta>): EqualityComparator<Meta> {
|
|
130
|
+
const comparator = createComparator<Meta>(
|
|
130
131
|
merge(
|
|
131
132
|
DEFAULT_CIRCULAR_CONFIG,
|
|
132
133
|
getComparatorOptions(DEFAULT_CIRCULAR_CONFIG as any),
|
|
133
134
|
),
|
|
134
135
|
);
|
|
136
|
+
|
|
137
|
+
return ((a: any, b: any, meta: any = new WeakMap()) =>
|
|
138
|
+
comparator(a, b, meta)) as EqualityComparator<Meta>;
|
|
135
139
|
}
|
package/src/maps.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { InternalEqualityComparator } from './utils';
|
|
|
8
8
|
export function areMapsEqual(
|
|
9
9
|
a: Map<any, any>,
|
|
10
10
|
b: Map<any, any>,
|
|
11
|
-
isEqual: InternalEqualityComparator
|
|
11
|
+
isEqual: InternalEqualityComparator<any>,
|
|
12
12
|
meta: any,
|
|
13
13
|
): boolean {
|
|
14
14
|
let isValueEqual = a.size === b.size;
|
package/src/objects.ts
CHANGED
|
@@ -15,7 +15,7 @@ const { hasOwnProperty } = Object.prototype;
|
|
|
15
15
|
export function areObjectsEqual(
|
|
16
16
|
a: Dictionary<any>,
|
|
17
17
|
b: Dictionary<any>,
|
|
18
|
-
isEqual: InternalEqualityComparator
|
|
18
|
+
isEqual: InternalEqualityComparator<any>,
|
|
19
19
|
meta: any,
|
|
20
20
|
): boolean {
|
|
21
21
|
const keysA = Object.keys(a);
|
package/src/sets.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { InternalEqualityComparator } from './utils';
|
|
|
8
8
|
export function areSetsEqual(
|
|
9
9
|
a: Set<any>,
|
|
10
10
|
b: Set<any>,
|
|
11
|
-
isEqual: InternalEqualityComparator
|
|
11
|
+
isEqual: InternalEqualityComparator<any>,
|
|
12
12
|
meta: any,
|
|
13
13
|
): boolean {
|
|
14
14
|
let isValueEqual = a.size === b.size;
|
package/src/utils.ts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
export type InternalEqualityComparator = (
|
|
1
|
+
export type InternalEqualityComparator<Meta> = (
|
|
2
2
|
a: any,
|
|
3
3
|
b: any,
|
|
4
4
|
indexOrKeyA: any,
|
|
5
5
|
indexOrKeyB: any,
|
|
6
6
|
parentA: any,
|
|
7
7
|
parentB: any,
|
|
8
|
-
meta:
|
|
8
|
+
meta: Meta,
|
|
9
9
|
) => boolean;
|
|
10
10
|
|
|
11
|
-
export type EqualityComparator<Meta> =
|
|
12
|
-
a: A,
|
|
13
|
-
b: B,
|
|
14
|
-
meta?: Meta,
|
|
15
|
-
) => boolean;
|
|
11
|
+
export type EqualityComparator<Meta> = Meta extends undefined
|
|
12
|
+
? <A, B>(a: A, b: B, meta?: Meta) => boolean
|
|
13
|
+
: <A, B>(a: A, b: B, meta: Meta) => boolean;
|
|
16
14
|
|
|
17
15
|
export type EqualityComparatorCreator<Meta> = (
|
|
18
16
|
fn: EqualityComparator<Meta>,
|
|
19
|
-
) => InternalEqualityComparator
|
|
17
|
+
) => InternalEqualityComparator<Meta>;
|
|
20
18
|
|
|
21
19
|
export type NativeEqualityComparator = <A, B>(a: A, b: B) => boolean;
|
|
22
20
|
|
|
23
21
|
export type TypeEqualityComparator<Type, Meta> = (
|
|
24
22
|
a: Type,
|
|
25
23
|
b: Type,
|
|
26
|
-
isEqual: InternalEqualityComparator
|
|
24
|
+
isEqual: InternalEqualityComparator<Meta>,
|
|
27
25
|
meta: Meta,
|
|
28
26
|
) => boolean;
|
|
29
27
|
|
|
@@ -33,7 +31,7 @@ export type TypeEqualityComparator<Type, Meta> = (
|
|
|
33
31
|
*/
|
|
34
32
|
export function createDefaultIsNestedEqual<Meta>(
|
|
35
33
|
comparator: EqualityComparator<Meta>,
|
|
36
|
-
): InternalEqualityComparator {
|
|
34
|
+
): InternalEqualityComparator<Meta> {
|
|
37
35
|
return function isEqual<A, B>(
|
|
38
36
|
a: A,
|
|
39
37
|
b: B,
|
|
@@ -58,7 +56,7 @@ export function createIsCircular<
|
|
|
58
56
|
return function isCircular(
|
|
59
57
|
a: any,
|
|
60
58
|
b: any,
|
|
61
|
-
isEqual: InternalEqualityComparator,
|
|
59
|
+
isEqual: InternalEqualityComparator<WeakMap<any, any>>,
|
|
62
60
|
cache: WeakMap<any, any>,
|
|
63
61
|
) {
|
|
64
62
|
if (!a || !b || typeof a !== 'object' || typeof b !== 'object') {
|