Nodejs String Format format()

Here you can find the source of format()

Method Source Code

"use strict";//w ww.  ja v a 2 s.c o m

String.prototype.format = function () {
    var args = arguments;

    return this.replace(/\{(\d+)\}/g, function () {
        return args[arguments[1]];
    });
};

Related

  1. format()
    String.prototype.format = function() {
        var pattern = /\{\d+\}/g;
        var args = arguments;
        return this.replace(pattern,function(capture){return args[capture.match(/\d+/)];});
    var getRandomInt = function(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    };
    
  2. format()
    String.prototype.format=function(){
      var args = arguments;
      return this.replace(/{(\d+)}/g, function(match, number){return typeof args[number] != 'undefined'?args[number]:match;});
    };
    
  3. format()
    String.prototype.format = function () {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function (match, number) {
            return args[number] != undefined
                ? args[number]
                : match;
        });
    };
    
  4. format()
    'use strict';
    String.prototype.format = function(){
        var args = arguments;
        return this.replace(/{(\d+)}/g, function(match, index){
            return args[index];
        });
    };
    module.exports = String;
    
  5. format()
    String.prototype.format = function() {
        var formatted = this;
        for (var arg in arguments) {
            formatted = formatted.replace("{" + arg + "}", arguments[arg]);
        return formatted;
    };
    $(document).on("click", "input.click-select", function(e) {
        $(e.target).select();
    ...
    
  6. format()
    String.prototype.format = function() {
      var pattern = /\{\d+\}/g;
      var args = arguments;
      return this.replace(pattern, function(capture){return args[capture.match(/\d+/)]});
    
  7. format()
    String.prototype.format = function () {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function (match, number) {
            return typeof args[number] != 'undefined'
                ? args[number]
                : match
                ;
        });
    };
    ...
    
  8. format()
    function $log(text, obj) {
      if (window.console && console.log) {
        console.log(text);
        if (obj) {
          console.log(obj);
    String.prototype.format = function () {
    ...
    
  9. format()
    String.prototype.format = function() {
      var args = [].slice.call(arguments);
      return this.replace(/%(\d+)/g, function(w, m) {
        var offset = parseInt(m) - 1;
        if (args[offset] != undefined) {
          return String(args[offset]);
        return w;
      });
    ...