UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

41 lines (37 loc) • 1.43 kB
import { areObjectsEqual } from "./objectEquality.mjs"; //#region src/utils/deepEquality.ts function deepEquality(x, y) { const isXSimpleEqualY = simpleEqual(x, y); if (isXSimpleEqualY !== void 0) return isXSimpleEqualY; if (!(x instanceof Map) || !(y instanceof Map)) return areObjectsEqual(x, y); const xMap = x; const yMap = y; if (!equalsIgnoreOrder(Array.from(xMap.keys()), Array.from(yMap.keys()))) return false; return Array.from(xMap.entries()).every(([key, xVal]) => deepEquality(xVal, yMap.get(key))); } /** * @note This will only work for primitive array equality */ function equalsIgnoreOrder(a, b) { if (a.length !== b.length) return false; return a.every((k) => b.includes(k)); } /** * @note This will only work for primitive array equality */ function equalsWithOrder(lhs, rhs) { if (lhs.length !== rhs.length) return false; return lhs.every((k, i) => k === rhs[i]); } function simpleEqual(x, y) { if (x === y) return true; if ((x === null || x === void 0) && (y === null || y === void 0)) return x === y; if (x.constructor !== y.constructor) return false; if (x instanceof Function) return x === y; if (x instanceof RegExp) return x === y; if (x.valueOf && y.valueOf && x.valueOf() === y.valueOf()) return true; if (x instanceof Date || y instanceof Date) return false; } //#endregion export { deepEquality, equalsIgnoreOrder, equalsWithOrder }; //# sourceMappingURL=deepEquality.mjs.map