[1]: https://zeronet.io
Here is my rendition. Mind you, this is mainly for IE as ES6 has a String.padStart method. I would also use Array(n).fill() but again, IE does not support it, so manual string appending is the sacrifice to make..
module.exports = function(str, len, ch) {
if (ch === undefined || ch === '') ch = ' ';
str += "";
len -= str.length;
len /= ch.length;
var pre = "";
while (--len >= 0) pre += ch;
return pre + str;
}