UNPKG

json-schema-library

Version:

Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation

12 lines (11 loc) 376 B
export function render(template, data = {}) { 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); }); }