Actual real ES6 templates. Just dynamic.
Because you have a whole bunch of templates, and don't want to write a function for every possible template string. The purpose of the module is that variables are resolved later, which makes it easier to do dynamic templating. This is surprisingly tricky as this
for TemplateStrings is a bit weird.
Version 1 used eval
, requiring you to sanitise user input before use. While that's a commopn expectation for web development, the new version uses a regex based approach while keeping the same API.
Load the module:
const fillTemplate = require('es6-dynamic-template');
Use it (use regular quotes, not backticks, for template string):
const greeting = fillTemplate('Hi ${firstName}', {firstName: 'Joe'});
Returns:
'Hi Joe'
mocha
Everything works, AFAIK, if it doesn't, send a PR rather than complaining otherwise I will mock you.