20 ms·
NPM – "is-even", 160k weekly downloads
- sethammons 5y agoThe entire package boils down to the following. I find it funny. 'use strict'; var isOdd = require('is-odd'); module.exports = function isEven(i) { return !isOdd(i); };
- maxbaines 5y agoYes and is-odd contains const isNumber = require('is-number'); module.exports = 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; };
- pibi 5y agoI love the fact that this small code is still wrong: var isOdd = require("is-odd"); console.log(isOdd([1])); // TRUE!!
- maxbaines 5y agoFor good measure is-number contains 'use strict'; module.exports = function(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; };
- deleted 5y ago[deleted]
- rahkiin 5y agoFor those wondering: num-num===0 is a check for NaN.
- afavour 5y agoSmart, but isNaN already exists… https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- Ajedi32 5y agoIt didn't at the time this library was created. I assume now that line only exists for backwards compatibility.
- jazzyjackson 5y agothis library uses the global isFinite, which actually you could just use instead of the whole function, since it does the string coercion and infinity check for you. Check out the compatibility table on MDN, Chrome Firefox and Safari version 1 all support it, so I'm pretty sure isNaN and isFinite were in the original spec.
- Ajedi32 5y agoSee the MDN section on "confusing special case behavior"[1] for why they probably didn't want to use the global version of isNaN. Number.isNaN handles those cases better but is not as widely supported. [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN#confusing_special-case_behavior https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- jazzyjackson 5y agoThanks for this, I had forgot that empty strings get coerced to 0... interesting choice.
- 5y ago
- deleted 5y ago[deleted]
- Ajedi32 5y agoSo in conclusion... maybe checking whether a number is even in JS isn't as trivial as everyone thought, and projects reusing that code was a good thing? Or are are all those extra checks unnecessary now that TypeScript exists and new functions like Number.isInteger have widespread browser support?
- hmrr 5y agoI think the assertion (sorry for the pun) is that JavaScript is a completely unholy creation and should be chucked off the edge of the disc. I can’t imagine trying to get some of our fintech business logic in there without arming a nuclear foot gun or ten. I would never sleep again without medication.
- mannerheim 5y agoIf so, the implementation of isEven isn't even right because it assumes anything that isn't an odd number is an even number.
- Ajedi32 5y agoNo, the code posted in this thread clearly indicates it will raise an exception in such cases.
- mannerheim 5y agoAh, that's right, never mind.
- runes 5y agoTypeScript can't help at all, it vanishes before the code runs.
- tinco 5y agoThat horrible realisation that because of its dependency on is-number, and all of its checks and pretty error messages I can imagine there's actually some valid use cases for this package. You can plug this right into a user input validation system and it would work perfect for production use cases in a way that num % 2 === 0 just wouldn't. Almost other use case for it though.. horrible. This package would be much better if it was in some sort of namespace that indicated it's for user input validation only.
- eurekin 5y agoImagine, if isOdd suddenly changed to: 'use strict'; var isEven = require('is-even'); module.exports = function isOdd(i) { return !isEven(i); };
- 2fast4you 5y agoYou joke, but: https://www.npmjs.com/package/is-uneven https://www.npmjs.com/package/is-uneven
- f00zz 5y agofunction isOdd(i) { return i > 0 && isEven(i - 1); } function isEven(i) { return i == 0 || isOdd(i - 1); }
- the_gipsy 5y agoI did it. https://www.npmjs.com/package/is-even-cyclic https://www.npmjs.com/package/is-even-cyclic has a cyclic dependency with https://www.npmjs.com/package/is-odd-cyclic https://www.npmjs.com/package/is-odd-cyclic.
- mbesto 5y agoAnd has 100% test code coverage. Brilliant.
- hahamrfunnyguy 5y agoWhy would you even use this?
- keeganjw 5y agoIt even has one dependency, package is-odd
- worik 5y agoWhy is that even a package? Hmmm... Why NPM? Why Node.js? I am staying well clear of this in any important infrastructure. I build test frame works out of Node.js (I had a set of bad choices) so I can get to know the thing. Made me hate it more. All the mistakes ever made in computing rolled into one convenient system. Do not use this in important infrastructure. It is very bad.
- mynameismon 5y agoDuring the week between 22nd and 28th Dec 2020, it shows a spike. Not an ordinary one, but more than 100x the regular figure! 19,960,098 downloads to be precise. Edit: whoops, 100x
- madacol 5y agoThe developer's most recent PR merged, with drama included https://github.com/jonschlinkert/cache-base/pull/23 https://github.com/jonschlinkert/cache-base/pull/23 I'm not sure what to think about this guy, but I think it's more guilty those packages that decide to depend on these dependencies rabbit holes and is also fault of the platform for not showing how deep the dependency-chain goes. We should focus more on improving how we choose dependencies
- runes 5y agoSome visualization on the package repo and in the CLIs would be excellent. Often when I run a dependency analyzer on a project I'm disgruntled. I think what that Schlinkert guy is doing is obviously grifting, so I don't have to speculate on his intentions to call him a grifter.
- beepbooptheory 5y agoThoughtful of the developer to add type defs.
- Turing_Machine 5y agoIts dependency, is-odd, has 431,198 weekly downloads.
- kps 5y ago`is-odd` seems overly complicated. Someone should put up a PR to simplify it to var isEven = require('is-even'); module.exports = function isOdd(i) { return !isEven(i); };
- Rickthedick 5y agoLOL and is-even(x) => x % 2 === 0 with a couple type checks... smh just check yourself?
- tyingq 5y agoNot a node person...is this, like, satire? >>is-even/package.json "dependencies": { "is-odd": "^0.1.2" },
- marlowe221 5y agoAlso, both packages are made by the same two guys
- Turing_Machine 5y agoSadly, no.
- Cthulhu_ 5y agoAnd the current repo's owner is "i-voted-for-trump"
- moray 5y agowhat happened between the 22 and 28 of December 2020? Almost 20 million downloads...
- Cycl0ps 5y agoChristmas?
- jamil7 5y agoAdvent of Code?
- emaginniss 5y agoSounds like a joke, but probably a lot of people got new computers and rebuilt their npm caches
- Grieving 5y ago2̶7̶ 2 dependencies, travis ci configured, fully tested and documented, even the readme depends on some external tool. github username is i-voted-for-trump. Looks like a joke that people actually started using. edit: Confused dependents with dependencies
- dgrin91 5y agoIn the about for the project it says > I created this in 2014, when I was learning how to program.
- uxp 5y agoIt would be one thing if it was _just_ a little demo utility used to showcase packaging and distribution of a trivial use case, however the creator of this has also created a number of packages which pull in these "demo" packages, like `handlebar-helpers`, which is again just these trivial function packages wrapped in handlebar decorators. Several of these utility and helper packages are then pulled into other packages and build tools and marketed as legitimate packages, effectively hiding and masking the "just a demo" labels of the root is-even, is-odd, is-number packages. When people like myself complain about the absurdity of NPM supply chain verification, this is what we're arguing against.
- 1_player 5y agoI'm not sure where are you seeing that username, but no, sadly it's not a joke.
- baal80spam 5y agoI see a missed opportunity for an "is-odd-or-even" package. /s
- jayd16 5y agoNo no no. You need to think about separation of concerns.
- moray 5y agoWell... https://www.npmjs.com/package/is-odd-or-even https://www.npmjs.com/package/is-odd-or-even that of course depends on is-odd and is-even.
- oftenwrong 5y agoThere's still room for an is-odd-and-even package.
- lloydatkinson 5y agoSo, who's going to be the person to find all these dumb packages and replace them with PR's to their dependents? Make PR's to repos using is-even, is-odd, etc with n % 2 == 0; etc?
- handrous 5y agoReplacing it with just that would be a bad idea, since (see upthread, where the code's posted) it also verifies that its argument is an integer, erroring if it's not. Some code out there might be relying on that functionality, and hell, type coercion might even do something crazy without those checks, turning erroring-bugs into data-corrupting bugs.
- dvtkrlbs 5y agoI did similiar to a repo using a npm package called empty-string. The whole library was basically this `module.exports.empty_string= ""`
- zamadatix 5y agoI went looking through the dependency chain of this for even more popular simple packages and picked a 4 million/month package that was calling is-number thinking it must be added to most of these as a joke/snuck it in and it turned out it was the original/main dev that added the dependency. So it seems the best case scenario of "fixing it by PR" is every PR request is accepted even though it was (at least sometimes) intentionally added by the main dev and this is done continuously and endlessly for this and every package like it (there seem to be hundreds of equally trivial packages that are popular) yet they problem will still continue to exist anyways. Not that there is anything wrong with greatly reducing the usage rate when we can just the real interesting problem presented with this package isn't literally the package itself it's troubles in the dependency ecosystem of NPM. All that said I'm going to try to tackle a handful after work, particularly of is-number which is about as many lines to import as define and unchanged for many years.
- lloydatkinson 5y agoDo share your progress!
- eunos 5y agoWhy can't NPM has something like Apache commons? There you can include all simple and fundamental functionality. Instead of having one package each like this.
- thrower123 5y agoWhy couldn't Javascript have ever built a halfway decent standard library? Much of the terribleness of the current programming environment could have been rectified if this fundamental failure had not been allowed to continue.
- goohle 5y agoBrowser is the standard library for JavaScript language.
- PeterisP 5y agoYes, but it's not a "halfway decent" standard library because it does not include so many basic things that would be expected to be in the standard library.
- throw_m239339 5y agoNo, browser API and web standards are not part of the Javascript language AKA ECMAScript, otherwise Node.js would be forced to implement them.
- chrisfinazzo 5y agoWe've been down this road before, and learned...nothing. https://www.davidhaney.io/npm-left-pad-have-we-forgotten-how-to-program/ https://www.davidhaney.io/npm-left-pad-have-we-forgotten-how... Stupid debates over a formatting tool - or in this case, a simple conditional - should tell you that something is seriously FUBAR in Javascriptland.
- toyg 5y agoI reckon the problem is simply that the bar for entry in that world is non-existent. Anybody can learn html and javascript in a couple of days, so there is no filter. It's a blessing and a curse. But yes, a JS stdlib would solve 95% of the joke-level problems with the ecosystem.
- globalise83 5y agoIronic that this post makes it to front page but an admission that any npm package published before 2020 may have been hacked gets no interest! https://news.ycombinator.com/item?id=29234098 https://news.ycombinator.com/item?id=29234098
- Nicksil 5y ago>Ironic that this post makes it to front page but an admission that any npm package published before 2020 may have been hacked gets no interest! https://news.ycombinator.com/item?id=29234098 https://news.ycombinator.com/item?id=29234098 Not ironic. That article's unfortunate and misleading title isn't nearly as eye-catching as one describing the true nature of its content; a deliberate decision.
- consumer451 5y agoYeah, it really deserves a re-post or admin bump.. this is just crazy. Does saying dang 3 times work?
- floatingatoll 5y agoThe only thing that works is emailing the mods using the footer Contact link. Everything else doesn't work.
- JohnWhigham 5y agoWhy doesn't the ECMAScript Committee tackle low-hanging bullshit like this?
- WorldMaker 5y agoBy teaching the modulus operator? This is a built in language feature if you understand basic math: numberYouWantToKnowIsEven % 2 == 0
- JohnWhigham 5y agoNo, by taking care of all the exception handling these packages do. It's why these stupid packages exist: because the standard library doesn't handle them.
- sesm 5y agoThis approach is called “garbage in - garbage out”. The idea is, you can add extra checks and sacrifice some performance. But if checks are built in there is no way to remove them, even if you don’t need them and they hurt performance. Clojure’s standard library uses “garbage in - garbage out” approach too.
- kazinator 5y ago> But if checks are built in there is no way to remove them Sure there is: you have a compiler which recognizes uses library functions and makes code generation decisions based on whatever information is available at the call site. And this is easier to do for built-in functions, whose definition you can assume from the spec. The simplest example is constant folding. If isEven is part of the language, a compiler can constant-fold isEven(0) to true even if no inline definition of it is visible.
- sesm 5y agoThat’s interesting. How does compiler know that some piece of code is a removable check?
- jeroenhd 5y agoHa, I remember this package. It's a dependency of a dependency of a dependency in several projects inside the company I work for. I think either React, Babel, or Webpack depended on it at some point in time. Nobody needs to write satire about the state of Javascript package management when people write (and use!) libraries like these.
- sulam 5y agoThe writing, okay, fine, dude was having some fun. Actually depending on it? Sigh.
- smt88 5y agoThis package certainly seems like satire. It has no actual implementation in it. Instead it depends on another npm package: `is-odd`. https://github.com/i-voted-for-trump/is-even/blob/master/package.json https://github.com/i-voted-for-trump/is-even/blob/master/pac...
- ratww 5y ago`is-odd` is made by the same developer. This was created to inflate NPM numbers.
- 3pt14159 5y agoThis is what I like about ruby. I search, I find, they have almost no downloads: https://rubygems.org/gems/is_odd/versions/0.1.1 https://rubygems.org/gems/is_odd/versions/0.1.1 https://rubygems.org/gems/is_even/versions/0.1.0 https://rubygems.org/gems/is_even/versions/0.1.0
- rezonant 5y agoIt is built into Ruby. 2.7.3 :003 > 1.odd? => true 2.7.3 :004 > 2.odd? => false 2.7.3 :005 > 1.even? => false 2.7.3 :006 > 2.even? => true 2.7.3 :007 >
- deleted 5y ago[deleted]
- PragmaticPulp 5y ago732K downloads per month. 722K of those downloads come from this package by the same authors: https://www.npmjs.com/package/handlebars-helpers-ncc https://www.npmjs.com/package/handlebars-helpers-ncc The handlebars-helpers-ncc package contains 130 different utility dependencies including a few actually useful things like functions to convert Markdown to HTML, but also some weirdly trivial packages like is-even. I suppose this was a brilliant way for the authors to generate staggeringly high NPM download counts for their packages: Repackage other people’s useful code into convenience functions and then include their own trivial package dependencies several layers deep to multiply their overall downloads count. I wonder how many jobs they’ve applied to while bragging about their millions of monthly NPM downloads.
- athenot 5y ago> Several years ago I switched careers from sales, marketing and consulting[1] The author's bio on his GitHub profile explains it: he's approaching development with a mindset of sales and marketing. It's also followed by his GitHub stats front and center. [1] https://github.com/jonschlinkert https://github.com/jonschlinkert
- crimper 5y agoansi-red, making the world a better place!
- shashashasha___ 5y agomaking the world a better place, one ascii color at a time
- phatfish 5y agoI think we know how he created more than "1000 open source projects". s/projects/functions
- deleted 5y ago[deleted]
- 5y ago
- penjelly 5y agoisEven is ridiculous but appears to be a joke so thats fine. isOdd being an actual dep is ridiculous and i dont think its a joke? edit: yeah is-odd seems to be a serious project. This is one of the first things people learn in a new language and we have a package for it? I guess its a teaching point? or maybe the author just wanted reputation..
- game_the0ry 5y agoThis is beautiful. From the github user's ("i-voted-for-trump") bio: > 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. I give this troll effort a score of 9/10. Well done - love the testing, readme, docs, continuous integration, etc. Honestly, this is better than most enterprise software I see. I might contribute for fun and lulz... EDIT - read some of the comments and there is some anger and confusion. Folks, this is a troll. Yes, npm and the JS ecosystem have some flaws, but let's not get bent out of shape.
- pizza234 5y ago> From the github user's ("i-voted-for-trump") bio: > EDIT - read some of the comments and there is some anger and confusion. Folks, this is a troll. Yes, npm and the JS ecosystem have some flaws, but let's not get bent out of shape. It doesn't look like so. The author is definitely creating some confusion with redirects, but the readme of his professional Github's account (https://github.com/jonschlinkert https://github.com/jonschlinkert) says: > Several years ago 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. [...] 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. You can help me to achieve my goals of changing the world through code, help me create better developer experiences, or just say thank you by sponsoring me on GitHub. He's asking for real money; he's definitely not a troll.
- gizdan 5y ago> From the github user's ("i-voted-for-trump") Well, his Twitter is on point. Anyway, I'm pretty sure it wasn't a joke originally. I recall him heavily defending it even after people trolled him for creating such a package.
- locallost 5y agohttps://github.com/i-voted-for-trump/ https://github.com/i-voted-for-trump/ > 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 > 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 https://github.com/micromatch/micromatch. I've done a few other things since: https://gith… https://xn--gith-tc7a
- lhorie 5y agohttps://www.npmjs.com/package/is-ci https://www.npmjs.com/package/is-ci tells you everything you need to know about where inflated download numbers comes from.
- deleted 5y ago[deleted]
- floatingatoll 5y agoSee also: I will pay you cash to delete your NPM module https://news.ycombinator.com/item?id=29240952 https://news.ycombinator.com/item?id=29240952
- johnsonap 5y agosomehow "is-odd" has even more https://news.ycombinator.com/item?id=29242598 https://news.ycombinator.com/item?id=29242598
- gzer0 5y agohttps://github.com/jonschlinkert https://github.com/jonschlinkert Interesting, 845 repositories by the user, and the vast majority of them are simple NPM modules such as this one. Has there been any recent instances of someone abusing simple NPM repos like this for malicious intent?
- jacomoRodriguez 5y agothis may no seem like an odd comment (please at least admire the pun), but generally I can see value in this. All this stuff is-even and is-number is doing to make sure that it is actually a number, throwing errors etc. pp. sure, I could do it myself, but I would probably miss half of the cases and would spend some time finding the right solutions for the other half. Why I should reinvent the wheel if someone already has, and that in a good and thought through way? Don't get me wrong, there are tons of needless packages on npm, but in this case I can see the value (ok, maybe the is-odd is one too much and !is-even would be enough) just to to trigger a bit more: Pretty sure a case manufacturer could develop it's own screws... but I think in most cases they just use what someone else provides...
- kevin_thibedeau 5y agoWhy would a computer language make working with integers needlessly difficult? This should have been standard functionality from day one.
- city41 5y agoJavaScript was hacked together extremely quickly and Eich almost certainly had no idea we'd be where we are today.
- city41 5y agoIn that case I'd argue use lodash: https://lodash.com/docs/4.17.15#isNumber https://lodash.com/docs/4.17.15#isNumber It's well respected, battle tested, and you can just pull in the functions you actually use. It doesn't have isEven, but it probably drew a good line there.
- feketegy 5y agoThere are two contributors to this package.
- rectang 5y agoAdding a package like this as a dependency is a net negative, because for the sake of trivial functionality you take on all the supply chain overhead and security risk. The culture of relying on small dependencies needs to adapt to account for security. It's one of many aspects of open source supply chain management due for a reckoning.
- comeonseriously 5y agoBut DAMMIT, developer productivity, man! But, honestly, do developers these days just not have their OWN libraries of code they bring along with them? Are they SO dependent on others they can't write trivial code?
- toyg 5y agoI reckon that centralized package management actually _reduced_ the amount of people relying on their own library of snippets. Why bother saving how you solved Problem A, when there is probably a package doing it better...?
- emodendroket 5y agoThis package in turn depends on is-odd.
- deleted 5y ago[deleted]
- cool-RR 5y agoThis package is useful if you can't even.
- undebuggable 5y agoThis package is for children who can't count good.
- dpweb 5y agoThese packages serve a very useful purpose in that they illustrate dependency abuse, but the fact isOdd DEPENDS ON isEven and isNumber is pretty funny.
- haolez 5y agoHow does your company protect itself against supply chain attacks on NPM? At my company, we try to keep dependencies at a minimum, but I doubt this is effective as a protective measure.
- yardstick 5y agoState exact versions and checksums of all deps plus run your own server hosting the deps and firewall it from accessing the internet at large. Only update deps when needed. This is what we have to do in our env.
- davidhariri 5y agoWho wants to make an is-not-uneven package with me?
- croes 5y agoSorry but I cannot take seriously any programmer who uses the package deliberately.
- squid_demon 5y agoWhich has a freaking DEPENDENCY on is-odd! Seriously?
- soheil 5y agoWhat's odd is that "is-odd" has 430k weekly downloads. https://www.npmjs.com/package/is-odd https://www.npmjs.com/package/is-odd
- listless 5y agoIf I ever have an interview where I can use this, I’m 100% doing it and I hope that people appreciate it as the social commentary that it is.
- deleted 5y ago[deleted]
- jilles 5y agoVarious boilerplate projects use "is-even" as a joke. It's meant to be removed from your package.json when you start your project.
- ratww 5y agoIndeed. Some of packages that depend on it seems to be "hello world" NPM modules created from boilerplate projects.
- maxpert 5y agoHilarious! It takes dependency on is-odd and just does a not (`!`).
- aledalgrande 5y agoThis issue of dependencies is exacerbated when a popular library has old and unmaintained dependencies 2-3 levels down that have security holes, and taking them out is a huge refactor. I hope the JS community is moving away from this model, and I think a good example of that is DayJS.
- thunderbong 5y agoThe code: 'use strict'; var isOdd = require('is-odd'); module.exports = function isEven(i) { return !isOdd(i); }; https://github.com/i-voted-for-trump/is-even/blob/master/index.js https://github.com/i-voted-for-trump/is-even/blob/master/ind...
- jillesvangurp 5y agoAnyone wants to take a bet that there are multiple packages called is-odd that depend on this one?
- Pensacola 5y agoFunniest thing about this is that is-even requires as a dependency another node package written by the same author, called "is-odd." the is-even code just returns !is-odd. The "is-odd" package actually contains the logic for determining if a number is odd or even.
- shashashasha___ 5y agowell, at least it gets an input and returns an output. what about this one https://www.npmjs.com/package/noop2 https://www.npmjs.com/package/noop2 it has almost 90k downloads a week
- aerojoe23 5y agoThe source requires is-odd... and then ! the call to it.
- claudiug 5y agothis remind me of the standarjs dude, that add some nice ads on logs, just because he want it. standajs, is a yml config file. that is all
- Rickthedick 5y agoThis is too funny. I had to investigate and saw that is-even(x) => return !is-odd(x). went to is-odd and found is-odd(x) => return x % 2 === 1. Crazy ass hell and I'm not sure why people would import bundles with junk in them that may be taking up space in the js file...