Skip to content

Instantly share code, notes, and snippets.

@kbrgl
Created March 14, 2016 04:18
Show Gist options
  • Save kbrgl/02527eb0a073ae440a0c to your computer and use it in GitHub Desktop.
Save kbrgl/02527eb0a073ae440a0c to your computer and use it in GitHub Desktop.
Simplistic node templates
'use strict';
const render = function(template, mappings) {
for (let mapping in mappings) {
template = template.replace(new RegExp(`\\{\\{\\s?${mapping}\\s?\\}\\}`, 'g'), function (capture) {
if (typeof mappings[mapping] === 'function') {
return mappings[mapping]();
} else {
return mappings[mapping];
}
});
}
return template;
};
module.exports = {
render: render
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment