Last Updated: February 25, 2016
·
465
· kayue

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."