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