Skip to content

Instantly share code, notes, and snippets.

@GitHub30
Created March 19, 2016 14:51
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 GitHub30/7bd0dacddf4ffb0b00ac to your computer and use it in GitHub Desktop.
Save GitHub30/7bd0dacddf4ffb0b00ac to your computer and use it in GitHub Desktop.
String.prototype.f = function(arg){
var args = typeof arg === 'object' ? arg : arguments,
keys = Object.keys(args).map(function(s){return s.replace(/\\|\(|\)|\|/g,'\\$&');}).join('|');
return this.replace(new RegExp('\\{('+keys+')\\}', 'gm'), function(match, key){return args[key];});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment