Skip to content

Instantly share code, notes, and snippets.

@joelcardinal
Created February 2, 2018 18:45
Show Gist options
  • Save joelcardinal/7854bb3a3e7a1b1217644feb5fdc8271 to your computer and use it in GitHub Desktop.
Save joelcardinal/7854bb3a3e7a1b1217644feb5fdc8271 to your computer and use it in GitHub Desktop.
Utility to populate templates for pre-ES2015 backticks
/*
* str = 'I went to the {{location}} and found {{item}}';
* obj = {location : 'store', item : 'milk'};
*/
function getFilledTplObj(str,obj){
function replacer() {
return obj[arguments[1]];
}
return str.replace(/{{([^}}]+)?}}/g, replacer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment