Here you can find the source of format(format)
String.prototype.format = function (format) { const holders = JSON.parse(format), regex = new RegExp('(#{(\\w+)})', 'g'); let transformed = this,/*from w w w .java 2 s .c o m*/ currentMatch = ''; while ((currentMatch = regex.exec(this)) !== null) { transformed = transformed.replace(currentMatch[1], holders[currentMatch[2]]); } return transformed; } console.log("My name is #{name} and I am #{age}-years-old".format('{ "name": "John", "age": 13 }'));
String.prototype.format = function(args, index) { return this.replace(/{(\w+)}/g, function(match, number) { return typeof args[index[number]] != 'undefined' ? args[index[number]] : match ; }); };
String.prototype.format = function (ctx) { return this.replace(/\$\{([\w\.]+)\}/g, function(all, varname) { var keys = varname.split('.'); var val = null; for (var i = 0, len = keys.length; i < len; i++) { val = ctx[keys[i]]; return val; }); ...
String.prototype.format = function(data) { return this.replace(/{(.+?)}/g, function(match, name) { return data[name] || match; }); };
String.prototype.format = function(dict) { var result = this; if(typeof(dict) === "object") { Object.keys(dict).forEach(function(key) { result = result.replace("{" + key + "}", dict[key]); }); return result; var args = []; ...
String.prototype.format = function (fmt) { if (fmt==null) fmt = "yyyy-MM-dd"; var myDate = new Date(this); var o = { "M+": myDate.getMonth() + 1, "d+": myDate.getDate(), "h+": myDate.getHours(), "m+": myDate.getMinutes(), "s+": myDate.getSeconds(), ...
String.format = function (format) { var args = Array.prototype.slice.call(arguments, 1); return format.replace(/{(\d+)}/g, function (match, number) { return typeof args[number] != 'undefined' ? args[number] : match; }); }; String.prototype.format = function () { ...
String.prototype.format = function(i, safe, arg) { function format() { var str = this, len = arguments.length+1; for (i=0; i < len; arg = arguments[i++]) { safe = typeof arg === 'object' ? JSON.stringify(arg) : arg; str = str.replace(RegExp('\\{'+(i-1)+'\\}', 'g'), safe); return str; format.native = String.prototype.format; return format; }();
String.prototype.format = function(i, safe, arg) { function format() { var str = this, len = arguments.length+1; for (i=0; i < len; arg = arguments[i++]) { safe = typeof arg === 'object' ? JSON.stringify(arg) : arg; str = str.replace(RegExp('\\{'+(i-1)+'\\}', 'g'), safe); return str; format.native = String.prototype.format; return format; }();
String.prototype.format = function (o) { return this.replace(/{([^{}]*)}/g, function (a, b) { var r = o[b]; return typeof r === 'string' || typeof r === 'number' ? r : a; ); };