A very simple, small js templating engine
// replace any occurences of str with a matching key:value pair
function replacements(template, replacement) {
return template.replace(/{([^}]+)}/g, function (match) {
return replacement[match];
});
}
// usage
var template = 'Hi { name }, you are { age } years old.';
console.log(
replacements(template, {
'{ name }': 'Chris',
'{ age }': 50
})
);
// outputs
// Hi Chris, you are 50 years old.