fast-equals 3.0.3 → 4.0.1-beta.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.
@@ -1,136 +1,190 @@
1
- var HAS_WEAK_MAP_SUPPORT = typeof WeakMap === 'function';
2
- var keys = Object.keys;
3
1
  /**
4
- * are the values passed strictly equal or both NaN
5
- *
6
- * @param a the value to compare against
7
- * @param b the value to test
8
- * @returns are the values equal by the SameValueZero principle
2
+ * Default equality comparator pass-through, used as the standard `isEqual` creator for
3
+ * use inside the built comparator.
9
4
  */
10
- function sameValueZeroEqual(a, b) {
11
- return a === b || (a !== a && b !== b);
5
+ function createDefaultIsNestedEqual(comparator) {
6
+ return function isEqual(a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, meta) {
7
+ return comparator(a, b, meta);
8
+ };
12
9
  }
13
10
  /**
14
- * is the value a plain object
15
- *
16
- * @param value the value to test
17
- * @returns is the value a plain object
11
+ * Wrap the provided `areItemsEqual` method to manage the circular cache, allowing
12
+ * for circular references to be safely included in the comparison without creating
13
+ * stack overflows.
18
14
  */
19
- function isPlainObject(value) {
20
- return value.constructor === Object || value.constructor == null;
15
+ function createIsCircular(areItemsEqual) {
16
+ return function isCircular(a, b, isEqual, cache) {
17
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object') {
18
+ return areItemsEqual(a, b, isEqual, cache);
19
+ }
20
+ var cachedA = cache.get(a);
21
+ var cachedB = cache.get(b);
22
+ if (cachedA && cachedB) {
23
+ return cachedA === b && cachedB === a;
24
+ }
25
+ cache.set(a, b);
26
+ cache.set(b, a);
27
+ var result = areItemsEqual(a, b, isEqual, cache);
28
+ cache.delete(a);
29
+ cache.delete(b);
30
+ return result;
31
+ };
21
32
  }
22
33
  /**
23
- * is the value promise-like (meaning it is thenable)
34
+ * Targeted shallow merge of two objects.
24
35
  *
25
- * @param value the value to test
26
- * @returns is the value promise-like
36
+ * @NOTE
37
+ * This exists as a tinier compiled version of the `__assign` helper that
38
+ * `tsc` injects in case of `Object.assign` not being present.
27
39
  */
28
- function isPromiseLike(value) {
29
- return !!value && typeof value.then === 'function';
40
+ function merge(a, b) {
41
+ var merged = {};
42
+ for (var key in a) {
43
+ merged[key] = a[key];
44
+ }
45
+ for (var key in b) {
46
+ merged[key] = b[key];
47
+ }
48
+ return merged;
30
49
  }
31
50
  /**
32
- * is the value passed a react element
51
+ * Whether the value is a plain object.
33
52
  *
34
- * @param value the value to test
35
- * @returns is the value a react element
53
+ * @NOTE
54
+ * This is a same-realm compariosn only.
36
55
  */
37
- function isReactElement(value) {
38
- return !!(value && value.$$typeof);
56
+ function isPlainObject(value) {
57
+ return value.constructor === Object || value.constructor == null;
39
58
  }
40
59
  /**
41
- * in cases where WeakMap is not supported, creates a new custom
42
- * object that mimics the necessary API aspects for cache purposes
43
- *
44
- * @returns the new cache object
60
+ * When the value is `Promise`-like, aka "then-able".
45
61
  */
46
- function getNewCacheFallback() {
47
- var entries = [];
48
- return {
49
- delete: function (key) {
50
- for (var index = 0; index < entries.length; ++index) {
51
- if (entries[index][0] === key) {
52
- entries.splice(index, 1);
53
- return;
54
- }
55
- }
56
- },
57
- get: function (key) {
58
- for (var index = 0; index < entries.length; ++index) {
59
- if (entries[index][0] === key) {
60
- return entries[index][1];
61
- }
62
- }
63
- },
64
- set: function (key, value) {
65
- for (var index = 0; index < entries.length; ++index) {
66
- if (entries[index][0] === key) {
67
- entries[index][1] = value;
68
- return;
69
- }
70
- }
71
- entries.push([key, value]);
72
- }
73
- };
62
+ function isPromiseLike(value) {
63
+ return typeof value.then === 'function';
74
64
  }
75
65
  /**
76
- * get a new cache object to prevent circular references
77
- *
78
- * @returns the new cache object
66
+ * Whether the values passed are strictly equal or both NaN.
79
67
  */
80
- var getNewCache = (function (canUseWeakMap) {
81
- if (canUseWeakMap) {
82
- return function _getNewCache() {
83
- return new WeakMap();
84
- };
68
+ function sameValueZeroEqual(a, b) {
69
+ return a === b || (a !== a && b !== b);
70
+ }
71
+
72
+ var ARGUMENTS_TAG = '[object Arguments]';
73
+ var BOOLEAN_TAG = '[object Boolean]';
74
+ var DATE_TAG = '[object Date]';
75
+ var REG_EXP_TAG = '[object RegExp]';
76
+ var MAP_TAG = '[object Map]';
77
+ var NUMBER_TAG = '[object Number]';
78
+ var OBJECT_TAG = '[object Object]';
79
+ var SET_TAG = '[object Set]';
80
+ var STRING_TAG = '[object String]';
81
+ var toString = Object.prototype.toString;
82
+ function createComparator(_a) {
83
+ var areArraysEqual = _a.areArraysEqual, areDatesEqual = _a.areDatesEqual, areMapsEqual = _a.areMapsEqual, areObjectsEqual = _a.areObjectsEqual, areRegExpsEqual = _a.areRegExpsEqual, areSetsEqual = _a.areSetsEqual, createIsNestedEqual = _a.createIsNestedEqual;
84
+ var isEqual = createIsNestedEqual(comparator);
85
+ /**
86
+ * compare the value of the two objects and return true if they are equivalent in values
87
+ */
88
+ function comparator(a, b, meta) {
89
+ // If the items are strictly equal, no need to do a value comparison.
90
+ if (a === b) {
91
+ return true;
92
+ }
93
+ // If the items are not non-nullish objects, then the only possibility
94
+ // of them being equal but not strictly is if they are both `NaN`. Since
95
+ // `NaN` is uniquely not equal to itself, we can use self-comparison of
96
+ // both objects, which is faster than `isNaN()`.
97
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object') {
98
+ return a !== a && b !== b;
99
+ }
100
+ // Checks are listed in order of commonality of use-case:
101
+ // 1. Common complex object types (plain object, array)
102
+ // 2. Common data values (date, regexp)
103
+ // 3. Less-common complex object types (map, set)
104
+ // 4. Less-common data values (promise, primitive wrappers)
105
+ // Inherently this is both subjective and assumptive, however
106
+ // when reviewing comparable libraries in the wild this order
107
+ // appears to be generally consistent.
108
+ // `isPlainObject` only checks against the object's own realm. Cross-realm
109
+ // comparisons are rare, and will be handled in the ultimate fallback, so
110
+ // we can avoid the `toString.call()` cost unless necessary.
111
+ if (isPlainObject(a) && isPlainObject(b)) {
112
+ return areObjectsEqual(a, b, isEqual, meta);
113
+ }
114
+ // `isArray()` works on subclasses and is cross-realm, so we can again avoid
115
+ // the `toString.call()` cost unless necessary by just checking if either
116
+ // and then both are arrays.
117
+ var aArray = Array.isArray(a);
118
+ var bArray = Array.isArray(b);
119
+ if (aArray || bArray) {
120
+ return aArray === bArray && areArraysEqual(a, b, isEqual, meta);
121
+ }
122
+ // Since this is a custom object, use the classic `toString.call()` to get its
123
+ // type. This is reasonably performant in modern environments like v8 and
124
+ // SpiderMonkey, and allows for cross-realm comparison when other checks like
125
+ // `instanceof` do not.
126
+ var aTag = toString.call(a);
127
+ if (aTag !== toString.call(b)) {
128
+ return false;
129
+ }
130
+ if (aTag === DATE_TAG) {
131
+ // `getTime()` showed better results compared to alternatives like `valueOf()`
132
+ // or the unary `+` operator.
133
+ return areDatesEqual(a, b, isEqual, meta);
134
+ }
135
+ if (aTag === REG_EXP_TAG) {
136
+ return areRegExpsEqual(a, b, isEqual, meta);
137
+ }
138
+ if (aTag === MAP_TAG) {
139
+ return areMapsEqual(a, b, isEqual, meta);
140
+ }
141
+ if (aTag === SET_TAG) {
142
+ return areSetsEqual(a, b, isEqual, meta);
143
+ }
144
+ // If a simple object tag, then we can prioritize a simple object comparison because
145
+ // it is likely a custom class. If an arguments tag, it should be treated as a standard
146
+ // object.
147
+ if (aTag === OBJECT_TAG || aTag === ARGUMENTS_TAG) {
148
+ // The exception for value comparison is `Promise`-like contracts. These should be
149
+ // treated the same as standard `Promise` objects, which means strict equality.
150
+ return isPromiseLike(a) || isPromiseLike(b)
151
+ ? a === b
152
+ : areObjectsEqual(a, b, isEqual, meta);
153
+ }
154
+ // As the penultimate fallback, check if the values passed are primitive wrappers. This
155
+ // is very rare in modern JS, which is why it is deprioritized compared to all other object
156
+ // types.
157
+ if (aTag === BOOLEAN_TAG || aTag === NUMBER_TAG || aTag === STRING_TAG) {
158
+ return sameValueZeroEqual(a.valueOf(), b.valueOf());
159
+ }
160
+ // If not matching any tags that require a specific type of comparison, then use strict
161
+ // equality. This is for a few reasons:
162
+ // - For types that cannot be introspected (`Promise`, `WeakMap`, etc.), this is the only
163
+ // comparison that can be made.
164
+ // - For types that can be introspected, but rarely have requirements to be compared
165
+ // (`ArrayBuffer`, `DataView`, etc.), the cost is avoided to prioritize the common
166
+ // use-cases.
167
+ // - For types that can be introspected, but do not have an objective definition of what
168
+ // equality is (`Error`, etc.), the subjective decision was to be conservative.
169
+ // In all cases, these decisions should be reevaluated based on changes to the language and
170
+ // common development practices.
171
+ return a === b;
85
172
  }
86
- return getNewCacheFallback;
87
- })(HAS_WEAK_MAP_SUPPORT);
88
- /**
89
- * create a custom isEqual handler specific to circular objects
90
- *
91
- * @param [isEqual] the isEqual comparator to use instead of isDeepEqual
92
- * @returns the method to create the `isEqual` function
93
- */
94
- function createCircularEqualCreator(isEqual) {
95
- return function createCircularEqual(comparator) {
96
- var _comparator = isEqual || comparator;
97
- return function circularEqual(a, b, indexOrKeyA, indexOrKeyB, parentA, parentB, cache) {
98
- if (cache === void 0) { cache = getNewCache(); }
99
- var isCacheableA = !!a && typeof a === 'object';
100
- var isCacheableB = !!b && typeof b === 'object';
101
- if (isCacheableA !== isCacheableB) {
102
- return false;
103
- }
104
- if (!isCacheableA && !isCacheableB) {
105
- return _comparator(a, b, cache);
106
- }
107
- var cachedA = cache.get(a);
108
- if (cachedA && cache.get(b)) {
109
- return cachedA === b;
110
- }
111
- cache.set(a, b);
112
- cache.set(b, a);
113
- var result = _comparator(a, b, cache);
114
- cache.delete(a);
115
- cache.delete(b);
116
- return result;
117
- };
118
- };
119
- }
173
+ return comparator;
174
+ }
175
+
120
176
  /**
121
- * are the arrays equal in value
122
- *
123
- * @param a the array to test
124
- * @param b the array to test against
125
- * @param isEqual the comparator to determine equality
126
- * @param meta the meta object to pass through
127
- * @returns are the arrays equal
177
+ * Whether the arrays are equal in value.
128
178
  */
129
179
  function areArraysEqual(a, b, isEqual, meta) {
130
180
  var index = a.length;
131
181
  if (b.length !== index) {
132
182
  return false;
133
183
  }
184
+ // Decrementing `while` showed faster results than either incrementing or
185
+ // decrementing `for` loop and than an incrementing `while` loop. Declarative
186
+ // methods like `some` / `every` were not used to avoid incurring the garbage
187
+ // cost of anonymous callbacks.
134
188
  while (index-- > 0) {
135
189
  if (!isEqual(a[index], b[index], index, index, a, b, meta)) {
136
190
  return false;
@@ -139,206 +193,230 @@ function areArraysEqual(a, b, isEqual, meta) {
139
193
  return true;
140
194
  }
141
195
  /**
142
- * are the maps equal in value
196
+ * Whether the arrays are equal in value, including circular references.
197
+ */
198
+ var areArraysEqualCircular = createIsCircular(areArraysEqual);
199
+
200
+ /**
201
+ * Whether the dates passed are equal in value.
143
202
  *
144
- * @param a the map to test
145
- * @param b the map to test against
146
- * @param isEqual the comparator to determine equality
147
- * @param meta the meta map to pass through
148
- * @returns are the maps equal
203
+ * @NOTE
204
+ * This is a standalone function instead of done inline in the comparator
205
+ * to allow for overrides.
206
+ */
207
+ function areDatesEqual(a, b) {
208
+ return sameValueZeroEqual(a.valueOf(), b.valueOf());
209
+ }
210
+
211
+ /**
212
+ * Whether the `Map`s are equal in value.
149
213
  */
150
214
  function areMapsEqual(a, b, isEqual, meta) {
151
215
  var isValueEqual = a.size === b.size;
152
- if (isValueEqual && a.size) {
153
- var matchedIndices_1 = {};
154
- var indexA_1 = 0;
155
- a.forEach(function (aValue, aKey) {
156
- if (isValueEqual) {
157
- var hasMatch_1 = false;
158
- var matchIndexB_1 = 0;
159
- b.forEach(function (bValue, bKey) {
160
- if (!hasMatch_1 && !matchedIndices_1[matchIndexB_1]) {
161
- hasMatch_1 =
162
- isEqual(aKey, bKey, indexA_1, matchIndexB_1, a, b, meta) &&
163
- isEqual(aValue, bValue, aKey, bKey, a, b, meta);
164
- if (hasMatch_1) {
165
- matchedIndices_1[matchIndexB_1] = true;
166
- }
167
- }
168
- matchIndexB_1++;
169
- });
170
- indexA_1++;
171
- isValueEqual = hasMatch_1;
216
+ if (!isValueEqual) {
217
+ return false;
218
+ }
219
+ if (!a.size) {
220
+ return true;
221
+ }
222
+ // The use of `forEach()` is to avoid the transpilation cost of `for...of` comparisons, and
223
+ // the inability to control the performance of the resulting code. It also avoids excessive
224
+ // iteration compared to doing comparisons of `keys()` and `values()`. As a result, though,
225
+ // we cannot short-circuit the iterations; bookkeeping must be done to short-circuit the
226
+ // equality checks themselves.
227
+ var matchedIndices = {};
228
+ var indexA = 0;
229
+ a.forEach(function (aValue, aKey) {
230
+ if (!isValueEqual) {
231
+ return;
232
+ }
233
+ var hasMatch = false;
234
+ var matchIndexB = 0;
235
+ b.forEach(function (bValue, bKey) {
236
+ if (!hasMatch &&
237
+ !matchedIndices[matchIndexB] &&
238
+ (hasMatch =
239
+ isEqual(aKey, bKey, indexA, matchIndexB, a, b, meta) &&
240
+ isEqual(aValue, bValue, aKey, bKey, a, b, meta))) {
241
+ matchedIndices[matchIndexB] = true;
172
242
  }
243
+ matchIndexB++;
173
244
  });
174
- }
245
+ indexA++;
246
+ isValueEqual = hasMatch;
247
+ });
175
248
  return isValueEqual;
176
249
  }
250
+ /**
251
+ * Whether the `Map`s are equal in value, including circular references.
252
+ */
253
+ var areMapsEqualCircular = createIsCircular(areMapsEqual);
254
+
177
255
  var OWNER = '_owner';
178
- var hasOwnProperty = Function.prototype.bind.call(Function.prototype.call, Object.prototype.hasOwnProperty);
256
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
179
257
  /**
180
- * are the objects equal in value
181
- *
182
- * @param a the object to test
183
- * @param b the object to test against
184
- * @param isEqual the comparator to determine equality
185
- * @param meta the meta object to pass through
186
- * @returns are the objects equal
258
+ * Whether the objects are equal in value.
187
259
  */
188
260
  function areObjectsEqual(a, b, isEqual, meta) {
189
- var keysA = keys(a);
261
+ var keysA = Object.keys(a);
190
262
  var index = keysA.length;
191
- if (keys(b).length !== index) {
263
+ if (Object.keys(b).length !== index) {
192
264
  return false;
193
265
  }
194
- if (index) {
195
- var key = void 0;
196
- while (index-- > 0) {
197
- key = keysA[index];
198
- if (key === OWNER) {
199
- var reactElementA = isReactElement(a);
200
- var reactElementB = isReactElement(b);
201
- if ((reactElementA || reactElementB) &&
202
- reactElementA !== reactElementB) {
203
- return false;
204
- }
205
- }
206
- if (!hasOwnProperty(b, key) ||
207
- !isEqual(a[key], b[key], key, key, a, b, meta)) {
266
+ var key;
267
+ // Decrementing `while` showed faster results than either incrementing or
268
+ // decrementing `for` loop and than an incrementing `while` loop. Declarative
269
+ // methods like `some` / `every` were not used to avoid incurring the garbage
270
+ // cost of anonymous callbacks.
271
+ while (index-- > 0) {
272
+ key = keysA[index];
273
+ if (key === OWNER) {
274
+ var reactElementA = !!a.$$typeof;
275
+ var reactElementB = !!b.$$typeof;
276
+ if ((reactElementA || reactElementB) && reactElementA !== reactElementB) {
208
277
  return false;
209
278
  }
210
279
  }
280
+ if (!hasOwnProperty.call(b, key) ||
281
+ !isEqual(a[key], b[key], key, key, a, b, meta)) {
282
+ return false;
283
+ }
211
284
  }
212
285
  return true;
213
286
  }
214
287
  /**
215
- * are the regExps equal in value
216
- *
217
- * @param a the regExp to test
218
- * @param b the regExp to test agains
219
- * @returns are the regExps equal
288
+ * Whether the objects are equal in value, including circular references.
220
289
  */
221
- var areRegExpsEqual = (function () {
222
- if (/foo/g.flags === 'g') {
223
- return function areRegExpsEqual(a, b) {
224
- return a.source === b.source && a.flags === b.flags;
225
- };
226
- }
227
- return function areRegExpsEqualFallback(a, b) {
228
- return (a.source === b.source &&
229
- a.global === b.global &&
230
- a.ignoreCase === b.ignoreCase &&
231
- a.multiline === b.multiline &&
232
- a.unicode === b.unicode &&
233
- a.sticky === b.sticky &&
234
- a.lastIndex === b.lastIndex);
235
- };
236
- })();
290
+ var areObjectsEqualCircular = createIsCircular(areObjectsEqual);
291
+
237
292
  /**
238
- * are the sets equal in value
293
+ * Whether the regexps passed are equal in value.
239
294
  *
240
- * @param a the set to test
241
- * @param b the set to test against
242
- * @param isEqual the comparator to determine equality
243
- * @param meta the meta set to pass through
244
- * @returns are the sets equal
295
+ * @NOTE
296
+ * This is a standalone function instead of done inline in the comparator
297
+ * to allow for overrides. An example of this would be supporting a
298
+ * pre-ES2015 environment where the `flags` property is not available.
299
+ */
300
+ function areRegExpsEqual(a, b) {
301
+ return a.source === b.source && a.flags === b.flags;
302
+ }
303
+
304
+ /**
305
+ * Whether the `Set`s are equal in value.
245
306
  */
246
307
  function areSetsEqual(a, b, isEqual, meta) {
247
308
  var isValueEqual = a.size === b.size;
248
- if (isValueEqual && a.size) {
249
- var matchedIndices_2 = {};
250
- a.forEach(function (aValue, aKey) {
251
- if (isValueEqual) {
252
- var hasMatch_2 = false;
253
- var matchIndex_1 = 0;
254
- b.forEach(function (bValue, bKey) {
255
- if (!hasMatch_2 && !matchedIndices_2[matchIndex_1]) {
256
- hasMatch_2 = isEqual(aValue, bValue, aKey, bKey, a, b, meta);
257
- if (hasMatch_2) {
258
- matchedIndices_2[matchIndex_1] = true;
259
- }
260
- }
261
- matchIndex_1++;
262
- });
263
- isValueEqual = hasMatch_2;
309
+ if (!isValueEqual) {
310
+ return false;
311
+ }
312
+ if (!a.size) {
313
+ return true;
314
+ }
315
+ // The use of `forEach()` is to avoid the transpilation cost of `for...of` comparisons, and
316
+ // the inability to control the performance of the resulting code. It also avoids excessive
317
+ // iteration compared to doing comparisons of `keys()` and `values()`. As a result, though,
318
+ // we cannot short-circuit the iterations; bookkeeping must be done to short-circuit the
319
+ // equality checks themselves.
320
+ var matchedIndices = {};
321
+ a.forEach(function (aValue, aKey) {
322
+ if (!isValueEqual) {
323
+ return;
324
+ }
325
+ var hasMatch = false;
326
+ var matchIndex = 0;
327
+ b.forEach(function (bValue, bKey) {
328
+ if (!hasMatch &&
329
+ !matchedIndices[matchIndex] &&
330
+ (hasMatch = isEqual(aValue, bValue, aKey, bKey, a, b, meta))) {
331
+ matchedIndices[matchIndex] = true;
264
332
  }
333
+ matchIndex++;
265
334
  });
266
- }
335
+ isValueEqual = hasMatch;
336
+ });
267
337
  return isValueEqual;
268
- }
338
+ }
339
+ /**
340
+ * Whether the `Set`s are equal in value, including circular references.
341
+ */
342
+ var areSetsEqualCircular = createIsCircular(areSetsEqual);
269
343
 
270
- var HAS_MAP_SUPPORT = typeof Map === 'function';
271
- var HAS_SET_SUPPORT = typeof Set === 'function';
272
- var valueOf = Object.prototype.valueOf;
273
- function createComparator(createIsEqual) {
274
- var isEqual =
275
- /* eslint-disable no-use-before-define */
276
- typeof createIsEqual === 'function'
277
- ? createIsEqual(comparator)
278
- : function (a, b, indexOrKeyA, indexOrKeyB, parentA, parentB, meta) { return comparator(a, b, meta); };
279
- /* eslint-enable */
280
- /**
281
- * compare the value of the two objects and return true if they are equivalent in values
282
- *
283
- * @param a the value to test against
284
- * @param b the value to test
285
- * @param [meta] an optional meta object that is passed through to all equality test calls
286
- * @returns are a and b equivalent in value
287
- */
288
- function comparator(a, b, meta) {
289
- if (a === b) {
290
- return true;
291
- }
292
- if (a && b && typeof a === 'object' && typeof b === 'object') {
293
- if (isPlainObject(a) && isPlainObject(b)) {
294
- return areObjectsEqual(a, b, isEqual, meta);
295
- }
296
- var aShape = Array.isArray(a);
297
- var bShape = Array.isArray(b);
298
- if (aShape || bShape) {
299
- return aShape === bShape && areArraysEqual(a, b, isEqual, meta);
300
- }
301
- aShape = a instanceof Date;
302
- bShape = b instanceof Date;
303
- if (aShape || bShape) {
304
- return (aShape === bShape && sameValueZeroEqual(a.getTime(), b.getTime()));
305
- }
306
- aShape = a instanceof RegExp;
307
- bShape = b instanceof RegExp;
308
- if (aShape || bShape) {
309
- return aShape === bShape && areRegExpsEqual(a, b);
310
- }
311
- if (isPromiseLike(a) || isPromiseLike(b)) {
312
- return a === b;
313
- }
314
- if (HAS_MAP_SUPPORT) {
315
- aShape = a instanceof Map;
316
- bShape = b instanceof Map;
317
- if (aShape || bShape) {
318
- return aShape === bShape && areMapsEqual(a, b, isEqual, meta);
319
- }
320
- }
321
- if (HAS_SET_SUPPORT) {
322
- aShape = a instanceof Set;
323
- bShape = b instanceof Set;
324
- if (aShape || bShape) {
325
- return aShape === bShape && areSetsEqual(a, b, isEqual, meta);
326
- }
327
- }
328
- if (a.valueOf !== valueOf || b.valueOf !== valueOf) {
329
- return sameValueZeroEqual(a.valueOf(), b.valueOf());
330
- }
331
- return areObjectsEqual(a, b, isEqual, meta);
332
- }
333
- return a !== a && b !== b;
334
- }
335
- return comparator;
344
+ var DEFAULT_CONFIG = Object.freeze({
345
+ areArraysEqual: areArraysEqual,
346
+ areDatesEqual: areDatesEqual,
347
+ areMapsEqual: areMapsEqual,
348
+ areObjectsEqual: areObjectsEqual,
349
+ areRegExpsEqual: areRegExpsEqual,
350
+ areSetsEqual: areSetsEqual,
351
+ createIsNestedEqual: createDefaultIsNestedEqual,
352
+ });
353
+ var DEFAULT_CIRCULAR_CONFIG = Object.freeze({
354
+ areArraysEqual: areArraysEqualCircular,
355
+ areDatesEqual: areDatesEqual,
356
+ areMapsEqual: areMapsEqualCircular,
357
+ areObjectsEqual: areObjectsEqualCircular,
358
+ areRegExpsEqual: areRegExpsEqual,
359
+ areSetsEqual: areSetsEqualCircular,
360
+ createIsNestedEqual: createDefaultIsNestedEqual,
361
+ });
362
+ var isDeepEqual = createComparator(DEFAULT_CONFIG);
363
+ /**
364
+ * Whether the items passed are deeply-equal in value.
365
+ */
366
+ function deepEqual(a, b) {
367
+ return isDeepEqual(a, b, undefined);
368
+ }
369
+ var isShallowEqual = createComparator(merge(DEFAULT_CONFIG, { createIsNestedEqual: function () { return sameValueZeroEqual; } }));
370
+ /**
371
+ * Whether the items passed are shallowly-equal in value.
372
+ */
373
+ function shallowEqual(a, b) {
374
+ return isShallowEqual(a, b, undefined);
375
+ }
376
+ var isCircularDeepEqual = createComparator(DEFAULT_CIRCULAR_CONFIG);
377
+ /**
378
+ * Whether the items passed are deeply-equal in value, including circular references.
379
+ */
380
+ function circularDeepEqual(a, b) {
381
+ return isCircularDeepEqual(a, b, new WeakMap());
382
+ }
383
+ var isCircularShallowEqual = createComparator(merge(DEFAULT_CIRCULAR_CONFIG, {
384
+ createIsNestedEqual: function () { return sameValueZeroEqual; },
385
+ }));
386
+ /**
387
+ * Whether the items passed are shallowly-equal in value, including circular references.
388
+ */
389
+ function circularShallowEqual(a, b) {
390
+ return isCircularShallowEqual(a, b, new WeakMap());
391
+ }
392
+ /**
393
+ * Create a custom equality comparison method.
394
+ *
395
+ * This can be done to create very targeted comparisons in extreme hot-path scenarios
396
+ * where the standard methods are not performant enough, but can also be used to provide
397
+ * support for legacy environments that do not support expected features like
398
+ * `RegExp.prototype.flags` out of the box.
399
+ */
400
+ function createCustomEqual(getComparatorOptions) {
401
+ return createComparator(merge(DEFAULT_CONFIG, getComparatorOptions(DEFAULT_CONFIG)));
402
+ }
403
+ /**
404
+ * Create a custom equality comparison method that handles circular references. This is very
405
+ * similar to `createCustomEqual`, with the only difference being that `meta` expects to be
406
+ * populated with a `WeakMap`-like contract.
407
+ *
408
+ * This can be done to create very targeted comparisons in extreme hot-path scenarios
409
+ * where the standard methods are not performant enough, but can also be used to provide
410
+ * support for legacy environments that do not support expected features like
411
+ * `WeakMap` out of the box.
412
+ */
413
+ function createCustomCircularEqual(getComparatorOptions) {
414
+ var comparator = createComparator(merge(DEFAULT_CIRCULAR_CONFIG, getComparatorOptions(DEFAULT_CIRCULAR_CONFIG)));
415
+ return (function (a, b, meta) {
416
+ if (meta === void 0) { meta = new WeakMap(); }
417
+ return comparator(a, b, meta);
418
+ });
336
419
  }
337
420
 
338
- var deepEqual = createComparator();
339
- var shallowEqual = createComparator(function () { return sameValueZeroEqual; });
340
- var circularDeepEqual = createComparator(createCircularEqualCreator());
341
- var circularShallowEqual = createComparator(createCircularEqualCreator(sameValueZeroEqual));
342
-
343
- export { circularDeepEqual, circularShallowEqual, createComparator as createCustomEqual, deepEqual, sameValueZeroEqual, shallowEqual };
421
+ export { circularDeepEqual, circularShallowEqual, createCustomCircularEqual, createCustomEqual, deepEqual, sameValueZeroEqual, shallowEqual };
344
422
  //# sourceMappingURL=fast-equals.mjs.map