Adding async function support to handlebars helpers
npm install handlebars-async-helpers-tsLibrary that adds support to asynchronous function helpers to handlebars lib.
``shell`
npm install handlebars-async-helpers-ts
`javascript
import Handlebars from "handlebars";
import asyncHelpers from "handlebars-async-helpers-ts";
const hb = asyncHelpers(Handlebars);
hb.registerHelper(
"sleep",
async (): Promise
new Promise((resolve) => {
setTimeout(() => resolve("Done!"), 1000);
})
);
const compileTemplate = async (): Promise
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);
``