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

Function deepAssignTable

toml/_parser.ts:179–199  ·  view source on GitHub ↗
(
  target: Record<string, unknown>,
  table: Table,
)

Source from the content-addressed store, hash-verified

177}
178
179function deepAssignTable(
180 target: Record<string, unknown>,
181 table: Table,
182) {
183 const { keys, type, value } = table;
184 const currentValue = getTargetValue(target, keys);
185
186 if (currentValue === undefined) {
187 return Object.assign(target, unflat(keys, value));
188 }
189 if (Array.isArray(currentValue)) {
190 const last = currentValue.at(-1);
191 deepAssign(last, { type, keys: keys.slice(1), value });
192 return target;
193 }
194 if (isObject(currentValue)) {
195 deepAssign(currentValue, { type, keys: keys.slice(1), value });
196 return target;
197 }
198 throw new Error("Unexpected assign");
199}
200
201function deepAssignTableArray(
202 target: Record<string, unknown>,

Callers 1

deepAssignFunction · 0.85

Calls 6

getTargetValueFunction · 0.85
unflatFunction · 0.85
deepAssignFunction · 0.85
isObjectFunction · 0.70
atMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected