Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

_baseIsEqualDeep.js 2.9KB

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