diff options
author | Aria Stewart <aredridel@dinhe.net> | 2015-11-30 07:26:57 +0300 |
---|---|---|
committer | Kat Marchán <kzm@sykosomatic.org> | 2016-10-13 22:36:21 +0300 |
commit | cfd43b49aed36d0e8ea6c35b07ed8b303b69be61 (patch) | |
tree | 914efc46ffa5f75feb5bb06c5fed0b302823a229 /lib/search.js | |
parent | 643dae2197c56f1c725ecc6539786bf82962d0fe (diff) |
search: first stab at streaming search
Credit: @aredridel
PR-URL: https://github.com/npm/npm/pull/13746
Reviewed-By: @othiym23
Diffstat (limited to 'lib/search.js')
-rw-r--r-- | lib/search.js | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/lib/search.js b/lib/search.js index cd6d5ed8e..5e8aa96d3 100644 --- a/lib/search.js +++ b/lib/search.js @@ -6,12 +6,16 @@ var columnify = require('columnify') var updateIndex = require('./cache/update-index.js') var usage = require('./utils/usage') var output = require('./utils/output.js') +var log = require('npmlog') search.usage = usage( 'search', 'npm search [--long] [search terms ...]' ) +search.usage = 'npm search [--long] [search terms ...]' + + '\n\naliases: s, se' + search.completion = function (opts, cb) { var compl = {} var partial = opts.partialWord @@ -66,35 +70,24 @@ function search (args, silent, staleness, cb) { return s.toLowerCase() }) - getFilteredData(staleness, opts, searchexclude, function (er, data) { + updateIndex(staleness, opts, searchexclude, filter, function (er, data) { // now data is the list of data that we want to show. // prettify and print it, and then provide the raw // data to the cb. if (er || silent) return cb(er, data) + log.clearProgress() output(prettify(data, args)) cb(null, data) }) } -function getFilteredData (staleness, args, notArgs, cb) { - updateIndex(staleness, function (er, data) { - if (er) return cb(er) - return cb(null, filter(data, args, notArgs)) - }) -} - function filter (data, args, notArgs) { - // data={<name>:{package data}} - return Object.keys(data).map(function (d) { - return data[d] - }).filter(function (d) { - return typeof d === 'object' - }).map(stripData).map(getWords).filter(function (data) { - return filterWords(data, args, notArgs) - }).reduce(function (l, r) { - l[r.name] = r - return l - }, {}) + if (typeof data !== 'object') return false + + data = getWords(stripData(data)) + if (filterWords(data, args, notArgs)) return true + + return false } function stripData (data) { @@ -163,7 +156,7 @@ function prettify (data, args) { var lines = Object.keys(data).map(function (d) { // strip keyname return data[d] - }).map(function (dat) { + }).map(stripData).map(function (dat) { dat.author = dat.maintainers delete dat.maintainers dat.date = dat.time |