1 var Symbol = require('./_Symbol'),
2 Uint8Array = require('./_Uint8Array'),
3 mapToArray = require('./_mapToArray'),
4 setToArray = require('./_setToArray');
6 /** Used to compose bitmasks for comparison styles. */
7 var UNORDERED_COMPARE_FLAG = 1,
8 PARTIAL_COMPARE_FLAG = 2;
10 /** `Object#toString` result references. */
11 var boolTag = '[object Boolean]',
12 dateTag = '[object Date]',
13 errorTag = '[object Error]',
14 mapTag = '[object Map]',
15 numberTag = '[object Number]',
16 regexpTag = '[object RegExp]',
17 setTag = '[object Set]',
18 stringTag = '[object String]',
19 symbolTag = '[object Symbol]';
21 var arrayBufferTag = '[object ArrayBuffer]';
23 /** Used to convert symbols to primitives and strings. */
24 var symbolProto = Symbol ? Symbol.prototype : undefined,
25 symbolValueOf = Symbol ? symbolProto.valueOf : undefined;
28 * A specialized version of `baseIsEqualDeep` for comparing objects of
29 * the same `toStringTag`.
31 * **Note:** This function only supports comparing values with tags of
32 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
35 * @param {Object} object The object to compare.
36 * @param {Object} other The other object to compare.
37 * @param {string} tag The `toStringTag` of the objects to compare.
38 * @param {Function} equalFunc The function to determine equivalents of values.
39 * @param {Function} [customizer] The function to customize comparisons.
40 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
41 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
43 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
46 if ((object.byteLength != other.byteLength) ||
47 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
54 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
55 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
56 return +object == +other;
59 return object.name == other.name && object.message == other.message;
62 // Treat `NaN` vs. `NaN` as equal.
63 return (object != +object) ? other != +other : object == +other;
67 // Coerce regexes to strings and treat strings primitives and string
68 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
69 return object == (other + '');
72 var convert = mapToArray;
75 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
76 convert || (convert = setToArray);
78 // Recursively compare objects (susceptible to call stack limits).
79 return (isPartial || object.size == other.size) &&
80 equalFunc(convert(object), convert(other), customizer, bitmask | UNORDERED_COMPARE_FLAG);
83 return !!Symbol && (symbolValueOf.call(object) == symbolValueOf.call(other));
88 module.exports = equalByTag;