fast-equals 1.6.3 → 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.
Files changed (66) hide show
  1. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
  2. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +1 -0
  3. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
  4. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
  5. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +1 -0
  6. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
  7. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
  8. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +1 -0
  9. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
  10. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
  11. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
  12. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
  13. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/0ab301188498506f5c998a00679f29b8929634e4 +1 -0
  14. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
  15. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
  16. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/0ab301188498506f5c998a00679f29b8929634e4 +1 -0
  17. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
  18. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
  19. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/0ab301188498506f5c998a00679f29b8929634e4 +1 -0
  20. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +1 -0
  21. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +1 -0
  22. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/6982fa2ac1e62f4aebb1debc73977393caa0d5a4 +0 -0
  23. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
  24. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
  25. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
  26. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +1 -0
  27. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +1 -0
  28. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +1 -0
  29. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +1 -0
  30. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +1 -0
  31. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +1 -0
  32. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +1 -0
  33. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +1 -0
  34. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +1 -0
  35. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
  36. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
  37. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
  38. package/BUILD.md +37 -0
  39. package/CHANGELOG.md +23 -0
  40. package/README.md +65 -84
  41. package/dist/fast-equals.cjs.js +415 -446
  42. package/dist/fast-equals.cjs.js.map +1 -1
  43. package/dist/fast-equals.esm.js +415 -446
  44. package/dist/fast-equals.esm.js.map +1 -1
  45. package/dist/fast-equals.js +415 -446
  46. package/dist/fast-equals.js.map +1 -1
  47. package/dist/fast-equals.min.js +1 -1
  48. package/dist/fast-equals.mjs +418 -0
  49. package/dist/fast-equals.mjs.map +1 -0
  50. package/index.d.ts +15 -14
  51. package/package.json +31 -47
  52. package/es/comparator.js +0 -86
  53. package/es/constants.js +0 -14
  54. package/es/index.js +0 -19
  55. package/es/utils.js +0 -333
  56. package/es-to-mjs.js +0 -14
  57. package/lib/comparator.js +0 -94
  58. package/lib/constants.js +0 -22
  59. package/lib/index.js +0 -36
  60. package/lib/utils.js +0 -386
  61. package/mjs/comparator.mjs +0 -86
  62. package/mjs/constants.mjs +0 -14
  63. package/mjs/index.mjs +0 -19
  64. package/mjs/utils.mjs +0 -333
  65. package/rollup.config.js +0 -55
  66. package/yarn-error.log +0 -8175
@@ -2,457 +2,426 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /**
6
- * @constant {boolean} HAS_MAP_SUPPORT
7
- */
8
- var HAS_MAP_SUPPORT = typeof Map === 'function';
9
- /**
10
- * @constant {boolean} HAS_SET_SUPPORT
11
- */
12
-
13
- var HAS_SET_SUPPORT = typeof Set === 'function';
14
- /**
15
- * @constant {boolean} HAS_WEAKSET_SUPPORT
16
- */
17
-
18
- var HAS_WEAKSET_SUPPORT = typeof WeakSet === 'function';
19
-
20
- // constants
21
- var keys = Object.keys;
22
- /**
23
- * @function addObjectToCache
24
- *
25
- * @description
26
- * add object to cache if it is indeed an object
27
- *
28
- * @param {any} object the object to potentially add to the cache
29
- * @param {Object|WeakSet} cache the cache to add to
30
- * @returns {void}
31
- */
32
-
33
- var addObjectToCache = function addObjectToCache(object, cache) {
34
- return object && typeof object === 'object' && cache.add(object);
35
- };
36
- /**
37
- *
38
- * @param {Array<Array<any>>} pairs the pairs to check in
39
- * @param {Array<any>} pairToMatch the pair to check if exists
40
- * @param {function} isEqual the equality comparator
41
- * @param {any} meta the meta item to pass through
42
- * @returns {boolean} does the pair exist in the pairs
43
- */
44
-
45
- var hasPair = function hasPair(pairs, pairToMatch, isEqual, meta) {
46
- var pair;
47
-
48
- for (var index = 0; index < pairs.length; index++) {
49
- pair = pairs[index];
50
-
51
- if (isEqual(pair[0], pairToMatch[0], meta) && isEqual(pair[1], pairToMatch[1], meta)) {
52
- return true;
53
- }
54
- }
55
-
56
- return false;
57
- };
58
- /**
59
- * @function hasValue
60
- *
61
- * @description
62
- * does the values include the vakye passed
63
- *
64
- * @param {Array<any>} values the values to check in
65
- * @param {any} item the value to locate
66
- * @param {function} isEqual the equality comparator
67
- * @param {any} meta the meta item to pass through
68
- * @returns {boolean} does the value exist in the values
69
- */
70
-
71
- var hasValue = function hasValue(values, item, isEqual, meta) {
72
- for (var index = 0; index < values.length; index++) {
73
- if (isEqual(values[index], item, meta)) {
74
- return true;
75
- }
76
- }
77
-
78
- return false;
79
- };
80
- /**
81
- * @function sameValueZeroEqual
82
- *
83
- * @description
84
- * are the objects passed strictly equal or both NaN
85
- *
86
- * @param {any} objectA the object to compare against
87
- * @param {any} objectB the object to test
88
- * @returns {boolean} are the objects equal by the SameValueZero principle
89
- */
90
-
91
- var sameValueZeroEqual = function sameValueZeroEqual(objectA, objectB) {
92
- return objectA === objectB || objectA !== objectA && objectB !== objectB;
93
- };
94
- /**
95
- * @function isPlainObject
96
- *
97
- * @description
98
- * is the object a plain object
99
- *
100
- * @param {any} object the object to test
101
- * @returns {boolean} is the object a plain object
102
- */
103
-
104
- var isPlainObject = function isPlainObject(object) {
105
- return object.constructor === Object;
106
- };
107
- /**
108
- * @function isPromiseLike
109
- *
110
- * @description
111
- * is the object promise-like (thenable)
112
- *
113
- * @param {any} object the object to test
114
- * @returns {boolean} is the object promise-like
115
- */
116
-
117
- var isPromiseLike = function isPromiseLike(object) {
118
- return typeof object.then === 'function';
119
- };
120
- /**
121
- * @function isReactElement
122
- *
123
- * @description
124
- * is the object passed a react element
125
- *
126
- * @param {any} object the object to test
127
- * @returns {boolean} is the object a react element
128
- */
129
-
130
- var isReactElement = function isReactElement(object) {
131
- return !!(object.$$typeof && object._store);
132
- };
133
- /**
134
- * @function getNewCache
135
- *
136
- * @description
137
- * get a new cache object to prevent circular references
138
- *
139
- * @returns {Object|Weakset} the new cache object
140
- */
141
-
142
- var getNewCache = function getNewCache() {
143
- return HAS_WEAKSET_SUPPORT ? new WeakSet() : Object.create({
144
- _values: [],
145
- add: function add(value) {
146
- this._values.push(value);
147
- },
148
- has: function has(value) {
149
- return !!~this._values.indexOf(value);
150
- }
151
- });
152
- };
153
- /**
154
- * @function createCircularEqual
155
- *
156
- * @description
157
- * create a custom isEqual handler specific to circular objects
158
- *
159
- * @param {funtion} [isEqual] the isEqual comparator to use instead of isDeepEqual
160
- * @returns {function(any, any): boolean}
161
- */
162
-
163
- var createCircularEqual = function createCircularEqual(isEqual) {
164
- return function (isDeepEqual) {
165
- var comparator = isEqual || isDeepEqual;
166
- return function (objectA, objectB, cache) {
167
- if (cache === void 0) {
168
- cache = getNewCache();
169
- }
170
-
171
- var cacheHasA = cache.has(objectA);
172
- var cacheHasB = cache.has(objectB);
173
-
174
- if (cacheHasA || cacheHasB) {
175
- return cacheHasA && cacheHasB;
176
- }
177
-
178
- addObjectToCache(objectA, cache);
179
- addObjectToCache(objectB, cache);
180
- return comparator(objectA, objectB, cache);
181
- };
182
- };
183
- };
184
- /**
185
- * @function toPairs
186
- *
187
- * @param {Map} map the map to convert to [key, value] pairs (entries)
188
- * @returns {Array<Array<*>>} the [key, value] pairs
189
- */
190
-
191
- var toPairs = function toPairs(map) {
192
- var pairs = [];
193
- map.forEach(function (value, key) {
194
- return pairs.push([key, value]);
195
- });
196
- return pairs;
197
- };
198
- /**
199
- * @function toValues
200
- *
201
- * @param {Set} set the set to convert to values
202
- * @returns {Array<*>} the values
203
- */
204
-
205
- var toValues = function toValues(set) {
206
- var values = [];
207
- set.forEach(function (value) {
208
- return values.push(value);
209
- });
210
- return values;
211
- };
212
- /**
213
- * @function areArraysEqual
214
- *
215
- * @description
216
- * are the arrays equal in value
217
- *
218
- * @param {Array<any>} arrayA the array to test
219
- * @param {Array<any>} arrayB the array to test against
220
- * @param {function} isEqual the comparator to determine equality
221
- * @param {any} meta the meta object to pass through
222
- * @returns {boolean} are the arrays equal
223
- */
224
-
225
- var areArraysEqual = function areArraysEqual(arrayA, arrayB, isEqual, meta) {
226
- if (arrayA.length !== arrayB.length) {
227
- return false;
228
- }
229
-
230
- for (var index = 0; index < arrayA.length; index++) {
231
- if (!isEqual(arrayA[index], arrayB[index], meta)) {
232
- return false;
233
- }
234
- }
235
-
236
- return true;
237
- };
238
- /**
239
- * @function areMapsEqual
240
- *
241
- * @description
242
- * are the maps equal in value
243
- *
244
- * @param {Map} mapA the map to test
245
- * @param {Map} mapB the map to test against
246
- * @param {function} isEqual the comparator to determine equality
247
- * @param {any} meta the meta map to pass through
248
- * @returns {boolean} are the maps equal
249
- */
250
-
251
- var areMapsEqual = function areMapsEqual(mapA, mapB, isEqual, meta) {
252
- if (mapA.size !== mapB.size) {
253
- return false;
254
- }
255
-
256
- var pairsA = toPairs(mapA);
257
- var pairsB = toPairs(mapB);
258
-
259
- for (var index = 0; index < pairsA.length; index++) {
260
- if (!hasPair(pairsB, pairsA[index], isEqual, meta) || !hasPair(pairsA, pairsB[index], isEqual, meta)) {
261
- return false;
262
- }
263
- }
264
-
265
- return true;
266
- };
267
- /**
268
- * @function areObjectsEqual
269
- *
270
- * @description
271
- * are the objects equal in value
272
- *
273
- * @param {Object} objectA the object to test
274
- * @param {Object} objectB the object to test against
275
- * @param {function} isEqual the comparator to determine equality
276
- * @param {any} meta the meta object to pass through
277
- * @returns {boolean} are the objects equal
278
- */
279
-
280
- var areObjectsEqual = function areObjectsEqual(objectA, objectB, isEqual, meta) {
281
- var keysA = keys(objectA);
282
- var keysB = keys(objectB);
283
-
284
- if (keysA.length !== keysB.length) {
285
- return false;
286
- }
287
-
288
- var key;
289
-
290
- for (var index = 0; index < keysA.length; index++) {
291
- key = keysA[index];
292
-
293
- if (!hasValue(keysB, key, sameValueZeroEqual)) {
294
- return false;
295
- } // if a react element, ignore the "_owner" key because its not necessary for equality comparisons
296
-
297
-
298
- if (key === '_owner' && isReactElement(objectA) && isReactElement(objectB)) {
299
- continue;
300
- }
301
-
302
- if (!isEqual(objectA[key], objectB[key], meta)) {
303
- return false;
304
- }
305
- }
306
-
307
- return true;
308
- };
309
- /**
310
- * @function areRegExpsEqual
311
- *
312
- * @description
313
- * are the regExps equal in value
314
- *
315
- * @param {RegExp} regExpA the regExp to test
316
- * @param {RegExp} regExpB the regExp to test agains
317
- * @returns {boolean} are the regExps equal
318
- */
319
-
320
- var areRegExpsEqual = function areRegExpsEqual(regExpA, regExpB) {
321
- 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;
322
- };
323
- /**
324
- * @function areSetsEqual
325
- *
326
- * @description
327
- * are the sets equal in value
328
- *
329
- * @param {Set} setA the set to test
330
- * @param {Set} setB the set to test against
331
- * @param {function} isEqual the comparator to determine equality
332
- * @param {any} meta the meta set to pass through
333
- * @returns {boolean} are the sets equal
334
- */
335
-
336
- var areSetsEqual = function areSetsEqual(setA, setB, isEqual, meta) {
337
- if (setA.size !== setB.size) {
338
- return false;
339
- }
340
-
341
- var valuesA = toValues(setA);
342
- var valuesB = toValues(setB);
343
-
344
- for (var index = 0; index < valuesA.length; index++) {
345
- if (!hasValue(valuesB, valuesA[index], isEqual, meta) || !hasValue(valuesA, valuesB[index], isEqual, meta)) {
346
- return false;
347
- }
348
- }
349
-
350
- return true;
351
- };
352
-
353
- // constants
354
- var isArray = Array.isArray;
355
-
356
- var createComparator = function createComparator(createIsEqual) {
357
- // eslint-disable-next-line no-use-before-define
358
- var isEqual = typeof createIsEqual === 'function' ? createIsEqual(comparator) : comparator;
359
- /**
360
- * @function comparator
361
- *
362
- * @description
363
- * compare the value of the two objects and return true if they are equivalent in values
364
- *
365
- * @param {any} objectA the object to test against
366
- * @param {any} objectB the object to test
367
- * @param {any} [meta] an optional meta object that is passed through to all equality test calls
368
- * @returns {boolean} are objectA and objectB equivalent in value
369
- */
370
-
371
- function comparator(objectA, objectB, meta) {
372
- if (sameValueZeroEqual(objectA, objectB)) {
373
- return true;
374
- }
375
-
376
- var typeOfA = typeof objectA;
377
-
378
- if (typeOfA !== typeof objectB || typeOfA !== 'object' || !objectA || !objectB) {
379
- return false;
380
- }
381
-
382
- if (isPlainObject(objectA) && isPlainObject(objectB)) {
383
- return areObjectsEqual(objectA, objectB, isEqual, meta);
384
- }
385
-
386
- var arrayA = isArray(objectA);
387
- var arrayB = isArray(objectB);
388
-
389
- if (arrayA || arrayB) {
390
- return arrayA === arrayB && areArraysEqual(objectA, objectB, isEqual, meta);
391
- }
392
-
393
- var dateA = objectA instanceof Date;
394
- var dateB = objectB instanceof Date;
395
-
396
- if (dateA || dateB) {
397
- return dateA === dateB && sameValueZeroEqual(objectA.getTime(), objectB.getTime());
398
- }
399
-
400
- var regexpA = objectA instanceof RegExp;
401
- var regexpB = objectB instanceof RegExp;
402
-
403
- if (regexpA || regexpB) {
404
- return regexpA === regexpB && areRegExpsEqual(objectA, objectB);
405
- }
406
-
407
- if (isPromiseLike(objectA) || isPromiseLike(objectB)) {
408
- return objectA === objectB;
409
- }
410
-
411
- if (HAS_MAP_SUPPORT) {
412
- var mapA = objectA instanceof Map;
413
- var mapB = objectB instanceof Map;
414
-
415
- if (mapA || mapB) {
416
- return mapA === mapB && areMapsEqual(objectA, objectB, isEqual, meta);
417
- }
418
- }
419
-
420
- if (HAS_SET_SUPPORT) {
421
- var setA = objectA instanceof Set;
422
- var setB = objectB instanceof Set;
423
-
424
- if (setA || setB) {
425
- return setA === setB && areSetsEqual(objectA, objectB, isEqual, meta);
426
- }
427
- }
428
-
429
- return areObjectsEqual(objectA, objectB, isEqual, meta);
430
- }
431
-
432
- return comparator;
433
- };
434
-
435
- // comparator
436
- var circularDeepEqual = createComparator(createCircularEqual());
437
- var circularShallowEqual = createComparator(createCircularEqual(sameValueZeroEqual));
438
- var deepEqual = createComparator();
439
- var shallowEqual = createComparator(function () {
440
- return sameValueZeroEqual;
441
- });
442
- var index = {
443
- circularDeep: circularDeepEqual,
444
- circularShallow: circularShallowEqual,
445
- createCustom: createComparator,
446
- deep: deepEqual,
447
- sameValueZero: sameValueZeroEqual,
448
- shallow: shallowEqual
449
- };
5
+ var HAS_WEAKSET_SUPPORT = typeof WeakSet === 'function';
6
+ var keys = Object.keys;
7
+ /**
8
+ * @function addToCache
9
+ *
10
+ * add object to cache if an object
11
+ *
12
+ * @param value the value to potentially add to cache
13
+ * @param cache the cache to add to
14
+ */
15
+ function addToCache(value, cache) {
16
+ if (value && typeof value === 'object') {
17
+ cache.add(value);
18
+ }
19
+ }
20
+ /**
21
+ * @function hasPair
22
+ *
23
+ * @description
24
+ * does the `pairToMatch` exist in the list of `pairs` provided based on the
25
+ * `isEqual` check
26
+ *
27
+ * @param pairs the pairs to compare against
28
+ * @param pairToMatch the pair to match
29
+ * @param isEqual the equality comparator used
30
+ * @param meta the meta provided
31
+ * @returns does the pair exist in the pairs provided
32
+ */
33
+ function hasPair(pairs, pairToMatch, isEqual, meta) {
34
+ var length = pairs.length;
35
+ var pair;
36
+ for (var index = 0; index < length; index++) {
37
+ pair = pairs[index];
38
+ if (isEqual(pair[0], pairToMatch[0], meta) &&
39
+ isEqual(pair[1], pairToMatch[1], meta)) {
40
+ return true;
41
+ }
42
+ }
43
+ return false;
44
+ }
45
+ /**
46
+ * @function hasValue
47
+ *
48
+ * @description
49
+ * does the `valueToMatch` exist in the list of `values` provided based on the
50
+ * `isEqual` check
51
+ *
52
+ * @param values the values to compare against
53
+ * @param valueToMatch the value to match
54
+ * @param isEqual the equality comparator used
55
+ * @param meta the meta provided
56
+ * @returns does the value exist in the values provided
57
+ */
58
+ function hasValue(values, valueToMatch, isEqual, meta) {
59
+ var length = values.length;
60
+ for (var index = 0; index < length; index++) {
61
+ if (isEqual(values[index], valueToMatch, meta)) {
62
+ return true;
63
+ }
64
+ }
65
+ return false;
66
+ }
67
+ /**
68
+ * @function sameValueZeroEqual
69
+ *
70
+ * @description
71
+ * are the values passed strictly equal or both NaN
72
+ *
73
+ * @param a the value to compare against
74
+ * @param b the value to test
75
+ * @returns are the values equal by the SameValueZero principle
76
+ */
77
+ function sameValueZeroEqual(a, b) {
78
+ return a === b || (a !== a && b !== b);
79
+ }
80
+ /**
81
+ * @function isPlainObject
82
+ *
83
+ * @description
84
+ * is the value a plain object
85
+ *
86
+ * @param value the value to test
87
+ * @returns is the value a plain object
88
+ */
89
+ function isPlainObject(value) {
90
+ return value.constructor === Object || value.constructor == null;
91
+ }
92
+ /**
93
+ * @function isPromiseLike
94
+ *
95
+ * @description
96
+ * is the value promise-like (meaning it is thenable)
97
+ *
98
+ * @param value the value to test
99
+ * @returns is the value promise-like
100
+ */
101
+ function isPromiseLike(value) {
102
+ return !!value && typeof value.then === 'function';
103
+ }
104
+ /**
105
+ * @function isReactElement
106
+ *
107
+ * @description
108
+ * is the value passed a react element
109
+ *
110
+ * @param value the value to test
111
+ * @returns is the value a react element
112
+ */
113
+ function isReactElement(value) {
114
+ return !!(value && value.$$typeof);
115
+ }
116
+ /**
117
+ * @function getNewCacheFallback
118
+ *
119
+ * @description
120
+ * in cases where WeakSet is not supported, creates a new custom
121
+ * object that mimics the necessary API aspects for cache purposes
122
+ *
123
+ * @returns the new cache object
124
+ */
125
+ function getNewCacheFallback() {
126
+ return Object.create({
127
+ _values: [],
128
+ add: function (value) {
129
+ this._values.push(value);
130
+ },
131
+ has: function (value) {
132
+ return this._values.indexOf(value) !== -1;
133
+ },
134
+ });
135
+ }
136
+ /**
137
+ * @function getNewCache
138
+ *
139
+ * @description
140
+ * get a new cache object to prevent circular references
141
+ *
142
+ * @returns the new cache object
143
+ */
144
+ var getNewCache = (function (canUseWeakMap) {
145
+ if (canUseWeakMap) {
146
+ return function _getNewCache() {
147
+ return new WeakSet();
148
+ };
149
+ }
150
+ return getNewCacheFallback;
151
+ })(HAS_WEAKSET_SUPPORT);
152
+ /**
153
+ * @function createCircularEqualCreator
154
+ *
155
+ * @description
156
+ * create a custom isEqual handler specific to circular objects
157
+ *
158
+ * @param [isEqual] the isEqual comparator to use instead of isDeepEqual
159
+ * @returns the method to create the `isEqual` function
160
+ */
161
+ function createCircularEqualCreator(isEqual) {
162
+ return function createCircularEqual(comparator) {
163
+ var _comparator = isEqual || comparator;
164
+ return function circularEqual(a, b, cache) {
165
+ if (cache === void 0) { cache = getNewCache(); }
166
+ var hasA = cache.has(a);
167
+ var hasB = cache.has(b);
168
+ if (hasA || hasB) {
169
+ return hasA && hasB;
170
+ }
171
+ addToCache(a, cache);
172
+ addToCache(b, cache);
173
+ return _comparator(a, b, cache);
174
+ };
175
+ };
176
+ }
177
+ /**
178
+ * @function toPairs
179
+ *
180
+ * @description
181
+ * convert the map passed into pairs (meaning an array of [key, value] tuples)
182
+ *
183
+ * @param map the map to convert to [key, value] pairs (entries)
184
+ * @returns the [key, value] pairs
185
+ */
186
+ function toPairs(map) {
187
+ var pairs = new Array(map.size);
188
+ var index = 0;
189
+ map.forEach(function (value, key) {
190
+ pairs[index++] = [key, value];
191
+ });
192
+ return pairs;
193
+ }
194
+ /**
195
+ * @function toValues
196
+ *
197
+ * @description
198
+ * convert the set passed into values
199
+ *
200
+ * @param set the set to convert to values
201
+ * @returns the values
202
+ */
203
+ function toValues(set) {
204
+ var values = new Array(set.size);
205
+ var index = 0;
206
+ set.forEach(function (value) {
207
+ values[index++] = value;
208
+ });
209
+ return values;
210
+ }
211
+ /**
212
+ * @function areArraysEqual
213
+ *
214
+ * @description
215
+ * are the arrays equal in value
216
+ *
217
+ * @param a the array to test
218
+ * @param b the array to test against
219
+ * @param isEqual the comparator to determine equality
220
+ * @param meta the meta object to pass through
221
+ * @returns are the arrays equal
222
+ */
223
+ function areArraysEqual(a, b, isEqual, meta) {
224
+ var length = a.length;
225
+ if (b.length !== length) {
226
+ return false;
227
+ }
228
+ for (var index = 0; index < length; index++) {
229
+ if (!isEqual(a[index], b[index], meta)) {
230
+ return false;
231
+ }
232
+ }
233
+ return true;
234
+ }
235
+ /**
236
+ * @function areMapsEqual
237
+ *
238
+ * @description
239
+ * are the maps equal in value
240
+ *
241
+ * @param a the map to test
242
+ * @param b the map to test against
243
+ * @param isEqual the comparator to determine equality
244
+ * @param meta the meta map to pass through
245
+ * @returns are the maps equal
246
+ */
247
+ function areMapsEqual(a, b, isEqual, meta) {
248
+ if (a.size !== b.size) {
249
+ return false;
250
+ }
251
+ var pairsA = toPairs(a);
252
+ var pairsB = toPairs(b);
253
+ var length = pairsA.length;
254
+ for (var index = 0; index < length; index++) {
255
+ if (!hasPair(pairsB, pairsA[index], isEqual, meta) ||
256
+ !hasPair(pairsA, pairsB[index], isEqual, meta)) {
257
+ return false;
258
+ }
259
+ }
260
+ return true;
261
+ }
262
+ var OWNER = '_owner';
263
+ var hasOwnProperty = Function.prototype.bind.call(Function.prototype.call, Object.prototype.hasOwnProperty);
264
+ /**
265
+ * @function areObjectsEqual
266
+ *
267
+ * @description
268
+ * are the objects equal in value
269
+ *
270
+ * @param a the object to test
271
+ * @param b the object to test against
272
+ * @param isEqual the comparator to determine equality
273
+ * @param meta the meta object to pass through
274
+ * @returns are the objects equal
275
+ */
276
+ function areObjectsEqual(a, b, isEqual, meta) {
277
+ var keysA = keys(a);
278
+ var length = keysA.length;
279
+ if (keys(b).length !== length) {
280
+ return false;
281
+ }
282
+ var key;
283
+ for (var index = 0; index < length; index++) {
284
+ key = keysA[index];
285
+ if (!hasOwnProperty(b, key)) {
286
+ return false;
287
+ }
288
+ if (key === OWNER && isReactElement(a)) {
289
+ if (!isReactElement(b)) {
290
+ return false;
291
+ }
292
+ }
293
+ else if (!isEqual(a[key], b[key], meta)) {
294
+ return false;
295
+ }
296
+ }
297
+ return true;
298
+ }
299
+ /**
300
+ * @function areRegExpsEqual
301
+ *
302
+ * @description
303
+ * are the regExps equal in value
304
+ *
305
+ * @param a the regExp to test
306
+ * @param b the regExp to test agains
307
+ * @returns are the regExps equal
308
+ */
309
+ function areRegExpsEqual(a, b) {
310
+ return (a.source === b.source &&
311
+ a.global === b.global &&
312
+ a.ignoreCase === b.ignoreCase &&
313
+ a.multiline === b.multiline &&
314
+ a.unicode === b.unicode &&
315
+ a.sticky === b.sticky &&
316
+ a.lastIndex === b.lastIndex);
317
+ }
318
+ /**
319
+ * @function areSetsEqual
320
+ *
321
+ * @description
322
+ * are the sets equal in value
323
+ *
324
+ * @param a the set to test
325
+ * @param b the set to test against
326
+ * @param isEqual the comparator to determine equality
327
+ * @param meta the meta set to pass through
328
+ * @returns are the sets equal
329
+ */
330
+ function areSetsEqual(a, b, isEqual, meta) {
331
+ if (a.size !== b.size) {
332
+ return false;
333
+ }
334
+ var valuesA = toValues(a);
335
+ var valuesB = toValues(b);
336
+ var length = valuesA.length;
337
+ for (var index = 0; index < length; index++) {
338
+ if (!hasValue(valuesB, valuesA[index], isEqual, meta) ||
339
+ !hasValue(valuesA, valuesB[index], isEqual, meta)) {
340
+ return false;
341
+ }
342
+ }
343
+ return true;
344
+ }
345
+
346
+ var isArray = Array.isArray;
347
+ var HAS_MAP_SUPPORT = typeof Map === 'function';
348
+ var HAS_SET_SUPPORT = typeof Set === 'function';
349
+ var OBJECT_TYPEOF = 'object';
350
+ function createComparator(createIsEqual) {
351
+ var isEqual =
352
+ /* eslint-disable no-use-before-define */
353
+ typeof createIsEqual === 'function'
354
+ ? createIsEqual(comparator)
355
+ : comparator;
356
+ /* eslint-enable */
357
+ /**
358
+ * @function comparator
359
+ *
360
+ * @description
361
+ * compare the value of the two objects and return true if they are equivalent in values
362
+ *
363
+ * @param a the value to test against
364
+ * @param b the value to test
365
+ * @param [meta] an optional meta object that is passed through to all equality test calls
366
+ * @returns are a and b equivalent in value
367
+ */
368
+ function comparator(a, b, meta) {
369
+ if (sameValueZeroEqual(a, b)) {
370
+ return true;
371
+ }
372
+ if (a && b && typeof a === OBJECT_TYPEOF && typeof b === OBJECT_TYPEOF) {
373
+ if (isPlainObject(a) && isPlainObject(b)) {
374
+ return areObjectsEqual(a, b, isEqual, meta);
375
+ }
376
+ var arrayA = isArray(a);
377
+ var arrayB = isArray(b);
378
+ if (arrayA || arrayB) {
379
+ return arrayA === arrayB && areArraysEqual(a, b, isEqual, meta);
380
+ }
381
+ var aDate = a instanceof Date;
382
+ var bDate = b instanceof Date;
383
+ if (aDate || bDate) {
384
+ return aDate === bDate && sameValueZeroEqual(a.getTime(), b.getTime());
385
+ }
386
+ var aRegExp = a instanceof RegExp;
387
+ var bRegExp = b instanceof RegExp;
388
+ if (aRegExp || bRegExp) {
389
+ return aRegExp === bRegExp && areRegExpsEqual(a, b);
390
+ }
391
+ if (isPromiseLike(a) || isPromiseLike(b)) {
392
+ return a === b;
393
+ }
394
+ if (HAS_MAP_SUPPORT) {
395
+ var aMap = a instanceof Map;
396
+ var bMap = b instanceof Map;
397
+ if (aMap || bMap) {
398
+ return aMap === bMap && areMapsEqual(a, b, isEqual, meta);
399
+ }
400
+ }
401
+ if (HAS_SET_SUPPORT) {
402
+ var aSet = a instanceof Set;
403
+ var bSet = b instanceof Set;
404
+ if (aSet || bSet) {
405
+ return aSet === bSet && areSetsEqual(a, b, isEqual, meta);
406
+ }
407
+ }
408
+ return areObjectsEqual(a, b, isEqual, meta);
409
+ }
410
+ return false;
411
+ }
412
+ return comparator;
413
+ }
414
+
415
+ // comparator
416
+ var deepEqual = createComparator();
417
+ var shallowEqual = createComparator(function () { return sameValueZeroEqual; });
418
+ var circularDeepEqual = createComparator(createCircularEqualCreator());
419
+ var circularShallowEqual = createComparator(createCircularEqualCreator(sameValueZeroEqual));
450
420
 
451
421
  exports.circularDeepEqual = circularDeepEqual;
452
422
  exports.circularShallowEqual = circularShallowEqual;
453
423
  exports.createCustomEqual = createComparator;
454
424
  exports.deepEqual = deepEqual;
455
- exports.default = index;
456
425
  exports.sameValueZeroEqual = sameValueZeroEqual;
457
426
  exports.shallowEqual = shallowEqual;
458
427
  //# sourceMappingURL=fast-equals.cjs.js.map