Left-pad
lastmod 2018-08-17created 2016-04-051 edits
Source code
here is the entire code of left-pad:
module.exports = leftpad;
function leftpad (str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) {
str = ch + str;
}
return str;
}
See also
Favorite site
- 11 lines of code that threw the internet into a panic (NPM, the left-pad incident)