MCPcopy Index your code
hub / github.com/TanStack/query / _cloneDeep

Function _cloneDeep

packages/vue-query/src/utils.ts:22–57  ·  view source on GitHub ↗
(
  value: MaybeRefDeep<T>,
  customize?: (
    val: MaybeRefDeep<T>,
    key: string,
    level: number,
  ) => T | undefined,
  currentKey: string = '',
  currentLevel: number = 0,
)

Source from the content-addressed store, hash-verified

20// Helper function for cloning deep objects where
21// the level and key is provided to the callback function.
22function _cloneDeep<T>(
23 value: MaybeRefDeep<T>,
24 customize?: (
25 val: MaybeRefDeep<T>,
26 key: string,
27 level: number,
28 ) => T | undefined,
29 currentKey: string = '',
30 currentLevel: number = 0,
31): T {
32 if (customize) {
33 const result = customize(value, currentKey, currentLevel)
34 if (result === undefined && isRef(value)) {
35 return result as T
36 }
37 if (result !== undefined) {
38 return result
39 }
40 }
41
42 if (Array.isArray(value)) {
43 return value.map((val, index) =>
44 _cloneDeep(val, customize, String(index), currentLevel + 1),
45 ) as unknown as T
46 }
47
48 if (typeof value === 'object' && isPlainObject(value)) {
49 const entries = Object.entries(value).map(([key, val]) => [
50 key,
51 _cloneDeep(val, customize, key, currentLevel + 1),
52 ])
53 return Object.fromEntries(entries)
54 }
55
56 return value as T
57}
58
59export function cloneDeep<T>(
60 value: MaybeRefDeep<T>,

Callers 1

cloneDeepFunction · 0.85

Calls 1

isPlainObjectFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…