Eliminating a tiny OSS dependency
Eliminating a tiny OSS dependency that can be actually implemented in a few lines of code
Last updated
Eliminating a tiny OSS dependency that can be actually implemented in a few lines of code
Last updated
This may be of limited applicability. As more cases are discovered, this maturity level will increase.
Do you know about the left-pad issue? In 2016, the left-pad library was suspended from npm, causing well-known libraries that depended on it to cease working. left-pad is a simple JavaScript library that only fills the left side of a string with a specified number of characters, or spaces if not specified. Excluding blank lines, it's a simple code with only about 10 lines.
There are many ideas to avoid reinventing the wheel, On the other hand, we must also pay attention to external code that can have a significant impact. If the provided code's scope is very limited, it might be better to contain it internally rather than depending on an external source.
Implementing a left-pad function can be done as shown below:
Exercise 1: Implement the left-pad function that takes the string, length, and character to pad with. The default character should be a space.
Exercise 2: Consider a scenario where multiple small external dependencies exist in a project. Identify a small utility function that can replace one such dependency and implement it.
Have you considered the trade-offs between using an external dependency and implementing the code yourself?
How might this pattern of eliminating tiny dependencies affect the maintainability of the code?
What principles or guidelines can be used to decide when to replace a tiny external dependency with an internal implementation?