All Projects → npm → libnpmsearch

npm / libnpmsearch

Licence: ISC license
programmatic API for the shiny new npm search endpoint

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to libnpmsearch

cross-post
Cross Post a blog to multiple websites
Stars: ✭ 66 (+164%)
Mutual labels:  npm-cli
git
a util for spawning git from npm CLI contexts
Stars: ✭ 48 (+92%)
Mutual labels:  npm-cli
fs-minipass
fs read and write streams based on minipass
Stars: ✭ 15 (-40%)
Mutual labels:  npm-cli
npm-registry-mock
mock the npm registry
Stars: ✭ 26 (+4%)
Mutual labels:  npm-cli
node-cli-boilerplate
🪓 Create node cli with this user friendly boilerplate
Stars: ✭ 17 (-32%)
Mutual labels:  npm-cli
npm-profile
Make changes to your npmjs.com profile via cli or library
Stars: ✭ 29 (+16%)
Mutual labels:  npm-cli
inflight
Add callbacks to requests in flight to avoid async duplication
Stars: ✭ 63 (+152%)
Mutual labels:  npm-cli
Cli
the package manager for JavaScript
Stars: ✭ 5,277 (+21008%)
Mutual labels:  npm-cli
Node Semver
The semver parser for node (the one npm uses)
Stars: ✭ 3,944 (+15676%)
Mutual labels:  npm-cli
run-script
Run a lifecycle script for a package (descendant of npm-lifecycle)
Stars: ✭ 29 (+16%)
Mutual labels:  npm-cli
lint
lint the npmcli way
Stars: ✭ 27 (+8%)
Mutual labels:  npm-cli
proggy
Progress bar updates at a distance
Stars: ✭ 12 (-52%)
Mutual labels:  npm-cli
pacote
npm fetcher
Stars: ✭ 179 (+616%)
Mutual labels:  npm-cli
parse-conflict-json
Parse a JSON string that has git merge conflicts, resolving if possible
Stars: ✭ 24 (-4%)
Mutual labels:  npm-cli
libnpmpublish
programmatically publish and unpublish npm packages
Stars: ✭ 44 (+76%)
Mutual labels:  npm-cli
config
Configuration management for https://github.com/npm/cli
Stars: ✭ 22 (-12%)
Mutual labels:  npm-cli
cacache
npm's content-addressable cache
Stars: ✭ 181 (+624%)
Mutual labels:  npm-cli
cmd-shim
The cmd-shim used in npm
Stars: ✭ 65 (+160%)
Mutual labels:  npm-cli

We've Moved! 🚚

The code for this repo is now a workspace in the npm CLI repo.

github.com/npm/cli

You can find the workspace in /workspaces/libnpmsearch

Please file bugs and feature requests as issues on the CLI and tag the issue with "ws:libnpmsearch".

github.com/npm/cli/issues

libnpmsearch

npm version license Coverage Status

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

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

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')

libnpmsearch uses npm-registry-fetch. Most options are passed through directly to that library, so please refer to its own opts documentation for options that can be passed in.

A couple of options of note for those in a hurry:

  • 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.

> search(query, [opts]) -> Promise

query must be either a String or an Array of search terms.

If opts.limit is provided, it will be sent to the API to constrain the number of returned results. You may receive more, or fewer results, at the endpoint's discretion.

The returned Promise resolved to an Array of search results with the following format:

{
  name: String,
  version: SemverString,
  description: String || null,
  maintainers: [
    {
      username: String,
      email: String
    },
    ...etc
  ] || null,
  keywords: [String] || null,
  date: Date || null
}

If opts.limit is provided, it will be sent to the API to constrain the number of returned results. You may receive more, or fewer results, at the endpoint's discretion.

For streamed results, see search.stream.

Example
await search('libnpm')
=>
[
  {
    name: 'libnpm',
    description: 'programmatic npm API',
    ...etc
  },
  {
    name: 'libnpmsearch',
    description: 'Programmatic API for searching in npm and compatible registries',
    ...etc
  },
  ...more
]

> search.stream(query, [opts]) -> Stream

query must be either a String or an Array of search terms.

If opts.limit is provided, it will be sent to the API to constrain the number of returned results. You may receive more, or fewer results, at the endpoint's discretion.

The returned Stream emits one entry per search result, with each entry having the following format:

{
  name: String,
  version: SemverString,
  description: String || null,
  maintainers: [
    {
      username: String,
      email: String
    },
    ...etc
  ] || null,
  keywords: [String] || null,
  date: Date || null
}

For getting results in one chunk, see search.

Example
search.stream('libnpm').on('data', console.log)
=>
// entry 1
{
  name: 'libnpm',
  description: 'programmatic npm API',
  ...etc
}
// entry 2
{
  name: 'libnpmsearch',
  description: 'Programmatic API for searching in npm and compatible registries',
  ...etc
}
// etc
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].