(a: any, b: any)
| 1 | export const run = <T>(f: () => T) => f(); |
| 2 | export const deepEqual = (a: any, b: any): boolean => { |
| 3 | if (a === b) return true; |
| 4 | |
| 5 | if (a && b && typeof a === "object" && typeof b === "object") { |
| 6 | if (Array.isArray(a) && Array.isArray(b)) { |
| 7 | if (a.length !== b.length) return false; |
| 8 | for (let i = 0; i < a.length; i++) { |
| 9 | if (!deepEqual(a[i], b[i])) { |
| 10 | return false; |
| 11 | } |
| 12 | } |
| 13 | return true; |
| 14 | } |
| 15 | |
| 16 | if (a.constructor !== b.constructor) { |
| 17 | return false; |
| 18 | } |
| 19 | |
| 20 | const keysA = Object.keys(a); |
| 21 | const keysB = Object.keys(b); |
| 22 | |
| 23 | if (keysA.length !== keysB.length) { |
| 24 | return false; |
| 25 | } |
| 26 | |
| 27 | for (const key of keysA) { |
| 28 | if (!keysB.includes(key)) { |
| 29 | return false; |
| 30 | } |
| 31 | if (!deepEqual(a[key], b[key])) { |
| 32 | return false; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | return true; |
| 37 | } |
| 38 | return false; |
| 39 | }; |
| 40 | |
| 41 | export const deepCloneTree = <T>(obj: T, seen = new WeakSet()): T => { |
| 42 | if (obj === null || typeof obj !== "object") { |
nothing calls this directly
no outgoing calls
no test coverage detected