[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  /******/ (() => { // webpackBootstrap
   2  /******/     "use strict";
   3  /******/     // The require scope
   4  /******/     var __webpack_require__ = {};
   5  /******/     
   6  /************************************************************************/
   7  /******/     /* webpack/runtime/define property getters */
   8  /******/     (() => {
   9  /******/         // define getter functions for harmony exports
  10  /******/         __webpack_require__.d = (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  /******/     (() => {
  21  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  22  /******/     })();
  23  /******/     
  24  /******/     /* webpack/runtime/make namespace object */
  25  /******/     (() => {
  26  /******/         // define __esModule on exports
  27  /******/         __webpack_require__.r = (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": () => (/* binding */ isShallowEqual),
  43    isShallowEqualArrays: () => (/* reexport */ isShallowEqualArrays),
  44    isShallowEqualObjects: () => (/* reexport */ isShallowEqualObjects)
  45  });
  46  
  47  ;// ./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    const aKeys = Object.keys(a);
  61    const bKeys = Object.keys(b);
  62    if (aKeys.length !== bKeys.length) {
  63      return false;
  64    }
  65    let i = 0;
  66    while (i < aKeys.length) {
  67      const key = aKeys[i];
  68      const aValue = a[key];
  69      if (
  70      // In iterating only the keys of the first object after verifying
  71      // equal lengths, account for the case that an explicit `undefined`
  72      // value in the first is implicitly undefined in the second.
  73      //
  74      // Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
  75      aValue === undefined && !b.hasOwnProperty(key) || aValue !== b[key]) {
  76        return false;
  77      }
  78      i++;
  79    }
  80    return true;
  81  }
  82  
  83  ;// ./node_modules/@wordpress/is-shallow-equal/build-module/arrays.js
  84  /**
  85   * Returns true if the two arrays are shallow equal, or false otherwise.
  86   *
  87   * @param {any[]} a First array to compare.
  88   * @param {any[]} b Second array to compare.
  89   *
  90   * @return {boolean} Whether the two arrays are shallow equal.
  91   */
  92  function isShallowEqualArrays(a, b) {
  93    if (a === b) {
  94      return true;
  95    }
  96    if (a.length !== b.length) {
  97      return false;
  98    }
  99    for (let i = 0, len = a.length; i < len; i++) {
 100      if (a[i] !== b[i]) {
 101        return false;
 102      }
 103    }
 104    return true;
 105  }
 106  
 107  ;// ./node_modules/@wordpress/is-shallow-equal/build-module/index.js
 108  /**
 109   * Internal dependencies
 110   */
 111  
 112  
 113  
 114  
 115  
 116  /**
 117   * @typedef {Record<string, any>} ComparableObject
 118   */
 119  
 120  /**
 121   * Returns true if the two arrays or objects are shallow equal, or false
 122   * otherwise. Also handles primitive values, just in case.
 123   *
 124   * @param {unknown} a First object or array to compare.
 125   * @param {unknown} b Second object or array to compare.
 126   *
 127   * @return {boolean} Whether the two values are shallow equal.
 128   */
 129  function isShallowEqual(a, b) {
 130    if (a && b) {
 131      if (a.constructor === Object && b.constructor === Object) {
 132        return isShallowEqualObjects(a, b);
 133      } else if (Array.isArray(a) && Array.isArray(b)) {
 134        return isShallowEqualArrays(a, b);
 135      }
 136    }
 137    return a === b;
 138  }
 139  
 140  (window.wp = window.wp || {}).isShallowEqual = __webpack_exports__;
 141  /******/ })()
 142  ;


Generated : Sun Dec 22 08:20:01 2024 Cross-referenced by PHPXref