1 /** `Object#toString` result references. */
2 var boolTag = '[object Boolean]',
3 dateTag = '[object Date]',
4 errorTag = '[object Error]',
5 numberTag = '[object Number]',
6 regexpTag = '[object RegExp]',
7 stringTag = '[object String]';
10 * A specialized version of `baseIsEqualDeep` for comparing objects of
11 * the same `toStringTag`.
13 * **Note:** This function only supports comparing values with tags of
14 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
17 * @param {Object} object The object to compare.
18 * @param {Object} other The other object to compare.
19 * @param {string} tag The `toStringTag` of the objects to compare.
20 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
22 function equalByTag(object, other, tag) {
26 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
27 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
28 return +object == +other;
31 return object.name == other.name && object.message == other.message;
34 // Treat `NaN` vs. `NaN` as equal.
35 return (object != +object)
41 // Coerce regexes to strings and treat strings primitives and string
42 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
43 return object == (other + '');
48 module.exports = equalByTag;