UNPKG

713 BJavaScriptView Raw
1/*!
2 * get-pkgs <https://github.com/jonschlinkert/get-pkgs>
3 *
4 * Copyright (c) 2014-2015, Jon Schlinkert.
5 * Licensed under the MIT License.
6 */
7
8'use strict';
9
10var async = require('async');
11var filter = require('filter-object');
12var pkg = require('package-json');
13
14module.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
30function arrayify(val) {
31 return !Array.isArray(val) ? [val] : val;
32}