Here you can find the source of format(params)
String.prototype.format = function(params){ var formatted = this; var fn = function(key, value){ var regexp = new RegExp('\\{' + key + '\\}', 'gi'); formatted = formatted.replace(regexp, value); };//ww w.j ava2 s .co m if (typeof(params) == 'object') { for (var x in params) { fn(x, params[x]); } } else { for (var i = 0; i < arguments.length; i++) { fn(i, arguments[i]); } } return formatted; };
String.prototype.format = function(opts) { var option, regex, formatted = this; for (option in opts) { regex = new RegExp('#{' + option + '}', 'g'); formatted = formatted.replace(regex, opts[option]); return formatted; ...
String.prototype.format = function(opts) { var source = this, data = Array.prototype.slice.call(arguments, 0), toString = Object.prototype.toString; if (data.length) { data = data.length == 1 ? (opts !== null && (/\[object Array\]|\[object Object\]/.test(toString.call(opts))) ? opts : data) : data; return source.replace(/%\{(.+?)\}/g, function(match, key) { var replacer = data[key]; ...
String.prototype.format = function(param) { var formatted = this; for(i in param ){ var regexp = new RegExp('\\{'+i+'\\}', 'gi'); formatted = formatted.replace(regexp, param[i]); return formatted; };
var FORMAT_PARAMETER_PATTERN; FORMAT_PARAMETER_PATTERN = /\@\(([a-zA-Z](?:[a-zA-Z0-9_]*))\)/g; String.prototype.format = function(parameters) { var value; value = this.valueOf(); return value.replace(FORMAT_PARAMETER_PATTERN, function(match, name) { var _ref; return (_ref = parameters != null ? parameters[name] : void 0) != null ? _ref : "<>"; }); ...
String.prototype.format = function(params) { if (!params) {throw new Error('No arguments passed');} return this.replace(/\{([a-zA-Z0-9]+)\}/g, function() { var key = arguments[1]; if (params.hasOwnProperty(key)) { return params[key]; } else { return arguments[0]; }); };
String.prototype.format = function (params) { 'use strict'; var p, regex, result; result = this; for (p in params) { if (params.hasOwnProperty(p)) { regex = new RegExp('#{' + p + '}', 'g'); ...
String.prototype.format = function (params){ var reg = /{(\d+)}/gm; return this.replace(reg,function(match,name){ return params[~~name];} ); };
function ms_to_days(m) { return Math.floor(m / (86400 * 1000) + 0.5) function date_period_to_ms(dp) { var ym = dp.split('-', 2) return new Date(ym[0], parseInt(ym[1], 10) - 1, 1); Date.prototype.format = function (string) { string = string.replace(/%b/, I18n.t('date.abbr_month_names')[this.getMonth() + 1], 'g'); ...
String.prototype.format = function(substitutions) { return this.replace(/\{([A-Za-z0-9]+)\}/g, function(match, key) { return substitutions[key] !== undefined ? substitutions[key] : ''; }); };