MCPcopy Create free account
hub / github.com/cloudflare/agents / deleteJsonPathValue

Function deleteJsonPathValue

packages/shell/src/extras.ts:301–325  ·  view source on GitHub ↗
(root: unknown, tokens: PathToken[])

Source from the content-addressed store, hash-verified

299}
300
301function deleteJsonPathValue(root: unknown, tokens: PathToken[]): void {
302 if (tokens.length === 0) {
303 throw new Error("JSON delete path must not be empty");
304 }
305 let current = root as Record<string, unknown> | unknown[];
306 for (let index = 0; index < tokens.length - 1; index++) {
307 const token = tokens[index];
308 const next =
309 typeof token === "number"
310 ? (current as unknown[])[token]
311 : (current as Record<string, unknown>)[token];
312 current = next as Record<string, unknown> | unknown[];
313 if (current === undefined) {
314 return;
315 }
316 }
317 const finalToken = tokens[tokens.length - 1];
318 if (typeof finalToken === "number") {
319 if (Array.isArray(current) && finalToken < current.length) {
320 current.splice(finalToken, 1);
321 }
322 } else if (current && typeof current === "object") {
323 delete (current as Record<string, unknown>)[finalToken];
324 }
325}
326
327async function buildTreeNode(
328 path: string,

Callers 1

updateJsonValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected