UNPKG

918 BJavaScriptView Raw
1/*!
2 * get-pkgs <https://github.com/jonschlinkert/get-pkgs>
3 *
4 * Copyright (c) 2014-present, Jon Schlinkert.
5 * Released under the MIT License.
6 */
7
8'use strict';
9
10const pkg = require('get-pkg');
11
12module.exports = function get(names, options = {}, cb) {
13 if (typeof options === 'function') {
14 cb = options;
15 options = {};
16 }
17
18 if (typeof names === 'string') {
19 names = [names];
20 }
21
22 const pending = [];
23 const pkgs = [];
24
25 for (const name of names) {
26 const promise = pkg(name)
27 .then(res => {
28 if (res) pkgs.push(res);
29 })
30 .catch(err => {
31 if (err.message === 'document not found' && options.silent) return;
32 return Promise.reject(err);
33 });
34
35 pending.push(promise);
36 }
37
38 const promise = Promise.all(pending);
39
40 if (typeof cb === 'function') {
41 promise.then(() => cb(null, pkgs)).catch(cb);
42 return;
43 }
44
45 return promise.then(() => pkgs);
46};