1 var Symbol = require('./_Symbol'),
2 Uint8Array = require('./_Uint8Array'),
4 equalArrays = require('./_equalArrays'),
5 mapToArray = require('./_mapToArray'),
6 setToArray = require('./_setToArray');
8 /** Used to compose bitmasks for value comparisons. */
9 var COMPARE_PARTIAL_FLAG = 1,
10 COMPARE_UNORDERED_FLAG = 2;
12 /** `Object#toString` result references. */
13 var boolTag = '[object Boolean]',
14 dateTag = '[object Date]',
15 errorTag = '[object Error]',
16 mapTag = '[object Map]',
17 numberTag = '[object Number]',
18 regexpTag = '[object RegExp]',
19 setTag = '[object Set]',
20 stringTag = '[object String]',
21 symbolTag = '[object Symbol]';
23 var arrayBufferTag = '[object ArrayBuffer]',
24 dataViewTag = '[object DataView]';
26 /** Used to convert symbols to primitives and strings. */
27 var symbolProto = Symbol ? Symbol.prototype : undefined,
28 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
31 * A specialized version of `baseIsEqualDeep` for comparing objects of
32 * the same `toStringTag`.
34 * **Note:** This function only supports comparing values with tags of
35 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
38 * @param {Object} object The object to compare.
39 * @param {Object} other The other object to compare.
40 * @param {string} tag The `toStringTag` of the objects to compare.
41 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
42 * @param {Function} customizer The function to customize comparisons.
43 * @param {Function} equalFunc The function to determine equivalents of values.
44 * @param {Object} stack Tracks traversed `object` and `other` objects.
45 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
47 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
50 if ((object.byteLength != other.byteLength) ||
51 (object.byteOffset != other.byteOffset)) {
54 object = object.buffer;
58 if ((object.byteLength != other.byteLength) ||
59 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
67 // Coerce booleans to `1` or `0` and dates to milliseconds.
68 // Invalid dates are coerced to `NaN`.
69 return eq(+object, +other);
72 return object.name == other.name && object.message == other.message;
76 // Coerce regexes to strings and treat strings, primitives and objects,
77 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
79 return object == (other + '');
82 var convert = mapToArray;
85 var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
86 convert || (convert = setToArray);
88 if (object.size != other.size && !isPartial) {
91 // Assume cyclic values are equal.
92 var stacked = stack.get(object);
94 return stacked == other;
96 bitmask |= COMPARE_UNORDERED_FLAG;
98 // Recursively compare objects (susceptible to call stack limits).
99 stack.set(object, other);
100 var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
101 stack['delete'](object);
106 return symbolValueOf.call(object) == symbolValueOf.call(other);
112 module.exports = equalByTag;