8 ms·
NPM package 'isarray' is downloaded 40M times a week
- bluetidepro 6y agohttps://github.com/juliangruber/isarray/issues/27 https://github.com/juliangruber/isarray/issues/27
- kzrdude 6y agoI have to say I think the implementation is very non-obvious, so I see the sense in shipping a canonical solution https://github.com/juliangruber/isarray/blob/master/index.js https://github.com/juliangruber/isarray/blob/master/index.js
- raspyberr 6y agoReading issue #27 on the github page really gives an insight into..something: https://github.com/juliangruber/isarray/issues/27 https://github.com/juliangruber/isarray/issues/27
- seattle_spring 6y agoThe biggest insight in that thread is how big of a jerk "PublicByte" is. I sure hope I never have th misfortune of working with that person or anyone like him.
- gonzo41 6y agoYeah that person really dialed things up to 11 there. But I think it's a tone that stems from a legitimacy thing with javascript having a super low barrier to entry.
- hn_throwaway_99 6y agoDid you actually read the function in this library. While yes it's a single line I'm convinced that anyone who thinks this is an "obvious" implementation hasn't actually read the code.
- gonzo41 6y agoActually I did read the function, and I thought about the cycles that toString.call(arr) == '[object Array]' costs.
- hn_throwaway_99 6y agoIs there some other implementation you think would work?
- seattle_spring 6y ago... which only gets called if the native implementation of `isArray` is not found.
- karmakaze 6y agoES5 is a low requirement. I'd rather use a lib that did a better job than one that returns true for the string '[object Array]' or have the app decide for itself what its own types are.
- amadeuspagel 6y agoYeah, github desperately needs moderation. Maintainers should be able to flag issues, and prevent people who more then x flags from filing issues.
- jchook 6y agoSome seriously relevant psychoanalysis of this behavior in this article (also on HN front page) about toxic workplaces: https://articles.tilt365.com/identify-destructive-leadership-patterns/ https://articles.tilt365.com/identify-destructive-leadership...
- disown 6y agoPlease use harrassment free language. You've broken a few comment rules. Can you review the community guidelines and refrain from breaking the rules? https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- burke 6y agoIt’s completely stupid that this kind of module gets used in the JavaScript ecosystem, but as the author points out, it’s not his fault, it’s downstream modules’ fault for actually using something so trivial. It’s deeply unfortunate that the lack of a standard library in JavaScript combined with the constraint of wanting to minimize shipped code size in a language that resisted dead code elimination for a long time led to... whatever this is, instead of a comprehensive stdlib.
- seattle_spring 6y agoDid you read the code? It is standard functionality, but only in newer Node versions and browsers. The linked package is basically a polyfill.
- wongarsu 6y agoIt is now, but it wasn't standard functionality back when this library was first published.
- aPoCoMiLogin 6y agofirst commit is from 2013 [0], first Node that had Array.isArray was 0.1.15 from 2009 [1], thus making is as Node module was pointless, but polyfill for browsers might have some sense. - [0] https://github.com/juliangruber/isarray/commit/c8601522e31366d0ce1bfd11818c4bb3ebd032a4 https://github.com/juliangruber/isarray/commit/c8601522e3136... - [1] https://github.com/nodejs/node-v0.x-archive/blob/v0.1.15/ChangeLog https://github.com/nodejs/node-v0.x-archive/blob/v0.1.15/Cha...
- hn_throwaway_99 6y agoPeople keep saying this is "so trivial", denigrating anyone who would use this, but I am convinced they haven't even looked at the "one line of code" they are denigrating. I've been a JS/Node dev for years now (granted, post a time when Array.isArray was part of the standard), and if someone asked me to write isArray, I wouldn't have done it like this, and I'm assuming there is a reason it was done like this. What I really see is a bunch of typical "I'm a cooler dev than you" posturing for people who haven't even actually looked at the code. That's a shame because there is a valid discussion to be had around how lots of teeny dependencies can make the npm ecosystem brittle, but bullshit posturing around how any dev should be able to write this one line is just false.
- Benjammer 6y agoI don't understand the mindset of "you did it wrong once, so you can't do it anymore, you must let me do it for you." Why is the fact that some devs sometimes screw up one-liners of any material importance to the existence of this library? Some devs write code with bugs, does that mean they shouldn't write code any more? Is it either you write pristine, bug-free code on the first try for everything, or else you should be relegated to the back room gluing things together built by the _real_ devs? This is such snooty behavior that I'm not surprised at all by a response like the angry dude in there. He's an asshole for sure, but he's not totally wrong in my view.
- falcolas 6y agoI’m with you. Some people occasionally forget semicolons, should we have a library for that too? “Wrap all your statements in this pre-processor function call (it’s just another line in your build pipeline) and we’ll take care of the semicolons for you.”
- dmitriid 6y ago1. This stems from JS having literally no stdlib or convenience functions to speak of. 2. Array.isArray was added to browsers in 2009-2011. The time when IE 6 was still alive and kicking. No idea when it was added to node 3. This package plugged a hole in the stdlib, so obviously people started using it 4. It does on thing, and does it well. Unix-way! 5. How is using it any different than having the same code in a 20000-line utils.js file that any project inevitably grows to have to plug holes in JS's libs?
- ilkkao 6y agoNative Array.isArray was added to IE9 and Chrome 5, meaning totally obsolete node v0.8 supports it. Hard to imagine who really needs the library in 2020. https://caniuse.com/?search=isArray https://caniuse.com/?search=isArray
- aPoCoMiLogin 6y agoArray.isArray has been implemented in 1.3.16 of V8 [0] which was used in node 0.1.15! [1] doubt that someone even is using that old node.js this to me looks like 3rd-party packages that were added very long ago and the code was never updated. - [0] https://chromium.googlesource.com/v8/v8/+/refs/tags/1.3.16 https://chromium.googlesource.com/v8/v8/+/refs/tags/1.3.16 - [1] https://github.com/nodejs/node-v0.x-archive/blob/v0.1.15/ChangeLog https://github.com/nodejs/node-v0.x-archive/blob/v0.1.15/Cha...
- whollacsek 6y agoFor the betterment of the npm ecosystem the company should step in and depreciate all these simple packages. Or take over the responsibility over them for security reasons.
- KaiserPro 6y agoThe problem is that there no real stdlib. Sure someone _could_ make a stdlib in npm, but it'd change everyweek.
- andrew_ 6y agoA stdlib wouldn't solve the problem for older environments because a stdlib would almost certainly be tied to engine versions.
- wongarsu 6y agoWhich company? Npm Inc? Github? Microsoft? Google? Mozilla? Each of those would cause an outroar, and it would be near-universally agreed that having a decentralized ecosystem is better than being beholden to the whims of $company. (it doesn't help that 3/5 of the companies I mentioned are Microsoft, famous for embrace-extend-extuinish)
- quaffapint 6y agoIn regards to his reply in issue 27...The bummer is you often don't know whether you use it or not. If I want to use react and react is using package x which depends on package y which depends on package z. Of course you could check your packages, but how many of us are really looking through all those minor dependencies.
- lhnz 6y agoIf you don't like that a package you're using depends on this via a dependency chain then you're free to PR into the respective upstream package to either inline this code or (in this case) to drop the support for an older version of Node (within a breaking change, if necessary). In general, you can always avoid picking packages with deep dependency chains. That seems like a good idea to me. Also, I think `isarray` is quite dated, but I can understand why people used to use it, since it is basically an explicit polyfill for non-browser environments.
- axiosgunnar 6y agoYou can think of these NPM micropackages as Github Gist snippets that you can programmatically link to your code. The first advantage to just copy-pasting is that the snippet author might update it (e.g. if he finds a faster/safer way to do the one thing his package does), and you don't have to do anything. Imagine finding a solution on Stackoverflow and just being able to import foo from stackoverflow/a/12345, and when the community finds a better way to do it, your software is automatically using the new version! The second advantage is that it's basically built-in refactoring: Code from these micropackages will not litter your code, there is a clean separation between what is your business logic vs where you just need some generic functionality.
- jen20 6y ago> The first advantage to just copy-pasting is that the snippet author might update it The first disadvantage of “micro packages” over copy-pasting is that the author might update it to do something completely different - either because the author is malicious, or because of a transfer in maintainership of the package to someone who is malicious, or because of a compromise.
- usefulcat 6y agoOr even without any malicious intent, simply because the functionality provided by the package is under/poorly specified.
- vbezhenar 6y ago> Imagine finding a solution on Stackoverflow and just being able to import foo from stackoverflow/a/12345, and when the community finds a better way to do it, your software is automatically using the new version! What a nightmare!
- spicybright 6y agoThe downside is, your code and your heavier libraries now have their dependencies changing constantly, which can lead to things breaking if either depend on specific behavior, or if the micro package author does something wrong. It's a trade off, although personally I've been bit by that enough to keep strict version numbers in my dependencies.
- andrew_ 6y agoSmall packages like this are key to easily/quickly building polyfill, backport, backcompat bundles for deployment in environments that are quite a bit behind in terms of language support. They still exist and they are still making people money. Having a stdlib in JavaScript would not preclude packages like this due to the afore mentioned legacy environments. NPM bashing is increasingly popular, and for folks that haven't had to utilize these tiny packages they probably do rightly seem superfluous. Are people abusing it? Probably. Is it being used where it doesn't need to be? Probably. Are there long-stable, rarely changed NPM packages created before `Array.isArray` was a thing, which have this as a transitive dependency? Definitely.
- Benjammer 6y agoThis argument makes a ton of sense to me. Why is this not how most people explain it, rather than "all developers are stupid and they mess up one-liners so we should write their software for them"? How it normally goes: A: why does this exist it's one line? B: people mess up one-liners all the time. A: those people are dumb and shouldn't be programmers How it should go: A: why does this exist, it's one line? B: it's not about that, it's used to easily/quickly compose with other similar functions into more complicated things like polyfill, backport, and backcompat bundles for deployment in environments that are quite a bit behind in terms of language support. A: oh, neat, thanks!
- marcus_holmes 6y agoIt's literally 5 lines of code. My question is always "why is this a dependency and not a Stack Overflow answer?" For anyone who imported this as a dependency, why didn't you copy-paste the five lines into your code? I'm genuinely curious.
- brightball 6y agoThis is always my question as well.
- slooonz 6y agoDo you also copy-paste the 36 lines of unit tests in your project ?
- amadeuspagel 6y agoI'm always glad when there's an npm package for something, no matter how small, and I don't have to sift through stackoverflow answers, particularly when something is hard to test, like browser support. 40 million people using a package is far better evidence then a few hundred people upvoting an answer.
- jamesgeck0 6y agoUntil the micropackage has a security vulnerability, and the secure version is a breaking change, and the vulnerable version is locked in deep in your dependency tree.
- amadeuspagel 6y agoRight, code that you copy from stackoverflow never has security vulnerabilities.
- usr1106 6y agoWhat does this tell us about the energy efficieny about the whole Javascript ecosystem? I am not in the position to make realistic estimates, but it sounds pretty wasteful. I have worked in mobile devices space and there you need to think about about energy efficiency to have your battery last. Shouldn't the server and Web guys need to do the same to save the planet? Not pointing to isarray in particular, but this looks like a tremendous overhead to get minimal functionality. Is isarray an exception we can ignore or a pattern that repeats in scale?
- eeZah7Ux 6y ago> What does this tell us about the energy efficieny about the whole Javascript ecosystem? Not to mention the exclusiveness: more than 3 billion people on this planet - have old computer and phones with limited RAM - ...and limited storage - ...and slow CPUs - have slow Internet access (even in "developed" countries if you are in low-density areas) - have traffic caps (same) - sometimes have intermittent Internet access - have unreliable or expensive electricity Reminder: this is not an inevitable problem. A lot of Linux distros run just fine on old hardware, and websites without cruft are still usable.
- jspash 6y agoDoes browserlist not help with packages like this in any way? Ie if you aren’t supporting IE6 or whatever, doesn’t something throw up a warning like “you probably don’t need this package”.
- ausjke 6y agowhy not make it into the standard js library without import/require at all
- jchook 6y agoPSA: make sure your Website has a strict Content Security Policy[1]. 1. https://medium.com/hackernoon/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8cb347c5b5 https://medium.com/hackernoon/im-harvesting-credit-card-numb...
- crtasm 6y ago> ...the following four lines of code will glide right through even the strictest content security policy. > (In an earlier iteration of this post I said that a solid content security policy would keep you (and I quote) “100% safe”. Unfortunately 130k people read that before I learned the above trick. So I guess the lesson there is that you can’t trust any thing or any one on the internet.) Though the approach only applied to Chrome, and the post is two years old so I don't know if it still works today?
- jmisavage 6y agoWow there are 492 packages that depend on this. My favorite is isNotArray which as you may guess is just !isArray(whatever); https://github.com/zlatinejc/isnotarray https://github.com/zlatinejc/isnotarray
- NiceWayToDoIT 6y agoOk, this is crazy, somewhat I can understand guy making this just as joke, but who are those 40 million who download it each week?! What is next each line on GitHub will become npm module?
- dagw 6y agoOver a quarter of those downloads seem to be due to a package called deep-equals (https://www.npmjs.com/package/deep-equal https://www.npmjs.com/package/deep-equal) having it as a dependency.