Nodejs String Padding Right padRight(count, character)

Here you can find the source of padRight(count, character)

Method Source Code

String.prototype.padRight = function(count, character) {
    character = character || ' ' ;
    return this.toString() + character.repeat(count);
};

Related

  1. padRight(count, ch)
    String.prototype.padRight = function(count, ch) {
        var char = ch || ' ';
        var result = new Array(count + 1).join(char);
        return this + result;
    };
    
  2. padRight(count, character)
    String.prototype.padRight = function (count, character) {
        if (typeof (character) === "undefined") character = " ";
        return this.length <= count ? this + Array(count + 1 - this.length).join(character) : this.toString();
    
  3. padRight(count, character)
    String.prototype.padRight = function(count, character) {
        var result = "" + this;
        if (character === undefined) {
            character = " ";
        count -= this.length;
        if (count < 0) {
            count = 0;
        var i;
        for (i = 0; i < count; i += 1) {
            result += character;
        return result;
    };
    
  4. padRight(count, character)
    String.prototype.padRight = function (count, character) {
        if (typeof (character) === "undefined") {
            character = " ";
        return this.length <= count ? this + Array(count + 1 - this.length).join(character) : this.toString();
    };
    
  5. padRight(count, character)
    String.prototype.padRight = function(count, character) {
      var ch = character || ' ';
      var result = this;
      for (var i = 0; i < count; i++) {
        result += ch;
      };
      return result;
    
  6. padRight(l,c)
    String.prototype.padRight = function(l,c) {
        var m = l;
        if(this.length > m) {
            m = ((this.length % m) + 1) * m;
        return this+Array(m-this.length+1).join(c||" ");
    };
    var str = 'TextMustBe16Bytes';
    console.log(
    ...
    
  7. padRight(max, c)
    if (!String.prototype.padRight) {
      String.prototype.padRight = function(max, c) {
        var self = this;
        return self + new Array(Math.max(0, max - self.length + 1)).join(c || ' ');
      };
    
  8. padRight(n, c)
    String.prototype.padRight = function(n, c) {
      var len = this.length;
      ch = c || ' ';
      if (n <= len) {
        return this;
      else {
        var s = this;
        for (var i=0; i < n - len; i++) {
    ...
    
  9. rpad(character, count)
    String.prototype.rpad = function(character, count) {
      var ch = character || "0";
      var cnt = count || 2;
      var s = "";
      while (s.length < (cnt - this.length)) { s += ch; }
      s = s.substring(0, cnt-this.length);
      return this+s;