@martinmilo/verve
Version:
TypeScript domain modeling library with field-level authorization, business rule validation, and context-aware access control
49 lines • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isObjectEqual = isObjectEqual;
exports.isArrayEqual = isArrayEqual;
function isObjectEqual(a, b) {
if (typeof a !== 'object' || typeof b !== 'object') {
return a === b;
}
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
if (aKeys.length !== bKeys.length) {
return false;
}
const foundDiff = aKeys.find((key) => {
const aValue = a[key];
const bValue = b[key];
if (typeof aValue !== typeof bValue) {
return true;
}
if (Array.isArray(aValue) && Array.isArray(bValue)) {
return !isArrayEqual(aValue, bValue);
}
if (typeof aValue === 'object' && typeof bValue === 'object') {
return !isObjectEqual(aValue, bValue);
}
return aValue !== bValue;
});
return foundDiff === undefined;
}
function isArrayEqual(a, b) {
if (a.length !== b.length) {
return false;
}
const sortedA = a.sort();
const sortedB = b.sort();
return sortedA.every((item, index) => {
if (typeof item !== typeof sortedB[index]) {
return false;
}
if (typeof item === 'object' && typeof sortedB[index] === 'object') {
return isObjectEqual(item, sortedB[index]);
}
if (Array.isArray(item) && Array.isArray(sortedB[index])) {
return isArrayEqual(item, sortedB[index]);
}
return item === sortedB[index];
});
}
//# sourceMappingURL=utils.js.map