Nodejs Utililty Methods String Format

List of utility methods to do String Format

Description

The list of methods to do String Format are organized into topic(s).

Method

format()
String.prototype.format = function () {
    "use strict";
    var args = [].slice.call(arguments);
    return this.replace(/(\{\d+\})/g, function (a) {
        return args[+(a.substr(1, a.length - 2)) || 0];
    });
};
format()
String.prototype.format = function () {
  var args = arguments;
  if (args && args.length > 0) {
    return this.replace(/\{(\d+)\}/g, function (term, index) {
      return args[index] || '';
    });
  return this;
};
...
format()
String.prototype.format = String.prototype.f = function() {
    var s = this,
        i = arguments.length;
    while (i--) {
        s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
    return s;
};
format()
String.prototype.format = String.prototype.f = function () {
    var s = this,
        i = arguments.length;
    while (i--) {
        s = s.replace(new RegExp("\\{" + i + "\\}", "gm"), arguments[i]);
    return s;
};
format()
String.prototype.format = function() {
  var args = arguments;
  return this.replace(/\{\{|\}\}|\{(\d+)\}/g, function(m, n) {
    if (m == "{{") {
      return "{";
    if (m == "}}") {
      return "}";
    return args[n];
  });
};
format()
String.prototype.format = function () {  
    var str = this;   
    for(var i = 0, j = arguments.length; i < j; i++){  
        str = str.replace(new RegExp('\\{' + i +'\\}', 'g'), arguments[i]);  
    return str;  
format()
String.prototype.format = function() {
    var s = this,
        i = arguments.length;
    while (i--) {
        s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
    return s;
};
format()
String.prototype.format = function() {
  var args = arguments;
  return this.replace(/{(\d+)}/g, function(match, number) { 
    return typeof args[number] != 'undefined'
      ? args[number]
      : '{' + number + '}'
    ;
  });
};
...
format()
String.prototype.format = function () {
    var str = this;
    for (var i = 0; i < arguments.length; i++) {
        var reg = new RegExp("\\{" + i + "\\}", "gm");
        str = str.replace(reg, arguments[i]);
    return str;
};
format()
'use strict';
String.prototype.format = function () {
  let str = this;
  for (let i = 0; i < arguments.length; i++) {
    let reg = new RegExp("\\{" + i + "\\}", "gm");
    str = str.replace(reg, arguments[i]);
  return str;
};
...