UNPKG

mahler

Version:

A automated task composer and HTN based planner for building autonomous system agents

42 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deepEqual = deepEqual; const assert_1 = require("../assert"); function isObject(value) { return typeof value === 'object' && value !== null; } const Eq = { is(x) { return isObject(x) && typeof x.equals === 'function'; }, }; /** * Calculates deep equality between javascript * objects */ function deepEqual(value, other) { // Allow user to override the comparison if (Eq.is(value)) { return value.equals(other); } if (Eq.is(other)) { return other.equals(value); } if (isObject(value) && isObject(other)) { const [vProps, oProps] = [value, other].map((a) => Object.getOwnPropertyNames(a)); // This will never fail but it prevents the compiler from // complaining (0, assert_1.assert)(vProps != null && oProps != null); if (vProps.length !== oProps.length) { // If the property lists are different lengths we don't need // to check any further return false; } // Otherwise this comparison will catch it. This works even // for arrays as getOwnPropertyNames returns the list of indexes // for each array return vProps.every((key) => deepEqual(value[key], other[key])); } return value === other; } //# sourceMappingURL=deep-equal.js.map