Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
String.prototype.template
(function () {
String.prototype.template = function (param) {
function esc (c) { return '&#'+c.charCodeAt(0)+';'; };
var reg = new RegExp('[&"<>\']', 'g');
return this.replace(/\[%(.+?)%\]/g, function (arg1, key) {
return ((param[key] || '')+'').replace(reg, esc);
});
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment