Files
medusa-store/packages/medusa/src/utils/has-changes.ts
Derek Wene bd53adb238 fix(medusa): has-changes (#4023)
* fix(medusa): has-changes

* add changeset
2023-05-05 11:05:20 +02:00

27 lines
528 B
TypeScript

import { isObject } from "./is-object"
/**
* Compare two objects and return true if there is changes detected from obj2 compared to obj1
* @param obj1
* @param obj2
*/
export function hasChanges<T1 extends Object, T2 extends Object>(
obj1: T1,
obj2: T2
): boolean {
for (const [key, value] of Object.entries(obj2)) {
if (isObject(obj1[key])) {
if (hasChanges(obj1[key], value)) {
return true
}
continue
}
if (obj1[key] !== value) {
return true
}
}
return false
}