[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  "use strict";
   2  var wp;
   3  (wp ||= {}).isShallowEqual = (() => {
   4    var __defProp = Object.defineProperty;
   5    var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
   6    var __getOwnPropNames = Object.getOwnPropertyNames;
   7    var __hasOwnProp = Object.prototype.hasOwnProperty;
   8    var __export = (target, all) => {
   9      for (var name in all)
  10        __defProp(target, name, { get: all[name], enumerable: true });
  11    };
  12    var __copyProps = (to, from, except, desc) => {
  13      if (from && typeof from === "object" || typeof from === "function") {
  14        for (let key of __getOwnPropNames(from))
  15          if (!__hasOwnProp.call(to, key) && key !== except)
  16            __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17      }
  18      return to;
  19    };
  20    var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  21  
  22    // packages/is-shallow-equal/build-module/index.js
  23    var index_exports = {};
  24    __export(index_exports, {
  25      default: () => isShallowEqual,
  26      isShallowEqualArrays: () => isShallowEqualArrays,
  27      isShallowEqualObjects: () => isShallowEqualObjects
  28    });
  29  
  30    // packages/is-shallow-equal/build-module/objects.js
  31    function isShallowEqualObjects(a, b) {
  32      if (a === b) {
  33        return true;
  34      }
  35      const aKeys = Object.keys(a);
  36      const bKeys = Object.keys(b);
  37      if (aKeys.length !== bKeys.length) {
  38        return false;
  39      }
  40      let i = 0;
  41      while (i < aKeys.length) {
  42        const key = aKeys[i];
  43        const aValue = a[key];
  44        if (
  45          // In iterating only the keys of the first object after verifying
  46          // equal lengths, account for the case that an explicit `undefined`
  47          // value in the first is implicitly undefined in the second.
  48          //
  49          // Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
  50          aValue === void 0 && !b.hasOwnProperty(key) || aValue !== b[key]
  51        ) {
  52          return false;
  53        }
  54        i++;
  55      }
  56      return true;
  57    }
  58  
  59    // packages/is-shallow-equal/build-module/arrays.js
  60    function isShallowEqualArrays(a, b) {
  61      if (a === b) {
  62        return true;
  63      }
  64      if (a.length !== b.length) {
  65        return false;
  66      }
  67      for (let i = 0, len = a.length; i < len; i++) {
  68        if (a[i] !== b[i]) {
  69          return false;
  70        }
  71      }
  72      return true;
  73    }
  74  
  75    // packages/is-shallow-equal/build-module/index.js
  76    function isShallowEqual(a, b) {
  77      if (a && b) {
  78        if (a.constructor === Object && b.constructor === Object) {
  79          return isShallowEqualObjects(a, b);
  80        } else if (Array.isArray(a) && Array.isArray(b)) {
  81          return isShallowEqualArrays(a, b);
  82        }
  83      }
  84      return a === b;
  85    }
  86    return __toCommonJS(index_exports);
  87  })();


Generated : Mon Apr 20 08:20:11 2026 Cross-referenced by PHPXref