Nodejs String Padding Left padLeft(character, length)

Here you can find the source of padLeft(character, length)

Method Source Code

'use strict';/*w w w  .j ava2s.  co  m*/

String.prototype.padLeft = function (character, length)  {
  return character.repeat(Math.max(0, length - this.length)) + this;
};

Related

  1. padLeft( pPadChar, pTotalLength )
    String.prototype.padLeft = function( pPadChar, pTotalLength )
      return ( pTotalLength <= this.length ) ? this :
        ( pPadChar + this ).padLeft(pPadChar, pTotalLength);
    };
    
  2. padLeft(c, length)
    String.prototype.padLeft = function(c, length) {
        var str = this;
        while (str.length < length)
            str = c + str;
        return str;
    function formatDuration (duration) {
        var totalSeconds = Math.floor(duration);
        var minutes = Math.floor(totalSeconds / 60);
    ...
    
  3. padLeft(ch, n)
    'use strict';
    String.prototype.padLeft = function(ch, n) {
      let myString = '';
      while(myString.length < n - this.length) {
        myString += ch;
      myString += this;
      return myString;
    };
    ...
    
  4. padLeft(ch, n)
    String.prototype.padLeft = function(ch, n) {
      if(this.length < n) {
        var diff = n - this.length;
        var tempArr = this.split('');
        var tmp;
        for(var i = 0; i < diff; i++) {
          tempArr.unshift(ch);
        tmp = tempArr.toString().replace(/,/g, '');
    ...
    
  5. padLeft(char, length)
    String.prototype.padLeft = function (char, length) {
        var len = this.length;
        if (len === 0) return '';
        var str = this;
        while (len < length) {
            str = char + str;
            len++;
        return str;
    ...
    
  6. padLeft(character, length)
    'use strict';
    String.prototype.padLeft = String.prototype.padLeft || function (character, length) {
      return character.repeat(Math.max(0, length - this.length)) + this;
    };
    
  7. padLeft(count, ch)
    String.prototype.padLeft = function(count, ch) {
         var char = ch || ' ';
         var result = new Array(count + 1).join(char);
         return result + this;
     };
    
  8. padLeft(count, character)
    String.prototype.padLeft = function (count, character) {
        if (typeof (character) === "undefined") character = " ";
        return this.length <= count ? Array(count + 1 - this.length).join(character) + this : this.toString();
    
  9. padLeft(count, character)
    String.prototype.padLeft  = function(count, character) {
        var result = "";
        if (character === undefined) {
            character = " ";
        count -= this.length;
        if (count < 0) {
            count = 0;
        var i;
        for (i = 0; i < count; i += 1) {
            result += character;
        result += this;
        return result;
    };