Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Created November 1, 2017 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/59bacaee9c4209353e3b8b6ea37fa460 to your computer and use it in GitHub Desktop.
Save steveosoule/59bacaee9c4209353e3b8b6ea37fa460 to your computer and use it in GitHub Desktop.
Tweet Sized JavaScript Templating Engine
// http://mir.aculo.us/2011/03/09/little-helpers-a-tweet-sized-javascript-templating-engine/
function t(s,d){
for(var p in d)
s=s.replace(new RegExp('{'+p+'}','g'), d[p]);
return s;
}
t("Hello {who}! It's {time} ms since epoch.", { who: "JavaScript", time: Date.now });
// "Hello JavaScript! It's 1299680443046 ms since epoch."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment