Skip to content

Instantly share code, notes, and snippets.

@KraigWalker
Created June 7, 2015 08:45
Show Gist options
  • Save KraigWalker/98748abf3502b83ad3d9 to your computer and use it in GitHub Desktop.
Save KraigWalker/98748abf3502b83ad3d9 to your computer and use it in GitHub Desktop.
Tweet Sized JavaScript Templating Library to Eliminate String Concatenation
// Props to Thomas Fuchs ;)
// usage:
// var options = {
// id: SiteLink
// href: https://kraigwalker.com
//}
// return t('<a href="{href}" id="{id}"></a>', options);
function t(s, d) {
for(var p in d)
s = s.replace(new RegExp('{' + p + '}', 'g'), d[p]);
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment