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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#