Skip to content

Instantly share code, notes, and snippets.

@roboli
Last active September 9, 2015 14:00
Show Gist options
  • Save roboli/84d69696620e1de631c8 to your computer and use it in GitHub Desktop.
Save roboli/84d69696620e1de631c8 to your computer and use it in GitHub Desktop.
'use strict';
function parse(obj, str) {
var regex = /\{\{\s(\w{8})\.(\w+)\s\}\}/g,
matches,
results = [];
while (matches = regex.exec(str)) {
results.push({ key: matches[1], prop: matches[2] });
}
results.forEach(function(n) {
var val = obj[n.key][n.prop] || '<nothing>';
str = str.replace('{{ ' + n.key + '.' + n.prop + ' }}', val);
});
return str;
}
module.exports = parse;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment