Skip to main content

Bigodin

Secure Handlebars/Mustache templating for user-provided templates, with async helpers and human-friendly parsing errors.

Safe by design

Templates are parsed into a JSON AST and interpreted at runtime, never compiled to JavaScript. Prototype-pollution guards and execution-time limits keep user-provided templates contained.

Async helpers

Helpers can be async and run in parallel. Register your own with addHelper on a Bigodin instance, or use the bundled array, string, math, date, and comparison helpers.

Mustache & Handlebars feel

Familiar {{...}} syntax with blocks, else if, path expressions, variables, and helpful parsing errors that point at the offending line and column.

Install

yarn add bigodin
# or
npm install bigodin

Use the singleton with built-in helpers, or new Bigodin() when you want to register your own.

Render a template

import {Bigodin} from 'bigodin';

const bigodin = new Bigodin();
bigodin.addHelper('shout', (s) => String(s).toUpperCase());

const ast = bigodin.parse('Hello, {{shout name}}!');
const out = await bigodin.run(ast, {name: 'world'});
// "Hello, WORLD!"