Nodejs String Padding Left padLeft(pad, len)

Here you can find the source of padLeft(pad, len)

Method Source Code

String.prototype.padLeft = function (pad, len)
{

   if (typeof(len) == "undefined") { var len = 0; }
   if (typeof(pad) == "undefined") { var pad = ' '; }

   if (len + 1 >= this.length)
   {/*ww w  .  j  a  v  a2 s .  c o  m*/
       str = Array(len + 1 - this.length).join(pad) + this;

   } // switch

    return str;
}

Related

  1. padLeft(count, character)
    String.prototype.padLeft = function(count, character) {
        character = character || ' ';
        return character.repeat(count) + this.toString();
    };
    
  2. padLeft(length, char)
    String.prototype.padLeft = function(length, char) {
      return Array(length - this.length + 1).join(char || " ") + this;
    };
    
  3. padLeft(max, c)
    if (!String.prototype.padLeft) {
      String.prototype.padLeft = function(max, c) {
        var self = this;
        return new Array(Math.max(0, max - self.length + 1)).join(c || ' ') + self;
      };
    
  4. padLeft(n, ch)
    String.prototype.padLeft = function(n, ch){
        var s = this;
        while(s.length < n){
            s = ch + s;
        return s;
    
  5. padLeft(n, str)
    String.prototype.padLeft = function(n, str) {
      return Array(n - String(this).length + 1).join(str || '0') + this;
    
  6. padLeft(padString,length)
    String.prototype.padLeft = function(padString,length){
        var str = this;
        while (str.length < length)
            str = padString + str;
        return str;
    
  7. padLeft(paddingValue)
    String.prototype.padLeft = function (paddingValue) {
      return String(paddingValue + this).slice(-paddingValue.length);
    };
    
  8. padLeft(size, char)
    String.prototype.padLeft = function (size, char) {
        if (size === 0) {
            return '';
        return (Array(size + 1).join(char) + this).slice(-size);
    };
    
  9. padLeft(size, prefix)
    (function(){
    String.prototype.padLeft = function(size, prefix) {
        prefix = prefix || " ";
        var s = ''+this;
        while (s.length < size) s = prefix + s;
        return s;
    };
    Math.randInt = function(min, max){
      return Math.floor(Math.random() * (max - min + 1)) + min;
    ...