(value: unknown)
| 107 | const processValue = (value: unknown): ProcessedValue => { |
| 108 | if (typeof value === "string") { |
| 109 | return value.replace(/{{([^}]+)}}/g, (_match, varName: string) => { |
| 110 | const trimmed = varName.trim(); |
| 111 | const parts = trimmed.split("."); |
| 112 | const lastPart = parts[parts.length - 1] ?? ""; |
| 113 | |
| 114 | return getDummyValue(lastPart); |
| 115 | }); |
| 116 | } |
| 117 | |
| 118 | if (Array.isArray(value)) { |
| 119 | return value.map(processValue); |
| 120 | } |
| 121 | |
| 122 | if (typeof value === "object" && value !== null) { |
| 123 | const out: Record<string, ProcessedValue> = {}; |
| 124 | |
| 125 | for (const [key, nestedValue] of Object.entries(value)) { |
| 126 | out[key] = processValue(nestedValue); |
| 127 | } |
| 128 | |
| 129 | return out; |
| 130 | } |
| 131 | |
| 132 | return typeof value === "number" || typeof value === "boolean" |
| 133 | ? String(value) |
| 134 | : ""; |
| 135 | }; |
| 136 | |
| 137 | const generateDummyData = (variablesPath: string): Record<string, unknown> => { |
| 138 | const fileContent = fs.readFileSync(variablesPath, "utf8"); |
| 139 | const parsed: unknown = JSON.parse(fileContent); |
| 140 | const processed = processValue(parsed); |
| 141 | |
| 142 | return typeof processed === "object" && !Array.isArray(processed) |
no test coverage detected