mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-13 16:17:54 +00:00
17 lines
549 B
JavaScript
17 lines
549 B
JavaScript
const HANDLEBARS_CDN = "https://cdn.jsdelivr.net/npm/handlebars@4.7.8/+esm"
|
|
|
|
let hbP
|
|
const tplCache = new Map()
|
|
|
|
const loadHB = () => hbP ??= import(HANDLEBARS_CDN).then(m => m.default ?? m)
|
|
|
|
async function renderTemplate(template, data = {}) {
|
|
if (typeof template != "string") throw new TypeError("Template must be a string")
|
|
const HB = await loadHB()
|
|
let fn = tplCache.get(template)
|
|
fn || tplCache.set(template, fn = HB.compile(template))
|
|
return fn(data ?? {})
|
|
}
|
|
export default renderTemplate;
|
|
// Generation time: 77.305s
|
|
// Result: PASS
|