Skip to content
forked from npms-io/queries

Module that offers a variety of queries around npms data.

License

Notifications You must be signed in to change notification settings

AlexxNica/queries

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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:

  • size: The total number of results to return, defaults to 25

Tests

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

License

Released under the MIT License.

About

Module that offers a variety of queries around npms data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%