Hacker News new | ask | show | jobs
by jrvxo 2554 days ago
https://www.npmjs.com/package/is-odd

is-odd 831,460 weekly downloads

5 comments

Even better is 'is-even'. It depends on 'is-odd' and this is the entire thing:

  var isOdd = require('is-odd');
  
  module.exports = function isEven(i) {
    return !isOdd(i);
  };
What does it return for zero?
(Thankfully?) it gets that right
Zero is even.
I don't know if it's happening here, but I suspect this has happened before:

1) write actually useful package, get 10k weekly downloads

2) split out 100 utility functions and use them as dependencies

3) magic - your packages now have ~1M weekly downloads. You are now a JS superstar.

My problem with these kinds of libraries is it’s not at all obvious how it behaves in edge cases, and they’re so simple I’d rather just implement it myself. Maybe I want it to throw an error, maybe I just want it to return false. Even the documentation doesn’t tell you what happens for non-integer values, you have to look at the source, at which point you may as well copy it into your own source tree.
It's very easy to flippantly go "why would you ever use that???", but I'm honestly wondering what is the actual justification for the use of such a package. I see it does some initial checking (which will take more lines in your own code to deal with), but I can't figure out why someone would actually use that.
This one year old reddit discussion [1] seems to indicate that the package was used in another, pretty popular and more complex, package by the same author. The dependency doesn't look current anymore but it might be downloads of previous versions.

As for justification and usage I couldn't tell you, apparently it was only used once in that whole codebase anyway (also according to that thread).

[1] https://www.reddit.com/r/programming/comments/886zji/why_has...

Even worse: it is only used one time in the entire code-base, and that one time was to check whether or not a value returned by the string length function was odd.

What.... why.... the only concievable point of a package like this is that at least it does the kind of type-checking needed to compensate for JavaScripts weak typing system, but why do you need to check the type of String.length?! Do you really think it's going to start spitting anything other than a positive integer? Fucking hell....

0 is not a positive number.
Fair enough, "non-negative integers" then.
is-odd's behavior is also extremely odd. It depends on "is-number" (why would this need a dependency to begin with?), which checks in the most bizarre way imaginable if the input number or string(??) is finite. is-number, and by extension is-odd, also doesn't support BigInts.

These projects seem to have been created and promoted just to boost the author's "npm score" / package count. These micro-modules must cause more problems than they solve.

To be fair, it is actually far from trivial to determine whether a value is a numeric value in JavaScript, and most all-in-one utility libraries (jQuery, Lodash, etc.) java something of similar functionality. If there is one function that needs its own NPM entry, this probably is.
This is the one I wanted to point out. At least it adds a few type checks.