bborn / handlebars-async-helpers-ts

Adding async functions support to handlebars

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handlebars Async Helpers

Library that adds support to asynchronous function helpers to handlebars lib.

How to install

npm install handlebars-async-helpers-ts

How to use

import Handlebars from "handlebars";
import asyncHelpers from "handlebars-async-helpers-ts";

const hb = asyncHelpers(Handlebars);

hb.registerHelper(
  "sleep",
  async (): Promise<string> =>
    new Promise((resolve) => {
      setTimeout(() => resolve("Done!"), 1000);
    })
);

const compileTemplate = async (): Promise<void> => {
  const template = hb.compile("Mark when is completed: {{#sleep}}{{/sleep}}");
  const result = await template();
  console.log(result);
  // 'Mark when is completed: Done!'
};

compileTemplate().catch(console.error);

About

Adding async functions support to handlebars

License:MIT License


Languages

Language:TypeScript 97.3%Language:JavaScript 2.7%