-
-
Save amackworth/961760 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function t(s,d,p){for(p in d)s=s.replace(new RegExp('{'+p+'}','g'),d[p]);return s;} | |
| /* | |
| String templating engine: | |
| t("Hello {name}!, It is {date}!", { name: "Thomas", date: function(){ return new Date }}); | |
| // = "Hello Thomas!, It is Sun May 08 2011 15:15:33 GMT-0400 (EDT)!" | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment