-
-
Save KraigWalker/98748abf3502b83ad3d9 to your computer and use it in GitHub Desktop.
Tweet Sized JavaScript Templating Library to Eliminate String Concatenation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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