Re:JavaScript Growing Pains: From 0 to 13,000 Dependencies
by berkes on Sunday June 14, 2020 @11:45AM
(#23518518)
The obvious solution would be to have some stdlib or even a common-utils project or something like it, which contain all such items. In one package.
Because, indeed, no-one should be rewriting obvious code like isArray, leftPad, isEven and so on.
Yes, that might cause some overhead in some situations (when you need isOdd, but not leftPad). But I'm certain that overhead is minimal. In practice, however, we currently see dependency-trees where these "should-be-stdlib" modules like "leftPad" or "isArray" are repeated numerous times in one project.
Any stdlib could even be optimized by browsers and engines, turning that "overhead" into a net benefit.
Re:JavaScript Growing Pains: From 0 to 13,000 Dependencies
by eeereerews on Sunday June 14, 2020 @01:47PM
(#23519660)
It doesn't.
isOdd('') => false
isOdd(null) => false
isOdd(2n) => TypeError: Cannot convert a BigInt value to a number
But even if it did, the same line of reasoning leads to the absurd conclusion we should have an addOne function.
A lot of JS devs wouldn't bother check those things, so really a lot of code is improved by this library. It's kind of a shame that so many developers just skip over checking inputs really. That's the real problem.