Skip to content

Instantly share code, notes, and snippets.

@urain39
Last active May 15, 2020 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urain39/eaf1b07215f7c2c2c2b9db2e1c3eca42 to your computer and use it in GitHub Desktop.
Save urain39/eaf1b07215f7c2c2c2b9db2e1c3eca42 to your computer and use it in GitHub Desktop.
if (typeof String.prototype.format !== "function") {
String.prototype.format = function (mappable, filter) {
var self = this;
return self.replace(/\{([0-9A-Za-z_$]+)\}/g, filter ?
function(_, key) { return filter(mappable[key]); }
:
function(_, key) { return mappable[key]; }
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment