update
This commit is contained in:
13
package/node_modules/libnpmsearch/LICENSE
generated
vendored
Normal file
13
package/node_modules/libnpmsearch/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright npm, Inc
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
173
package/node_modules/libnpmsearch/README.md
generated
vendored
Normal file
173
package/node_modules/libnpmsearch/README.md
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
# libnpmsearch
|
||||
|
||||
[](https://npm.im/libnpmsearch)
|
||||
[](https://npm.im/libnpmsearch)
|
||||
[](https://github.com/npm/cli/actions/workflows/ci-libnpmsearch.yml)
|
||||
|
||||
[`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'`)
|
||||
|
||||
`libnpmsearch` uses [`npm-registry-fetch`](https://npm.im/npm-registry-fetch).
|
||||
Most options are passed through directly to that library, so please refer to
|
||||
[its own `opts`
|
||||
documentation](https://www.npmjs.com/package/npm-registry-fetch#fetch-options)
|
||||
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.
|
||||
|
||||
#### <a name="search"></a> `> 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:
|
||||
|
||||
```js
|
||||
{
|
||||
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`](#search-stream).
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
await search('libnpm')
|
||||
=>
|
||||
[
|
||||
{
|
||||
name: 'libnpm',
|
||||
description: 'programmatic npm API',
|
||||
...etc
|
||||
},
|
||||
{
|
||||
name: 'libnpmsearch',
|
||||
description: 'Programmatic API for searching in npm and compatible registries',
|
||||
...etc
|
||||
},
|
||||
...more
|
||||
]
|
||||
```
|
||||
|
||||
#### <a name="search-stream"></a> `> 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:
|
||||
|
||||
```js
|
||||
{
|
||||
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`](#search-stream).
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
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
|
||||
```
|
71
package/node_modules/libnpmsearch/lib/index.js
generated
vendored
Normal file
71
package/node_modules/libnpmsearch/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
'use strict'
|
||||
|
||||
const npmFetch = require('npm-registry-fetch')
|
||||
|
||||
module.exports = search
|
||||
function search (query, opts) {
|
||||
return search.stream(query, opts).collect()
|
||||
}
|
||||
search.stream = searchStream
|
||||
function searchStream (query, opts = {}) {
|
||||
opts = {
|
||||
detailed: false,
|
||||
limit: 20,
|
||||
from: 0,
|
||||
quality: 0.65,
|
||||
popularity: 0.98,
|
||||
maintenance: 0.5,
|
||||
...opts.opts, // this is to support the cli's --searchopts parameter
|
||||
...opts,
|
||||
}
|
||||
|
||||
switch (opts.sortBy) {
|
||||
case 'optimal': {
|
||||
opts.quality = 0.65
|
||||
opts.popularity = 0.98
|
||||
opts.maintenance = 0.5
|
||||
break
|
||||
}
|
||||
case 'quality': {
|
||||
opts.quality = 1
|
||||
opts.popularity = 0
|
||||
opts.maintenance = 0
|
||||
break
|
||||
}
|
||||
case 'popularity': {
|
||||
opts.quality = 0
|
||||
opts.popularity = 1
|
||||
opts.maintenance = 0
|
||||
break
|
||||
}
|
||||
case 'maintenance': {
|
||||
opts.quality = 0
|
||||
opts.popularity = 0
|
||||
opts.maintenance = 1
|
||||
break
|
||||
}
|
||||
}
|
||||
return npmFetch.json.stream('/-/v1/search', 'objects.*',
|
||||
{
|
||||
...opts,
|
||||
query: {
|
||||
text: Array.isArray(query) ? query.join(' ') : query,
|
||||
size: opts.limit,
|
||||
from: opts.from,
|
||||
quality: opts.quality,
|
||||
popularity: opts.popularity,
|
||||
maintenance: opts.maintenance,
|
||||
},
|
||||
mapJSON: (obj) => {
|
||||
if (obj.package.date) {
|
||||
obj.package.date = new Date(obj.package.date)
|
||||
}
|
||||
if (opts.detailed) {
|
||||
return obj
|
||||
} else {
|
||||
return obj.package
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
57
package/node_modules/libnpmsearch/package.json
generated
vendored
Normal file
57
package/node_modules/libnpmsearch/package.json
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "libnpmsearch",
|
||||
"version": "7.0.6",
|
||||
"description": "Programmatic API for searching in npm and compatible registries.",
|
||||
"author": "GitHub Inc.",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
"bin/",
|
||||
"lib/"
|
||||
],
|
||||
"keywords": [
|
||||
"npm",
|
||||
"search",
|
||||
"api",
|
||||
"libnpm"
|
||||
],
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"posttest": "npm run lint",
|
||||
"test": "tap",
|
||||
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
|
||||
"postlint": "template-oss-check",
|
||||
"lintfix": "npm run lint -- --fix",
|
||||
"snap": "tap",
|
||||
"template-oss-apply": "template-oss-apply --force"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^4.0.0",
|
||||
"@npmcli/template-oss": "4.22.0",
|
||||
"nock": "^13.3.3",
|
||||
"tap": "^16.3.8"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/npm/cli.git",
|
||||
"directory": "workspaces/libnpmsearch"
|
||||
},
|
||||
"bugs": "https://github.com/npm/libnpmsearch/issues",
|
||||
"homepage": "https://npmjs.com/package/libnpmsearch",
|
||||
"dependencies": {
|
||||
"npm-registry-fetch": "^17.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.14.0 || >=18.0.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.22.0",
|
||||
"content": "../../scripts/template-oss/index.js"
|
||||
},
|
||||
"tap": {
|
||||
"nyc-arg": [
|
||||
"--exclude",
|
||||
"tap-snapshots/**"
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user