Secure Handlebars/Mustache templating for user-provided templates with async helpers support and human-friendly parsing errors
APACHE-2.0 License
Secure Handlebars/Mustache templating for user-provided templates with async helpers support and human-friendly parsing errors.
As well as most Handlebars features like:
{{foo.bar}}
){{add 5 6}}
){{! ... }}
){{capitalize (append data.firstName data.secondName)}}
){{#name}}...{{/name}}
){{^name}}...{{/name}}
){{#name}}...{{else}}...{{/name}}
){{#list}}{{$parent.name}} {{$this}}{{/list}}
)Bigodon also supports:
Bigodon is used in production by Mocko.
Add the bigodon
dependency to your project. Types included:
npm install bigodon
const { compile } = require('bigodon');
async function main() {
const source = 'Hello, {{name}}!';
const template = compile(source);
const result = await template({
name: 'George'
});
console.log(result); // Hello, George!
}
main().catch(console.error);
Or, if you want to split parsing from execution between services or cache the parsed AST:
const { parse, run } = require('bigodon');
const source = 'Hello, {{name}}!';
const ast = parse(source); // This will return a JSON object that can be persisted for later usage
// In another process or later:
async function main() {
const result = await run(ast, {
name: 'George'
});
console.log(result); // Hello, George!
}
main().catch(console.error);