At one end are single-function npm libraries that led to the left-pad fiasco[1].
At another end are things that you should only be implementing yourself in highly unusual circumstances, such as cryptography libraries.
Where on this spectrum do you usually implement the thing yourself, and what is your thought process?
What are the costs of importing a library, and how are those costs different for different projects? Are there security risks? What are the benefits?
Conversely, what are the costs and benefits of implementing something in-house?
Has there ever been a case where you've tried to roll your own and it ended in disaster? Or where you'd wished you'd never added a dependency on some library?
[1] https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
1. It is still alive
2. It is on GitHub so I can easily read the source and look for issues
3. People star it
4. It has traction ie >10k downloads preferably >50k
5. It occupies a name that makes sense ie I’d rather trust using “redux-immutable” than “steel-porcupine”, since it unofficially lends itself to the “vetted one true solution”
6. Then I look at the source quickly and make sure it looks well done under the hood
7. Finally, if it’s particularly confusing, I might run a quick google check to see if there’s blogs about it on the internet explaining how to use the advanced features and check the date on the blogs (1-2 years ago = good, it’s mature)
If any of the above are too dicey and there’s no good options, I put the relevant code in a top level folder called “modules” (or otherwise) with the intention that in the future I might get to delete it if the package ecosystem gets more mature in that space. Sometimes I even get to polish those files up and actually publish them.