Tweet-sized templating engine
function t(s,d){
for(var p in d) s=s.replace(new RegExp('{'+p+'}','g'), typeof d[p][1]=='f' ? d[p]() : d[p]);
return s;
}
Usage
t("Hello {who}! It's {time} ms since epoch.", { who: "JavaScript", time: Date.now });
// "Hello JavaScript! It's 1299680443046 ms since epoch."
Written by 家儒
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Template
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#