/
search.js
44 lines (39 loc) · 1.08 KB
/
search.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* show information of the package */
var color = require('colorful');
var yuan = require('./sdk/yuan');
module.exports = function(options) {
yuan(options).search({query: options.query}, function(err, res, body) {
if (err) {
console.error('error:', err);
process.exit();
} else {
var msg;
if (body.data.total === 1) {
msg = '1 result';
} else {
msg = body.data.total + ' results';
}
console.log(' ', color.bold(msg));
body.data.results.forEach(function(item) {
console.log();
print(item);
});
}
});
};
function print(data) {
var title = data.family + '/' + data.name;
console.log(' ' + color.cyan(title));
if (data.keywords && data.keywords.length) {
console.log(' keys:', color.magenta(data.keywords.join(' ')));
}
if (data.description) {
console.log(' desc:', color.grey(data.description));
}
if (data.homepage) {
console.log(' link:', color.underline(data.homepage));
}
if (data.repository) {
console.log(' repo:', color.underline(data.repository));
}
}