is-shallow-equal.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(exports, definition) {
  11. /******/ for(var key in definition) {
  12. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14. /******/ }
  15. /******/ }
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  20. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /******/ /* webpack/runtime/make namespace object */
  25. /******/ !function() {
  26. /******/ // define __esModule on exports
  27. /******/ __webpack_require__.r = function(exports) {
  28. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  29. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30. /******/ }
  31. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  32. /******/ };
  33. /******/ }();
  34. /******/
  35. /************************************************************************/
  36. var __webpack_exports__ = {};
  37. // ESM COMPAT FLAG
  38. __webpack_require__.r(__webpack_exports__);
  39. // EXPORTS
  40. __webpack_require__.d(__webpack_exports__, {
  41. "default": function() { return /* binding */ isShallowEqual; },
  42. "isShallowEqualArrays": function() { return /* reexport */ isShallowEqualArrays; },
  43. "isShallowEqualObjects": function() { return /* reexport */ isShallowEqualObjects; }
  44. });
  45. ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/objects.js
  46. /**
  47. * Returns true if the two objects are shallow equal, or false otherwise.
  48. *
  49. * @param {import('.').ComparableObject} a First object to compare.
  50. * @param {import('.').ComparableObject} b Second object to compare.
  51. *
  52. * @return {boolean} Whether the two objects are shallow equal.
  53. */
  54. function isShallowEqualObjects(a, b) {
  55. if (a === b) {
  56. return true;
  57. }
  58. const aKeys = Object.keys(a);
  59. const bKeys = Object.keys(b);
  60. if (aKeys.length !== bKeys.length) {
  61. return false;
  62. }
  63. let i = 0;
  64. while (i < aKeys.length) {
  65. const key = aKeys[i];
  66. const aValue = a[key];
  67. if ( // In iterating only the keys of the first object after verifying
  68. // equal lengths, account for the case that an explicit `undefined`
  69. // value in the first is implicitly undefined in the second.
  70. //
  71. // Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
  72. aValue === undefined && !b.hasOwnProperty(key) || aValue !== b[key]) {
  73. return false;
  74. }
  75. i++;
  76. }
  77. return true;
  78. }
  79. ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/arrays.js
  80. /**
  81. * Returns true if the two arrays are shallow equal, or false otherwise.
  82. *
  83. * @param {any[]} a First array to compare.
  84. * @param {any[]} b Second array to compare.
  85. *
  86. * @return {boolean} Whether the two arrays are shallow equal.
  87. */
  88. function isShallowEqualArrays(a, b) {
  89. if (a === b) {
  90. return true;
  91. }
  92. if (a.length !== b.length) {
  93. return false;
  94. }
  95. for (let i = 0, len = a.length; i < len; i++) {
  96. if (a[i] !== b[i]) {
  97. return false;
  98. }
  99. }
  100. return true;
  101. }
  102. ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/index.js
  103. /**
  104. * Internal dependencies
  105. */
  106. /**
  107. * @typedef {Record<string, any>} ComparableObject
  108. */
  109. /**
  110. * Returns true if the two arrays or objects are shallow equal, or false
  111. * otherwise.
  112. *
  113. * @param {any[]|ComparableObject} a First object or array to compare.
  114. * @param {any[]|ComparableObject} b Second object or array to compare.
  115. *
  116. * @return {boolean} Whether the two values are shallow equal.
  117. */
  118. function isShallowEqual(a, b) {
  119. if (a && b) {
  120. if (a.constructor === Object && b.constructor === Object) {
  121. return isShallowEqualObjects(a, b);
  122. } else if (Array.isArray(a) && Array.isArray(b)) {
  123. return isShallowEqualArrays(a, b);
  124. }
  125. }
  126. return a === b;
  127. }
  128. (window.wp = window.wp || {}).isShallowEqual = __webpack_exports__;
  129. /******/ })()
  130. ;