Nodejs String Format format()

Here you can find the source of format()

Method Source Code

String.prototype.format = function() {
  a = this;/*  www  .  ja v  a 2 s  .  c om*/
  for (k in arguments) {
    a = a.replace("{" + k + "}", arguments[k]);
  }
  return a;
};

Related

  1. format( formatString)
    Date.prototype.format = function ( formatString) {
      var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
      var yyyy = this.getFullYear();
      var yy = yyyy.toString().substring(2);
      var m = this.getMonth();
      var mm = m < 10 ? "0" + m : m;
      var mmm = months[m];
      var d = this.getDate();
      var dd = d < 10 ? "0" + d : d;
    ...
    
  2. format()
    String.format = function() {
      var s = arguments[0];
      for (var i = 0; i < arguments.length - 1; i++) {       
        var reg = new RegExp("\\{" + i + "\\}", "gm");             
        s = s.replace(reg, arguments[i + 1]);
      return s;
    
  3. format()
    String.prototype.format = function() {
        var args = arguments;
        return this.replace(/\{(\d+)\}/g, function (m, n) { return args[n]; });
    };
    
  4. format()
    String.prototype.format=function(){
      var a=arguments;
      return this.replace(/\{(\d+)\}/g,function(b,c){return a[c]})
    };
    
  5. format()
    String.prototype.format = function() {
      var args = arguments;
      return this.replace(/{(\d{1})}/g, function() {
        return new String(args[arguments[1]]);
      });
    };
    
  6. format()
    String.prototype.format=function(){
      if(0==arguments.length)
         return this;
      var t=arguments;
      return this.replace(/\{(\d+)\}/g,function(r,n){
         return void 0===t[n]?"{"+n+"}":t[n]})
    };
    
  7. format()
    String.prototype.format = function() {
        var newStr = this, i = 0;
        while (/%s/.test(newStr))
            newStr = newStr.replace("%s", arguments[i++])
        return newStr;
    
  8. format()
    String.prototype.format = function() {
        var args = arguments;
        return this.replace(/\{(\d+)\}/g, function() {
            return args[arguments[1]];
        });
    };