MCPcopy
hub / github.com/openai/chatkit-js / visit

Function visit

packages/chatkit-react/src/useStableOptions.ts:81–108  ·  view source on GitHub ↗
(v: any)

Source from the content-addressed store, hash-verified

79 };
80
81 const visit = (v: any): any => {
82 if (typeof v === 'function') {
83 const key = path[path.length - 1];
84 const parentPath = path.slice(0, -1);
85 return wrap(parentPath, key);
86 }
87 if (Array.isArray(v)) {
88 const base = path.length;
89 const out = new Array(v.length);
90 for (let i = 0; i < v.length; i++) {
91 path[base] = i;
92 out[i] = visit(v[i]);
93 }
94 path.length = base;
95 return out as any;
96 }
97 if (v && typeof v === 'object') {
98 const base = path.length;
99 const out: Record<string, any> = {};
100 for (const k of Object.keys(v)) {
101 path[base] = k;
102 out[k] = visit(v[k]);
103 }
104 path.length = base;
105 return out as any;
106 }
107 return v;
108 };
109
110 return visit(ref.current);
111}

Callers 1

Calls 1

wrapFunction · 0.85

Tested by

no test coverage detected