fast-equals 5.0.0-beta.5 → 5.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 +17 -1
- package/README.md +68 -48
- package/dist/cjs/index.cjs +165 -140
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/types/comparator.d.ts +20 -3
- package/dist/cjs/types/equals.d.ts +5 -2
- package/dist/cjs/types/index.d.ts +9 -9
- package/dist/cjs/types/internalTypes.d.ts +100 -12
- package/dist/cjs/types/utils.d.ts +1 -6
- package/dist/esm/index.mjs +165 -140
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/types/comparator.d.ts +20 -3
- package/dist/esm/types/equals.d.ts +5 -2
- package/dist/esm/types/index.d.ts +9 -9
- package/dist/esm/types/internalTypes.d.ts +100 -12
- package/dist/esm/types/utils.d.ts +1 -6
- package/dist/min/index.js +1 -1
- package/dist/min/types/comparator.d.ts +20 -3
- package/dist/min/types/equals.d.ts +5 -2
- package/dist/min/types/index.d.ts +9 -9
- package/dist/min/types/internalTypes.d.ts +100 -12
- package/dist/min/types/utils.d.ts +1 -6
- package/dist/umd/index.js +165 -140
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/types/comparator.d.ts +20 -3
- package/dist/umd/types/equals.d.ts +5 -2
- package/dist/umd/types/index.d.ts +9 -9
- package/dist/umd/types/internalTypes.d.ts +100 -12
- package/dist/umd/types/utils.d.ts +1 -6
- package/package.json +7 -7
- package/recipes/legacy-circular-equal-support.md +3 -2
- package/recipes/legacy-regexp-support.md +2 -3
- package/recipes/non-standard-properties.md +4 -2
- package/src/comparator.ts +126 -38
- package/src/equals.ts +97 -63
- package/src/index.ts +21 -65
- package/src/internalTypes.ts +104 -16
- package/src/utils.ts +2 -24
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Dictionary, State, TypedArray } from './internalTypes';
|
|
1
|
+
import type { Dictionary, PrimitiveWrapper, State, TypedArray } from './internalTypes';
|
|
2
2
|
/**
|
|
3
3
|
* Whether the arrays are equal in value.
|
|
4
4
|
*/
|
|
@@ -22,7 +22,7 @@ export declare function areObjectsEqualStrict(a: Dictionary, b: Dictionary, stat
|
|
|
22
22
|
/**
|
|
23
23
|
* Whether the primitive wrappers passed are equal in value.
|
|
24
24
|
*/
|
|
25
|
-
export declare function arePrimitiveWrappersEqual(a:
|
|
25
|
+
export declare function arePrimitiveWrappersEqual(a: PrimitiveWrapper, b: PrimitiveWrapper): boolean;
|
|
26
26
|
/**
|
|
27
27
|
* Whether the regexps passed are equal in value.
|
|
28
28
|
*/
|
|
@@ -31,4 +31,7 @@ export declare function areRegExpsEqual(a: RegExp, b: RegExp): boolean;
|
|
|
31
31
|
* Whether the `Set`s are equal in value.
|
|
32
32
|
*/
|
|
33
33
|
export declare function areSetsEqual(a: Set<any>, b: Set<any>, state: State<any>): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the TypedArray instances are equal in value.
|
|
36
|
+
*/
|
|
34
37
|
export declare function areTypedArraysEqual(a: TypedArray, b: TypedArray): boolean;
|
|
@@ -5,37 +5,37 @@ export * from './internalTypes';
|
|
|
5
5
|
/**
|
|
6
6
|
* Whether the items passed are deeply-equal in value.
|
|
7
7
|
*/
|
|
8
|
-
export declare const deepEqual: <A, B>(a: A, b: B
|
|
8
|
+
export declare const deepEqual: <A, B>(a: A, b: B) => boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Whether the items passed are deeply-equal in value based on strict comparison.
|
|
11
11
|
*/
|
|
12
|
-
export declare const strictDeepEqual: <A, B>(a: A, b: B
|
|
12
|
+
export declare const strictDeepEqual: <A, B>(a: A, b: B) => boolean;
|
|
13
13
|
/**
|
|
14
14
|
* Whether the items passed are deeply-equal in value, including circular references.
|
|
15
15
|
*/
|
|
16
|
-
export declare const circularDeepEqual: <A, B>(a: A, b: B
|
|
16
|
+
export declare const circularDeepEqual: <A, B>(a: A, b: B) => boolean;
|
|
17
17
|
/**
|
|
18
18
|
* Whether the items passed are deeply-equal in value, including circular references,
|
|
19
19
|
* based on strict comparison.
|
|
20
20
|
*/
|
|
21
|
-
export declare const strictCircularDeepEqual: <A, B>(a: A, b: B
|
|
21
|
+
export declare const strictCircularDeepEqual: <A, B>(a: A, b: B) => boolean;
|
|
22
22
|
/**
|
|
23
23
|
* Whether the items passed are shallowly-equal in value.
|
|
24
24
|
*/
|
|
25
|
-
export declare const shallowEqual: <A, B>(a: A, b: B
|
|
25
|
+
export declare const shallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
26
26
|
/**
|
|
27
27
|
* Whether the items passed are shallowly-equal in value based on strict comparison
|
|
28
28
|
*/
|
|
29
|
-
export declare const strictShallowEqual: <A, B>(a: A, b: B
|
|
29
|
+
export declare const strictShallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
30
30
|
/**
|
|
31
31
|
* Whether the items passed are shallowly-equal in value, including circular references.
|
|
32
32
|
*/
|
|
33
|
-
export declare const circularShallowEqual: <A, B>(a: A, b: B
|
|
33
|
+
export declare const circularShallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
34
34
|
/**
|
|
35
35
|
* Whether the items passed are shallowly-equal in value, including circular references,
|
|
36
36
|
* based on strict comparison.
|
|
37
37
|
*/
|
|
38
|
-
export declare const strictCircularShallowEqual: <A, B>(a: A, b: B
|
|
38
|
+
export declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
39
39
|
/**
|
|
40
40
|
* Create a custom equality comparison method.
|
|
41
41
|
*
|
|
@@ -44,4 +44,4 @@ export declare const strictCircularShallowEqual: <A, B>(a: A, b: B, metaOverride
|
|
|
44
44
|
* support for legacy environments that do not support expected features like
|
|
45
45
|
* `RegExp.prototype.flags` out of the box.
|
|
46
46
|
*/
|
|
47
|
-
export declare function createCustomEqual<Meta>(options?: CustomEqualCreatorOptions<Meta>): <A, B>(a: A, b: B
|
|
47
|
+
export declare function createCustomEqual<Meta = undefined>(options?: CustomEqualCreatorOptions<Meta>): <A, B>(a: A, b: B) => boolean;
|
|
@@ -1,46 +1,134 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
|
3
9
|
}
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
*/
|
|
7
18
|
readonly equals: InternalEqualityComparator<Meta>;
|
|
19
|
+
/**
|
|
20
|
+
* Additional value that can be used for comparisons.
|
|
21
|
+
*/
|
|
8
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
|
+
*/
|
|
9
28
|
readonly strict: boolean;
|
|
10
29
|
}
|
|
11
|
-
export interface
|
|
30
|
+
export interface CircularState<Meta> extends State<Meta> {
|
|
31
|
+
readonly cache: Cache<any, any>;
|
|
32
|
+
}
|
|
33
|
+
export interface DefaultState<Meta> extends State<Meta> {
|
|
12
34
|
readonly cache: undefined;
|
|
13
|
-
readonly equals: InternalEqualityComparator<Meta>;
|
|
14
|
-
meta: Meta;
|
|
15
|
-
readonly strict: boolean;
|
|
16
35
|
}
|
|
17
36
|
export interface Dictionary<Value = any> {
|
|
18
37
|
[key: string | symbol]: Value;
|
|
19
38
|
$$typeof?: any;
|
|
20
39
|
}
|
|
21
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
|
+
*/
|
|
22
45
|
areArraysEqual: TypeEqualityComparator<any, Meta>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the dates passed are equal in value.
|
|
48
|
+
*/
|
|
23
49
|
areDatesEqual: TypeEqualityComparator<any, Meta>;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the maps passed are equal in value. In strict mode, this includes
|
|
52
|
+
* additional properties added to the map.
|
|
53
|
+
*/
|
|
24
54
|
areMapsEqual: TypeEqualityComparator<any, Meta>;
|
|
55
|
+
/**
|
|
56
|
+
* Whether the objects passed are equal in value. In strict mode, this includes
|
|
57
|
+
* non-enumerable properties added to the map, as well as symbol properties.
|
|
58
|
+
*/
|
|
25
59
|
areObjectsEqual: TypeEqualityComparator<any, Meta>;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the primitive wrappers passed are equal in value.
|
|
62
|
+
*/
|
|
26
63
|
arePrimitiveWrappersEqual: TypeEqualityComparator<any, Meta>;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the regexps passed are equal in value.
|
|
66
|
+
*/
|
|
27
67
|
areRegExpsEqual: TypeEqualityComparator<any, Meta>;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the sets passed are equal in value. In strict mode, this includes
|
|
70
|
+
* additional properties added to the set.
|
|
71
|
+
*/
|
|
28
72
|
areSetsEqual: TypeEqualityComparator<any, Meta>;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the typed arrays passed are equal in value. In strict mode, this includes
|
|
75
|
+
* additional properties added to the typed array.
|
|
76
|
+
*/
|
|
29
77
|
areTypedArraysEqual: TypeEqualityComparator<any, Meta>;
|
|
30
78
|
}
|
|
31
79
|
export type CreateCustomComparatorConfig<Meta> = (config: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
|
|
32
|
-
export type CreateState<Meta> = (
|
|
80
|
+
export type CreateState<Meta> = () => {
|
|
81
|
+
cache?: Cache<any, any> | undefined;
|
|
82
|
+
meta?: Meta;
|
|
83
|
+
};
|
|
33
84
|
export type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;
|
|
34
85
|
export type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
35
86
|
export type EqualityComparatorCreator<Meta> = (fn: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
|
|
36
87
|
export type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
88
|
+
export type PrimitiveWrapper = Boolean | Number | String;
|
|
89
|
+
/**
|
|
90
|
+
* Type which encompasses possible instances of TypedArray
|
|
91
|
+
* classes.
|
|
92
|
+
*
|
|
93
|
+
* **NOTE**: This does not include `BigInt64Array` and
|
|
94
|
+
* `BitUint64Array` because those are part of ES2020 and
|
|
95
|
+
* not supported by certain TS configurations. If using
|
|
96
|
+
* either in `areTypedArraysEqual`, you can cast the
|
|
97
|
+
* instance as `TypedArray` and it will work as expected,
|
|
98
|
+
* because runtime checks will still work for those classes.
|
|
99
|
+
*/
|
|
37
100
|
export type TypedArray = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray;
|
|
38
101
|
export type TypeEqualityComparator<Type, Meta = undefined> = (a: Type, b: Type, state: State<Meta>) => boolean;
|
|
39
102
|
export interface CustomEqualCreatorOptions<Meta> {
|
|
103
|
+
/**
|
|
104
|
+
* Whether circular references should be supported. It causes the
|
|
105
|
+
* comparison to be slower, but for objects that have circular references
|
|
106
|
+
* it is required to avoid stack overflows.
|
|
107
|
+
*/
|
|
40
108
|
circular?: boolean;
|
|
41
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Create a custom configuration of type-specific equality comparators.
|
|
111
|
+
* This receives the default configuration, which allows either replacement
|
|
112
|
+
* or supersetting of the default methods.
|
|
113
|
+
*/
|
|
42
114
|
createCustomConfig?: CreateCustomComparatorConfig<Meta>;
|
|
43
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Create a custom internal comparator, which is used as an override to the
|
|
117
|
+
* default entry point for nested value equality comparisons. This is often
|
|
118
|
+
* used for doing custom logic for specific types (such as handling a specific
|
|
119
|
+
* class instance differently than other objects) or to incorporate `meta` in
|
|
120
|
+
* the comparison. See the recipes for examples.
|
|
121
|
+
*/
|
|
122
|
+
createInternalComparator?: (compare: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
|
|
123
|
+
/**
|
|
124
|
+
* Create a custom `state` object passed between the methods. This allows for
|
|
125
|
+
* custom `cache` and/or `meta` values to be used.
|
|
126
|
+
*/
|
|
44
127
|
createState?: CreateState<Meta>;
|
|
128
|
+
/**
|
|
129
|
+
* Whether the equality comparison is strict, meaning it matches
|
|
130
|
+
* all properties (including symbols and non-enumerable properties)
|
|
131
|
+
* with equal shape of descriptors.
|
|
132
|
+
*/
|
|
45
133
|
strict?: boolean;
|
|
46
134
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { AnyEqualityComparator, Dictionary,
|
|
1
|
+
import { AnyEqualityComparator, Dictionary, State, TypeEqualityComparator } from './internalTypes';
|
|
2
2
|
/**
|
|
3
3
|
* Combine two comparators into a single comparators.
|
|
4
4
|
*/
|
|
5
5
|
export declare function combineComparators<Meta>(comparatorA: AnyEqualityComparator<Meta>, comparatorB: AnyEqualityComparator<Meta>): <A, B>(a: A, b: B, state: State<Meta>) => boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Default equality comparator pass-through, used as the standard `isEqual` creator for
|
|
8
|
-
* use inside the built comparator.
|
|
9
|
-
*/
|
|
10
|
-
export declare function createInternalComparator<Meta>(compare: EqualityComparator<Meta>): InternalEqualityComparator<Meta>;
|
|
11
6
|
/**
|
|
12
7
|
* Wrap the provided `areItemsEqual` method to manage the circular state, allowing
|
|
13
8
|
* for circular references to be safely included in the comparison without creating
|
package/dist/min/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(r
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self)["fast-equals"]={})}(this,(function(e){"use strict";var r=Object.getOwnPropertyNames,t=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty;function n(e,r){return function(t,a,n){return e(t,a,n)&&r(t,a,n)}}function u(e){return function(r,t,a){if(!r||!t||"object"!=typeof r||"object"!=typeof t)return e(r,t,a);var n=a.cache,u=n.get(r),o=n.get(t);if(u&&o)return u===t&&o===r;n.set(r,t),n.set(t,r);var i=e(r,t,a);return n.delete(r),n.delete(t),i}}function o(e){return r(e).concat(t(e))}var i=Object.hasOwn||function(e,r){return a.call(e,r)};function c(e,r){return e||r?e===r:e===r||e!=e&&r!=r}var l="_owner",f=Object.getOwnPropertyDescriptor,s=Object.keys;function p(e,r,t){var a=e.length;if(r.length!==a)return!1;for(;a-- >0;)if(!t.equals(e[a],r[a],a,a,e,r,t))return!1;return!0}function q(e,r){return c(e.getTime(),r.getTime())}function v(e,r,t){if(e.size!==r.size)return!1;for(var a,n,u={},o=e.entries(),i=0;(a=o.next())&&!a.done;){for(var c=r.entries(),l=!1,f=0;(n=c.next())&&!n.done;){var s=a.value,p=s[0],q=s[1],v=n.value,y=v[0],b=v[1];l||u[f]||!(l=t.equals(p,y,i,f,e,r,t)&&t.equals(q,b,p,y,e,r,t))||(u[f]=!0),f++}if(!l)return!1;i++}return!0}function y(e,r,t){var a,n=s(e),u=n.length;if(s(r).length!==u)return!1;for(;u-- >0;){if((a=n[u])===l&&(e.$$typeof||r.$$typeof)&&e.$$typeof!==r.$$typeof)return!1;if(!i(r,a)||!t.equals(e[a],r[a],a,a,e,r,t))return!1}return!0}function b(e,r,t){var a,n,u,c=o(e),s=c.length;if(o(r).length!==s)return!1;for(;s-- >0;){if((a=c[s])===l&&(e.$$typeof||r.$$typeof)&&e.$$typeof!==r.$$typeof)return!1;if(!i(r,a))return!1;if(!t.equals(e[a],r[a],a,a,e,r,t))return!1;if(n=f(e,a),u=f(r,a),(n||u)&&(!n||!u||n.configurable!==u.configurable||n.enumerable!==u.enumerable||n.writable!==u.writable))return!1}return!0}function E(e,r){return c(e.valueOf(),r.valueOf())}function g(e,r){return e.source===r.source&&e.flags===r.flags}function j(e,r,t){if(e.size!==r.size)return!1;for(var a,n,u={},o=e.values();(a=o.next())&&!a.done;){for(var i=r.values(),c=!1,l=0;(n=i.next())&&!n.done;)c||u[l]||!(c=t.equals(a.value,n.value,a.value,n.value,e,r,t))||(u[l]=!0),l++;if(!c)return!1}return!0}function d(e,r){var t=e.length;if(r.length!==t)return!1;for(;t-- >0;)if(e[t]!==r[t])return!1;return!0}var m="[object Arguments]",h="[object Boolean]",O="[object Date]",w="[object Map]",S="[object Number]",$="[object Object]",A="[object RegExp]",x="[object Set]",C="[object String]",D=Array.isArray,M="function"==typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView:null,P=Object.assign,T=Object.prototype.toString.call.bind(Object.prototype.toString);var I=Z(),z=Z({strict:!0}),B=Z({circular:!0}),R=Z({circular:!0,strict:!0}),W=Z({createInternalComparator:function(){return c}}),k=Z({strict:!0,createInternalComparator:function(){return c}}),V=Z({circular:!0,createInternalComparator:function(){return c}}),N=Z({circular:!0,createInternalComparator:function(){return c},strict:!0});function Z(e){void 0===e&&(e={});var r,t=e.circular,a=void 0!==t&&t,o=e.createInternalComparator,i=e.createState,c=e.strict,l=void 0!==c&&c,f=function(e){var r=e.circular,t=e.createCustomConfig,a=e.strict,o={areArraysEqual:a?b:p,areDatesEqual:q,areMapsEqual:a?n(v,b):v,areObjectsEqual:a?b:y,arePrimitiveWrappersEqual:E,areRegExpsEqual:g,areSetsEqual:a?n(j,b):j,areTypedArraysEqual:a?b:d};if(t&&(o=P({},o,t(o))),r){var i=u(o.areArraysEqual),c=u(o.areMapsEqual),l=u(o.areObjectsEqual),f=u(o.areSetsEqual);o=P({},o,{areArraysEqual:i,areMapsEqual:c,areObjectsEqual:l,areSetsEqual:f})}return o}(e),s=function(e){var r=e.areArraysEqual,t=e.areDatesEqual,a=e.areMapsEqual,n=e.areObjectsEqual,u=e.arePrimitiveWrappersEqual,o=e.areRegExpsEqual,i=e.areSetsEqual,c=e.areTypedArraysEqual;return function(e,l,f){if(e===l)return!0;if(null==e||null==l||"object"!=typeof e||"object"!=typeof l)return e!=e&&l!=l;var s=e.constructor;if(s!==l.constructor)return!1;if(s===Object)return n(e,l,f);if(D(e))return r(e,l,f);if(null!=M&&M(e))return c(e,l,f);if(s===Date)return t(e,l,f);if(s===RegExp)return o(e,l,f);if(s===Map)return a(e,l,f);if(s===Set)return i(e,l,f);var p=T(e);return p===O?t(e,l,f):p===A?o(e,l,f):p===w?a(e,l,f):p===x?i(e,l,f):p===$?"function"!=typeof e.then&&"function"!=typeof l.then&&n(e,l,f):p===m?n(e,l,f):(p===h||p===S||p===C)&&u(e,l,f)}}(f);return function(e){var r=e.circular,t=e.comparator,a=e.createState,n=e.equals,u=e.strict;if(a)return function(e,o){var i=a(),c=i.cache,l=void 0===c?r?new WeakMap:void 0:c,f=i.meta;return t(e,o,{cache:l,equals:n,meta:f,strict:u})};if(r)return function(e,r){return t(e,r,{cache:new WeakMap,equals:n,meta:void 0,strict:u})};var o={cache:void 0,equals:n,meta:void 0,strict:u};return function(e,r){return t(e,r,o)}}({circular:a,comparator:s,createState:i,equals:o?o(s):(r=s,function(e,t,a,n,u,o,i){return r(e,t,i)}),strict:l})}e.circularDeepEqual=B,e.circularShallowEqual=V,e.createCustomEqual=Z,e.deepEqual=I,e.sameValueZeroEqual=c,e.shallowEqual=W,e.strictCircularDeepEqual=R,e.strictCircularShallowEqual=N,e.strictDeepEqual=z,e.strictShallowEqual=k}));
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import type { ComparatorConfig, CustomEqualCreatorOptions, EqualityComparator } from './internalTypes';
|
|
1
|
+
import type { ComparatorConfig, CreateState, CustomEqualCreatorOptions, EqualityComparator, InternalEqualityComparator } from './internalTypes';
|
|
2
|
+
interface CreateIsEqualOptions<Meta> {
|
|
3
|
+
circular: boolean;
|
|
4
|
+
comparator: EqualityComparator<Meta>;
|
|
5
|
+
createState: CreateState<Meta> | undefined;
|
|
6
|
+
equals: InternalEqualityComparator<Meta>;
|
|
7
|
+
strict: boolean;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Create a comparator method based on the type-specific equality comparators passed.
|
|
4
11
|
*/
|
|
5
|
-
export declare function
|
|
12
|
+
export declare function createEqualityComparator<Meta>({ areArraysEqual, areDatesEqual, areMapsEqual, areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual, areTypedArraysEqual, }: ComparatorConfig<Meta>): EqualityComparator<Meta>;
|
|
6
13
|
/**
|
|
7
14
|
* Create the configuration object used for building comparators.
|
|
8
15
|
*/
|
|
9
|
-
export declare function
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import type { Dictionary, State, TypedArray } from './internalTypes';
|
|
1
|
+
import type { Dictionary, PrimitiveWrapper, State, TypedArray } from './internalTypes';
|
|
2
2
|
/**
|
|
3
3
|
* Whether the arrays are equal in value.
|
|
4
4
|
*/
|
|
@@ -22,7 +22,7 @@ export declare function areObjectsEqualStrict(a: Dictionary, b: Dictionary, stat
|
|
|
22
22
|
/**
|
|
23
23
|
* Whether the primitive wrappers passed are equal in value.
|
|
24
24
|
*/
|
|
25
|
-
export declare function arePrimitiveWrappersEqual(a:
|
|
25
|
+
export declare function arePrimitiveWrappersEqual(a: PrimitiveWrapper, b: PrimitiveWrapper): boolean;
|
|
26
26
|
/**
|
|
27
27
|
* Whether the regexps passed are equal in value.
|
|
28
28
|
*/
|
|
@@ -31,4 +31,7 @@ export declare function areRegExpsEqual(a: RegExp, b: RegExp): boolean;
|
|
|
31
31
|
* Whether the `Set`s are equal in value.
|
|
32
32
|
*/
|
|
33
33
|
export declare function areSetsEqual(a: Set<any>, b: Set<any>, state: State<any>): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the TypedArray instances are equal in value.
|
|
36
|
+
*/
|
|
34
37
|
export declare function areTypedArraysEqual(a: TypedArray, b: TypedArray): boolean;
|
|
@@ -5,37 +5,37 @@ export * from './internalTypes';
|
|
|
5
5
|
/**
|
|
6
6
|
* Whether the items passed are deeply-equal in value.
|
|
7
7
|
*/
|
|
8
|
-
export declare const deepEqual: <A, B>(a: A, b: B
|
|
8
|
+
export declare const deepEqual: <A, B>(a: A, b: B) => boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Whether the items passed are deeply-equal in value based on strict comparison.
|
|
11
11
|
*/
|
|
12
|
-
export declare const strictDeepEqual: <A, B>(a: A, b: B
|
|
12
|
+
export declare const strictDeepEqual: <A, B>(a: A, b: B) => boolean;
|
|
13
13
|
/**
|
|
14
14
|
* Whether the items passed are deeply-equal in value, including circular references.
|
|
15
15
|
*/
|
|
16
|
-
export declare const circularDeepEqual: <A, B>(a: A, b: B
|
|
16
|
+
export declare const circularDeepEqual: <A, B>(a: A, b: B) => boolean;
|
|
17
17
|
/**
|
|
18
18
|
* Whether the items passed are deeply-equal in value, including circular references,
|
|
19
19
|
* based on strict comparison.
|
|
20
20
|
*/
|
|
21
|
-
export declare const strictCircularDeepEqual: <A, B>(a: A, b: B
|
|
21
|
+
export declare const strictCircularDeepEqual: <A, B>(a: A, b: B) => boolean;
|
|
22
22
|
/**
|
|
23
23
|
* Whether the items passed are shallowly-equal in value.
|
|
24
24
|
*/
|
|
25
|
-
export declare const shallowEqual: <A, B>(a: A, b: B
|
|
25
|
+
export declare const shallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
26
26
|
/**
|
|
27
27
|
* Whether the items passed are shallowly-equal in value based on strict comparison
|
|
28
28
|
*/
|
|
29
|
-
export declare const strictShallowEqual: <A, B>(a: A, b: B
|
|
29
|
+
export declare const strictShallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
30
30
|
/**
|
|
31
31
|
* Whether the items passed are shallowly-equal in value, including circular references.
|
|
32
32
|
*/
|
|
33
|
-
export declare const circularShallowEqual: <A, B>(a: A, b: B
|
|
33
|
+
export declare const circularShallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
34
34
|
/**
|
|
35
35
|
* Whether the items passed are shallowly-equal in value, including circular references,
|
|
36
36
|
* based on strict comparison.
|
|
37
37
|
*/
|
|
38
|
-
export declare const strictCircularShallowEqual: <A, B>(a: A, b: B
|
|
38
|
+
export declare const strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
|
|
39
39
|
/**
|
|
40
40
|
* Create a custom equality comparison method.
|
|
41
41
|
*
|
|
@@ -44,4 +44,4 @@ export declare const strictCircularShallowEqual: <A, B>(a: A, b: B, metaOverride
|
|
|
44
44
|
* support for legacy environments that do not support expected features like
|
|
45
45
|
* `RegExp.prototype.flags` out of the box.
|
|
46
46
|
*/
|
|
47
|
-
export declare function createCustomEqual<Meta>(options?: CustomEqualCreatorOptions<Meta>): <A, B>(a: A, b: B
|
|
47
|
+
export declare function createCustomEqual<Meta = undefined>(options?: CustomEqualCreatorOptions<Meta>): <A, B>(a: A, b: B) => boolean;
|
|
@@ -1,46 +1,134 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
|
3
9
|
}
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
*/
|
|
7
18
|
readonly equals: InternalEqualityComparator<Meta>;
|
|
19
|
+
/**
|
|
20
|
+
* Additional value that can be used for comparisons.
|
|
21
|
+
*/
|
|
8
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
|
+
*/
|
|
9
28
|
readonly strict: boolean;
|
|
10
29
|
}
|
|
11
|
-
export interface
|
|
30
|
+
export interface CircularState<Meta> extends State<Meta> {
|
|
31
|
+
readonly cache: Cache<any, any>;
|
|
32
|
+
}
|
|
33
|
+
export interface DefaultState<Meta> extends State<Meta> {
|
|
12
34
|
readonly cache: undefined;
|
|
13
|
-
readonly equals: InternalEqualityComparator<Meta>;
|
|
14
|
-
meta: Meta;
|
|
15
|
-
readonly strict: boolean;
|
|
16
35
|
}
|
|
17
36
|
export interface Dictionary<Value = any> {
|
|
18
37
|
[key: string | symbol]: Value;
|
|
19
38
|
$$typeof?: any;
|
|
20
39
|
}
|
|
21
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
|
+
*/
|
|
22
45
|
areArraysEqual: TypeEqualityComparator<any, Meta>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the dates passed are equal in value.
|
|
48
|
+
*/
|
|
23
49
|
areDatesEqual: TypeEqualityComparator<any, Meta>;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the maps passed are equal in value. In strict mode, this includes
|
|
52
|
+
* additional properties added to the map.
|
|
53
|
+
*/
|
|
24
54
|
areMapsEqual: TypeEqualityComparator<any, Meta>;
|
|
55
|
+
/**
|
|
56
|
+
* Whether the objects passed are equal in value. In strict mode, this includes
|
|
57
|
+
* non-enumerable properties added to the map, as well as symbol properties.
|
|
58
|
+
*/
|
|
25
59
|
areObjectsEqual: TypeEqualityComparator<any, Meta>;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the primitive wrappers passed are equal in value.
|
|
62
|
+
*/
|
|
26
63
|
arePrimitiveWrappersEqual: TypeEqualityComparator<any, Meta>;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the regexps passed are equal in value.
|
|
66
|
+
*/
|
|
27
67
|
areRegExpsEqual: TypeEqualityComparator<any, Meta>;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the sets passed are equal in value. In strict mode, this includes
|
|
70
|
+
* additional properties added to the set.
|
|
71
|
+
*/
|
|
28
72
|
areSetsEqual: TypeEqualityComparator<any, Meta>;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the typed arrays passed are equal in value. In strict mode, this includes
|
|
75
|
+
* additional properties added to the typed array.
|
|
76
|
+
*/
|
|
29
77
|
areTypedArraysEqual: TypeEqualityComparator<any, Meta>;
|
|
30
78
|
}
|
|
31
79
|
export type CreateCustomComparatorConfig<Meta> = (config: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
|
|
32
|
-
export type CreateState<Meta> = (
|
|
80
|
+
export type CreateState<Meta> = () => {
|
|
81
|
+
cache?: Cache<any, any> | undefined;
|
|
82
|
+
meta?: Meta;
|
|
83
|
+
};
|
|
33
84
|
export type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;
|
|
34
85
|
export type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;
|
|
35
86
|
export type EqualityComparatorCreator<Meta> = (fn: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
|
|
36
87
|
export type InternalEqualityComparator<Meta> = (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
88
|
+
export type PrimitiveWrapper = Boolean | Number | String;
|
|
89
|
+
/**
|
|
90
|
+
* Type which encompasses possible instances of TypedArray
|
|
91
|
+
* classes.
|
|
92
|
+
*
|
|
93
|
+
* **NOTE**: This does not include `BigInt64Array` and
|
|
94
|
+
* `BitUint64Array` because those are part of ES2020 and
|
|
95
|
+
* not supported by certain TS configurations. If using
|
|
96
|
+
* either in `areTypedArraysEqual`, you can cast the
|
|
97
|
+
* instance as `TypedArray` and it will work as expected,
|
|
98
|
+
* because runtime checks will still work for those classes.
|
|
99
|
+
*/
|
|
37
100
|
export type TypedArray = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray;
|
|
38
101
|
export type TypeEqualityComparator<Type, Meta = undefined> = (a: Type, b: Type, state: State<Meta>) => boolean;
|
|
39
102
|
export interface CustomEqualCreatorOptions<Meta> {
|
|
103
|
+
/**
|
|
104
|
+
* Whether circular references should be supported. It causes the
|
|
105
|
+
* comparison to be slower, but for objects that have circular references
|
|
106
|
+
* it is required to avoid stack overflows.
|
|
107
|
+
*/
|
|
40
108
|
circular?: boolean;
|
|
41
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Create a custom configuration of type-specific equality comparators.
|
|
111
|
+
* This receives the default configuration, which allows either replacement
|
|
112
|
+
* or supersetting of the default methods.
|
|
113
|
+
*/
|
|
42
114
|
createCustomConfig?: CreateCustomComparatorConfig<Meta>;
|
|
43
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Create a custom internal comparator, which is used as an override to the
|
|
117
|
+
* default entry point for nested value equality comparisons. This is often
|
|
118
|
+
* used for doing custom logic for specific types (such as handling a specific
|
|
119
|
+
* class instance differently than other objects) or to incorporate `meta` in
|
|
120
|
+
* the comparison. See the recipes for examples.
|
|
121
|
+
*/
|
|
122
|
+
createInternalComparator?: (compare: EqualityComparator<Meta>) => InternalEqualityComparator<Meta>;
|
|
123
|
+
/**
|
|
124
|
+
* Create a custom `state` object passed between the methods. This allows for
|
|
125
|
+
* custom `cache` and/or `meta` values to be used.
|
|
126
|
+
*/
|
|
44
127
|
createState?: CreateState<Meta>;
|
|
128
|
+
/**
|
|
129
|
+
* Whether the equality comparison is strict, meaning it matches
|
|
130
|
+
* all properties (including symbols and non-enumerable properties)
|
|
131
|
+
* with equal shape of descriptors.
|
|
132
|
+
*/
|
|
45
133
|
strict?: boolean;
|
|
46
134
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { AnyEqualityComparator, Dictionary,
|
|
1
|
+
import { AnyEqualityComparator, Dictionary, State, TypeEqualityComparator } from './internalTypes';
|
|
2
2
|
/**
|
|
3
3
|
* Combine two comparators into a single comparators.
|
|
4
4
|
*/
|
|
5
5
|
export declare function combineComparators<Meta>(comparatorA: AnyEqualityComparator<Meta>, comparatorB: AnyEqualityComparator<Meta>): <A, B>(a: A, b: B, state: State<Meta>) => boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Default equality comparator pass-through, used as the standard `isEqual` creator for
|
|
8
|
-
* use inside the built comparator.
|
|
9
|
-
*/
|
|
10
|
-
export declare function createInternalComparator<Meta>(compare: EqualityComparator<Meta>): InternalEqualityComparator<Meta>;
|
|
11
6
|
/**
|
|
12
7
|
* Wrap the provided `areItemsEqual` method to manage the circular state, allowing
|
|
13
8
|
* for circular references to be safely included in the comparison without creating
|