ba00fa3b3f9c2a3aee457d17d0a39b613fb231d5
[yaffs-website] / node_modules / uncss / node_modules / lodash / internal / equalByTag.js
1 var Symbol = require('./Symbol'),
2     Uint8Array = require('./Uint8Array'),
3     mapToArray = require('./mapToArray'),
4     setToArray = require('./setToArray');
5
6 /** Used to compose bitmasks for comparison styles. */
7 var UNORDERED_COMPARE_FLAG = 1,
8     PARTIAL_COMPARE_FLAG = 2;
9
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]';
20
21 var arrayBufferTag = '[object ArrayBuffer]';
22
23 /** Used to convert symbols to primitives and strings. */
24 var symbolProto = Symbol ? Symbol.prototype : undefined,
25     symbolValueOf = Symbol ? symbolProto.valueOf : undefined;
26
27 /**
28  * A specialized version of `baseIsEqualDeep` for comparing objects of
29  * the same `toStringTag`.
30  *
31  * **Note:** This function only supports comparing values with tags of
32  * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
33  *
34  * @private
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`.
42  */
43 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
44   switch (tag) {
45     case arrayBufferTag:
46       if ((object.byteLength != other.byteLength) ||
47           !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
48         return false;
49       }
50       return true;
51
52     case boolTag:
53     case dateTag:
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;
57
58     case errorTag:
59       return object.name == other.name && object.message == other.message;
60
61     case numberTag:
62       // Treat `NaN` vs. `NaN` as equal.
63       return (object != +object) ? other != +other : object == +other;
64
65     case regexpTag:
66     case stringTag:
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 + '');
70
71     case mapTag:
72       var convert = mapToArray;
73
74     case setTag:
75       var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
76       convert || (convert = setToArray);
77
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);
81
82     case symbolTag:
83       return !!Symbol && (symbolValueOf.call(object) == symbolValueOf.call(other));
84   }
85   return false;
86 }
87
88 module.exports = equalByTag;