fast-equals 1.6.0 → 2.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/.release-it.beta.json +13 -0
- package/.release-it.json +9 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +1 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +1 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +1 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/0ab301188498506f5c998a00679f29b8929634e4 +1 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/0ab301188498506f5c998a00679f29b8929634e4 +1 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/0ab301188498506f5c998a00679f29b8929634e4 +1 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/6982fa2ac1e62f4aebb1debc73977393caa0d5a4 +0 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +1 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +1 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +1 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +1 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +1 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +1 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +1 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +1 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +1 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
- package/BUILD.md +37 -0
- package/CHANGELOG.md +39 -0
- package/README.md +69 -88
- package/dist/fast-equals.cjs.js +427 -0
- package/dist/fast-equals.cjs.js.map +1 -0
- package/dist/fast-equals.esm.js +418 -0
- package/dist/fast-equals.esm.js.map +1 -0
- package/dist/fast-equals.js +418 -11
- package/dist/fast-equals.js.map +1 -1
- package/dist/fast-equals.min.js +1 -1
- package/dist/fast-equals.mjs +418 -0
- package/dist/fast-equals.mjs.map +1 -0
- package/index.d.ts +15 -14
- package/package.json +52 -65
- package/es/comparator.js +0 -91
- package/es/constants.js +0 -14
- package/es/index.js +0 -23
- package/es/utils.js +0 -295
- package/es-to-mjs.js +0 -14
- package/lib/comparator.js +0 -97
- package/lib/constants.js +0 -17
- package/lib/index.js +0 -34
- package/lib/utils.js +0 -300
- package/mjs/comparator.mjs +0 -91
- package/mjs/constants.mjs +0 -14
- package/mjs/index.mjs +0 -23
- package/mjs/utils.mjs +0 -295
- package/rollup.config.js +0 -44
- package/yarn-error.log +0 -8175
package/es/comparator.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// constants
|
|
2
|
-
import { HAS_MAP_SUPPORT, HAS_SET_SUPPORT } from './constants';
|
|
3
|
-
|
|
4
|
-
// utils
|
|
5
|
-
import { areArraysEqual, areObjectsEqual, areRegExpsEqual, createAreIterablesEqual, isPlainObject, isPromiseLike, isReactElement, sameValueZeroEqual } from './utils';
|
|
6
|
-
|
|
7
|
-
var isArray = Array.isArray;
|
|
8
|
-
|
|
9
|
-
var areMapsEqual = createAreIterablesEqual(true);
|
|
10
|
-
var areSetsEqual = createAreIterablesEqual(false);
|
|
11
|
-
|
|
12
|
-
var createComparator = function createComparator(createIsEqual) {
|
|
13
|
-
// eslint-disable-next-line no-use-before-define
|
|
14
|
-
var isEqual = typeof createIsEqual === 'function' ? createIsEqual(comparator) : comparator;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @function comparator
|
|
18
|
-
*
|
|
19
|
-
* @description
|
|
20
|
-
* compare the value of the two objects and return true if they are equivalent in values
|
|
21
|
-
*
|
|
22
|
-
* @param {any} objectA the object to test against
|
|
23
|
-
* @param {any} objectB the object to test
|
|
24
|
-
* @param {any} [meta] an optional meta object that is passed through to all equality test calls
|
|
25
|
-
* @returns {boolean} are objectA and objectB equivalent in value
|
|
26
|
-
*/
|
|
27
|
-
function comparator(objectA, objectB, meta) {
|
|
28
|
-
if (sameValueZeroEqual(objectA, objectB)) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var typeOfA = typeof objectA;
|
|
33
|
-
|
|
34
|
-
if (typeOfA !== typeof objectB || typeOfA !== 'object' || !objectA || !objectB) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (isPlainObject(objectA) && isPlainObject(objectB)) {
|
|
39
|
-
return areObjectsEqual(objectA, objectB, isEqual, meta);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var arrayA = isArray(objectA);
|
|
43
|
-
var arrayB = isArray(objectB);
|
|
44
|
-
|
|
45
|
-
if (arrayA || arrayB) {
|
|
46
|
-
return arrayA === arrayB && areArraysEqual(objectA, objectB, isEqual, meta);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
var dateA = objectA instanceof Date;
|
|
50
|
-
var dateB = objectB instanceof Date;
|
|
51
|
-
|
|
52
|
-
if (dateA || dateB) {
|
|
53
|
-
return dateA === dateB && sameValueZeroEqual(objectA.getTime(), objectB.getTime());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
var regexpA = objectA instanceof RegExp;
|
|
57
|
-
var regexpB = objectB instanceof RegExp;
|
|
58
|
-
|
|
59
|
-
if (regexpA || regexpB) {
|
|
60
|
-
return regexpA === regexpB && areRegExpsEqual(objectA, objectB);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (isPromiseLike(objectA) || isPromiseLike(objectB)) {
|
|
64
|
-
return objectA === objectB;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (HAS_MAP_SUPPORT) {
|
|
68
|
-
var mapA = objectA instanceof Map;
|
|
69
|
-
var mapB = objectB instanceof Map;
|
|
70
|
-
|
|
71
|
-
if (mapA || mapB) {
|
|
72
|
-
return mapA === mapB && areMapsEqual(objectA, objectB, isEqual, meta);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (HAS_SET_SUPPORT) {
|
|
77
|
-
var setA = objectA instanceof Set;
|
|
78
|
-
var setB = objectB instanceof Set;
|
|
79
|
-
|
|
80
|
-
if (setA || setB) {
|
|
81
|
-
return setA === setB && areSetsEqual(objectA, objectB, isEqual, meta);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return areObjectsEqual(objectA, objectB, isEqual, meta);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return comparator;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export default createComparator;
|
package/es/constants.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @constant {boolean} HAS_MAP_SUPPORT
|
|
3
|
-
*/
|
|
4
|
-
export var HAS_MAP_SUPPORT = typeof Map === 'function';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @constant {boolean} HAS_SET_SUPPORT
|
|
8
|
-
*/
|
|
9
|
-
export var HAS_SET_SUPPORT = typeof Set === 'function';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @constant {boolean} HAS_WEAKSET_SUPPORT
|
|
13
|
-
*/
|
|
14
|
-
export var HAS_WEAKSET_SUPPORT = typeof WeakSet === 'function';
|
package/es/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// comparator
|
|
2
|
-
import createCustomEqual from './comparator';
|
|
3
|
-
|
|
4
|
-
// utils
|
|
5
|
-
import { createCircularEqual, sameValueZeroEqual } from './utils';
|
|
6
|
-
|
|
7
|
-
export { createCustomEqual, sameValueZeroEqual };
|
|
8
|
-
|
|
9
|
-
export var circularDeepEqual = createCustomEqual(createCircularEqual());
|
|
10
|
-
export var circularShallowEqual = createCustomEqual(createCircularEqual(sameValueZeroEqual));
|
|
11
|
-
export var deepEqual = createCustomEqual();
|
|
12
|
-
export var shallowEqual = createCustomEqual(function () {
|
|
13
|
-
return sameValueZeroEqual;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export default {
|
|
17
|
-
circularDeep: circularDeepEqual,
|
|
18
|
-
circularShallow: circularShallowEqual,
|
|
19
|
-
createCustom: createCustomEqual,
|
|
20
|
-
deep: deepEqual,
|
|
21
|
-
sameValueZero: sameValueZeroEqual,
|
|
22
|
-
shallow: shallowEqual
|
|
23
|
-
};
|
package/es/utils.js
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
// constants
|
|
2
|
-
import { HAS_WEAKSET_SUPPORT } from './constants';
|
|
3
|
-
|
|
4
|
-
var keys = Object.keys;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @function addObjectToCache
|
|
8
|
-
*
|
|
9
|
-
* @description
|
|
10
|
-
* add object to cache if it is indeed an object
|
|
11
|
-
*
|
|
12
|
-
* @param {any} object the object to potentially add to the cache
|
|
13
|
-
* @param {Object|WeakSet} cache the cache to add to
|
|
14
|
-
* @returns {void}
|
|
15
|
-
*/
|
|
16
|
-
export var addObjectToCache = function addObjectToCache(object, cache) {
|
|
17
|
-
return object && typeof object === 'object' && cache.add(object);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @function hasItem
|
|
22
|
-
*
|
|
23
|
-
* @description
|
|
24
|
-
* does the array include the item passed
|
|
25
|
-
*
|
|
26
|
-
* @param {Array<any>} array the array to check in
|
|
27
|
-
* @param {any} item the item to locate
|
|
28
|
-
* @param {function} isEqual the equality comparator
|
|
29
|
-
* @param {any} meta the meta item to pass through
|
|
30
|
-
* @returns {boolean} does the item exist in the array
|
|
31
|
-
*/
|
|
32
|
-
export var hasItem = function hasItem(array, item, isEqual, meta) {
|
|
33
|
-
for (var index = 0; index < array.length; index++) {
|
|
34
|
-
if (isEqual(array[index], item, meta)) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return false;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @function hasItems
|
|
44
|
-
*
|
|
45
|
-
* @description
|
|
46
|
-
* are the arrays equal in value, despite being in different order
|
|
47
|
-
*
|
|
48
|
-
* @param {Array<any>} arrayA the first array to test
|
|
49
|
-
* @param {Array<any>} arrayB the second array to test
|
|
50
|
-
* @param {function} isEqual the equality comparator
|
|
51
|
-
* @param {any} meta the meta item to pass through
|
|
52
|
-
* @returns {boolean} are the arrays equal absent order
|
|
53
|
-
*/
|
|
54
|
-
export var hasItems = function hasItems(arrayA, arrayB, isEqual, meta) {
|
|
55
|
-
if (arrayA.length !== arrayB.length) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
for (var index = 0; index < arrayA.length; index++) {
|
|
60
|
-
if (!hasItem(arrayB, arrayA[index], isEqual, meta)) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return true;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @function sameValueZeroEqual
|
|
70
|
-
*
|
|
71
|
-
* @description
|
|
72
|
-
* are the objects passed strictly equal or both NaN
|
|
73
|
-
*
|
|
74
|
-
* @param {any} objectA the object to compare against
|
|
75
|
-
* @param {any} objectB the object to test
|
|
76
|
-
* @returns {boolean} are the objects equal by the SameValueZero principle
|
|
77
|
-
*/
|
|
78
|
-
export var sameValueZeroEqual = function sameValueZeroEqual(objectA, objectB) {
|
|
79
|
-
return objectA === objectB || objectA !== objectA && objectB !== objectB;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @function isPlainObject
|
|
84
|
-
*
|
|
85
|
-
* @description
|
|
86
|
-
* is the object a plain object
|
|
87
|
-
*
|
|
88
|
-
* @param {any} object the object to test
|
|
89
|
-
* @returns {boolean} is the object a plain object
|
|
90
|
-
*/
|
|
91
|
-
export var isPlainObject = function isPlainObject(object) {
|
|
92
|
-
return object.constructor === Object;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @function isPromiseLike
|
|
97
|
-
*
|
|
98
|
-
* @description
|
|
99
|
-
* is the object promise-like (thenable)
|
|
100
|
-
*
|
|
101
|
-
* @param {any} object the object to test
|
|
102
|
-
* @returns {boolean} is the object promise-like
|
|
103
|
-
*/
|
|
104
|
-
export var isPromiseLike = function isPromiseLike(object) {
|
|
105
|
-
return typeof object.then === 'function';
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @function isReactElement
|
|
110
|
-
*
|
|
111
|
-
* @description
|
|
112
|
-
* is the object passed a react element
|
|
113
|
-
*
|
|
114
|
-
* @param {any} object the object to test
|
|
115
|
-
* @returns {boolean} is the object a react element
|
|
116
|
-
*/
|
|
117
|
-
export var isReactElement = function isReactElement(object) {
|
|
118
|
-
return !!(object.$$typeof && object._store);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @function getNewCache
|
|
123
|
-
*
|
|
124
|
-
* @description
|
|
125
|
-
* get a new cache object to prevent circular references
|
|
126
|
-
*
|
|
127
|
-
* @returns {Object|Weakset} the new cache object
|
|
128
|
-
*/
|
|
129
|
-
export var getNewCache = function getNewCache() {
|
|
130
|
-
return HAS_WEAKSET_SUPPORT ? new WeakSet() : Object.create({
|
|
131
|
-
_values: [],
|
|
132
|
-
add: function add(value) {
|
|
133
|
-
this._values.push(value);
|
|
134
|
-
},
|
|
135
|
-
has: function has(value) {
|
|
136
|
-
return !!~this._values.indexOf(value);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* @function createCircularEqual
|
|
143
|
-
*
|
|
144
|
-
* @description
|
|
145
|
-
* create a custom isEqual handler specific to circular objects
|
|
146
|
-
*
|
|
147
|
-
* @param {funtion} [isEqual] the isEqual comparator to use instead of isDeepEqual
|
|
148
|
-
* @returns {function(any, any): boolean}
|
|
149
|
-
*/
|
|
150
|
-
export var createCircularEqual = function createCircularEqual(isEqual) {
|
|
151
|
-
return function (isDeepEqual) {
|
|
152
|
-
var comparator = isEqual || isDeepEqual;
|
|
153
|
-
|
|
154
|
-
return function (objectA, objectB) {
|
|
155
|
-
var cache = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getNewCache();
|
|
156
|
-
|
|
157
|
-
var cacheHasA = cache.has(objectA);
|
|
158
|
-
var cacheHasB = cache.has(objectB);
|
|
159
|
-
|
|
160
|
-
if (cacheHasA || cacheHasB) {
|
|
161
|
-
return cacheHasA && cacheHasB;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
addObjectToCache(objectA, cache);
|
|
165
|
-
addObjectToCache(objectB, cache);
|
|
166
|
-
|
|
167
|
-
return comparator(objectA, objectB, cache);
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* @function toPairs
|
|
174
|
-
*
|
|
175
|
-
* @param {Map|Set} iterable the iterable to convert to [key, value] pairs (entries)
|
|
176
|
-
* @returns {{keys: Array<*>, values: Array<*>}} the [key, value] pairs
|
|
177
|
-
*/
|
|
178
|
-
export var toPairs = function toPairs(iterable) {
|
|
179
|
-
var pairs = {
|
|
180
|
-
keys: [],
|
|
181
|
-
values: []
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
iterable.forEach(function (value, key) {
|
|
185
|
-
return pairs.keys.push(key) && pairs.values.push(value);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
return pairs;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* @function areArraysEqual
|
|
193
|
-
*
|
|
194
|
-
* @description
|
|
195
|
-
* are the arrays equal in value
|
|
196
|
-
*
|
|
197
|
-
* @param {Array<any>} arrayA the array to test
|
|
198
|
-
* @param {Array<any>} arrayB the array to test against
|
|
199
|
-
* @param {function} isEqual the comparator to determine equality
|
|
200
|
-
* @param {any} meta the meta object to pass through
|
|
201
|
-
* @returns {boolean} are the arrays equal
|
|
202
|
-
*/
|
|
203
|
-
export var areArraysEqual = function areArraysEqual(arrayA, arrayB, isEqual, meta) {
|
|
204
|
-
if (arrayA.length !== arrayB.length) {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
for (var index = 0; index < arrayA.length; index++) {
|
|
209
|
-
if (!isEqual(arrayA[index], arrayB[index], meta)) {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return true;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
export var createAreIterablesEqual = function createAreIterablesEqual(shouldCompareKeys) {
|
|
218
|
-
/**
|
|
219
|
-
* @function areIterablesEqual
|
|
220
|
-
*
|
|
221
|
-
* @description
|
|
222
|
-
* determine if the iterables are equivalent in value
|
|
223
|
-
*
|
|
224
|
-
* @param {Array<Array<any>>} pairsA the pairs to test
|
|
225
|
-
* @param {Array<Array<any>>} pairsB the pairs to test against
|
|
226
|
-
* @param {function} isEqual the comparator to determine equality
|
|
227
|
-
* @param {any} meta the cache possibly being used
|
|
228
|
-
* @returns {boolean} are the objects equal in value
|
|
229
|
-
*/
|
|
230
|
-
var areIterablesEqual = shouldCompareKeys ? function (pairsA, pairsB, isEqual, meta) {
|
|
231
|
-
return hasItems(pairsA.keys, pairsB.keys, isEqual, meta) && hasItems(pairsA.values, pairsB.values, isEqual, meta);
|
|
232
|
-
} : function (pairsA, pairsB, isEqual, meta) {
|
|
233
|
-
return hasItems(pairsA.values, pairsB.values, isEqual, meta);
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
return function (iterableA, iterableB, isEqual, meta) {
|
|
237
|
-
return areIterablesEqual(toPairs(iterableA), toPairs(iterableB), isEqual, meta);
|
|
238
|
-
};
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* @function areArraysEqual
|
|
243
|
-
*
|
|
244
|
-
* @description
|
|
245
|
-
* are the objects equal in value
|
|
246
|
-
*
|
|
247
|
-
* @param {Array<any>} objectA the object to test
|
|
248
|
-
* @param {Array<any>} objectB the object to test against
|
|
249
|
-
* @param {function} isEqual the comparator to determine equality
|
|
250
|
-
* @param {any} meta the meta object to pass through
|
|
251
|
-
* @returns {boolean} are the objects equal
|
|
252
|
-
*/
|
|
253
|
-
export var areObjectsEqual = function areObjectsEqual(objectA, objectB, isEqual, meta) {
|
|
254
|
-
var keysA = keys(objectA);
|
|
255
|
-
var keysB = keys(objectB);
|
|
256
|
-
|
|
257
|
-
if (keysA.length !== keysB.length) {
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
var key = void 0;
|
|
262
|
-
|
|
263
|
-
for (var index = 0; index < keysA.length; index++) {
|
|
264
|
-
key = keysA[index];
|
|
265
|
-
|
|
266
|
-
if (!hasItem(keysB, key, sameValueZeroEqual)) {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// if a react element, ignore the "_owner" key because its not necessary for equality comparisons
|
|
271
|
-
if (key === '_owner' && isReactElement(objectA) && isReactElement(objectB)) {
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (!isEqual(objectA[key], objectB[key], meta)) {
|
|
276
|
-
return false;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return true;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* @function areRegExpsEqual
|
|
285
|
-
*
|
|
286
|
-
* @description
|
|
287
|
-
* are the regExps equal in value
|
|
288
|
-
*
|
|
289
|
-
* @param {RegExp} regExpA the regExp to test
|
|
290
|
-
* @param {RegExp} regExpB the regExp to test agains
|
|
291
|
-
* @returns {boolean} are the regExps equal
|
|
292
|
-
*/
|
|
293
|
-
export var areRegExpsEqual = function areRegExpsEqual(regExpA, regExpB) {
|
|
294
|
-
return regExpA.source === regExpB.source && regExpA.global === regExpB.global && regExpA.ignoreCase === regExpB.ignoreCase && regExpA.multiline === regExpB.multiline && regExpA.unicode === regExpB.unicode && regExpA.sticky === regExpB.sticky && regExpA.lastIndex === regExpB.lastIndex;
|
|
295
|
-
};
|
package/es-to-mjs.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const fs = require('fs-extra');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const ES_DIRECTORY = path.join(__dirname, 'es');
|
|
5
|
-
const MJS_DIRECTORY = path.join(__dirname, 'mjs');
|
|
6
|
-
|
|
7
|
-
fs.readdirSync(ES_DIRECTORY).forEach((file) => {
|
|
8
|
-
const fullPathJsFilename = path.resolve(ES_DIRECTORY, file);
|
|
9
|
-
const fullPathMjsFilename = path.resolve(MJS_DIRECTORY, `${file.slice(0, -3)}.mjs`);
|
|
10
|
-
|
|
11
|
-
fs.copySync(fullPathJsFilename, fullPathMjsFilename);
|
|
12
|
-
|
|
13
|
-
console.log(`es/${file} -> mjs/${file.slice(0, -3)}.mjs`);
|
|
14
|
-
});
|
package/lib/comparator.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
|
|
5
|
-
var _constants = require('./constants');
|
|
6
|
-
|
|
7
|
-
var _utils = require('./utils');
|
|
8
|
-
|
|
9
|
-
// constants
|
|
10
|
-
var isArray = Array.isArray;
|
|
11
|
-
|
|
12
|
-
// utils
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var areMapsEqual = (0, _utils.createAreIterablesEqual)(true);
|
|
16
|
-
var areSetsEqual = (0, _utils.createAreIterablesEqual)(false);
|
|
17
|
-
|
|
18
|
-
var createComparator = function createComparator(createIsEqual) {
|
|
19
|
-
// eslint-disable-next-line no-use-before-define
|
|
20
|
-
var isEqual = typeof createIsEqual === 'function' ? createIsEqual(comparator) : comparator;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @function comparator
|
|
24
|
-
*
|
|
25
|
-
* @description
|
|
26
|
-
* compare the value of the two objects and return true if they are equivalent in values
|
|
27
|
-
*
|
|
28
|
-
* @param {any} objectA the object to test against
|
|
29
|
-
* @param {any} objectB the object to test
|
|
30
|
-
* @param {any} [meta] an optional meta object that is passed through to all equality test calls
|
|
31
|
-
* @returns {boolean} are objectA and objectB equivalent in value
|
|
32
|
-
*/
|
|
33
|
-
function comparator(objectA, objectB, meta) {
|
|
34
|
-
if ((0, _utils.sameValueZeroEqual)(objectA, objectB)) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var typeOfA = typeof objectA;
|
|
39
|
-
|
|
40
|
-
if (typeOfA !== typeof objectB || typeOfA !== 'object' || !objectA || !objectB) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if ((0, _utils.isPlainObject)(objectA) && (0, _utils.isPlainObject)(objectB)) {
|
|
45
|
-
return (0, _utils.areObjectsEqual)(objectA, objectB, isEqual, meta);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var arrayA = isArray(objectA);
|
|
49
|
-
var arrayB = isArray(objectB);
|
|
50
|
-
|
|
51
|
-
if (arrayA || arrayB) {
|
|
52
|
-
return arrayA === arrayB && (0, _utils.areArraysEqual)(objectA, objectB, isEqual, meta);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
var dateA = objectA instanceof Date;
|
|
56
|
-
var dateB = objectB instanceof Date;
|
|
57
|
-
|
|
58
|
-
if (dateA || dateB) {
|
|
59
|
-
return dateA === dateB && (0, _utils.sameValueZeroEqual)(objectA.getTime(), objectB.getTime());
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var regexpA = objectA instanceof RegExp;
|
|
63
|
-
var regexpB = objectB instanceof RegExp;
|
|
64
|
-
|
|
65
|
-
if (regexpA || regexpB) {
|
|
66
|
-
return regexpA === regexpB && (0, _utils.areRegExpsEqual)(objectA, objectB);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if ((0, _utils.isPromiseLike)(objectA) || (0, _utils.isPromiseLike)(objectB)) {
|
|
70
|
-
return objectA === objectB;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (_constants.HAS_MAP_SUPPORT) {
|
|
74
|
-
var mapA = objectA instanceof Map;
|
|
75
|
-
var mapB = objectB instanceof Map;
|
|
76
|
-
|
|
77
|
-
if (mapA || mapB) {
|
|
78
|
-
return mapA === mapB && areMapsEqual(objectA, objectB, isEqual, meta);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (_constants.HAS_SET_SUPPORT) {
|
|
83
|
-
var setA = objectA instanceof Set;
|
|
84
|
-
var setB = objectB instanceof Set;
|
|
85
|
-
|
|
86
|
-
if (setA || setB) {
|
|
87
|
-
return setA === setB && areSetsEqual(objectA, objectB, isEqual, meta);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return (0, _utils.areObjectsEqual)(objectA, objectB, isEqual, meta);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return comparator;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
exports.default = createComparator;
|
package/lib/constants.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
/**
|
|
5
|
-
* @constant {boolean} HAS_MAP_SUPPORT
|
|
6
|
-
*/
|
|
7
|
-
var HAS_MAP_SUPPORT = exports.HAS_MAP_SUPPORT = typeof Map === 'function';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @constant {boolean} HAS_SET_SUPPORT
|
|
11
|
-
*/
|
|
12
|
-
var HAS_SET_SUPPORT = exports.HAS_SET_SUPPORT = typeof Set === 'function';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @constant {boolean} HAS_WEAKSET_SUPPORT
|
|
16
|
-
*/
|
|
17
|
-
var HAS_WEAKSET_SUPPORT = exports.HAS_WEAKSET_SUPPORT = typeof WeakSet === 'function';
|
package/lib/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.shallowEqual = exports.deepEqual = exports.circularShallowEqual = exports.circularDeepEqual = exports.sameValueZeroEqual = exports.createCustomEqual = undefined;
|
|
5
|
-
|
|
6
|
-
var _comparator = require('./comparator');
|
|
7
|
-
|
|
8
|
-
var _comparator2 = _interopRequireDefault(_comparator);
|
|
9
|
-
|
|
10
|
-
var _utils = require('./utils');
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
// comparator
|
|
15
|
-
exports.createCustomEqual = _comparator2.default;
|
|
16
|
-
exports.sameValueZeroEqual = _utils.sameValueZeroEqual;
|
|
17
|
-
|
|
18
|
-
// utils
|
|
19
|
-
|
|
20
|
-
var circularDeepEqual = exports.circularDeepEqual = (0, _comparator2.default)((0, _utils.createCircularEqual)());
|
|
21
|
-
var circularShallowEqual = exports.circularShallowEqual = (0, _comparator2.default)((0, _utils.createCircularEqual)(_utils.sameValueZeroEqual));
|
|
22
|
-
var deepEqual = exports.deepEqual = (0, _comparator2.default)();
|
|
23
|
-
var shallowEqual = exports.shallowEqual = (0, _comparator2.default)(function () {
|
|
24
|
-
return _utils.sameValueZeroEqual;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
exports.default = {
|
|
28
|
-
circularDeep: circularDeepEqual,
|
|
29
|
-
circularShallow: circularShallowEqual,
|
|
30
|
-
createCustom: _comparator2.default,
|
|
31
|
-
deep: deepEqual,
|
|
32
|
-
sameValueZero: _utils.sameValueZeroEqual,
|
|
33
|
-
shallow: shallowEqual
|
|
34
|
-
};
|