1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var utils = require('./utils');
|
11 |
|
12 | module.exports = function get(repos, options, cb) {
|
13 | if (typeof options === 'function') {
|
14 | cb = options;
|
15 | options = {};
|
16 | }
|
17 |
|
18 | if (typeof cb !== 'function') {
|
19 | throw new TypeError('expected a callback function');
|
20 | }
|
21 |
|
22 | if (typeof repos === 'string') {
|
23 | repos = [repos];
|
24 | }
|
25 |
|
26 | if (!Array.isArray(repos)) {
|
27 | cb(new TypeError('expected a string or array'));
|
28 | return;
|
29 | }
|
30 |
|
31 | options = options || {};
|
32 |
|
33 | utils.each(repos, function(name, next) {
|
34 | utils.pkg(name, function(err, pkg) {
|
35 | if (err) {
|
36 | if (err.message === 'document not found' && options.silent) {
|
37 | next();
|
38 | return;
|
39 | }
|
40 | next(err);
|
41 | return;
|
42 | }
|
43 | next(null, pkg);
|
44 | });
|
45 | }, function(err, pkgs) {
|
46 | if (err) {
|
47 | cb(err);
|
48 | return;
|
49 | }
|
50 | cb(null, pkgs.filter(Boolean));
|
51 | });
|
52 | };
|