// Template rendering and the MIME message, with nothing to import. // // fill replaces {{name}} with vars[name]: a missing name becomes "", a // value that isn't a string is JSON. Unknown braces are left as they are, // so a template that means to show an example still does. export function fill(text, vars) { return String(text ?? "").replace(/\{\{([A-Za-z0-9_.-]+)\}\}/g, (_, k) => { const v = vars[k] if (v === undefined || v === null) return "" return typeof v === "string" ? v : JSON.stringify(v) }) } // escape is text into HTML: a mail body the user's template wrote must not // turn an error's words into markup or a link. export function escape(text) { return String(text ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]) } // DEFAULT_HTML is the layout a mail goes out in when the user's html // option is unset: a card with a kind badge, the facts as a table, and the // error's words in a pre block. Everything inline-styled — mail clients // strip