Skip to main content

Introduction

Bigodin is a Handlebars/Mustache-flavored templating library built to safely evaluate templates submitted by end users. Templates are parsed into a JSON AST and interpreted at runtime, never compiled to JavaScript. Helpers may be async. Parse errors carry line and column.

Bigodin is a fork of Bigodon that drops unnecessary features and grows the supported subset of the Mustache spec. If you have used Handlebars or Mustache before, you can read the tutorial end-to-end in about ten minutes.

Install

npm install @jpbm135/bigodin

Types are bundled. Node ≥ 20 is required.

Hello, world

const { compile } = require('@jpbm135/bigodin');

const template = compile('Hello, {{name}}!');
const result = await template({ name: 'George' });
// "Hello, George!"

To register custom helpers, instantiate new Bigodin():

const Bigodin = require('@jpbm135/bigodin').default;

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

const template = bigodin.compile('Hello, {{shout name}}!');
await template({ name: 'world' }); // "Hello, WORLD!"

Where to next