The NPM ecosystem is cluttered with unnecessary packages like is-odd, is-even, is-number, and more. We donβt need this unnecessary clutter.
is-number
NPM package
The is-number
packageβan infamous package that simply checks if a value is a number or not.
Whatβs inside is-number
package?
I checked out the is-number package and hereβs what it actually does.
If only there were a built-in method to check if something is a number. Oh, wait⦠there is.
-
typeof num === βnumberβ: Verifies that num is of the type βnumberβ. This excludes other data types like strings, objects, etc.
-
Number.isFinite(num): Ensures that num is a finite number, meaning it is not NaN, Infinity, or -Infinity.
Infinity, -Infinity, and NaN are all considered numbers in JavaScript, so typeof returns βnumberβ for each of them. Thus, these statements are true.
While typeof returns true for each of these values, Number.isFinite returns false because Infinity, -Infinity, and NaN are not finite numbers. Therefore, the combined expressions using && evaluate to false.
Both 5 and -5 are valid, finite numbers, so both expressions are true.
Moving back to rubbish packages. How on earth does is-number have 68,049,915 weekly downloads?
I guess itβs likely because is-number is a dependency for many popular libraries and frameworks. Even if youβre not using it directly, it could be included in your project through another package that relies on it.
left-pad package
In 2016, the left-pad package was unexpectedly removed from the npm registry, causing widespread disruption in the JavaScript ecosystem.
Many projects depended on this tiny package for a simple string padding function.
Its removal led to broken builds and errors in numerous projects, highlighting the risks of relying on overly granular or unnecessary dependencies.
The incident underscored the importance of using native functionality whenever possible to avoid such issues. See the left-pad incident wikipedia page.
Since String.prototype.padStart is a standard part of modern JavaScript, thereβs no need to rely on an additional package for this.
eslint-plugin-depend
This ESLint plugin detects redundant packages and suggests more efficient alternatives.
Would trigger a notification inside the code editor/IDE
Installing
eslint.config.js
You may choose a preset list of dependencies (or none). The following are available:
- microutilities: micro utilities (e.g. one liners)
- native: redundant packages with native equivalents
- preferred: an opinionated list of packages with better maintained and lighter alternatives
The default is [βnativeβ, βmicroutilitiesβ, βpreferredβ].
modules: You may specify your own list of packages which will be disallowed in code.
Putting it together
Trim the fat, clear out the clutter, and let your code breathe. Your users will thank you for it.