NPM package is-even has over 140k weekly downloads
npmjs.com
npmjs.com
- is-is-even: checks if the passed function is is-even
- is-odd-or-even: determines if a given number is odd or even.
- is-ice-cream: Amazing lib to check if string contain your favorite ice cream flavor
Probably the main reason it has so many downloads is that it's imported as a module (rather than integrated as a constituent function) by the author's popular handlebars-helpers library of utility functions. Imagine if underscore.js were to separate out first() as its own module. Then you'd have a similar situation.
The absurdity of 140k weekly downloads is a result of CI/CD practices.
I'm probably in the minority here but I think npm and github should actively disallow (or atleast discourage by making it very uncomfortable) to re-download the same dependencies from the internet on every pull request.
num => typeof num === "number"
No joke.The beautiful journey seems to end there.
isNumber(x) && isString(x)
⇒ isNumber is better named “can-be-used-as-a-number”.Also, I don’t know JavaScript well enough, but https://www.npmjs.com/package/isnumber is different code from https://www.npmjs.com/package/is-number, but does it have different semantics?
(https://www.npmjs.com/package/lodash.isnumber is different, I think. It (rightfully, IMHO) thinks ∞ and NaN are numbers)
https://github.com/search?q=require%28%27is-odd%27%29&type=c...
> I created this in 2014, the year I learned how to program. All of the downloads are from an old version of https://github.com/micromatch/micromatch.
Takes me about 7 minutes at home to trigger 1 million fake downloads.
I want to use http2 to send less headers and be able to do that in less time.
Unless they apply some kind of filtering to discount requests from the same source. If each source address were to only count as a single download once per period and a period was 20 minutes, your million fake downloads if from a single source would be forced to not take 38 years rather than 7 minutes.
It would make sense but ALL the project counters would go down by a lot.
All of this is to say, instead of this being an indictment of the JS ecosystem and its programmers, its more indicative of a stdlib function that should exist but doesn't.
The simpler programming can be made to be, the better. I'm not going to die on the anti-modulo hill, I don't care that much about it. But I think it's silly to pretend that it's not overly complicated (even if only a little) for the task most commonly at hand.
Surely by now they would have recognised a need for some standard math packages and then created one and all the new projects should be using that and people would have migrated? Especially given how fast FE seems to move.
Instead they are content with pulling a thousand dependencies and an intractable dependency system.
isOdd = x => x % 2 === 1
...
It's one of those things that doesn't pop up all that often and never changes. I've looked through my whole codebase and there are 3 occurrences.Aside: I don't use Dart, but does that mean that you have to rely on each different type of iterable to implement these functions?
Also to address other posts in the thread, while I don't think this specific example is worth indicting JS developers over, I do think the culture of infinite dependencies common to JS developers is. This shouldn't be an entire additional dependency. Just implement the modulo operation, or as parent suggests, make a nicely named utility function that wraps the modulo operation. But when the culture strongly encourages downloading micro packages for every little thing, I can hardly blame them for adding this into the pile of yet more things they've downloaded.
On the whole I do agree with you about all this mess. The JS stdlib has a lot to answer for.
isOdd(-1) === false
(-1 % 2 === -1)
i-voted-for-trump
This is a joke. You'll only see this org if you are attempting to troll me about repositories I created when I was learning to program.
is-odd
Public archive I created this in 2014, the year I learned how to program. All of the downloads are from an old version of https://github.com/micromatch/micromatch.
I think it is worth putting this in its historic context. Most of this code was written at a nascent point in JS history where NPM packages could start to be shipped to the browser (i.e. the Browserify years). This was a pretty wild time but one of the concerns was about the amount of code being shipped to browsers (this is pre-tree shaking, which only really works with ESM). Additionally, the glaciation of the JS runtime and standard library at the time, alongside the NodeJS "Cambrian Expansion" of npm, meant lots of authors were working to build out packages that fixed these classes of deficiencies (another example being the now infamous left-pad). We saw the same thing about the same time in the PHP world with the MicroPHP manifest and Composer, and I believe there was cross-pollination of ideas between these two things.
It is also worth noting that a decent proportion of people entering into the JS world at this time were more traditional HTML/CSS designers, maybe with some backend experience, but usually not engineers with a strong programming background (my experience, mileage may vary).
Looking at the chain of dependencies, the underlying logic of `is-number` is both common enough and a big enough footgun for those particularly less experienced JS developers to warrant a module. And once you've got it, need to do something with it, and once you've got things depending on you, you can't take it down; and thus, a house of cards is built.
Lastly, I think its worth keeping in mind that this also tracks with an industry shift to GitHub and an explosion in MIT Licensing/sharing in a world untarnished by the kinds of supply-chain attacks a good deal of us are now rightly worried about. We take it for granted now, but GitHub was a huge change to the way FOSS happens, and that facilitated this kind of repo building (free hosting, free publishing to NPM, sharing culture etc).
[1]: https://www.npmjs.com/package/is-odd [2]: https://github.com/i-voted-for-trump/is-even/blob/585f8002bb...
And so this is a perfect abstraction to make something non- obvious obvious.
The real question is why this shouldn’t be part of the interpreter?
Yes the dependency on isOdd is needless, but is a red herring.
Most commenters here didn’t look deep enough, sadly.
isOdd coerces to a number using Math.abs, so the string checks in isNumber don't apply.
function isOdd(value) {
const n = Math.abs(value);
if (!isNumber(n)) {
throw new TypeError('expected a number');
}
if (!Number.isInteger(n)) {
throw new Error('expected an integer');
}
if (!Number.isSafeInteger(n)) {
throw new Error('value exceeds maximum safe integer');
}
return (n % 2) === 1;
}
function isNumber(num) {
if (typeof num === 'number') {
return num - num === 0;
}
if (typeof num === 'string' && num.trim() !== '') {
return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
}
return false;
}Even so: I'd much rather in my code have a function doing exactly this, rather then peppering it all through my code anyway.
"Several years ago, just before my 40th birthday, I switched careers from sales, marketing and consulting to learn how to program, with the goal of making the world a better place through code. Whether that means giving people access to information, the tools and technology to level the playing field with big corporations, or empowering people in impoverished regions to participate in the world economy.
To date, I've created more than 1,000 open source projects in an effort to reach my goal. Open source software takes a lot of time to create and maintain, and millions of projects now depend on my code. You can help me to achieve my goals of improving the world through code, help me create better developer experiences, or just say "thank you" by sponsoring me on GitHub. Any and all contributions are greatly appreciated."
What's worse is that it comes with a special generated readme page.
> I've created more than 1,000 open source projects in an effort to reach my goal. Open source software takes a lot of time to create and maintain, and millions of projects now depend on my code.
Having said which, if his intention was to use his skills in sales, marketing and consulting to achieve these results, he has certainly achieved it.
Ordering and showing dependent-downloads would be useful in security issues when wanting to contact package authors who have the largest exposure to an exploited package.
It was raised on npm’s feedback before, I don’t think they were interested in adding it.
EDIT: the bulk of downloads appear to be from handlebars-helpers
“isZero”
Which checks if a number is 0
“is”
Which just returns true for truthy values and false for falsely values