UNPKG

3.01 kBJavaScriptView Raw
1import Stack from './_Stack.js';
2import equalArrays from './_equalArrays.js';
3import equalByTag from './_equalByTag.js';
4import equalObjects from './_equalObjects.js';
5import getTag from './_getTag.js';
6import isArray from './isArray.js';
7import isBuffer from './isBuffer.js';
8import isTypedArray from './isTypedArray.js';
9
10/** Used to compose bitmasks for value comparisons. */
11var COMPARE_PARTIAL_FLAG = 1;
12
13/** `Object#toString` result references. */
14var argsTag = '[object Arguments]',
15 arrayTag = '[object Array]',
16 objectTag = '[object Object]';
17
18/** Used for built-in method references. */
19var objectProto = Object.prototype;
20
21/** Used to check objects for own properties. */
22var hasOwnProperty = objectProto.hasOwnProperty;
23
24/**
25 * A specialized version of `baseIsEqual` for arrays and objects which performs
26 * deep comparisons and tracks traversed objects enabling objects with circular
27 * references to be compared.
28 *
29 * @private
30 * @param {Object} object The object to compare.
31 * @param {Object} other The other object to compare.
32 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
33 * @param {Function} customizer The function to customize comparisons.
34 * @param {Function} equalFunc The function to determine equivalents of values.
35 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
36 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
37 */
38function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
39 var objIsArr = isArray(object),
40 othIsArr = isArray(other),
41 objTag = objIsArr ? arrayTag : getTag(object),
42 othTag = othIsArr ? arrayTag : getTag(other);
43
44 objTag = objTag == argsTag ? objectTag : objTag;
45 othTag = othTag == argsTag ? objectTag : othTag;
46
47 var objIsObj = objTag == objectTag,
48 othIsObj = othTag == objectTag,
49 isSameTag = objTag == othTag;
50
51 if (isSameTag && isBuffer(object)) {
52 if (!isBuffer(other)) {
53 return false;
54 }
55 objIsArr = true;
56 objIsObj = false;
57 }
58 if (isSameTag && !objIsObj) {
59 stack || (stack = new Stack);
60 return (objIsArr || isTypedArray(object))
61 ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
62 : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
63 }
64 if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
65 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
66 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
67
68 if (objIsWrapped || othIsWrapped) {
69 var objUnwrapped = objIsWrapped ? object.value() : object,
70 othUnwrapped = othIsWrapped ? other.value() : other;
71
72 stack || (stack = new Stack);
73 return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
74 }
75 }
76 if (!isSameTag) {
77 return false;
78 }
79 stack || (stack = new Stack);
80 return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
81}
82
83export default baseIsEqualDeep;