UNPKG

857 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 utils = require('./utils');
11
12module.exports = function get(repos, cb) {
13 if (typeof cb !== 'function') {
14 throw new TypeError('expected callback to be a function');
15 }
16
17 if (typeof repos === 'string') {
18 repos = [repos];
19 }
20
21 if (!Array.isArray(repos)) {
22 throw new TypeError('expected the first argument to be a string or array');
23 }
24
25 var i = 0;
26 utils.async.map(repos, utils.pkg, function(err, res) {
27 var name = repos[i];
28 i++;
29
30 if (err) {
31 if (err.message !== 'document not found') {
32 cb(err);
33 return;
34 }
35 console.error('npm package "%s" does not exist', name);
36 res = res.filter(Boolean);
37 }
38 cb(null, res);
39 });
40};