Nodejs String Padding Left leftPad(character, totalLength)

Here you can find the source of leftPad(character, totalLength)

Method Source Code

/**/*from   w  w  w.ja  v  a 2s  .c  o  m*/
 * Padding character to string until it reaches given length
 */
String.prototype.leftPad = function (character, totalLength) {
    var s = this;
    while (s.length < totalLength)
        s = character + s;
    return s;
}

Related

  1. 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;
    ...
    
  2. 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;
    };
    
  3. padl(ch, len)
    'use strict';
    String.prototype.padl = function(ch, len) {
        var s = this;
        while (s.length < len) {
            s = ch + s;
        return s;
    };
    
  4. padl(ch, len)
    String.prototype.padl = function(ch, len) {
        var s = this;
        while (s.length < len) {
            s = ch + s;
        return s;
    };
    
  5. paddingLeft(paddingValue)
    String.prototype.paddingLeft = function(paddingValue)
      return String(paddingValue + this).slice(-paddingValue.length);
    };
    
  6. leftPad(l, c)
    String.prototype.leftPad = function (l, c) { 
      return new Array(l - this.length + 1).join(c || ' ') + this;