left-pad
Replacing left-pad leftPad()
Vanilla JavaScript
const leftPad = (str, len, ch = ' ') => String(str).padStart(len, ch);
// Usage:
// leftPad("5", 3, "0"); // "005"
Why Use This?
The famous `left-pad` incident broke the internet when the author removed it from NPM because it cascaded and broke thousands of modules. Since ES2017, JavaScript natively provides `padStart` and `padEnd` directly on the String prototype!