Nodejs String Padding Left padLeft( pPadChar, pTotalLength )

Here you can find the source of padLeft( pPadChar, pTotalLength )

Method Source Code

/**//www . j a v  a2  s .c  om
 * JS util functions. Mostly augmentations.
*/

/**
 * This function augments the native String object.
 * Returns a left-padded string. Leaves the original string intact.
 * First parameter is the padding character, and it is expected to be exactly 
 * one character long, but using longer paddings should work just as well.
 * Second parameter is the targeted total length of the padded string.
 */
String.prototype.padLeft = function( pPadChar, pTotalLength )
{
   return ( pTotalLength <= this.length ) ? this :
      ( pPadChar + this ).padLeft(pPadChar, pTotalLength);
};

Related

  1. lpad(padString, length)
    String.prototype.lpad = function(padString, length) {
      var str = this;
        while (str.length < length){
            str = padString + str;
        return str;
    
  2. lpad(padString, length)
    String.prototype.lpad = function(padString, length) {
      var str = this;
        while (str.length < length)
            str = padString + str;
        return str;
    
  3. lpad(pad_str, length)
    String.prototype.lpad = function(pad_str, length) {
      var str = this;
      while (str.length < length) str = pad_str + str;
      return str;
    
  4. padL(width, pad)
    String.repeat = function(chr, count) {
      var str = "";
      for (var x = 0; x < count; x++) {
        str += chr;
      return str;
    };
    String.prototype.padL = function(width, pad) {
      if (!width || width < 1)
    ...
    
  5. padLeft( length, padding )
    Math.TO_DEGREES = 180 / Math.PI;
    Math.TO_RADIANS = Math.PI / 180;
    String.prototype.padLeft = function( length, padding )
        return Array( length - this.length + 1 ).join( padding || '0' ) + this;
    };
    
  6. 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);
    ...
    
  7. 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;
    };
    ...
    
  8. 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, '');
    ...
    
  9. 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;
    ...