MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / processValue

Function processValue

apps/api/src/templates/email/preview.ts:109–139  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

107const 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
137const 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)

Callers 1

generateDummyDataFunction · 0.85

Calls 1

getDummyValueFunction · 0.85

Tested by

no test coverage detected