diff options
author | Kat Marchán <kzm@zkat.tech> | 2019-01-29 14:43:00 -0800 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2019-02-12 00:06:29 -0800 |
commit | 43dd49c9782848c25e5b03448c8a0f923f13c158 (patch) | |
tree | f7ac5d645019b2b844f26be66c291bbae734d097 /deps/npm/node_modules/libnpmsearch/index.js | |
parent | b361f9577fbd72e518438d3fa0b01f7d34d814a5 (diff) | |
download | node-new-43dd49c9782848c25e5b03448c8a0f923f13c158.tar.gz |
deps: upgrade npm to 6.7.0
PR-URL: https://github.com/nodejs/node/pull/25804
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/npm/node_modules/libnpmsearch/index.js')
-rw-r--r-- | deps/npm/node_modules/libnpmsearch/index.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/deps/npm/node_modules/libnpmsearch/index.js b/deps/npm/node_modules/libnpmsearch/index.js new file mode 100644 index 0000000000..b84cab150b --- /dev/null +++ b/deps/npm/node_modules/libnpmsearch/index.js @@ -0,0 +1,79 @@ +'use strict' + +const figgyPudding = require('figgy-pudding') +const getStream = require('get-stream') +const npmFetch = require('npm-registry-fetch') + +const SearchOpts = figgyPudding({ + detailed: {default: false}, + limit: {default: 20}, + from: {default: 0}, + quality: {default: 0.65}, + popularity: {default: 0.98}, + maintenance: {default: 0.5}, + sortBy: {} +}) + +module.exports = search +function search (query, opts) { + return getStream.array(search.stream(query, opts)) +} +search.stream = searchStream +function searchStream (query, opts) { + opts = SearchOpts(opts) + switch (opts.sortBy) { + case 'optimal': { + opts = opts.concat({ + quality: 0.65, + popularity: 0.98, + maintenance: 0.5 + }) + break + } + case 'quality': { + opts = opts.concat({ + quality: 1, + popularity: 0, + maintenance: 0 + }) + break + } + case 'popularity': { + opts = opts.concat({ + quality: 0, + popularity: 1, + maintenance: 0 + }) + break + } + case 'maintenance': { + opts = opts.concat({ + quality: 0, + popularity: 0, + maintenance: 1 + }) + break + } + } + return npmFetch.json.stream('/-/v1/search', 'objects.*', + opts.concat({ + query: { + text: Array.isArray(query) ? query.join(' ') : query, + size: opts.limit, + 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 + } + } + }) + ) +} |