npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@npms/queries

v3.0.0

Published

Module that offers a variety of queries around npms data

Downloads

2,291

Readme

@npms/queries

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

Module that offers a variety of queries around npms data.

Installation

$ npm install @npms/queries

Usage

For now, only queries related to search are available. Though, the goal of this module is to provide other interesting queries in the near future, such as top ranked modules, top authors, etc.

.search(q, esClient, [options]) -> Promise

Performs a search query.

Besides normal text, q supports qualifiers to express filters and other modifiers. The esClient accepts a elasticsearch instance or a config to instantiate it.

You may read the API docs to know which qualifiers are available.

const queries = require('@npms/queries');

// ...
queries.search('test framework', esClient)
.then((res) => {
    console.log('total', res.total);
    console.log('results', res.results);
});

Available options:

  • from: The offset in which to start searching from, defaults to 0
  • size: The total number of results to return, defaults to 25
  • throwOnInvalid: Whether to reject the promise if the query has invalid qualifiers or not, defaults to false (if false, invalid qualifiers will be removed from q)

.search.suggestions(q, esClient, [options]) -> Promise

Fetch search suggestions to be typically displayed when doing autocomplete.

Only normal text is supported in q but any qualifiers will be automatically discarded. The esClient accepts a elasticsearch instance or a config to instantiate it.

const queries = require('@npms/queries');

// ...
queries.search.suggestions('gulp', esClient)
.then((suggestions) => console.log('suggestions', suggestions));

Available options:

  • boostExact: How much should the score of exact matches be boosted? defaults to 100000.
  • size: The total number of results to return, defaults to 25
  • analyzerWeight: How much should we weight the analyzer's score.final by? defaults to 1.0.
  • scoreWeight: How much should we weight the search _score? defaults to 0.3.

.search.similar(q, esClient, [options]) -> Promise

Perform a fuzzy search for similarly named packages.

Results are ranked based on a combination of analyzer weightings (quality, popularity, maintenance) and the _score returned by the fuzzy match.

const queries = require('@npms/queries');

// ...
queries.search.similar('chaik', esClient)
.then(results => {
  // perhaps we were instead looking for chalk?
});

Available options:

  • size: The total number of results to return, defaults to 10.
  • analyzerWeight: How much should we weight the analyzer's score.final by? defaults to 2.2.
  • scoreWeight: How much should we weight the search _score? defaults to 1.5.
  • minScore: defaults to 4.5.

the above default values were based on trial and error examining the top npm modules, they will likely change over time.

Tests

$ npm test
$ npm test-cov to get coverage report

License

Released under the MIT License.