GithubHelp home page GithubHelp logo

midrissi / libnpmsearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from npm/libnpmsearch

0.0 2.0 0.0 86 KB

programmatic API for the shiny new npm search endpoint

Home Page: https://npmjs.com/package/libnpmsearch

License: ISC License

JavaScript 100.00%

libnpmsearch's Introduction

libnpmsearch npm version license Travis AppVeyor Coverage Status

libnpmsearch is a Node.js library for programmatically accessing the npm search endpoint. It does not support legacy search through /-/all.

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

Table of Contents

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.offset - 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.
  • opts.Promise - If you pass this in, the Promises returned by libnpmsearch commands will use this Promise class instead. For example: {Promise: require('bluebird')}

> 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

libnpmsearch's People

Contributors

zkat avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.