Here you can find the source of format()
'use strict';/*from w ww .java 2 s. c om*/ String.prototype.format = function () { var args = arguments; var unkeyed_index = 0; return this.replace(/\{{1,2}(\w*)\}{1,2}/g, function (match, key) { if (match.indexOf('{{') !== -1) { // {{dont-replace}} return match.replace('{{', '{').replace('}}', '}'); } if (key === '') { // {} key = unkeyed_index; unkeyed_index++ } if (key == +key) { // {0} return args[key] !== 'undefined' ? args[key] : match; } else { // {named} for (var i = 0; i < args.length; i++) { if (typeof args[i] === 'object' && typeof args[i][key] !== 'undefined') { return args[i][key]; } } return match; } }.bind(this)); }; function v(val, def) { if (val == null || typeof val === 'undefined') return def; if (typeof val === 'object') return Object.keys(val).length ? val : def; return val || def; }
String.prototype.format = function() { var txt = this; var i = arguments.length; var replaceTokens = function(txt, key, value) { return txt.replace(new RegExp('\\{' + key + '\\}', 'gm'), value); }; if(i > 0 && typeof(arguments[0]) == "object") { for(var key in arguments[0]) { txt = replaceTokens(txt, key, arguments[0][key]); ...
String.prototype.format = function() { var s = this, i = arguments.length; while (i--) { s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]); return s; };
String.prototype.format=function(){ if(arguments.length==0) return this; var args=[], i=0; for(;i<arguments.length;i++) args[i]=arguments[i]; return this.replace(/\%[sSfdDTt\%]/g, function(m){ if(m=='%%') return '%'; var v=args.shift(); switch(m.substr(1,1)){ case 's': return v.toString(); ...
String.prototype.format=function(){ if(arguments.length==0) return this; var args=[], i=0; for(;i<arguments.length;i++) args[i]=arguments[i]; return this.replace(/\%[sSfdDTt\%]/g, function(m){ if(m=='%%') return '%'; var v=args.shift(); switch(m.substr(1,1)){ case 's': return v.toString(); ...
String.prototype.format = function (){ var values = [].slice.call(arguments, 0, arguments.length), idx, length = values.length, regex, str = this; if(str.match(/\{\d+\}/g).length !== length){ throw{ name: 'ArgumentMissMatch', ...
String.prototype.format = function() { var newStr = this, i = 0; while (/%s/.test(newStr)) { newStr = newStr.replace("%s", arguments[i++]) return newStr;
String.prototype.printf = function (obj) { var useArguments = false; var _arguments = arguments; var i = -1; if (typeof _arguments[0] == "string") { useArguments = true; if (obj instanceof Array || useArguments) { return this.replace(/\%s/g, ...
String.prototype.format = function () { 'use strict'; var newString = this; function replace(string, search, replacement) { return string.replace(new RegExp(search.replace('{', '\\{').replace('}', '\\}'), 'g'), replacement.toString()); if (arguments[0] !== 'undefined') { switch (typeof arguments[0]) { case 'object': ...
String.prototype.format = function() { var args = Array.prototype.slice.call(arguments); var str = this; return str.replace(/%s/g, function(match, index) { if (str.charAt(index-1) == "%") { return match; } else { return args.shift(); });