Handlebars is a simple templating language where double braces are used to contain expressions. Convert handlebars templates in the browser with support for passing JSON data.
import handlebars from "https://cdn.jsdelivr.net/npm/handlebars@4.7.8/+esm"
export const take = [
{ key: "code", type: "code", label: "Handlebars" },
{ key: "data", type: "json", label: "Data" },
{ key: "escape", type: "toggle", label: "Escape characters" },
]
export const make = ({ code, data, escape }) => {
const value = handlebars.compile(code, { noEscape: !escape })(data)
return [
{ type: "code", value },
{ type: "html", value },
]
}