module.exports = function leftpad (str, len, ch) { return Array(len).join(ch || ' ') + String(str); };
module.exports = function leftpad (str, len, ch) { return Array(Math.max(0, len - String(str).length)).join(ch || ' ') + String(str); };
http://jsperf.com/leftpadtesting
Repeat + slice is too
http://jsperf.com/leftpad
module.exports = function leftpad (str, len, ch) { str = String(str); if (ch === 0) { ch = '0'; } return Array(Math.max(0, len - str.length)).join(ch || ' ') + str; };
module.exports = function leftpad (str, len, ch) { return Array(len).join(ch || ' ') + String(str); };