Remove left-pad
This codemod transforms code using the left-pad
package to instead use the native JavaScript method String.prototype.padStart().
The infamous "left-pad incident" occurred when the left-pad
package, a very small utility that simply left-padded strings, was removed from npm, causing many projects that depended on it to break.
Since then, native JavaScript has introduced String.prototype.padStart()
, which fulfills the same purpose without requiring an external dependency.
For more information on the incident, you can refer to this article.
Before
The code may look something like this when using left-pad
:
import leftPad from 'left-pad'; const str = 'hello'; const paddedStr = leftPad(str, 10, ' ');
After
After applying this codemod, the code will use padStart
, eliminating the need for left-pad
:
const str = 'hello'; const paddedStr = str.padStart(10, ' ');
This transformation not only reduces dependencies but also makes the code cleaner by using a built-in JavaScript method.