Nodejs Utililty Methods String Padding Left

List of utility methods to do String Padding Left

Description

The list of methods to do String Padding Left are organized into topic(s).

Method

padLeft(count, ch)
String.prototype.padLeft = function(count, ch) {
     var char = ch || ' ';
     var result = new Array(count + 1).join(char);
     return result + this;
 };
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();
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;
};
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();
};
padLeft(count, character)
String.prototype.padLeft = function(count, character) {
  var ch = character || ' ';
  var result = '';
  for (var i = 0; i < count; i++) {
    result += ch;
  };
  result += this;
  return result;
padLeft(count, character)
String.prototype.padLeft = function(count, character) {
    character = character || ' ';
    return character.repeat(count) + this.toString();
};
padLeft(length, char)
String.prototype.padLeft = function(length, char) {
  return Array(length - this.length + 1).join(char || " ") + this;
};
padLeft(max, c)
if (!String.prototype.padLeft) {
  String.prototype.padLeft = function(max, c) {
    var self = this;
    return new Array(Math.max(0, max - self.length + 1)).join(c || ' ') + self;
  };
padLeft(n, ch)
String.prototype.padLeft = function(n, ch){
    var s = this;
    while(s.length < n){
        s = ch + s;
    return s;
padLeft(n, str)
String.prototype.padLeft = function(n, str) {
  return Array(n - String(this).length + 1).join(str || '0') + this;