1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var async = require('async');
|
11 | var filter = require('filter-object');
|
12 | var pkg = require('package-json');
|
13 |
|
14 | module.exports = function get(repos, pattern, cb) {
|
15 | if (typeof pattern === 'function') {
|
16 | cb = pattern; pattern = '*';
|
17 | }
|
18 |
|
19 | async.reduce(arrayify(repos), [], function(acc, repo, next) {
|
20 | pkg(repo, 'latest', function (err, json) {
|
21 | if (err) {
|
22 | next(err);
|
23 | return;
|
24 | }
|
25 | next(null, acc.concat(filter(json, pattern)));
|
26 | });
|
27 | }, cb);
|
28 | };
|
29 |
|
30 | function arrayify(val) {
|
31 | return !Array.isArray(val) ? [val] : val;
|
32 | }
|