11/* eslint-disable no-await-in-loop */
22
3- const style = require ( 'ansi-styles' ) ,
3+ const color = require ( 'ansi-styles' ) ,
44 fs = require ( 'fs' ) ,
55 table3 = require ( 'cli-table3' ) ;
66
7- // ansi style and colors
7+ // ansi colors
88
99const
1010 // table color
1111 tblclr = ( border ) => { return cyan ( border ) ; } ,
1212 // normal ansi colors
13- white = ( txt ) => { return style . white . open + txt + style . white . close ; } ,
14- black = ( txt ) => { return style . black . open + txt + style . black . close ; } ,
15- green = ( txt ) => { return style . green . open + txt + style . green . close ; } ,
16- cyan = ( txt ) => { return style . cyan . open + txt + style . cyan . close ; } ,
17- magenta = ( txt ) => { return style . magenta . open + txt + style . magenta . close ; } ,
18- yellow = ( txt ) => { return style . yellow . open + txt + style . yellow . close ; } ,
19- red = ( txt ) => { return style . red . open + txt + style . red . close ; } ,
13+ white = ( txt ) => { return color . white . open + txt + color . white . close ; } ,
14+ black = ( txt ) => { return color . black . open + txt + color . black . close ; } ,
15+ green = ( txt ) => { return color . green . open + txt + color . green . close ; } ,
16+ cyan = ( txt ) => { return color . cyan . open + txt + color . cyan . close ; } ,
17+ magenta = ( txt ) => { return color . magenta . open + txt + color . magenta . close ; } ,
18+ yellow = ( txt ) => { return color . yellow . open + txt + color . yellow . close ; } ,
19+ red = ( txt ) => { return color . red . open + txt + color . red . close ; } ,
2020 // bright ansi colors
21- cyanBright = ( txt ) => { return style . cyanBright . open + txt + style . cyanBright . close ; } ,
22- magentaBright = ( txt ) => { return style . magentaBright . open + txt + style . magentaBright . close ; } ,
23- redBright = ( txt ) => { return style . redBright . open + txt + style . redBright . close ; } ,
21+ cyanBright = ( txt ) => { return color . cyanBright . open + txt + color . cyanBright . close ; } ,
22+ magentaBright = ( txt ) => { return color . magentaBright . open + txt + color . magentaBright . close ; } ,
23+ redBright = ( txt ) => { return color . redBright . open + txt + color . redBright . close ; } ,
2424 // background ansi color
25- cyanBG = ( txt ) => { return style . bgCyan . open + txt + style . bgCyan . close ; } ;
25+ cyanBG = ( txt ) => { return color . bgCyan . open + txt + color . bgCyan . close ; } ,
26+ // horizontal line
27+ line = '-' . repeat ( 60 ) ;
2628
2729
2830// package.json information
2931const pkg = JSON . parse ( fs . readFileSync ( 'package.json' ) ) ;
3032
3133// format data
32- const formatNumber = ( num ) => {
33- return num . toString ( ) . replace ( / ( \d ) (? = ( \d { 3 } ) + (? ! \d ) ) / g, '$1,' ) ;
34+ const formatNumber = ( value ) => {
35+ return value . toString ( ) . replace ( / ( \d ) (? = ( \d { 3 } ) + (? ! \d ) ) / g, '$1,' ) ;
3436} ;
3537
3638// time data
@@ -96,7 +98,7 @@ exports.covid19countrytracker = (n, c, tC, d, tD, r, a, cl, cPOM, u) => {
9698 } ) ;
9799 table . push (
98100 [ { colSpan :5 , content :yellow ( 'As of ' + asof . toLocaleString ( ) + ' [Date:' + currentdate + ']' ) } ] ,
99- [ magenta ( 'Cases' ) , red ( 'Deaths' ) , green ( 'Recovered' ) , cyan ( 'Active' ) , cyanBright ( 'Cases Per Million' ) ] ,
101+ [ magenta ( 'Cases' ) , red ( 'Deaths' ) , green ( 'Recovered' ) , cyan ( 'Active' ) , cyanBright ( 'Cases/ Million' ) ] ,
100102 [ formatNumber ( cases ) , formatNumber ( deaths ) , formatNumber ( recovered ) , formatNumber ( active ) , formatNumber ( casesPerOneMillion ) ] ,
101103 [ magentaBright ( 'Today Cases' ) , redBright ( 'Today Deaths' ) , redBright ( 'Critical' ) , red ( 'Mortality %' ) , green ( 'Recovered %' ) ] ,
102104 [ formatNumber ( todayCases ) , formatNumber ( todayDeaths ) , formatNumber ( critical ) , mortalityPercentage . toFixed ( 2 ) , recoveredPercentage . toFixed ( 2 ) ] ,
@@ -105,6 +107,62 @@ exports.covid19countrytracker = (n, c, tC, d, tD, r, a, cl, cPOM, u) => {
105107 return table . toString ( ) + '\n' + footer ;
106108} ;
107109
110+ exports . plainglobaltracker = ( c , d , r , u ) => {
111+ const cases = c , deaths = d , recovered = r , asof = new Date ( u ) ,
112+ mortalityPercentage = ( d / c ) * 100 , recoveredPercentage = ( r / c ) * 100 ;
113+
114+ const visual = `
115+ ${ line }
116+ COVID-19 Tracker CLI v${ pkg . version } - Global Update
117+ ${ line }
118+ As of ${ asof . toLocaleString ( ) } [Date: ${ currentdate } ]
119+ ${ line }
120+ Cases | ${ formatNumber ( cases ) }
121+ Deaths | ${ formatNumber ( deaths ) }
122+ Mortality % | ${ mortalityPercentage . toFixed ( 2 ) }
123+ Recovered | ${ formatNumber ( recovered ) }
124+ Recovery % | ${ recoveredPercentage . toFixed ( 2 ) }
125+ ${ line }
126+ ${ source }
127+ ${ line }
128+ ${ repo }
129+ ${ line }
130+ ` ;
131+ return visual + plainfooter ;
132+ } ;
133+
134+ exports . plaincountrytracker = ( n , c , tC , d , tD , r , a , cl , cPOM , u ) => {
135+ const name = n , cases = c , todayCases = tC ,
136+ deaths = d , todayDeaths = tD , recovered = r ,
137+ active = a , critical = cl , casesPerOneMillion = cPOM ,
138+ mortalityPercentage = ( d / c ) * 100 , recoveredPercentage = ( r / c ) * 100 ,
139+ asof = new Date ( u ) ;
140+
141+ const visual = `
142+ ${ line }
143+ COVID-19 Tracker CLI v${ pkg . version } - ${ name } Update
144+ ${ line }
145+ As of ${ asof . toLocaleString ( ) } [Date: ${ currentdate } ]
146+ ${ line }
147+ Cases | ${ formatNumber ( cases ) }
148+ Today Cases | ${ formatNumber ( todayCases ) }
149+ Deaths | ${ formatNumber ( deaths ) }
150+ Today Deaths | ${ formatNumber ( todayDeaths ) }
151+ Critical | ${ formatNumber ( critical ) }
152+ Mortality % | ${ mortalityPercentage . toFixed ( 2 ) }
153+ Recovered | ${ formatNumber ( recovered ) }
154+ Recovery % | ${ recoveredPercentage . toFixed ( 2 ) }
155+ Active | ${ formatNumber ( active ) }
156+ Cases/Million | ${ formatNumber ( casesPerOneMillion ) }
157+ ${ line }
158+ ${ source }
159+ ${ line }
160+ ${ repo }
161+ ${ line }
162+ ` ;
163+ return visual + plainfooter ;
164+ } ;
165+
108166// cli footer
109167const footer = `
110168 Always wash your hands, stay safe...
@@ -116,3 +174,15 @@ const footer = `
116174 ---
117175 Follow ${ cyanBG ( black ( '@warengonzaga' ) ) } for more updates!
118176\n` ;
177+
178+ // cli plain footer
179+ const plainfooter = `
180+ Always wash your hands, stay safe...
181+
182+ ---
183+ Love this project? Please consider buying me a cup of coffee!
184+ [ warengonzaga.com/buymeacoffee ]
185+
186+ ---
187+ Follow [ @warengonzaga ] for more updates!
188+ \n` ;
0 commit comments