(json: Json | Json[])
| 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]; |
no test coverage detected