[`libnpmsearch`](https://github.com/npm/libnpmsearch) is a Node.js library for
programmatically accessing the npm search endpoint. It does **not** support
legacy search through `/-/all`.
## Table of Contents
* [Example](#example)
* [Install](#install)
* [Contributing](#contributing)
* [API](#api)
* [search opts](#opts)
* [`search()`](#search)
* [`search.stream()`](#search-stream)
## Example
```js
const search = require('libnpmsearch')
console.log(await search('libnpm'))
=>
[
{
name: 'libnpm',
description: 'programmatic npm API',
...etc
},
{
name: 'libnpmsearch',
description: 'Programmatic API for searching in npm and compatible registries',
...etc
},
...more
]
```
## Install
`$ npm install libnpmsearch`
### API
#### <a name="opts"></a> `opts` for `libnpmsearch` commands
The following opts are used directly by `libnpmsearch` itself:
*`opts.limit` - Number of results to limit the query to. Default: 20
*`opts.from` - Offset number for results. Used with `opts.limit` for pagination. Default: 0
*`opts.detailed` - If true, returns an object with `package`, `score`, and `searchScore` fields, with `package` being what would usually be returned, and the other two containing details about how that package scored. Useful for UIs. Default: false
*`opts.sortBy` - Used as a shorthand to set `opts.quality`, `opts.maintenance`, and `opts.popularity` with values that prioritize each one. Should be one of `'optimal'`, `'quality'`, `'maintenance'`, or `'popularity'`. Default: `'optimal'`
*`opts.maintenance` - Decimal number between `0` and `1` that defines the weight of `maintenance` metrics when scoring and sorting packages. Default: `0.65` (same as `opts.sortBy: 'optimal'`)
*`opts.popularity` - Decimal number between `0` and `1` that defines the weight of `popularity` metrics when scoring and sorting packages. Default: `0.98` (same as `opts.sortBy: 'optimal'`)
*`opts.quality` - Decimal number between `0` and `1` that defines the weight of `quality` metrics when scoring and sorting packages. Default: `0.5` (same as `opts.sortBy: 'optimal'`)
*`opts.token` - can be passed in and will be used as the authentication token for the registry. For other ways to pass in auth details, see the n-r-f docs.