> I get "trying to stay vanilla", but any reasonably-common snippet should either be installed from npm or published there.
And that's how you end up with the joke that was left-pad and the broken internet that resulted when the author yanked it.
Dependencies represent a real risk to your product. If it is actually a simple snippet, you shouldn't take that as an NPM dependency - the risk/reward ratio is just way out of whack with that.
NPM disallowed un-publishing modules within a few days of that incident. It's not a thing that happens any more. Also, NPM for years has defaulted to creating lockfiles with all the specific versions of dependencies pinned, so even if a dependency gets updated to have a bug, you will stay on the currently-pinned version unless you specifically change that.
But anyway whether or not the module is un-published doesn't really matter. The module could also just become malicious. Ownership changes, quality of code changes, etc... If you're pinning with lockfiles you're basically back to copy/pasting or checking in a clone of an upstream repo - the maintenance burden shifts back to you at that point. You still then have to manually go update, and remember to do that, or you become just as easily obsolete as the copy/pasted snippet.
There are downsides to use package libraries as well. Like: 200mb hello world applications, or some companies restrict npm packages for security reasons.
Or, you just want to write code in notepad.exe. There is benefit to simplicity in many cases.
It's up to you to chose reasonable modules by reasonable developers. Notice I didn't call it a library, it's a 1kb module that has the code from the example + fixes you'd want anyway.
What overhead? You don’t run any optimization step on your code? I haven’t seen a single front end project without package.json in years in all the companies I consulted for, and I don’t even deal with fancy frameworks.
https://htmldom.dev/copy-text-to-the-clipboard
I get "trying to stay vanilla", but any reasonably-common snippet should either be installed from npm or published there.
For this specific issue there's a module named almost exactly the same and it restores the previous selection and focus as well: https://github.com/sindresorhus/copy-text-to-clipboard/blob/...
This is the point of published modules: your code isn't stuck into the version someone wrote in 10 minutes 5 years ago.