Initial commit
[yaffs-website] / node_modules / node-sass / node_modules / lodash / _equalByTag.js
1 var Symbol = require('./_Symbol'),
2     Uint8Array = require('./_Uint8Array'),
3     eq = require('./eq'),
4     equalArrays = require('./_equalArrays'),
5     mapToArray = require('./_mapToArray'),
6     setToArray = require('./_setToArray');
7
8 /** Used to compose bitmasks for comparison styles. */
9 var UNORDERED_COMPARE_FLAG = 1,
10     PARTIAL_COMPARE_FLAG = 2;
11
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]';
22
23 var arrayBufferTag = '[object ArrayBuffer]',
24     dataViewTag = '[object DataView]';
25
26 /** Used to convert symbols to primitives and strings. */
27 var symbolProto = Symbol ? Symbol.prototype : undefined,
28     symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
29
30 /**
31  * A specialized version of `baseIsEqualDeep` for comparing objects of
32  * the same `toStringTag`.
33  *
34  * **Note:** This function only supports comparing values with tags of
35  * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
36  *
37  * @private
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 {Function} equalFunc The function to determine equivalents of values.
42  * @param {Function} customizer The function to customize comparisons.
43  * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
44  *  for more details.
45  * @param {Object} stack Tracks traversed `object` and `other` objects.
46  * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
47  */
48 function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
49   switch (tag) {
50     case dataViewTag:
51       if ((object.byteLength != other.byteLength) ||
52           (object.byteOffset != other.byteOffset)) {
53         return false;
54       }
55       object = object.buffer;
56       other = other.buffer;
57
58     case arrayBufferTag:
59       if ((object.byteLength != other.byteLength) ||
60           !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
61         return false;
62       }
63       return true;
64
65     case boolTag:
66     case dateTag:
67     case numberTag:
68       // Coerce booleans to `1` or `0` and dates to milliseconds.
69       // Invalid dates are coerced to `NaN`.
70       return eq(+object, +other);
71
72     case errorTag:
73       return object.name == other.name && object.message == other.message;
74
75     case regexpTag:
76     case stringTag:
77       // Coerce regexes to strings and treat strings, primitives and objects,
78       // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
79       // for more details.
80       return object == (other + '');
81
82     case mapTag:
83       var convert = mapToArray;
84
85     case setTag:
86       var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
87       convert || (convert = setToArray);
88
89       if (object.size != other.size && !isPartial) {
90         return false;
91       }
92       // Assume cyclic values are equal.
93       var stacked = stack.get(object);
94       if (stacked) {
95         return stacked == other;
96       }
97       bitmask |= UNORDERED_COMPARE_FLAG;
98
99       // Recursively compare objects (susceptible to call stack limits).
100       stack.set(object, other);
101       var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
102       stack['delete'](object);
103       return result;
104
105     case symbolTag:
106       if (symbolValueOf) {
107         return symbolValueOf.call(object) == symbolValueOf.call(other);
108       }
109   }
110   return false;
111 }
112
113 module.exports = equalByTag;