json-schema-library
Version:
Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation
11 lines (10 loc) • 402 B
text/typescript
export function render(template: string, data: { [p: string]: any } = {}): string {
return template.replace(/\{\{(\w+)\}\}/g, (_, key) => {
const variable = data[key];
if (variable === null || variable === undefined) return ""; // optional
if (typeof variable === "object") {
return JSON.stringify(variable);
}
return String(variable);
});
}