MCPcopy Create free account
hub / github.com/denoland/std / setNested

Function setNested

cli/parse_args.ts:447–474  ·  view source on GitHub ↗
(
  object: NestedMapping,
  keys: string[],
  value: unknown,
  collect = false,
)

Source from the content-addressed store, hash-verified

445}
446
447function setNested(
448 object: NestedMapping,
449 keys: string[],
450 value: unknown,
451 collect = false,
452) {
453 keys = [...keys];
454 const key = keys.pop()!;
455
456 for (const k of keys) {
457 if (isConstructorOrProto(object, k)) return;
458 object = (object[k] ??= {}) as NestedMapping;
459 }
460
461 if (isConstructorOrProto(object, key)) return;
462
463 if (collect) {
464 const v = object[key];
465 if (Array.isArray(v)) {
466 v.push(value);
467 return;
468 }
469
470 value = v ? [v, value] : [value];
471 }
472
473 object[key] = value;
474}
475
476function hasNested(object: NestedMapping, keys: string[]): boolean {
477 for (const key of keys) {

Callers 2

setArgumentFunction · 0.85
parseArgsFunction · 0.85

Calls 3

isConstructorOrProtoFunction · 0.85
popMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected