2

I would like to search for, e.g. 'carousel' and exclude results with 'react' in them. I have tried:

carousel -react

and

carousel NOT react

But this still turns up results with 'react' in them. How can I exclude search terms on npm?

mikemaccana
  • 110,530
  • 99
  • 389
  • 494

4 Answers4

2

How can I exclude search terms on npm?

If you are asking about NPM search in the shell I think the only way to exclude words is by using a search regex Here is an excerpt from the NPM Search documentation:

If a term starts with /, then it's interpreted as a regular expression. A trailing / will be ignored in this case. (Note that many regular expression characters must be escaped or quoted in most shells.)

A very simple example of regex search is:

npm search /carousel/

Implementing the actual regex to exclude react is outside the scope of this question and it would involve creating a negative lookahead/lookbehind regex expression.

Faris Zacina
  • 14,056
  • 7
  • 62
  • 75
1

I don't know if you want to do it specificly using npm, but you can also pipe it with grep:

npm search carousel | grep -v -i react

potato
  • 471
  • 2
  • 13
1

I gave up on grep and used google:

site:www.npmjs.com react camera -native

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
chaserino
  • 154
  • 2
  • 4
1

Try this:

keywords:carousel,-react

https://www.npmjs.com/search?q=keywords%3Acarousel%2C-react

The downside is that it looks for the keywords aka. tags, so it requires that the authors have added carousel as a tag.

You can potentially expand your search a bit to all packages with "carousel" anywhere in their text, but which has not got a react keyword/tag:

carousel keywords:-react

https://www.npmjs.com/search?q=carousel%20keywords%3A-react

For more search commands, see:

https://stackoverflow.com/a/70463885/380607

Magne
  • 16,401
  • 10
  • 68
  • 88