Personally I feel that dragging in a library just for a single function is a bad decision overall. It is not elegant and often causes problems with maintanance later on.
However... I must be wrong on this because I see so many Javascript developers drag in all sorts of crazy dependencies for doing extremely simple tasks. I am sure you have already seen the word "JQuery" pop up many many times on help forums.
Hey, JQuery is usually a good choice, because it provides you with a lot of functionality that you're probably going to use later. It's a bit like seeing someone struggle with text manipulation using char*, and telling them to use std::string instead. They may not really need everything that std::string provides, but you may as well have it.
But Javascript developers do far worse things than that - you may have heard of the left-pad incident where someone removed a trivial library from the NPM package manager, one that adds a few spaces to the left side of a string to make it up to a certain length, and tons of important software was immediately broken because they depended on it indirectly.
However, this is not really an argument against using 3rd party libraries - it's an argument against:
- deploying software by relying on every user having access to collaborative package managers
- installing packages by name and expecting them to never be revoked, replaced, or moved
- hiding a dependency's dependencies from the user
- making your standard libraries so anaemic that you can't do much without pulling in 3rd party code or reinventing your own wheels
- etc.
If a library does what you want, has already been tried and tested, and doesn't harm you or your users in some way (e.g. increased download times, difficulty of maintenance, security risks), then it's almost always more sensible to use it than to roll your own alternative.