1.7.0 • Published 2 years ago

bigodon v1.7.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Bigodon

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

Features

As well as most Handlebars features like:

  • Handlebars dot notation inside mustaches ({{foo.bar}})
  • Handlebars literal values ({{add 5 6}})
  • Comments ({{! ... }})
  • Nested expressions ({{capitalize (append data.firstName data.secondName)}})
  • Blocks ({{#name}}...{{/name}})
  • Inverted blocks ({{^name}}...{{/name}})
  • Else blocks ({{#name}}...{{else}}...{{/name}})
  • Parent and current context ({{#list}}{{$parent.name}} {{$this}}{{/list}})

Bigodon also supports:

  • Async helpers, you can await for requests, database access, file access and so on.
  • Safely evaluate user-provided templates. (Templates aren't transpiled to JavaScript, they're interpreted by Bigodon)
  • Much better performance.
  • Better error reporting.
  • Better native helpers.

Bigodon is used in production by Mocko.

Installation

Add the bigodon dependency to your project. Types included:

npm install bigodon

Usage

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);

Check how to use the lib here

Check how to use the language here

Check the available helpers here

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

3 years ago

1.2.0

3 years ago

1.3.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago