Nodejs Number Format Pad padLeft(n, str)

Here you can find the source of padLeft(n, str)

Method Source Code

Number.prototype.padLeft = function(n, str) {
    return Array(n-String(this).length+1).join(str||'0')+this;
};

Related

  1. padLeft(base, chr)
    Number.prototype.padLeft = function (base, chr) {
        var len = (String(base || 10).length - String(this).length) + 1;
        return len > 0 ? new Array(len).join(chr || '0') + this : this;
    function formatDate(d) {
        return [(d.getFullYear()).padLeft(),
                (d.getMonth() + 1).padLeft(),
                d.getDate().padLeft()].join('-') +
            ' ' +
    ...
    
  2. padLeft(base, chr)
    Number.prototype.padLeft = function (base, chr) {
        var len = (String(base || 10).length - String(this).length) + 1;
        return len > 0 ? new Array (len).join(chr || '0') + this : this;
    };
    Array.prototype.compare = function (array) {
        if (!array)
            return false;
        if (this.length != array.length)
            return false;
    ...
    
  3. padLeft(base, chr)
    Number.prototype.padLeft = function (base, chr) {
        var len = (String(base || 10).length - String(this).length) + 1;
        return len > 0 ? new Array(len).join(chr || '0') + this : this;
    };
    
  4. padLeft(base,chr)
    Number.prototype.padLeft = function(base,chr) {
      var len = (String(base || 10).length - String(this).length)+1;
      return len > 0? new Array(len).join(chr || '0')+this : this;
    };
    
  5. padLeft(max, c)
    Number.prototype.padLeft = function(max, c) {
      return this.toString().padLeft(max, c || '0');
    };
    
  6. padRight(max, c)
    Number.prototype.padRight = function(max, c) {
      return this.toString().padRight(max, c || '0');
    };
    
  7. padWithDigits(n)
    Number.prototype.padWithDigits = function (n) {  
      var txt = this.toString();
      while(txt.length < n) {
        txt = '0' + txt;
      return txt;  
    };
    
  8. padZeros(n)
    Number.prototype.padZeros = function(n){
      return this.toString().padZeros(n);
    };
    
  9. pad(length)
    Number.prototype.pad = function pad(length) {
      var str = '' + this;
      while (str.length < length) {
        str = '0' + str;
      return str;
    };