Created
March 19, 2016 01:36
-
-
Save GitHub30/a398ea72c62d52f9ec91 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
String.prototype.format = String.prototype.f = function(arg){ | |
var is_object = typeof arg === 'object', | |
keys = is_object ? Object.keys(arg) : (function(l){for(i=0,a=[];i<l;i++)a[i]=i;return a;})(arguments.length), | |
args = is_object ? arg : arguments; | |
return this.replace( new RegExp('\\{(keys)\\}'.replace('keys', keys.join('|')), '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