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