-
Notifications
You must be signed in to change notification settings - Fork 1
/
yong.js
executable file
·65 lines (58 loc) · 1.98 KB
/
yong.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
var command = require('commander');
var request = require('request');
var chalk = require('chalk');
command
.version('0.0.1')
.usage('<keywords>')
.option('-b, --browser [broswer]', 'Filter by the browser')
.parse(process.argv);
if(!command.args.length) {
command.help();
} else {
var keywords = command.args;
var url = 'http://me.skylerzhang.com:8080/caniuse?keyword='+keywords;
if(command.browser) {
url = url + '&browser=' + command.browser;
}
}
request({
method:'GET',
headers:{
'User-Agent':''
},
url: url
},function(err, res, body){
if(!err && res.statusCode == 200){
var json = JSON.parse(body);
if(json['err'] !== undefined){
console.log(chalk.red.bold('无此属性'));
process.exit(0);
}
for(var css in json){
console.log(chalk.red('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'));
console.log(chalk.red.bold(json[css].title+' (种类:'+json[css].categories+')'));
var bro = json[css].stats;
for(var browser in bro){
console.log(chalk.gray('~')+chalk.blue(browser));
var ver = json[css]['stats'][browser];
for(var version in ver){
if(ver[version] == 'y'){
process.stdout.write(chalk.green(' '+version+':'+ver[version]+' ')+' ');
} else if (ver[version] == 'n'){
process.stdout.write(chalk.red(' '+version+':'+ver[version]+' ')+' ');
} else {
process.stdout.write(chalk.yellow(' '+version+':'+ver[version]+' ')+' ');
}
}
console.log(' ');
}
console.log(chalk.red('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'));
console.log(' ');
}
process.exit(0);
} else if (err){
console.log(chalk.red('Error: ' + err));
process.exit(1);
}
});