1 export function deepEqualObj(obj1: unknown, obj2: unknown): boolean {
2 if (typeof obj1 !== typeof obj2) {
3 return false
4 }
5
6 if (typeof obj1 !== "object" || obj1 === null) {
7 return obj1 === obj2
8 }
9
10 if (typeof obj2 !== "object" || obj2 === null) {
11 return obj2 === obj1
12 }
13
14 // Dates expose no own enumerable keys, so the key comparison below would treat
15 // any two Date instances as equal; compare their time value instead.
16 if (obj1 instanceof Date || obj2 instanceof Date) {
17 return (
18 obj1 instanceof Date &&
19 obj2 instanceof Date &&
20 obj1.getTime() === obj2.getTime()
21 )
22 }
23
24 const obj1Keys = Object.keys(obj1)
25 const obj2Keys = Object.keys(obj2)
26
27 if (obj1Keys.length !== obj2Keys.length) {
28 return false
29 }
30
31 for (const key of obj1Keys) {
32 if (!obj2Keys.includes(key) || !deepEqualObj(obj1[key], obj2[key])) {
33 return false
34 }
35 }
36
37 return true
38 }