News for hackers. Stuff that matters.
Re:JavaScript Growing Pains: From 0 to 13,000 Dependencies by onion2k on Sunday June 14, 2020 @11:04AM (#23518171)
It's not just checking if the number is odd. It checks if the input is a number (modulus on a non-Number value returns a NaN in JS), if it's an integer (not strictly necessary I guess), and if it's within the bounds of JS's safe integer range (again, you'll get a NaN if the number is too big). If you want to make sure your code is safe those are sensible things to check.

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.

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.