[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> is-shallow-equal.js (source)

   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  
  40  // EXPORTS
  41  __webpack_require__.d(__webpack_exports__, {
  42    "default": function() { return /* binding */ isShallowEqual; },
  43    "isShallowEqualArrays": function() { return /* reexport */ isShallowEqualArrays; },
  44    "isShallowEqualObjects": function() { return /* reexport */ isShallowEqualObjects; }
  45  });
  46  
  47  ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/objects.js
  48  /**
  49   * Returns true if the two objects are shallow equal, or false otherwise.
  50   *
  51   * @param {import('.').ComparableObject} a First object to compare.
  52   * @param {import('.').ComparableObject} b Second object to compare.
  53   *
  54   * @return {boolean} Whether the two objects are shallow equal.
  55   */
  56  function isShallowEqualObjects(a, b) {
  57    if (a === b) {
  58      return true;
  59    }
  60  
  61    const aKeys = Object.keys(a);
  62    const bKeys = Object.keys(b);
  63  
  64    if (aKeys.length !== bKeys.length) {
  65      return false;
  66    }
  67  
  68    let i = 0;
  69  
  70    while (i < aKeys.length) {
  71      const key = aKeys[i];
  72      const aValue = a[key];
  73  
  74      if ( // In iterating only the keys of the first object after verifying
  75      // equal lengths, account for the case that an explicit `undefined`
  76      // value in the first is implicitly undefined in the second.
  77      //
  78      // Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
  79      aValue === undefined && !b.hasOwnProperty(key) || aValue !== b[key]) {
  80        return false;
  81      }
  82  
  83      i++;
  84    }
  85  
  86    return true;
  87  }
  88  
  89  ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/arrays.js
  90  /**
  91   * Returns true if the two arrays are shallow equal, or false otherwise.
  92   *
  93   * @param {any[]} a First array to compare.
  94   * @param {any[]} b Second array to compare.
  95   *
  96   * @return {boolean} Whether the two arrays are shallow equal.
  97   */
  98  function isShallowEqualArrays(a, b) {
  99    if (a === b) {
 100      return true;
 101    }
 102  
 103    if (a.length !== b.length) {
 104      return false;
 105    }
 106  
 107    for (let i = 0, len = a.length; i < len; i++) {
 108      if (a[i] !== b[i]) {
 109        return false;
 110      }
 111    }
 112  
 113    return true;
 114  }
 115  
 116  ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/index.js
 117  /**
 118   * Internal dependencies
 119   */
 120  
 121  
 122  
 123  
 124  /**
 125   * @typedef {Record<string, any>} ComparableObject
 126   */
 127  
 128  /**
 129   * Returns true if the two arrays or objects are shallow equal, or false
 130   * otherwise.
 131   *
 132   * @param {any[]|ComparableObject} a First object or array to compare.
 133   * @param {any[]|ComparableObject} b Second object or array to compare.
 134   *
 135   * @return {boolean} Whether the two values are shallow equal.
 136   */
 137  
 138  function isShallowEqual(a, b) {
 139    if (a && b) {
 140      if (a.constructor === Object && b.constructor === Object) {
 141        return isShallowEqualObjects(a, b);
 142      } else if (Array.isArray(a) && Array.isArray(b)) {
 143        return isShallowEqualArrays(a, b);
 144      }
 145    }
 146  
 147    return a === b;
 148  }
 149  
 150  (window.wp = window.wp || {}).isShallowEqual = __webpack_exports__;
 151  /******/ })()
 152  ;


Generated: Thu Nov 14 01:00:07 2024 Cross-referenced by PHPXref 0.7.1