@cch137/format-utils
Version:
A collection of utility modules for formatting and processing data
21 lines (20 loc) • 625 B
JavaScript
export function deepEqual(a, b) {
if (a === b)
return true;
if (a == null || b == null)
return false;
if (typeof a !== typeof b)
return false;
if (Array.isArray(a)) {
return (Array.isArray(b) &&
a.length === b.length &&
a.every((item, index) => deepEqual(item, b[index])));
}
if (typeof a === "object") {
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
return (aKeys.length === bKeys.length &&
aKeys.every((key) => b.hasOwnProperty(key) && deepEqual(a[key], b[key])));
}
return a === b;
}