MCPcopy Create free account
hub / github.com/dfinity/orbit / deepClone

Function deepClone

apps/wallet/src/utils/helper.utils.ts:671–691  ·  view source on GitHub ↗
(input: T)

Source from the content-addressed store, hash-verified

669 * transformed to plain objects.
670 */
671export 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.

Callers 2

useFormFunction · 0.90
submitFunction · 0.90

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected