fast-equals 5.3.4 → 5.4.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,174 +0,0 @@
1
- /**
2
- * Cache used to store references to objects, used for circular
3
- * reference checks.
4
- */
5
- export 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
- export 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
- export interface CircularState<Meta> extends State<Meta> {
31
- readonly cache: Cache<any, any>;
32
- }
33
- export interface DefaultState<Meta> extends State<Meta> {
34
- readonly cache: undefined;
35
- }
36
- export interface Dictionary<Value = any> {
37
- [key: string | symbol]: Value;
38
- $$typeof?: any;
39
- }
40
- export interface ComparatorConfig<Meta> {
41
- /**
42
- * Whether the arrays passed are equal in value. In strict mode, this includes
43
- * additional properties added to the array.
44
- */
45
- areArraysEqual: TypeEqualityComparator<any, Meta>;
46
- /**
47
- * Whether the dates passed are equal in value.
48
- */
49
- areDatesEqual: TypeEqualityComparator<any, Meta>;
50
- /**
51
- * Whether the errors passed are equal in value.
52
- */
53
- areErrorsEqual: TypeEqualityComparator<any, Meta>;
54
- /**
55
- * Whether the functions passed are equal in value.
56
- */
57
- areFunctionsEqual: TypeEqualityComparator<any, Meta>;
58
- /**
59
- * Whether the maps passed are equal in value. In strict mode, this includes
60
- * additional properties added to the map.
61
- */
62
- areMapsEqual: TypeEqualityComparator<any, Meta>;
63
- /**
64
- * Whether the numbers passed are equal in value.
65
- */
66
- areNumbersEqual: TypeEqualityComparator<any, Meta>;
67
- /**
68
- * Whether the objects passed are equal in value. In strict mode, this includes
69
- * non-enumerable properties added to the map, as well as symbol properties.
70
- */
71
- areObjectsEqual: TypeEqualityComparator<any, Meta>;
72
- /**
73
- * Whether the primitive wrappers passed are equal in value.
74
- */
75
- arePrimitiveWrappersEqual: TypeEqualityComparator<any, Meta>;
76
- /**
77
- * Whether the regexps passed are equal in value.
78
- */
79
- areRegExpsEqual: TypeEqualityComparator<any, Meta>;
80
- /**
81
- * Whether the sets passed are equal in value. In strict mode, this includes
82
- * additional properties added to the set.
83
- */
84
- areSetsEqual: TypeEqualityComparator<any, Meta>;
85
- /**
86
- * Whether the typed arrays passed are equal in value. In strict mode, this includes
87
- * additional properties added to the typed array.
88
- */
89
- areTypedArraysEqual: TypeEqualityComparator<any, Meta>;
90
- /**
91
- * Whether the URLs passed are equal in value.
92
- */
93
- areUrlsEqual: TypeEqualityComparator<any, Meta>;
94
- /**
95
- * Whether two values with unknown `@@toStringTag` are equal in value. This comparator is
96
- * called when no other comparator applies.
97
- *
98
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag
99
- */
100
- unknownTagComparators: Record<string, TypeEqualityComparator<any, Meta>> | undefined;
101
- }
102
- export type CreateCustomComparatorConfig<Meta> = (config: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
103
- export type CreateState<Meta> = () => {
104
- cache?: Cache<any, any> | undefined;
105
- meta?: Meta;
106
- };
107
- export type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;
108
- export type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
109
- export type EqualityComparatorCreator<Meta> = (fn: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
110
- export type InternalEqualityComparator<Meta> = (
111
- a: any,
112
- b: any,
113
- indexOrKeyA: any,
114
- indexOrKeyB: any,
115
- parentA: any,
116
- parentB: any,
117
- state: State<Meta>,
118
- ) => boolean;
119
- export type PrimitiveWrapper = Boolean | Number | String;
120
- /**
121
- * Type which encompasses possible instances of TypedArray
122
- * classes.
123
- *
124
- * **NOTE**: This does not include `BigInt64Array` and
125
- * `BitUint64Array` because those are part of ES2020 and
126
- * not supported by certain TS configurations. If using
127
- * either in `areTypedArraysEqual`, you can cast the
128
- * instance as `TypedArray` and it will work as expected,
129
- * because runtime checks will still work for those classes.
130
- */
131
- export type TypedArray =
132
- | Float32Array
133
- | Float64Array
134
- | Int8Array
135
- | Int16Array
136
- | Int32Array
137
- | Uint16Array
138
- | Uint32Array
139
- | Uint8Array
140
- | Uint8ClampedArray;
141
- export type TypeEqualityComparator<Type, Meta = undefined> = (a: Type, b: Type, state: State<Meta>) => boolean;
142
- export interface CustomEqualCreatorOptions<Meta> {
143
- /**
144
- * Whether circular references should be supported. It causes the
145
- * comparison to be slower, but for objects that have circular references
146
- * it is required to avoid stack overflows.
147
- */
148
- circular?: boolean;
149
- /**
150
- * Create a custom configuration of type-specific equality comparators.
151
- * This receives the default configuration, which allows either replacement
152
- * or supersetting of the default methods.
153
- */
154
- createCustomConfig?: CreateCustomComparatorConfig<Meta>;
155
- /**
156
- * Create a custom internal comparator, which is used as an override to the
157
- * default entry point for nested value equality comparisons. This is often
158
- * used for doing custom logic for specific types (such as handling a specific
159
- * class instance differently than other objects) or to incorporate `meta` in
160
- * the comparison. See the recipes for examples.
161
- */
162
- createInternalComparator?: (compare: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
163
- /**
164
- * Create a custom `state` object passed between the methods. This allows for
165
- * custom `cache` and/or `meta` values to be used.
166
- */
167
- createState?: CreateState<Meta>;
168
- /**
169
- * Whether the equality comparison is strict, meaning it matches
170
- * all properties (including symbols and non-enumerable properties)
171
- * with equal shape of descriptors.
172
- */
173
- strict?: boolean;
174
- }
@@ -1,33 +0,0 @@
1
- import type { AnyEqualityComparator, Dictionary, State, TypeEqualityComparator } from './internalTypes.d.mts';
2
- /**
3
- * Combine two comparators into a single comparators.
4
- */
5
- export declare function combineComparators<Meta>(
6
- comparatorA: AnyEqualityComparator<Meta>,
7
- comparatorB: AnyEqualityComparator<Meta>,
8
- ): <A, B>(a: A, b: B, state: State<Meta>) => boolean;
9
- /**
10
- * Wrap the provided `areItemsEqual` method to manage the circular state, allowing
11
- * for circular references to be safely included in the comparison without creating
12
- * stack overflows.
13
- */
14
- export declare function createIsCircular<AreItemsEqual extends TypeEqualityComparator<any, any>>(
15
- areItemsEqual: AreItemsEqual,
16
- ): AreItemsEqual;
17
- /**
18
- * Get the `@@toStringTag` of the value, if it exists.
19
- */
20
- export declare function getShortTag(value: any): string | undefined;
21
- /**
22
- * Get the properties to strictly examine, which include both own properties that are
23
- * not enumerable and symbol properties.
24
- */
25
- export declare function getStrictProperties(object: Dictionary): Array<string | symbol>;
26
- /**
27
- * Whether the object contains the property passed as an own property.
28
- */
29
- export declare const hasOwn: (o: object, v: PropertyKey) => boolean;
30
- /**
31
- * Whether the values passed are strictly equal or both NaN.
32
- */
33
- export declare function sameValueZeroEqual(a: any, b: any): boolean;
@@ -1,26 +0,0 @@
1
- import type { ComparatorConfig, CreateState, CustomEqualCreatorOptions, EqualityComparator, InternalEqualityComparator } from './internalTypes.js';
2
- interface CreateIsEqualOptions<Meta> {
3
- circular: boolean;
4
- comparator: EqualityComparator<Meta>;
5
- createState: CreateState<Meta> | undefined;
6
- equals: InternalEqualityComparator<Meta>;
7
- strict: boolean;
8
- }
9
- /**
10
- * Create a comparator method based on the type-specific equality comparators passed.
11
- */
12
- export declare function createEqualityComparator<Meta>({ areArraysEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual, areNumbersEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, areUrlsEqual, unknownTagComparators, }: ComparatorConfig<Meta>): EqualityComparator<Meta>;
13
- /**
14
- * Create the configuration object used for building comparators.
15
- */
16
- export declare function createEqualityComparatorConfig<Meta>({ circular, createCustomConfig, strict, }: CustomEqualCreatorOptions<Meta>): ComparatorConfig<Meta>;
17
- /**
18
- * Default equality comparator pass-through, used as the standard `isEqual` creator for
19
- * use inside the built comparator.
20
- */
21
- export declare function createInternalEqualityComparator<Meta>(compare: EqualityComparator<Meta>): InternalEqualityComparator<Meta>;
22
- /**
23
- * Create the `isEqual` function used by the consuming application.
24
- */
25
- export declare function createIsEqual<Meta>({ circular, comparator, createState, equals, strict }: CreateIsEqualOptions<Meta>): <A, B>(a: A, b: B) => boolean;
26
- export {};
@@ -1,54 +0,0 @@
1
- import type { Dictionary, PrimitiveWrapper, State, TypedArray } from './internalTypes.js';
2
- import { sameValueZeroEqual } from './utils.js';
3
- /**
4
- * Whether the arrays are equal in value.
5
- */
6
- export declare function areArraysEqual(a: any[], b: any[], state: State<any>): boolean;
7
- /**
8
- * Whether the dates passed are equal in value.
9
- */
10
- export declare function areDatesEqual(a: Date, b: Date): boolean;
11
- /**
12
- * Whether the errors passed are equal in value.
13
- */
14
- export declare function areErrorsEqual(a: Error, b: Error): boolean;
15
- /**
16
- * Whether the functions passed are equal in value.
17
- */
18
- export declare function areFunctionsEqual(a: (...args: any[]) => any, b: (...args: any[]) => any): boolean;
19
- /**
20
- * Whether the `Map`s are equal in value.
21
- */
22
- export declare function areMapsEqual(a: Map<any, any>, b: Map<any, any>, state: State<any>): boolean;
23
- /**
24
- * Whether the numbers are equal in value.
25
- */
26
- export declare const areNumbersEqual: typeof sameValueZeroEqual;
27
- /**
28
- * Whether the objects are equal in value.
29
- */
30
- export declare function areObjectsEqual(a: Dictionary, b: Dictionary, state: State<any>): boolean;
31
- /**
32
- * Whether the objects are equal in value with strict property checking.
33
- */
34
- export declare function areObjectsEqualStrict(a: Dictionary, b: Dictionary, state: State<any>): boolean;
35
- /**
36
- * Whether the primitive wrappers passed are equal in value.
37
- */
38
- export declare function arePrimitiveWrappersEqual(a: PrimitiveWrapper, b: PrimitiveWrapper): boolean;
39
- /**
40
- * Whether the regexps passed are equal in value.
41
- */
42
- export declare function areRegExpsEqual(a: RegExp, b: RegExp): boolean;
43
- /**
44
- * Whether the `Set`s are equal in value.
45
- */
46
- export declare function areSetsEqual(a: Set<any>, b: Set<any>, state: State<any>): boolean;
47
- /**
48
- * Whether the TypedArray instances are equal in value.
49
- */
50
- export declare function areTypedArraysEqual(a: TypedArray, b: TypedArray): boolean;
51
- /**
52
- * Whether the URL instances are equal in value.
53
- */
54
- export declare function areUrlsEqual(a: URL, b: URL): boolean;
@@ -1,157 +0,0 @@
1
- /**
2
- * Cache used to store references to objects, used for circular
3
- * reference checks.
4
- */
5
- export 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
- export 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
- export interface CircularState<Meta> extends State<Meta> {
31
- readonly cache: Cache<any, any>;
32
- }
33
- export interface DefaultState<Meta> extends State<Meta> {
34
- readonly cache: undefined;
35
- }
36
- export interface Dictionary<Value = any> {
37
- [key: string | symbol]: Value;
38
- $$typeof?: any;
39
- }
40
- export interface ComparatorConfig<Meta> {
41
- /**
42
- * Whether the arrays passed are equal in value. In strict mode, this includes
43
- * additional properties added to the array.
44
- */
45
- areArraysEqual: TypeEqualityComparator<any, Meta>;
46
- /**
47
- * Whether the dates passed are equal in value.
48
- */
49
- areDatesEqual: TypeEqualityComparator<any, Meta>;
50
- /**
51
- * Whether the errors passed are equal in value.
52
- */
53
- areErrorsEqual: TypeEqualityComparator<any, Meta>;
54
- /**
55
- * Whether the functions passed are equal in value.
56
- */
57
- areFunctionsEqual: TypeEqualityComparator<any, Meta>;
58
- /**
59
- * Whether the maps passed are equal in value. In strict mode, this includes
60
- * additional properties added to the map.
61
- */
62
- areMapsEqual: TypeEqualityComparator<any, Meta>;
63
- /**
64
- * Whether the numbers passed are equal in value.
65
- */
66
- areNumbersEqual: TypeEqualityComparator<any, Meta>;
67
- /**
68
- * Whether the objects passed are equal in value. In strict mode, this includes
69
- * non-enumerable properties added to the map, as well as symbol properties.
70
- */
71
- areObjectsEqual: TypeEqualityComparator<any, Meta>;
72
- /**
73
- * Whether the primitive wrappers passed are equal in value.
74
- */
75
- arePrimitiveWrappersEqual: TypeEqualityComparator<any, Meta>;
76
- /**
77
- * Whether the regexps passed are equal in value.
78
- */
79
- areRegExpsEqual: TypeEqualityComparator<any, Meta>;
80
- /**
81
- * Whether the sets passed are equal in value. In strict mode, this includes
82
- * additional properties added to the set.
83
- */
84
- areSetsEqual: TypeEqualityComparator<any, Meta>;
85
- /**
86
- * Whether the typed arrays passed are equal in value. In strict mode, this includes
87
- * additional properties added to the typed array.
88
- */
89
- areTypedArraysEqual: TypeEqualityComparator<any, Meta>;
90
- /**
91
- * Whether the URLs passed are equal in value.
92
- */
93
- areUrlsEqual: TypeEqualityComparator<any, Meta>;
94
- /**
95
- * Whether two values with unknown `@@toStringTag` are equal in value. This comparator is
96
- * called when no other comparator applies.
97
- *
98
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag
99
- */
100
- unknownTagComparators: Record<string, TypeEqualityComparator<any, Meta>> | undefined;
101
- }
102
- export type CreateCustomComparatorConfig<Meta> = (config: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
103
- export type CreateState<Meta> = () => {
104
- cache?: Cache<any, any> | undefined;
105
- meta?: Meta;
106
- };
107
- export type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;
108
- export type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
109
- export type EqualityComparatorCreator<Meta> = (fn: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
110
- export type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
111
- export type PrimitiveWrapper = Boolean | Number | String;
112
- /**
113
- * Type which encompasses possible instances of TypedArray
114
- * classes.
115
- *
116
- * **NOTE**: This does not include `BigInt64Array` and
117
- * `BitUint64Array` because those are part of ES2020 and
118
- * not supported by certain TS configurations. If using
119
- * either in `areTypedArraysEqual`, you can cast the
120
- * instance as `TypedArray` and it will work as expected,
121
- * because runtime checks will still work for those classes.
122
- */
123
- export type TypedArray = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray;
124
- export type TypeEqualityComparator<Type, Meta = undefined> = (a: Type, b: Type, state: State<Meta>) => boolean;
125
- export interface CustomEqualCreatorOptions<Meta> {
126
- /**
127
- * Whether circular references should be supported. It causes the
128
- * comparison to be slower, but for objects that have circular references
129
- * it is required to avoid stack overflows.
130
- */
131
- circular?: boolean;
132
- /**
133
- * Create a custom configuration of type-specific equality comparators.
134
- * This receives the default configuration, which allows either replacement
135
- * or supersetting of the default methods.
136
- */
137
- createCustomConfig?: CreateCustomComparatorConfig<Meta>;
138
- /**
139
- * Create a custom internal comparator, which is used as an override to the
140
- * default entry point for nested value equality comparisons. This is often
141
- * used for doing custom logic for specific types (such as handling a specific
142
- * class instance differently than other objects) or to incorporate `meta` in
143
- * the comparison. See the recipes for examples.
144
- */
145
- createInternalComparator?: (compare: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
146
- /**
147
- * Create a custom `state` object passed between the methods. This allows for
148
- * custom `cache` and/or `meta` values to be used.
149
- */
150
- createState?: CreateState<Meta>;
151
- /**
152
- * Whether the equality comparison is strict, meaning it matches
153
- * all properties (including symbols and non-enumerable properties)
154
- * with equal shape of descriptors.
155
- */
156
- strict?: boolean;
157
- }
@@ -1,28 +0,0 @@
1
- import type { AnyEqualityComparator, Dictionary, State, TypeEqualityComparator } from './internalTypes.js';
2
- /**
3
- * Combine two comparators into a single comparators.
4
- */
5
- export declare function combineComparators<Meta>(comparatorA: AnyEqualityComparator<Meta>, comparatorB: AnyEqualityComparator<Meta>): <A, B>(a: A, b: B, state: State<Meta>) => boolean;
6
- /**
7
- * Wrap the provided `areItemsEqual` method to manage the circular state, allowing
8
- * for circular references to be safely included in the comparison without creating
9
- * stack overflows.
10
- */
11
- export declare function createIsCircular<AreItemsEqual extends TypeEqualityComparator<any, any>>(areItemsEqual: AreItemsEqual): AreItemsEqual;
12
- /**
13
- * Get the `@@toStringTag` of the value, if it exists.
14
- */
15
- export declare function getShortTag(value: any): string | undefined;
16
- /**
17
- * Get the properties to strictly examine, which include both own properties that are
18
- * not enumerable and symbol properties.
19
- */
20
- export declare function getStrictProperties(object: Dictionary): Array<string | symbol>;
21
- /**
22
- * Whether the object contains the property passed as an own property.
23
- */
24
- export declare const hasOwn: (o: object, v: PropertyKey) => boolean;
25
- /**
26
- * Whether the values passed are strictly equal or both NaN.
27
- */
28
- export declare function sameValueZeroEqual(a: any, b: any): boolean;