fast-equals 5.3.3 → 5.3.4

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.
Files changed (41) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +127 -76
  3. package/dist/cjs/comparator.d.cts +58 -0
  4. package/dist/cjs/index.cjs +132 -155
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/cjs/{types/index.d.cts → index.d.cts} +21 -2
  7. package/{src/internalTypes.ts → dist/cjs/internalTypes.d.cts} +7 -43
  8. package/dist/cjs/{types/utils.d.cts → utils.d.cts} +7 -2
  9. package/dist/es/comparator.d.mts +58 -0
  10. package/dist/{esm/types → es}/index.d.mts +21 -2
  11. package/dist/{esm → es}/index.mjs +132 -155
  12. package/dist/es/index.mjs.map +1 -0
  13. package/dist/es/internalTypes.d.mts +174 -0
  14. package/dist/{esm/types → es}/utils.d.mts +7 -2
  15. package/dist/{min/types → umd}/comparator.d.ts +1 -1
  16. package/dist/umd/index.js +132 -155
  17. package/dist/umd/index.js.map +1 -1
  18. package/index.d.ts +62 -68
  19. package/package.json +44 -47
  20. package/CHANGELOG.md +0 -364
  21. package/dist/cjs/types/comparator.d.cts +0 -26
  22. package/dist/cjs/types/internalTypes.d.cts +0 -157
  23. package/dist/esm/index.mjs.map +0 -1
  24. package/dist/esm/types/comparator.d.mts +0 -26
  25. package/dist/esm/types/internalTypes.d.mts +0 -157
  26. package/dist/min/index.js +0 -1
  27. package/dist/umd/types/comparator.d.ts +0 -26
  28. package/dist/umd/types/equals.d.ts +0 -54
  29. package/dist/umd/types/index.d.ts +0 -47
  30. package/dist/umd/types/internalTypes.d.ts +0 -157
  31. package/dist/umd/types/utils.d.ts +0 -28
  32. package/src/comparator.ts +0 -376
  33. package/src/equals.ts +0 -355
  34. package/src/index.ts +0 -112
  35. package/src/utils.ts +0 -96
  36. /package/dist/cjs/{types/equals.d.cts → equals.d.cts} +0 -0
  37. /package/dist/{esm/types → es}/equals.d.mts +0 -0
  38. /package/dist/{min/types → umd}/equals.d.ts +0 -0
  39. /package/dist/{min/types → umd}/index.d.ts +0 -0
  40. /package/dist/{min/types → umd}/internalTypes.d.ts +0 -0
  41. /package/dist/{min/types → umd}/utils.d.ts +0 -0
@@ -0,0 +1,174 @@
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
+ }
@@ -2,13 +2,18 @@ import type { AnyEqualityComparator, Dictionary, State, TypeEqualityComparator }
2
2
  /**
3
3
  * Combine two comparators into a single comparators.
4
4
  */
5
- export declare function combineComparators<Meta>(comparatorA: AnyEqualityComparator<Meta>, comparatorB: AnyEqualityComparator<Meta>): <A, B>(a: A, b: B, state: State<Meta>) => boolean;
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;
6
9
  /**
7
10
  * Wrap the provided `areItemsEqual` method to manage the circular state, allowing
8
11
  * for circular references to be safely included in the comparison without creating
9
12
  * stack overflows.
10
13
  */
11
- export declare function createIsCircular<AreItemsEqual extends TypeEqualityComparator<any, any>>(areItemsEqual: AreItemsEqual): AreItemsEqual;
14
+ export declare function createIsCircular<AreItemsEqual extends TypeEqualityComparator<any, any>>(
15
+ areItemsEqual: AreItemsEqual,
16
+ ): AreItemsEqual;
12
17
  /**
13
18
  * Get the `@@toStringTag` of the value, if it exists.
14
19
  */
@@ -22,5 +22,5 @@ export declare function createInternalEqualityComparator<Meta>(compare: Equality
22
22
  /**
23
23
  * Create the `isEqual` function used by the consuming application.
24
24
  */
25
- export declare function createIsEqual<Meta>({ circular, comparator, createState, equals, strict, }: CreateIsEqualOptions<Meta>): <A, B>(a: A, b: B) => boolean;
25
+ export declare function createIsEqual<Meta>({ circular, comparator, createState, equals, strict }: CreateIsEqualOptions<Meta>): <A, B>(a: A, b: B) => boolean;
26
26
  export {};