@n3okill/utils
Version:
Many javascript helpers
30 lines • 1.14 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.equalObject = equalObject;
const equal_1 = require("./equal");
/**
* It checks if two objects have the same keys and values
* @param {T} a - The first object to compare.
* @param {U} b - The object to compare against.
* @returns The return value is `true` if the two objects are equal, `false` otherwise.
*/
function equalObject(a, b) {
const aEntries = [...Object.getOwnPropertyNames(a), ...Object.getOwnPropertySymbols(a)];
const bEntries = [...Object.getOwnPropertyNames(b), ...Object.getOwnPropertySymbols(b)];
if (aEntries.length !== bEntries.length) {
return false;
}
for (let i = 0; i < aEntries.length; i++) {
// eslint-disable-next-line security/detect-object-injection
const key = aEntries[i];
if (bEntries.indexOf(key) === -1) {
return false;
}
// eslint-disable-next-line security/detect-object-injection
if (!(0, equal_1.equal)(a[key], b[key])) {
return false;
}
}
return true;
}
//# sourceMappingURL=equalObject.js.map
;