-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
55 lines (49 loc) · 1.58 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*!
* npm-api-dependents <https://github.com/doowb/npm-api-dependents>
*
* Copyright (c) 2016-2017, Brian Woodward.
* Released under the MIT License.
*/
'use strict';
var utils = require('./utils');
module.exports = function(config) {
return function plugin(app) {
if (!this.isNpmapi) return;
return function() {
if (!this.isRepo) return;
/**
* Get the dependents for the current repo.
*
* ```js
* var repo = npm.repo('micromatch');
*
* // returns a readable stream
* repo.dependents()
* .on('data', function(repo) {
* console.log(repo);
* });
* ```
* @name .dependents
* @param {Object} `options` Options to handle returned results
* @param {Boolean} `options.raw` Optional. Set to `true` to receive objects of the form `{ name: 'module' }` instead of [Repo](https://github.com/doowb/npm-api#repo-1) objects.
* @return {Stream} Returns a readable stream (object mode).
* @api public
*/
this.define('dependents', function(options) {
var opts = utils.extend({}, options);
var view = app.view('dependedUpon');
var stream = view.stream({
group_level: 2,
startkey: JSON.stringify([this.name]),
endkey: JSON.stringify([this.name, {}])
});
var transform = utils.through2.obj(function(obj, enc, cb) {
var name = obj.key[1];
this.push(opts.raw ? {name: name} : app.repo(name));
cb();
});
return stream.pipe(transform);
});
};
};
};