kollapsminoriteten/wp-includes/js/dist/is-shallow-equal.js

142 lines
4.2 KiB
JavaScript
Raw Normal View History

2024-04-17 11:32:24 +02:00
/******/ (() => { // webpackBootstrap
2022-06-16 14:03:35 +02:00
/******/ "use strict";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
2024-04-17 11:32:24 +02:00
/******/ (() => {
2022-06-16 14:03:35 +02:00
/******/ // define getter functions for harmony exports
2024-04-17 11:32:24 +02:00
/******/ __webpack_require__.d = (exports, definition) => {
2022-06-16 14:03:35 +02:00
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
2024-04-17 11:32:24 +02:00
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
2024-04-17 11:32:24 +02:00
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
/******/ /* webpack/runtime/make namespace object */
2024-04-17 11:32:24 +02:00
/******/ (() => {
2022-06-16 14:03:35 +02:00
/******/ // define __esModule on exports
2024-04-17 11:32:24 +02:00
/******/ __webpack_require__.r = (exports) => {
2022-06-16 14:03:35 +02:00
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
2019-11-02 10:38:58 +01:00
/******/ };
2024-04-17 11:32:24 +02:00
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
2019-11-02 10:38:58 +01:00
/************************************************************************/
2022-06-16 14:03:35 +02:00
var __webpack_exports__ = {};
2021-04-27 08:32:47 +02:00
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
2019-11-02 10:38:58 +01:00
2021-04-27 08:32:47 +02:00
// EXPORTS
2022-06-16 14:03:35 +02:00
__webpack_require__.d(__webpack_exports__, {
2024-04-17 11:32:24 +02:00
"default": () => (/* binding */ isShallowEqual),
isShallowEqualArrays: () => (/* reexport */ isShallowEqualArrays),
isShallowEqualObjects: () => (/* reexport */ isShallowEqualObjects)
2022-06-16 14:03:35 +02:00
});
2019-11-02 10:38:58 +01:00
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/objects.js
2019-11-02 10:38:58 +01:00
/**
2021-04-27 08:32:47 +02:00
* Returns true if the two objects are shallow equal, or false otherwise.
2019-11-02 10:38:58 +01:00
*
2021-04-27 08:32:47 +02:00
* @param {import('.').ComparableObject} a First object to compare.
* @param {import('.').ComparableObject} b Second object to compare.
2019-11-02 10:38:58 +01:00
*
2021-04-27 08:32:47 +02:00
* @return {boolean} Whether the two objects are shallow equal.
2019-11-02 10:38:58 +01:00
*/
2021-04-27 08:32:47 +02:00
function isShallowEqualObjects(a, b) {
if (a === b) {
return true;
}
2021-07-23 11:58:50 +02:00
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
2021-04-27 08:32:47 +02:00
if (aKeys.length !== bKeys.length) {
return false;
}
2021-07-23 11:58:50 +02:00
let i = 0;
2021-04-27 08:32:47 +02:00
while (i < aKeys.length) {
2021-07-23 11:58:50 +02:00
const key = aKeys[i];
const aValue = a[key];
2023-12-07 09:44:11 +01:00
if (
// In iterating only the keys of the first object after verifying
2021-04-27 08:32:47 +02:00
// equal lengths, account for the case that an explicit `undefined`
// value in the first is implicitly undefined in the second.
//
// Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
aValue === undefined && !b.hasOwnProperty(key) || aValue !== b[key]) {
return false;
}
i++;
}
return true;
}
2019-11-02 10:38:58 +01:00
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/arrays.js
2019-11-02 10:38:58 +01:00
/**
2021-04-27 08:32:47 +02:00
* Returns true if the two arrays are shallow equal, or false otherwise.
2019-11-02 10:38:58 +01:00
*
2021-04-27 08:32:47 +02:00
* @param {any[]} a First array to compare.
* @param {any[]} b Second array to compare.
2019-11-02 10:38:58 +01:00
*
2021-04-27 08:32:47 +02:00
* @return {boolean} Whether the two arrays are shallow equal.
2019-11-02 10:38:58 +01:00
*/
2021-04-27 08:32:47 +02:00
function isShallowEqualArrays(a, b) {
if (a === b) {
return true;
}
if (a.length !== b.length) {
return false;
}
2021-07-23 11:58:50 +02:00
for (let i = 0, len = a.length; i < len; i++) {
2021-04-27 08:32:47 +02:00
if (a[i] !== b[i]) {
return false;
}
}
return true;
2019-11-02 10:38:58 +01:00
}
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/index.js
2021-04-27 08:32:47 +02:00
/**
* Internal dependencies
*/
2019-11-02 10:38:58 +01:00
2023-12-07 09:44:11 +01:00
2021-04-27 08:32:47 +02:00
/**
* @typedef {Record<string, any>} ComparableObject
*/
2019-11-02 10:38:58 +01:00
/**
2021-04-27 08:32:47 +02:00
* Returns true if the two arrays or objects are shallow equal, or false
2023-09-26 10:33:34 +02:00
* otherwise. Also handles primitive values, just in case.
2019-11-02 10:38:58 +01:00
*
2023-09-26 10:33:34 +02:00
* @param {unknown} a First object or array to compare.
* @param {unknown} b Second object or array to compare.
2019-11-02 10:38:58 +01:00
*
2021-04-27 08:32:47 +02:00
* @return {boolean} Whether the two values are shallow equal.
2019-11-02 10:38:58 +01:00
*/
2021-04-27 08:32:47 +02:00
function isShallowEqual(a, b) {
if (a && b) {
if (a.constructor === Object && b.constructor === Object) {
return isShallowEqualObjects(a, b);
} else if (Array.isArray(a) && Array.isArray(b)) {
return isShallowEqualArrays(a, b);
}
}
return a === b;
2019-11-02 10:38:58 +01:00
}
2022-06-16 14:03:35 +02:00
(window.wp = window.wp || {}).isShallowEqual = __webpack_exports__;
/******/ })()
;