Nodejs String Format format()

Here you can find the source of format()

Method Source Code

String.prototype.format = function() {
  var args = arguments;
  return this.replace(/\{(\d+)\}/g, function(orig,num) {
    return typeof args[num] != 'undefined' ? args[num] : orig;
  });// w ww .  ja v a  2s  . c o  m
};

Related

  1. format()
    String.prototype.format = function () {
      var str = this;
      for ( var i = 0; i < arguments.length; i ++ ) {
        str = str.replace( '{' + i + '}', arguments[ i ] );
      return str;
    
  2. format()
    var testSuite = testSuite || {};
    String.prototype.format = function() {
        var formatted = this;
        for( var arg in arguments ) {
            formatted = formatted.replace("{" + arg + "}", arguments[arg]);
        return formatted;
    };
    var testSuite = function (tableResultId){
    ...
    
  3. format()
    String.prototype.format = String.prototype.format = function() {
      var s = this,
        i = arguments.length;
      while (i--) {
        s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
      return s;
    };
    
  4. format()
    define(function () {
        return {
            currentDate: function () {
                var date = new Date();
                var dd = date.getDate();
                var mm = date.getMonth() + 1;
                var yyyy = date.getFullYear();
                var hh = date.getHours();
                var MM = date.getMinutes();
    ...
    
  5. format()
    String.prototype.format = function () {
        var o = Array.prototype.slice.call(arguments);
        return this.replace(/{([^{}]*)}/g,
            function (match, capture) {
                var r = o[capture];
                return (typeof r === 'string' || typeof r === 'number') ? r : match;
        );
    };
    ...
    
  6. format()
    String.prototype.format = function() {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function(match, number) {
            return typeof args[number] != 'undefined' ? args[number] : match;
        });
    };
    
  7. format()
    String.prototype.format = function() {
      var placeholderREG = /\{(\d+)\}/g;
      var args = arguments;
      return this.replace(placeholderREG, function(holder, num) {
        return args[num];
      });
    
  8. format()
    String.prototype.format = function() {
      var formatted = this;
      for( var arg in arguments ) {
        formatted = formatted.replace("{" + arg + "}", arguments[arg]);
      return formatted;
    };
    function assert(condition, msg) {
      if (!condition) {
    ...
    
  9. format()
    'use strict';
    String.prototype.format = function () {
      var args = arguments;
      return this.replace(/\{(\d+)\}/g, function (m, n) {
        return args[n];
      });
    };
    String.prototype.escapeRegExp = function () {
      return this.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    ...