Nodejs String Format format()

Here you can find the source of format()

Method Source Code


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;
        }//from  www .  j a  v a 2 s  .  c  om
    );
};

Related

  1. format()
    String.prototype.format = function () {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function (match, number) {
            if (typeof args[number] != 'undefined') {
                return args[number];
            return "";
        });
    };
    ...
    
  2. format()
    String.prototype.format = function () {
      var str = this;
      for ( var i = 0; i < arguments.length; i ++ ) {
        str = str.replace( '{' + i + '}', arguments[ i ] );
      return str;
    
  3. 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){
    ...
    
  4. 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;
    };
    
  5. 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();
    ...
    
  6. format()
    String.prototype.format = function() {
      var args = arguments;
      return this.replace(/\{(\d+)\}/g, function(orig,num) {
        return typeof args[num] != 'undefined' ? args[num] : orig;
      });
    };
    
  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()
    String.prototype.format = function() {
      var placeholderREG = /\{(\d+)\}/g;
      var args = arguments;
      return this.replace(placeholderREG, function(holder, num) {
        return args[num];
      });
    
  9. 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) {
    ...