| 669 | * transformed to plain objects. |
| 670 | */ |
| 671 | export function deepClone<T>(input: T): T { |
| 672 | const value = toRaw(input); |
| 673 | |
| 674 | if (Array.isArray(value)) { |
| 675 | return value.map(deepClone) as T; |
| 676 | } |
| 677 | |
| 678 | if (value === null) return null as T; |
| 679 | |
| 680 | if (value instanceof Principal) { |
| 681 | return Principal.fromUint8Array(value.toUint8Array()) as T; |
| 682 | } |
| 683 | |
| 684 | if (typeof value === 'object') { |
| 685 | const entries = Object.entries(value).map(([key, value]) => [key, deepClone(value)]); |
| 686 | |
| 687 | return Object.fromEntries(entries); |
| 688 | } |
| 689 | |
| 690 | return structuredClone(value); |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * Debounces a function and returns a promise that resolves with the result of the debounced function. |