(feat:tools) warn on unsaved changes, deep compare

This commit is contained in:
ManishMadan2882
2025-05-23 18:22:06 +05:30
parent 56b4b63749
commit 046f6c66ed
3 changed files with 116 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
/**
* Deeply compares two objects for equality
* @param obj1 First object to compare
* @param obj2 Second object to compare
* @returns boolean indicating if objects are equal
*/
export function areObjectsEqual(obj1: any, obj2: any): boolean {
if (obj1 === obj2) return true;
if (obj1 == null || obj2 == null) return false;
if (typeof obj1 !== 'object' || typeof obj2 !== 'object') return false;
if (Array.isArray(obj1) && Array.isArray(obj2)) {
if (obj1.length !== obj2.length) return false;
return obj1.every((val, idx) => areObjectsEqual(val, obj2[idx]));
}
if (obj1 instanceof Date && obj2 instanceof Date) {
return obj1.getTime() === obj2.getTime();
}
const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);
if (keys1.length !== keys2.length) return false;
return keys1.every((key) => {
return keys2.includes(key) && areObjectsEqual(obj1[key], obj2[key]);
});
}