Nodejs String Padding padding(val, len)

Here you can find the source of padding(val, len)

Method Source Code

String.prototype.padding = function (val, len) {
   var s = "";
   for (var i=0;i<len;i++)
      s+=val;/*  w ww  .ja  v  a  2 s  .  c om*/
   return s;
};

Related

  1. pad(n,left, str)
    String.prototype.pad = function (n,left, str) {
      var string = String(this).substr(0,n);
      var empty = Array(n-string.length+1).join(str||' ');
      return left ? empty + this : this + empty;
    
  2. pad(number, padChar)
    String.prototype.pad = function (number, padChar) {
        var toAddCount = Math.max(0, number - this.length + 1);
        padChar = padChar || '0';
        return new Array(toAddCount).join(padChar) + this;
    };
    
  3. pad(side, ch, maxLength)
    String.prototype.pad = function(side, ch, maxLength) {
      var padding = "";
      for(var i = this.length; i < maxLength; i++) {
        padding += ch;
      return (side === "left") ? (padding + this) : (this + padding);
    };
    
  4. pad(str, max)
    var pad = function (str, max) {
      str = str.toString();
      return str.length < max ? pad("0" + str, max) : str;
    
  5. pad(width, z)
    String.prototype.pad = function (width, z) {
        var n = this.substr(0);
        z = z || '0';
        var newval = n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
        return newval;
    };