Here's a little addition to JS's String type to be able to pad it just like in PHP

String.prototype.pad = function(character, length, after) {
    var ret = this;

    while (ret.length < length) {
        ret = (after ? ret + character : character + ret);
    }

    return ret;
}