Pad String from left and right - Node.js String

Node.js examples for String:Padding

Description

Pad String from left and right

Demo Code

String.prototype.PadLeft = function (n, pad) {
    if (typeof pad === "undefined") { pad = "0"; }
    var t = '';
    if (n > this.length)
        for (var i = 0; i < n - this.length; i++)
            t += pad;//  w  ww  .jav  a2 s  .c o  m
    return t + this;
};
String.prototype.PadRight = function (n, pad) {
    var t = this;
    if (n > this.length)
        for (var i = 0; i < n - this.length; i++)
            t += pad;
    return t;
};

Related Tutorials