MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / clone

Function clone

packages/common-helpers/src/clone.ts:6–24  ·  view source on GitHub ↗
(value: T)

Source from the content-addressed store, hash-verified

4 * Clones the given object. Only arrays and plain objects are cloned. Other values are returned as is.
5 */
6export function clone<T>(value: T): T {
7 if (Array.isArray(value)) {
8 return value.map((v) => clone(v)) as T;
9 }
10
11 if (typeof value === 'object') {
12 if (!value || !isPlainObject(value)) {
13 return value;
14 }
15
16 const result: any = {};
17 for (const key of Object.keys(value)) {
18 result[key] = clone(value[key as keyof T]);
19 }
20 return result;
21 }
22
23 return value;
24}

Callers 8

clone.test.tsFile · 0.90
serializeItemsMethod · 0.90
updateFunction · 0.90
normalizeArgsFunction · 0.90
createMutateFunction · 0.90
updateMutateFunction · 0.90
createClientFunction · 0.90

Calls 1

isPlainObjectFunction · 0.90

Tested by 1

createClientFunction · 0.72