npm i -g is-npm-free
# quickly check
is-npm-free my-package-name
# gets the latest names list to check against
is-npm-free my-package-name --refresh
The cli will exit with an error code if the name isn't free so it can be used in scripts.
Credits go to https://github.com/bconnorwhite/is-name-taken as this only packages that module as a simple cli.
MIT