[ 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.mjs
  23    var index_exports = {};
  24    __export(index_exports, {
  25      default: () => isShallowEqual,
  26      isShallowEqual: () => isShallowEqual,
  27      isShallowEqualArrays: () => isShallowEqualArrays,
  28      isShallowEqualObjects: () => isShallowEqualObjects
  29    });
  30  
  31    // packages/is-shallow-equal/build-module/objects.mjs
  32    function isShallowEqualObjects(a, b) {
  33      if (a === b) {
  34        return true;
  35      }
  36      const aKeys = Object.keys(a);
  37      const bKeys = Object.keys(b);
  38      if (aKeys.length !== bKeys.length) {
  39        return false;
  40      }
  41      let i = 0;
  42      while (i < aKeys.length) {
  43        const key = aKeys[i];
  44        const aValue = a[key];
  45        if (
  46          // In iterating only the keys of the first object after verifying
  47          // equal lengths, account for the case that an explicit `undefined`
  48          // value in the first is implicitly undefined in the second.
  49          //
  50          // Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
  51          aValue === void 0 && !b.hasOwnProperty(key) || aValue !== b[key]
  52        ) {
  53          return false;
  54        }
  55        i++;
  56      }
  57      return true;
  58    }
  59  
  60    // packages/is-shallow-equal/build-module/arrays.mjs
  61    function isShallowEqualArrays(a, b) {
  62      if (a === b) {
  63        return true;
  64      }
  65      if (a.length !== b.length) {
  66        return false;
  67      }
  68      for (let i = 0, len = a.length; i < len; i++) {
  69        if (a[i] !== b[i]) {
  70          return false;
  71        }
  72      }
  73      return true;
  74    }
  75  
  76    // packages/is-shallow-equal/build-module/index.mjs
  77    function isShallowEqual(a, b) {
  78      if (a && b) {
  79        if (a.constructor === Object && b.constructor === Object) {
  80          return isShallowEqualObjects(a, b);
  81        } else if (Array.isArray(a) && Array.isArray(b)) {
  82          return isShallowEqualArrays(a, b);
  83        }
  84      }
  85      return a === b;
  86    }
  87    return __toCommonJS(index_exports);
  88  })();


Generated : Wed Jun 17 08:20:09 2026 Cross-referenced by PHPXref