Nodejs String Padding Left leftPad(l, c)

Here you can find the source of leftPad(l, c)

Method Source Code

String.prototype.leftPad = function (l, c) { 
   return new Array(l - this.length + 1).join(c || ' ') + this; 
}

Related

  1. padLeft(totalLength, value)
    String.prototype.padLeft = function (totalLength, value) {
      if (this.length >= totalLength)
        return this;
      var str = this;
      while (str.length < totalLength)
        str = value + str;
      return str;
    };
    
  2. padl(ch, len)
    'use strict';
    String.prototype.padl = function(ch, len) {
        var s = this;
        while (s.length < len) {
            s = ch + s;
        return s;
    };
    
  3. padl(ch, len)
    String.prototype.padl = function(ch, len) {
        var s = this;
        while (s.length < len) {
            s = ch + s;
        return s;
    };
    
  4. paddingLeft(paddingValue)
    String.prototype.paddingLeft = function(paddingValue)
      return String(paddingValue + this).slice(-paddingValue.length);
    };
    
  5. leftPad(character, totalLength)
    String.prototype.leftPad = function (character, totalLength) {
        var s = this;
        while (s.length < totalLength)
            s = character + s;
        return s;