MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / findAndReplaceURL

Function findAndReplaceURL

lib/edge-runtime/apiResponseSimplification.ts:84–102  ·  view source on GitHub ↗
(json: Json | Json[])

Source from the content-addressed store, hash-verified

82 let urlIdx = Object.entries(store).length;
83
84 function findAndReplaceURL(json: Json | Json[]) {
85 if (!json || typeof json !== "object") return;
86
87 // Creates the same iterator for both arrays and objects
88 const entries = Array.isArray(json)
89 ? json.entries()
90 : Object.entries(json as { [key: string]: Json });
91
92 for (const [key, value] of entries) {
93 const k = key as string;
94 if (typeof value === "object") {
95 findAndReplaceURL(value);
96 } else if (typeof value === "string") {
97 if (isUrl(value)) {
98 (json as any)[k] = getOrGenerateURL(value);
99 }
100 }
101 }
102 }
103
104 function getOrGenerateURL(value: string): string {
105 let id = store[value];

Callers 1

removeUrlsFromObjsFunction · 0.85

Calls 2

isUrlFunction · 0.90
getOrGenerateURLFunction · 0.85

Tested by

no test coverage detected