Nodejs String Format format()

Here you can find the source of format()

Method Source Code

'use strict';//  w ww.  j ava2s . com

String.prototype.format = function () {
    var formatted = this,
        i;

    for (i = 0; i < arguments.length; i += 1) {
        formatted = formatted.replace("{" + i + "}", arguments[i]);
    }
    return formatted;
};

Related

  1. format()
    String.prototype.format = function() {
        var formatted = this;
        for (var i = 0; i < arguments.length; i++) {
            var regexp = new RegExp('%'+i, 'gi');
            formatted = formatted.replace(regexp, arguments[i]);
        return formatted;
    };
    
  2. format()
    String.prototype.format = function() {
        "use strict";
        var e = this.toString();
        if (!arguments.length) {
            return e;
        var t = typeof arguments[0],
            n = "string" == t || "number" == t ? Array.prototype.slice.call(arguments) : arguments[0];
        for (var i in n) {
    ...
    
  3. format()
    String.prototype.format = function() {
        var formatted = this;
        for (var i = 0; i < arguments.length; i++) {
            var regexp = new RegExp('\\{'+i+'\\}', 'gi');
            formatted = formatted.replace(regexp, arguments[i]);
        return formatted;
    };
    function pad(n) {
    ...
    
  4. format()
    String.prototype.format = function() { 
      s = this;
      if (arguments.length == 1 && arguments[0].constructor == Object) {
        for (var key in arguments[0]) {
          s = s.replace(new RegExp("\\{" + key + "\\}", "g"), arguments[0][key]);
      } else {
        for (var i = 0; i < arguments.length; i++) {
          s = s.replace(new RegExp("\\{" + (i+1) + "\\}", "g"), arguments[i]);
    ...
    
  5. format()
    String.prototype.format = function(){
      var args = arguments;
      return this.replace(/{(\d+)}/g, function(match, number){
        return typeof args[number] != 'undefined'
        ?args[number]
        :match;
      })
    function getUrlParam(name){
    ...
    
  6. format()
    String.prototype.format = function(){
      var ret = this.toString();
      for (var i = 0; i < arguments.length; i++) {
        ret = ret.replace("%s", arguments[i]);
      return ret;
    };
    
  7. format()
    String.prototype.format = function() {
        var newString = this;
        counter = 0;
        while (counter < arguments.length && newString.indexOf('{}') != -1) {
            newString = newString.replace('{}', arguments[counter++]);
        matches = newString.match(/{[0-9]+}/g);
        if (matches != null) {
            for (var i = 0; i < matches.length; i++) {
    ...
    
  8. format()
    String.prototype.format = function () {
        var txt = this;
        for (var i = 0; i < arguments.length; i++) {
            var exp = new RegExp('\\{' + (i) + '\\}', 'gm');
            txt = txt.replace(exp, arguments[i]);
        return txt;
    };
    if (!String.format) {
    ...
    
  9. format()
    function clearStorage() {
      localStorage.clear();
      setIcon();
    function setIcon() {
    String.prototype.format = function() {
      var formatted = this;
      for (var i = 0; i < arguments.length; i++) {
    ...