Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / equalByTag.js
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]';
8
9 /**
10  * A specialized version of `baseIsEqualDeep` for comparing objects of
11  * the same `toStringTag`.
12  *
13  * **Note:** This function only supports comparing values with tags of
14  * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
15  *
16  * @private
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`.
21  */
22 function equalByTag(object, other, tag) {
23   switch (tag) {
24     case boolTag:
25     case dateTag:
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;
29
30     case errorTag:
31       return object.name == other.name && object.message == other.message;
32
33     case numberTag:
34       // Treat `NaN` vs. `NaN` as equal.
35       return (object != +object)
36         ? other != +other
37         : object == +other;
38
39     case regexpTag:
40     case stringTag:
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 + '');
44   }
45   return false;
46 }
47
48 module.exports = equalByTag;