22
33const style = require ( 'ansi-styles' ) ,
44 request = require ( "request" ) ,
5- fs = require ( 'fs' ) ;
5+ fs = require ( 'fs' ) ,
6+ table3 = require ( 'cli-table3' ) ;
7+
8+ const tblopn = style . cyan . open ,
9+ tblcls = style . cyan . close ;
610
711// package.json information
8- const pkg = JSON . parse ( fs . readFileSync ( 'package.json' ) ) ;
12+ const pkg = JSON . parse ( fs . readFileSync ( 'package.json' ) ) ;
913
1014// format data
1115const formatNumber = ( num ) => {
1216 return num . toString ( ) . replace ( / ( \d ) (? = ( \d { 3 } ) + (? ! \d ) ) / g, '$1,' ) ;
1317} ;
1418
1519// time data
16- let ts = Date . now ( ) ;
17- let date_ob = new Date ( ts ) ;
18- let date = date_ob . getDate ( ) ;
19- let month = date_ob . getMonth ( ) + 1 ;
20- let year = date_ob . getFullYear ( ) ;
21- let currentdate = month + "/" + date + "/" + year ;
20+ let ts = Date . now ( ) ,
21+ date_ob = new Date ( ts ) ,
22+ date = date_ob . getDate ( ) ,
23+ month = date_ob . getMonth ( ) + 1 ,
24+ year = date_ob . getFullYear ( ) ,
25+ currentdate = month + "/" + date + "/" + year ;
2226
2327// api request for global data
2428request . get ( "https://corona.lmao.ninja/all" , ( error , response , body ) => {
@@ -29,33 +33,47 @@ request.get("https://corona.lmao.ninja/all", (error, response, body) => {
2933} ) ;
3034
3135// covid19 global tracker
32- const covid19globaltracker = (
33- trckrvrsn = pkg . version ,
34- cases = globalData . cases ,
35- deaths = globalData . deaths ,
36- recovered = globalData . recovered ,
37- asof = new Date ( globalData . updated )
38- ) => `
39- ──────────────────────────────────────────────────
40- ${ style . cyan . open } Waren Gonzaga's Tracker v${ trckrvrsn } ${ style . cyan . close } | ${ style . red . open } COVID19${ style . red . close } ${ style . yellow . open } [Global]${ style . yellow . close }
41- ──────────────────────────────────────────────────
42- As of ${ asof . toLocaleString ( ) }
43-
44- ${ style . magenta . open } Cases:${ style . magenta . close } ${ formatNumber ( cases ) }
45- ${ style . red . open } Deaths:${ style . red . close } ${ formatNumber ( deaths ) }
46- ${ style . green . open } Recovered:${ style . green . close } ${ formatNumber ( recovered ) }
47-
48- ---
49- ${ style . gray . open } Source: https://www.worldometers.info/coronavirus/${ style . gray . close }
50- ${ style . gray . open } Date: ${ currentdate } ${ style . gray . close }
51- ──────────────────────────────────────────────────
36+ exports . covid19globaltracker = ( ) => {
37+ const cases = globalData . cases ,
38+ deaths = globalData . deaths ,
39+ recovered = globalData . recovered ,
40+ asof = new Date ( globalData . updated ) ,
41+ table = new table3 ( {
42+ head : [ { colSpan :3 , content :`${ style . white . open } COVID-19 Tracker CLI v` + pkg . version + ` - Global Update${ style . white . close } ` } ] ,
43+ chars : { 'top' : `${ tblopn } ═${ tblcls } ` ,
44+ 'top-mid' : `${ tblopn } ╤${ tblcls } ` ,
45+ 'top-left' : `${ tblopn } ╔${ tblcls } ` ,
46+ 'top-right' : `${ tblopn } ╗${ tblcls } ` ,
47+ 'bottom' : `${ tblopn } ═${ tblcls } ` ,
48+ 'bottom-mid' : `${ tblopn } ╧${ tblcls } ` ,
49+ 'bottom-left' : `${ tblopn } ╚${ tblcls } ` ,
50+ 'bottom-right' : `${ tblopn } ╝${ tblcls } ` ,
51+ 'left' : `${ tblopn } ║${ tblcls } ` ,
52+ 'left-mid' : `${ tblopn } ╟${ tblcls } ` ,
53+ 'mid' : `${ tblopn } ─${ tblcls } ` ,
54+ 'mid-mid' : `${ tblopn } ┼${ tblcls } ` ,
55+ 'right' : `${ tblopn } ║${ tblcls } ` ,
56+ 'right-mid' : `${ tblopn } ╢${ tblcls } ` ,
57+ 'middle' : `${ tblopn } │${ tblcls } ` }
58+ } ) ;
59+
60+ table . push (
61+ [ { colSpan :3 , content :style . gray . open + 'As of ' + asof . toLocaleString ( ) + ' [Date:' + currentdate + ']' + style . gray . close } ] ,
62+ [ `${ style . magenta . open } Cases${ style . magenta . close } ` , `${ style . red . open } Deaths${ style . red . close } ` , `${ style . green . open } Recovered${ style . green . close } ` ] ,
63+ [ formatNumber ( cases ) , formatNumber ( deaths ) , formatNumber ( recovered ) ] ,
64+ [ { colSpan :3 , content :style . gray . open + `Source: https://www.worldometers.info/coronavirus/` + style . gray . close } ] ,
65+ [ { colSpan :3 , content :style . gray . open + `Code: https://github.com/warengonzaga/covid19-tracker-cli` + style . gray . close } ]
66+ ) ;
67+ return table . toString ( ) + '\n' + footer ;
68+ } ;
5269
70+ const footer = `
71+ Always wash your hands, stay safe...
72+
73+ ---
5374 Love this project? Please consider buying me a cup of coffee!
5475 ${ style . yellow . open } buymeacoff.ee/warengonzaga${ style . yellow . close }
76+
5577 ---
5678 Follow ${ style . bgCyan . open } ${ style . black . open } @warengonzaga${ style . black . close } ${ style . bgCyan . close } for more updates!
5779\n` ;
58-
59- module . exports = {
60- covid19globaltracker
61- } ;
0 commit comments