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

Function deepAssignTableArray

toml/_parser.ts:201–229  ·  view source on GitHub ↗
(
  target: Record<string, unknown>,
  table: TableArray,
)

Source from the content-addressed store, hash-verified

199}
200
201function deepAssignTableArray(
202 target: Record<string, unknown>,
203 table: TableArray,
204) {
205 const { type, keys, value } = table;
206 const currentValue = getTargetValue(target, keys);
207
208 if (currentValue === undefined) {
209 return Object.assign(target, unflat(keys, [value]));
210 }
211 if (Array.isArray(currentValue)) {
212 if (table.keys.length === 1) {
213 currentValue.push(value);
214 } else {
215 const last = currentValue.at(-1);
216 deepAssign(last, {
217 type: table.type,
218 keys: table.keys.slice(1),
219 value: table.value,
220 });
221 }
222 return target;
223 }
224 if (isObject(currentValue)) {
225 deepAssign(currentValue, { type, keys: keys.slice(1), value });
226 return target;
227 }
228 throw new Error("Unexpected assign");
229}
230
231export function deepAssign(
232 target: Record<string, unknown>,

Callers 1

deepAssignFunction · 0.85

Calls 7

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

Tested by

no test coverage detected