forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
116 lines (102 loc) · 4.62 KB
/
index.js
File metadata and controls
116 lines (102 loc) · 4.62 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* eslint-disable no-await-in-loop */
const style = require('ansi-styles'),
fs = require('fs'),
table3 = require('cli-table3');
// ansi style and colors
const
// table color
tblclr = (border) => {return cyan(border);},
// normal ansi colors
white = (txt) => {return style.white.open+txt+style.white.close;},
black = (txt) => {return style.black.open+txt+style.black.close;},
green = (txt) => {return style.green.open+txt+style.green.close;},
cyan = (txt) => {return style.cyan.open+txt+style.cyan.close;},
magenta = (txt) => {return style.magenta.open+txt+style.magenta.close;},
yellow = (txt) => {return style.yellow.open+txt+style.yellow.close;},
red = (txt) => {return style.red.open+txt+style.red.close;},
// bright ansi colors
cyanBright = (txt) => {return style.cyanBright.open+txt+style.cyanBright.close;},
magentaBright = (txt) => {return style.magentaBright.open+txt+style.magentaBright.close;},
redBright = (txt) => {return style.redBright.open+txt+style.redBright.close;},
// background ansi color
cyanBG = (txt) => {return style.bgCyan.open+txt+style.bgCyan.close;};
// package.json information
const pkg = JSON.parse(fs.readFileSync('package.json'));
// format data
const formatNumber = (num) => {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
};
// time data
let ts = Date.now(),
date_ob = new Date(ts),
date = date_ob.getDate(),
month = date_ob.getMonth() + 1,
year = date_ob.getFullYear(),
currentdate = month + "/" + date + "/" + year;
// table configuration
const borders = { 'top': tblclr('═'),
'top-mid': tblclr('╤'),
'top-left': tblclr('╔'),
'top-right': tblclr('╗'),
'bottom': tblclr('═'),
'bottom-mid': tblclr('╧'),
'bottom-left': tblclr('╚'),
'bottom-right': tblclr('╝'),
'left': tblclr('║'),
'left-mid': tblclr('╟'),
'mid': tblclr('─'),
'mid-mid': tblclr('┼'),
'right': tblclr('║'),
'right-mid': tblclr('╢'),
'middle': tblclr('│')};
// additional informaton
const source = 'Source: https://www.worldometers.info/coronavirus/',
repo = 'Code: https://github.com/warengonzaga/covid19-tracker-cli',
sourceGlobal = {colSpan:3,content:source},
repoGlobal = {colSpan:3,content:repo},
sourceCountry = {colSpan:4,content:source},
repoCountry = {colSpan:4,content:repo};
// covid19 global tracker
exports.covid19globaltracker = (c, d, r, u) => {
const cases = c, deaths = d, recovered = r, asof = new Date(u),
table = new table3({
head: [{colSpan:3,content:white('COVID-19 Tracker CLI v'+pkg.version+' - Global Update')}],
chars: borders
});
table.push(
[{colSpan:3,content:yellow('As of '+asof.toLocaleString()+' [Date:'+currentdate+']')}],
[magenta('Cases'), red('Deaths'), green('Recovered')],
[formatNumber(cases), formatNumber(deaths), formatNumber(recovered)],
[sourceGlobal],[repoGlobal]
);
return table.toString()+'\n'+footer;
};
// covid19 country tracker
exports.covid19countrytracker = (n, c, tC, d, tD, r, a, cl, cPOM, u) => {
const name = n, cases = c, todayCases = tC,
deaths = d, todayDeaths = tD, recovered = r,
active = a, critical = cl, casesPerOneMillion = cPOM,
asof = new Date(u);
table = new table3({
head: [{colSpan:4,content:white('COVID-19 Tracker CLI v'+pkg.version+' - '+name+' Update')}],
chars: borders
});
table.push(
[{colSpan:4,content:yellow('As of '+asof.toLocaleString()+' [Date:'+currentdate+']')}],
[magenta('Cases'), red('Deaths'), green('Recovered'), cyan('Active')],
[formatNumber(cases), formatNumber(deaths), formatNumber(recovered), formatNumber(active)],
[magentaBright('Today Cases'), redBright('Today Deaths'), redBright('Critical'), cyanBright('Cases Per Million')],
[formatNumber(todayCases), formatNumber(todayDeaths), formatNumber(critical), formatNumber(casesPerOneMillion)],
[sourceCountry],[repoCountry]
);
return table.toString()+'\n'+footer;
};
// cli footer
const footer = `
Always wash your hands, stay safe...
---
Love this project? Please consider buying me a cup of coffee!
${yellow('warengonzaga.com/buymeacoffee')}
---
Follow ${cyanBG(black('@warengonzaga'))} for more updates!
\n`;