Skip to content

Instantly share code, notes, and snippets.

@batogov
Created September 22, 2017 13:16
Show Gist options
  • Save batogov/798d2f96a1ead563bd8af2cab149c4c9 to your computer and use it in GitHub Desktop.
Save batogov/798d2f96a1ead563bd8af2cab149c4c9 to your computer and use it in GitHub Desktop.
Process Template
function processTemp(tempString, dataObject) {
for(var key in dataObject) {
if (dataObject.hasOwnProperty(key)) {
tempString = tempString.replace(new RegExp('{' + key + '}', 'g'), dataObject[key]);
}
}
return tempString;
}
var str = 'Hello {name}';
var data = {
name: 'Alex'
};
var result = processTemp(str, data);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment