(obj: T, seen = new WeakSet())
| 39 | }; |
| 40 | |
| 41 | export const deepCloneTree = <T>(obj: T, seen = new WeakSet()): T => { |
| 42 | if (obj === null || typeof obj !== "object") { |
| 43 | return obj; |
| 44 | } |
| 45 | |
| 46 | if (obj instanceof HTMLElement) { |
| 47 | return obj; |
| 48 | } |
| 49 | |
| 50 | if (typeof obj === "function") { |
| 51 | return (obj as any).bind({}); |
| 52 | } |
| 53 | |
| 54 | if (seen.has(obj)) { |
| 55 | return obj as T; // |
| 56 | } |
| 57 | |
| 58 | seen.add(obj); |
| 59 | |
| 60 | const copy: any = Array.isArray(obj) ? [] : {}; |
| 61 | |
| 62 | for (const key in obj) { |
| 63 | if (obj.hasOwnProperty(key)) { |
| 64 | copy[key] = deepCloneTree(obj[key], seen); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | seen.delete(obj); |
| 70 | |
| 71 | return copy; |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | export const findNodeOrThrow = <T extends { id: string; childNodes: Array<T> }>( |
nothing calls this directly
no outgoing calls
no test coverage detected