Nodejs String Padding Left padLeft(totalLength, value)

Here you can find the source of padLeft(totalLength, value)

Method Source Code

String.prototype.padLeft = function (totalLength, value) {
   if (this.length >= totalLength)
      return this;

   var str = this;
   while (str.length < totalLength)
      str = value + str;/*from ww  w.j av  a  2s.  c om*/
   return str;
};

Related

  1. padLeft(pad, len)
    String.prototype.padLeft = function (pad, len)
      if (typeof(len) == "undefined") { var len = 0; }
      if (typeof(pad) == "undefined") { var pad = ' '; }
      if (len + 1 >= this.length)
          str = Array(len + 1 - this.length).join(pad) + this;
        return str;
    ...
    
  2. padLeft(padString,length)
    String.prototype.padLeft = function(padString,length){
        var str = this;
        while (str.length < length)
            str = padString + str;
        return str;
    
  3. padLeft(paddingValue)
    String.prototype.padLeft = function (paddingValue) {
      return String(paddingValue + this).slice(-paddingValue.length);
    };
    
  4. padLeft(size, char)
    String.prototype.padLeft = function (size, char) {
        if (size === 0) {
            return '';
        return (Array(size + 1).join(char) + this).slice(-size);
    };
    
  5. 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;
    ...
    
  6. padl(ch, len)
    'use strict';
    String.prototype.padl = function(ch, len) {
        var s = this;
        while (s.length < len) {
            s = ch + s;
        return s;
    };
    
  7. padl(ch, len)
    String.prototype.padl = function(ch, len) {
        var s = this;
        while (s.length < len) {
            s = ch + s;
        return s;
    };
    
  8. paddingLeft(paddingValue)
    String.prototype.paddingLeft = function(paddingValue)
      return String(paddingValue + this).slice(-paddingValue.length);
    };
    
  9. leftPad(character, totalLength)
    String.prototype.leftPad = function (character, totalLength) {
        var s = this;
        while (s.length < totalLength)
            s = character + s;
        return s;