@restorecommerce/handlebars-helperized
Version:
Opinionated handlebars based templating engine for rendering e-mail like content
26 lines • 832 B
JavaScript
import hbs from 'handlebars';
const customHandlebarsExtensions = (opts) => {
// increment a given numerical string by one
hbs.registerHelper('increment', (value, hash) => {
const toIncrement = parseInt(value, 10);
if (isNaN(toIncrement))
return '0';
return toIncrement + 1;
});
/**
* Throws back an error to the caller of the render request!
* eg:
* {{#if some.data.expected.to.exist }}
* <p>{{ some.data.expected.to.exist }}</p>
* {{else}}
* {{throw 'Important data missing, abort rendering!'}}
* {{/if}}
*/
hbs.registerHelper('throw', (value, hash) => {
throw new class extends Error {
details = hash;
}(value);
});
};
export { customHandlebarsExtensions };
//# sourceMappingURL=custom-helpers.js.map