fast-equals 6.0.0-beta.0 → 6.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,58 +1,202 @@
1
- import type { CustomEqualCreatorOptions } from './internalTypes.d.cts';
2
- import type { sameValueZeroEqual } from './utils.d.cts';
3
- export { sameValueZeroEqual };
4
- export type {
5
- AnyEqualityComparator,
6
- Cache,
7
- CircularState,
8
- ComparatorConfig,
9
- CreateCustomComparatorConfig,
10
- CreateState,
11
- CustomEqualCreatorOptions,
12
- DefaultState,
13
- Dictionary,
14
- EqualityComparator,
15
- EqualityComparatorCreator,
16
- InternalEqualityComparator,
17
- PrimitiveWrapper,
18
- State,
19
- TypeEqualityComparator,
20
- TypedArray,
21
- } from './internalTypes.d.cts';
1
+ /**
2
+ * Cache used to store references to objects, used for circular
3
+ * reference checks.
4
+ */
5
+ interface Cache<Key extends object, Value> {
6
+ delete(key: Key): boolean;
7
+ get(key: Key): Value | undefined;
8
+ set(key: Key, value: any): any;
9
+ }
10
+ interface State<Meta> {
11
+ /**
12
+ * Cache used to identify circular references
13
+ */
14
+ readonly cache: Cache<any, any> | undefined;
15
+ /**
16
+ * Method used to determine equality of nested value.
17
+ */
18
+ readonly equals: InternalEqualityComparator<Meta>;
19
+ /**
20
+ * Additional value that can be used for comparisons.
21
+ */
22
+ meta: Meta;
23
+ /**
24
+ * Whether the equality comparison is strict, meaning it matches
25
+ * all properties (including symbols and non-enumerable properties)
26
+ * with equal shape of descriptors.
27
+ */
28
+ readonly strict: boolean;
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
+ interface ComparatorConfig<Meta> {
41
+ /**
42
+ * Whether the array buffers passed are equal in value. In strict mode, this includes
43
+ * additional properties added to the array.
44
+ */
45
+ areArrayBuffersEqual: TypeEqualityComparator<any, Meta>;
46
+ /**
47
+ * Whether the arrays passed are equal in value. In strict mode, this includes
48
+ * additional properties added to the array.
49
+ */
50
+ areArraysEqual: TypeEqualityComparator<any, Meta>;
51
+ /**
52
+ * Whether the data views passed are equal in value.
53
+ */
54
+ areDataViewsEqual: TypeEqualityComparator<any, Meta>;
55
+ /**
56
+ * Whether the dates passed are equal in value.
57
+ */
58
+ areDatesEqual: TypeEqualityComparator<any, Meta>;
59
+ /**
60
+ * Whether the errors passed are equal in value.
61
+ */
62
+ areErrorsEqual: TypeEqualityComparator<any, Meta>;
63
+ /**
64
+ * Whether the functions passed are equal in value.
65
+ */
66
+ areFunctionsEqual: TypeEqualityComparator<any, Meta>;
67
+ /**
68
+ * Whether the maps passed are equal in value. In strict mode, this includes
69
+ * additional properties added to the map.
70
+ */
71
+ areMapsEqual: TypeEqualityComparator<any, Meta>;
72
+ /**
73
+ * Whether the numbers passed are equal in value.
74
+ */
75
+ areNumbersEqual: TypeEqualityComparator<any, Meta>;
76
+ /**
77
+ * Whether the objects passed are equal in value. In strict mode, this includes
78
+ * non-enumerable properties added to the map, as well as symbol properties.
79
+ */
80
+ areObjectsEqual: TypeEqualityComparator<any, Meta>;
81
+ /**
82
+ * Whether the primitive wrappers passed are equal in value.
83
+ */
84
+ arePrimitiveWrappersEqual: TypeEqualityComparator<any, Meta>;
85
+ /**
86
+ * Whether the regexps passed are equal in value.
87
+ */
88
+ areRegExpsEqual: TypeEqualityComparator<any, Meta>;
89
+ /**
90
+ * Whether the sets passed are equal in value. In strict mode, this includes
91
+ * additional properties added to the set.
92
+ */
93
+ areSetsEqual: TypeEqualityComparator<any, Meta>;
94
+ /**
95
+ * Whether the typed arrays passed are equal in value. In strict mode, this includes
96
+ * additional properties added to the typed array.
97
+ */
98
+ areTypedArraysEqual: TypeEqualityComparator<any, Meta>;
99
+ /**
100
+ * Whether the URLs passed are equal in value.
101
+ */
102
+ areUrlsEqual: TypeEqualityComparator<any, Meta>;
103
+ /**
104
+ * Whether two values with unknown `@@toStringTag` are equal in value. This comparator is
105
+ * called when no other comparator applies.
106
+ *
107
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag
108
+ */
109
+ unknownTagComparators: Record<string, TypeEqualityComparator<any, Meta>> | undefined;
110
+ }
111
+ type CreateCustomComparatorConfig<Meta> = (config: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
112
+ type CreateState<Meta> = () => {
113
+ cache?: Cache<any, any> | undefined;
114
+ meta?: Meta;
115
+ };
116
+ type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;
117
+ type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
118
+ type EqualityComparatorCreator<Meta> = (fn: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
119
+ type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
120
+ type PrimitiveWrapper = Boolean | Number | String;
121
+ /**
122
+ * Type which encompasses possible instances of TypedArray
123
+ * classes.
124
+ */
125
+ type TypedArray = BigInt64Array | BigUint64Array | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray;
126
+ type TypeEqualityComparator<Type, Meta = undefined> = (a: Type, b: Type, state: State<Meta>) => boolean;
127
+ interface CustomEqualCreatorOptions<Meta> {
128
+ /**
129
+ * Whether circular references should be supported. It causes the
130
+ * comparison to be slower, but for objects that have circular references
131
+ * it is required to avoid stack overflows.
132
+ */
133
+ circular?: boolean;
134
+ /**
135
+ * Create a custom configuration of type-specific equality comparators.
136
+ * This receives the default configuration, which allows either replacement
137
+ * or supersetting of the default methods.
138
+ */
139
+ createCustomConfig?: CreateCustomComparatorConfig<Meta>;
140
+ /**
141
+ * Create a custom internal comparator, which is used as an override to the
142
+ * default entry point for nested value equality comparisons. This is often
143
+ * used for doing custom logic for specific types (such as handling a specific
144
+ * class instance differently than other objects) or to incorporate `meta` in
145
+ * the comparison. See the recipes for examples.
146
+ */
147
+ createInternalComparator?: (compare: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
148
+ /**
149
+ * Create a custom `state` object passed between the methods. This allows for
150
+ * custom `cache` and/or `meta` values to be used.
151
+ */
152
+ createState?: CreateState<Meta>;
153
+ /**
154
+ * Whether the equality comparison is strict, meaning it matches
155
+ * all properties (including symbols and non-enumerable properties)
156
+ * with equal shape of descriptors.
157
+ */
158
+ strict?: boolean;
159
+ }
160
+
161
+ /**
162
+ * Whether the values passed are strictly equal or both NaN.
163
+ */
164
+ declare function sameValueZeroEqual(a: any, b: any): boolean;
165
+
22
166
  /**
23
167
  * Whether the items passed are deeply-equal in value.
24
168
  */
25
- export declare const deepEqual: <A, B>(a: A, b: B) => boolean;
169
+ declare const deepEqual: <A, B>(a: A, b: B) => boolean;
26
170
  /**
27
171
  * Whether the items passed are deeply-equal in value based on strict comparison.
28
172
  */
29
- export declare const strictDeepEqual: <A, B>(a: A, b: B) => boolean;
173
+ declare const strictDeepEqual: <A, B>(a: A, b: B) => boolean;
30
174
  /**
31
175
  * Whether the items passed are deeply-equal in value, including circular references.
32
176
  */
33
- export declare const circularDeepEqual: <A, B>(a: A, b: B) => boolean;
177
+ declare const circularDeepEqual: <A, B>(a: A, b: B) => boolean;
34
178
  /**
35
179
  * Whether the items passed are deeply-equal in value, including circular references,
36
180
  * based on strict comparison.
37
181
  */
38
- export declare const strictCircularDeepEqual: <A, B>(a: A, b: B) => boolean;
182
+ declare const strictCircularDeepEqual: <A, B>(a: A, b: B) => boolean;
39
183
  /**
40
184
  * Whether the items passed are shallowly-equal in value.
41
185
  */
42
- export declare const shallowEqual: <A, B>(a: A, b: B) => boolean;
186
+ declare const shallowEqual: <A, B>(a: A, b: B) => boolean;
43
187
  /**
44
188
  * Whether the items passed are shallowly-equal in value based on strict comparison
45
189
  */
46
- export declare const strictShallowEqual: <A, B>(a: A, b: B) => boolean;
190
+ declare const strictShallowEqual: <A, B>(a: A, b: B) => boolean;
47
191
  /**
48
192
  * Whether the items passed are shallowly-equal in value, including circular references.
49
193
  */
50
- export declare const circularShallowEqual: <A, B>(a: A, b: B) => boolean;
194
+ declare const circularShallowEqual: <A, B>(a: A, b: B) => boolean;
51
195
  /**
52
196
  * Whether the items passed are shallowly-equal in value, including circular references,
53
197
  * based on strict comparison.
54
198
  */
55
- export declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
199
+ declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
56
200
  /**
57
201
  * Create a custom equality comparison method.
58
202
  *
@@ -61,6 +205,7 @@ export declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
61
205
  * support for legacy environments that do not support expected features like
62
206
  * `RegExp.prototype.flags` out of the box.
63
207
  */
64
- export declare function createCustomEqual<Meta = undefined>(
65
- options?: CustomEqualCreatorOptions<Meta>,
66
- ): <A, B>(a: A, b: B) => boolean;
208
+ declare function createCustomEqual<Meta = undefined>(options?: CustomEqualCreatorOptions<Meta>): <A, B>(a: A, b: B) => boolean;
209
+
210
+ export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictShallowEqual };
211
+ export type { AnyEqualityComparator, Cache, CircularState, ComparatorConfig, CreateCustomComparatorConfig, CreateState, CustomEqualCreatorOptions, DefaultState, Dictionary, EqualityComparator, EqualityComparatorCreator, InternalEqualityComparator, PrimitiveWrapper, State, TypeEqualityComparator, TypedArray };
@@ -1,58 +1,202 @@
1
- import type { CustomEqualCreatorOptions } from './internalTypes.d.mts';
2
- import type { sameValueZeroEqual } from './utils.d.mts';
3
- export { sameValueZeroEqual };
4
- export type {
5
- AnyEqualityComparator,
6
- Cache,
7
- CircularState,
8
- ComparatorConfig,
9
- CreateCustomComparatorConfig,
10
- CreateState,
11
- CustomEqualCreatorOptions,
12
- DefaultState,
13
- Dictionary,
14
- EqualityComparator,
15
- EqualityComparatorCreator,
16
- InternalEqualityComparator,
17
- PrimitiveWrapper,
18
- State,
19
- TypeEqualityComparator,
20
- TypedArray,
21
- } from './internalTypes.d.mts';
1
+ /**
2
+ * Cache used to store references to objects, used for circular
3
+ * reference checks.
4
+ */
5
+ interface Cache<Key extends object, Value> {
6
+ delete(key: Key): boolean;
7
+ get(key: Key): Value | undefined;
8
+ set(key: Key, value: any): any;
9
+ }
10
+ interface State<Meta> {
11
+ /**
12
+ * Cache used to identify circular references
13
+ */
14
+ readonly cache: Cache<any, any> | undefined;
15
+ /**
16
+ * Method used to determine equality of nested value.
17
+ */
18
+ readonly equals: InternalEqualityComparator<Meta>;
19
+ /**
20
+ * Additional value that can be used for comparisons.
21
+ */
22
+ meta: Meta;
23
+ /**
24
+ * Whether the equality comparison is strict, meaning it matches
25
+ * all properties (including symbols and non-enumerable properties)
26
+ * with equal shape of descriptors.
27
+ */
28
+ readonly strict: boolean;
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
+ interface ComparatorConfig<Meta> {
41
+ /**
42
+ * Whether the array buffers passed are equal in value. In strict mode, this includes
43
+ * additional properties added to the array.
44
+ */
45
+ areArrayBuffersEqual: TypeEqualityComparator<any, Meta>;
46
+ /**
47
+ * Whether the arrays passed are equal in value. In strict mode, this includes
48
+ * additional properties added to the array.
49
+ */
50
+ areArraysEqual: TypeEqualityComparator<any, Meta>;
51
+ /**
52
+ * Whether the data views passed are equal in value.
53
+ */
54
+ areDataViewsEqual: TypeEqualityComparator<any, Meta>;
55
+ /**
56
+ * Whether the dates passed are equal in value.
57
+ */
58
+ areDatesEqual: TypeEqualityComparator<any, Meta>;
59
+ /**
60
+ * Whether the errors passed are equal in value.
61
+ */
62
+ areErrorsEqual: TypeEqualityComparator<any, Meta>;
63
+ /**
64
+ * Whether the functions passed are equal in value.
65
+ */
66
+ areFunctionsEqual: TypeEqualityComparator<any, Meta>;
67
+ /**
68
+ * Whether the maps passed are equal in value. In strict mode, this includes
69
+ * additional properties added to the map.
70
+ */
71
+ areMapsEqual: TypeEqualityComparator<any, Meta>;
72
+ /**
73
+ * Whether the numbers passed are equal in value.
74
+ */
75
+ areNumbersEqual: TypeEqualityComparator<any, Meta>;
76
+ /**
77
+ * Whether the objects passed are equal in value. In strict mode, this includes
78
+ * non-enumerable properties added to the map, as well as symbol properties.
79
+ */
80
+ areObjectsEqual: TypeEqualityComparator<any, Meta>;
81
+ /**
82
+ * Whether the primitive wrappers passed are equal in value.
83
+ */
84
+ arePrimitiveWrappersEqual: TypeEqualityComparator<any, Meta>;
85
+ /**
86
+ * Whether the regexps passed are equal in value.
87
+ */
88
+ areRegExpsEqual: TypeEqualityComparator<any, Meta>;
89
+ /**
90
+ * Whether the sets passed are equal in value. In strict mode, this includes
91
+ * additional properties added to the set.
92
+ */
93
+ areSetsEqual: TypeEqualityComparator<any, Meta>;
94
+ /**
95
+ * Whether the typed arrays passed are equal in value. In strict mode, this includes
96
+ * additional properties added to the typed array.
97
+ */
98
+ areTypedArraysEqual: TypeEqualityComparator<any, Meta>;
99
+ /**
100
+ * Whether the URLs passed are equal in value.
101
+ */
102
+ areUrlsEqual: TypeEqualityComparator<any, Meta>;
103
+ /**
104
+ * Whether two values with unknown `@@toStringTag` are equal in value. This comparator is
105
+ * called when no other comparator applies.
106
+ *
107
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag
108
+ */
109
+ unknownTagComparators: Record<string, TypeEqualityComparator<any, Meta>> | undefined;
110
+ }
111
+ type CreateCustomComparatorConfig<Meta> = (config: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
112
+ type CreateState<Meta> = () => {
113
+ cache?: Cache<any, any> | undefined;
114
+ meta?: Meta;
115
+ };
116
+ type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;
117
+ type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
118
+ type EqualityComparatorCreator<Meta> = (fn: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
119
+ type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
120
+ type PrimitiveWrapper = Boolean | Number | String;
121
+ /**
122
+ * Type which encompasses possible instances of TypedArray
123
+ * classes.
124
+ */
125
+ type TypedArray = BigInt64Array | BigUint64Array | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray;
126
+ type TypeEqualityComparator<Type, Meta = undefined> = (a: Type, b: Type, state: State<Meta>) => boolean;
127
+ interface CustomEqualCreatorOptions<Meta> {
128
+ /**
129
+ * Whether circular references should be supported. It causes the
130
+ * comparison to be slower, but for objects that have circular references
131
+ * it is required to avoid stack overflows.
132
+ */
133
+ circular?: boolean;
134
+ /**
135
+ * Create a custom configuration of type-specific equality comparators.
136
+ * This receives the default configuration, which allows either replacement
137
+ * or supersetting of the default methods.
138
+ */
139
+ createCustomConfig?: CreateCustomComparatorConfig<Meta>;
140
+ /**
141
+ * Create a custom internal comparator, which is used as an override to the
142
+ * default entry point for nested value equality comparisons. This is often
143
+ * used for doing custom logic for specific types (such as handling a specific
144
+ * class instance differently than other objects) or to incorporate `meta` in
145
+ * the comparison. See the recipes for examples.
146
+ */
147
+ createInternalComparator?: (compare: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
148
+ /**
149
+ * Create a custom `state` object passed between the methods. This allows for
150
+ * custom `cache` and/or `meta` values to be used.
151
+ */
152
+ createState?: CreateState<Meta>;
153
+ /**
154
+ * Whether the equality comparison is strict, meaning it matches
155
+ * all properties (including symbols and non-enumerable properties)
156
+ * with equal shape of descriptors.
157
+ */
158
+ strict?: boolean;
159
+ }
160
+
161
+ /**
162
+ * Whether the values passed are strictly equal or both NaN.
163
+ */
164
+ declare function sameValueZeroEqual(a: any, b: any): boolean;
165
+
22
166
  /**
23
167
  * Whether the items passed are deeply-equal in value.
24
168
  */
25
- export declare const deepEqual: <A, B>(a: A, b: B) => boolean;
169
+ declare const deepEqual: <A, B>(a: A, b: B) => boolean;
26
170
  /**
27
171
  * Whether the items passed are deeply-equal in value based on strict comparison.
28
172
  */
29
- export declare const strictDeepEqual: <A, B>(a: A, b: B) => boolean;
173
+ declare const strictDeepEqual: <A, B>(a: A, b: B) => boolean;
30
174
  /**
31
175
  * Whether the items passed are deeply-equal in value, including circular references.
32
176
  */
33
- export declare const circularDeepEqual: <A, B>(a: A, b: B) => boolean;
177
+ declare const circularDeepEqual: <A, B>(a: A, b: B) => boolean;
34
178
  /**
35
179
  * Whether the items passed are deeply-equal in value, including circular references,
36
180
  * based on strict comparison.
37
181
  */
38
- export declare const strictCircularDeepEqual: <A, B>(a: A, b: B) => boolean;
182
+ declare const strictCircularDeepEqual: <A, B>(a: A, b: B) => boolean;
39
183
  /**
40
184
  * Whether the items passed are shallowly-equal in value.
41
185
  */
42
- export declare const shallowEqual: <A, B>(a: A, b: B) => boolean;
186
+ declare const shallowEqual: <A, B>(a: A, b: B) => boolean;
43
187
  /**
44
188
  * Whether the items passed are shallowly-equal in value based on strict comparison
45
189
  */
46
- export declare const strictShallowEqual: <A, B>(a: A, b: B) => boolean;
190
+ declare const strictShallowEqual: <A, B>(a: A, b: B) => boolean;
47
191
  /**
48
192
  * Whether the items passed are shallowly-equal in value, including circular references.
49
193
  */
50
- export declare const circularShallowEqual: <A, B>(a: A, b: B) => boolean;
194
+ declare const circularShallowEqual: <A, B>(a: A, b: B) => boolean;
51
195
  /**
52
196
  * Whether the items passed are shallowly-equal in value, including circular references,
53
197
  * based on strict comparison.
54
198
  */
55
- export declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
199
+ declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
56
200
  /**
57
201
  * Create a custom equality comparison method.
58
202
  *
@@ -61,6 +205,7 @@ export declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
61
205
  * support for legacy environments that do not support expected features like
62
206
  * `RegExp.prototype.flags` out of the box.
63
207
  */
64
- export declare function createCustomEqual<Meta = undefined>(
65
- options?: CustomEqualCreatorOptions<Meta>,
66
- ): <A, B>(a: A, b: B) => boolean;
208
+ declare function createCustomEqual<Meta = undefined>(options?: CustomEqualCreatorOptions<Meta>): <A, B>(a: A, b: B) => boolean;
209
+
210
+ export { circularDeepEqual, circularShallowEqual, createCustomEqual, deepEqual, sameValueZeroEqual, shallowEqual, strictCircularDeepEqual, strictCircularShallowEqual, strictDeepEqual, strictShallowEqual };
211
+ export type { AnyEqualityComparator, Cache, CircularState, ComparatorConfig, CreateCustomComparatorConfig, CreateState, CustomEqualCreatorOptions, DefaultState, Dictionary, EqualityComparator, EqualityComparatorCreator, InternalEqualityComparator, PrimitiveWrapper, State, TypeEqualityComparator, TypedArray };