MCPcopy Create free account
hub / github.com/anus-dev/ANUS / setNestedValue

Function setNestedValue

packages/cli/src/utils/settingsUtils.ts:299–320  ·  view source on GitHub ↗

* Recursively sets a value in a nested object using a key path array.

(
  obj: Record<string, unknown>,
  path: string[],
  value: unknown,
)

Source from the content-addressed store, hash-verified

297 * Recursively sets a value in a nested object using a key path array.
298 */
299function setNestedValue(
300 obj: Record<string, unknown>,
301 path: string[],
302 value: unknown,
303): Record<string, unknown> {
304 const [first, ...rest] = path;
305 if (!first) {
306 return obj;
307 }
308
309 if (rest.length === 0) {
310 obj[first] = value;
311 return obj;
312 }
313
314 if (!obj[first] || typeof obj[first] !== 'object') {
315 obj[first] = {};
316 }
317
318 setNestedValue(obj[first] as Record<string, unknown>, rest, value);
319 return obj;
320}
321
322/**
323 * Set a setting value in the pending settings

Callers 1

setPendingSettingValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected