Skip to content

Commit 1a4116a

Browse files
committed
added coronavirus story link in footer
1 parent a29f845 commit 1a4116a

File tree

1 file changed

+97
-46
lines changed

1 file changed

+97
-46
lines changed

lib/helpers.js

Lines changed: 97 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ e.getDeaths = (deaths) => {
4242
e.getActive = (active) => {
4343
return {
4444
content: chalk.magentaBright(h(active)),
45-
hAlign: 'right'
45+
hAlign: 'right',
4646
};
4747
};
4848

@@ -63,9 +63,12 @@ e.getEmoji = (countryCode) => {
6363
return '';
6464
};
6565

66-
e.calActive = ({ confirmed, recovered, deaths }) => confirmed - (recovered + deaths);
67-
e.calMortalityPer = ({ confirmed, deaths }) => ((deaths / confirmed) * 100).toFixed(2);
68-
e.calRecoveredPer = ({ confirmed, recovered }) => ((recovered / confirmed) * 100).toFixed(2);
66+
e.calActive = ({ confirmed, recovered, deaths }) =>
67+
confirmed - (recovered + deaths);
68+
e.calMortalityPer = ({ confirmed, deaths }) =>
69+
((deaths / confirmed) * 100).toFixed(2);
70+
e.calRecoveredPer = ({ confirmed, recovered }) =>
71+
((recovered / confirmed) * 100).toFixed(2);
6972

7073
/**
7174
historyObj = {
@@ -78,11 +81,11 @@ e.calRecoveredPer = ({ confirmed, recovered }) => ((recovered / confirmed) * 100
7881
*/
7982
e.historyObjToArr = (historyObj) => {
8083
const sortedTimestampArr = _.sortBy(
81-
Object.keys(historyObj).map(date => new Date(date).getTime()),
82-
Number
84+
Object.keys(historyObj).map((date) => new Date(date).getTime()),
85+
Number,
8386
);
8487

85-
return sortedTimestampArr.map(timestamp => {
88+
return sortedTimestampArr.map((timestamp) => {
8689
const dateFormatted = moment(timestamp).format('M/D/YY');
8790
return historyObj[dateFormatted];
8891
});
@@ -92,7 +95,7 @@ e.historyObjToArr = (historyObj) => {
9295
* Given both arr1 and arr2 has same number of elements
9396
* Returns -> sum[n] = arr1[n] + arr2[n]
9497
*
95-
*/
98+
*/
9699
e.addArr = (arr1, arr2) => {
97100
if (arr1.length === 0) {
98101
return arr2;
@@ -126,75 +129,123 @@ e.getOneWeekChange = ({ confirmedByDay }) => {
126129
};
127130

128131
e.getTotalStats = (countryData) => {
129-
const worldStats = countryData.reduce((acc, countryObj) => {
130-
acc.confirmed += countryObj.confirmed;
131-
acc.deaths += countryObj.deaths;
132-
acc.confirmedByDay = e.addArr(acc.confirmedByDay, countryObj.confirmedByDay);
133-
acc.deathsByDay = e.addArr(acc.deathsByDay, countryObj.deathsByDay);
134-
return acc;
135-
}, {
136-
confirmed: 0,
137-
deaths: 0,
138-
confirmedByDay: [],
139-
deathsByDay: [],
140-
});
132+
const worldStats = countryData.reduce(
133+
(acc, countryObj) => {
134+
acc.confirmed += countryObj.confirmed;
135+
acc.deaths += countryObj.deaths;
136+
acc.confirmedByDay = e.addArr(
137+
acc.confirmedByDay,
138+
countryObj.confirmedByDay,
139+
);
140+
acc.deathsByDay = e.addArr(acc.deathsByDay, countryObj.deathsByDay);
141+
return acc;
142+
},
143+
{
144+
confirmed: 0,
145+
deaths: 0,
146+
confirmedByDay: [],
147+
deathsByDay: [],
148+
},
149+
);
141150

142151
worldStats.mortalityPer = e.calMortalityPer(worldStats);
143152
return worldStats;
144153
};
145154

146-
e.countryUpperCase = country => {
155+
e.countryUpperCase = (country) => {
147156
if (country.length > 2) {
148-
return country.toLowerCase().split(/\s+/).map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
157+
return country
158+
.toLowerCase()
159+
.split(/\s+/)
160+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
161+
.join(' ');
149162
}
150163

151164
return country;
152165
};
153166

154-
e.lookupCountry = country => {
167+
e.lookupCountry = (country) => {
155168
country = e.countryUpperCase(country);
156169

157170
try {
158-
return lookup.byIso(country)
159-
|| lookup.byFips(country)
160-
|| lookup.byCountry(country);
171+
return (
172+
lookup.byIso(country) ||
173+
lookup.byFips(country) ||
174+
lookup.byCountry(country)
175+
);
161176
} catch (error) {
162177
return lookup.byFips(country) || lookup.byCountry(country);
163178
}
164179
};
165180

166181
e.footer = (lastUpdated) => `
167182
168-
${chalk.cyanBright('Stay safe. Stay inside.')}
169-
${chalk.greenBright('Code')}: ${chalk.blueBright('https://github.com/sagarkarira/coronavirus-tracker-cli')}
170-
${chalk.greenBright('Twitter')}: ${chalk.blueBright('https://twitter.com/ekrysis')}
171-
172-
${chalk.magentaBright('Last Updated on:')} ${moment(lastUpdated).utc().format('DD-MMM-YYYY HH:MM')} UTC
173-
174-
${chalk.red.bold('US STATES API')}: ${chalk.blueBright('https://corona-stats.online/states/us')}
175-
${chalk.red.bold('HELP')}: ${chalk.blueBright('https://corona-stats.online/help')}
183+
${chalk.greenBright('Code')}: ${chalk.blueBright(
184+
'https://github.com/sagarkarira/coronavirus-tracker-cli',
185+
)}
186+
${chalk.greenBright('Twitter')}: ${chalk.blueBright(
187+
'https://twitter.com/ekrysis',
188+
)}
189+
190+
${chalk.magentaBright('Last Updated on:')} ${moment(lastUpdated)
191+
.utc()
192+
.format('DD-MMM-YYYY HH:MM')} UTC
193+
194+
${chalk.red.bold('US STATES API')}: ${chalk.blueBright(
195+
'https://corona-stats.online/states/us',
196+
)}
197+
${chalk.red.bold('HELP')}: ${chalk.blueBright(
198+
'https://corona-stats.online/help',
199+
)}
176200
${chalk.red.bold('SPONSORED BY')}: ${chalk.blueBright('ZEIT NOW')}
201+
${chalk.greenBright(
202+
'Checkout fun new side project I am working on',
203+
)}: ${chalk.bold.blueBright(
204+
'https://messagink.com/story/5eefb79b77193090dd29d3ce/global-response-to-coronavirus',
205+
)}
177206
`;
178207

179-
e.getTableBorders = minimal => {
208+
e.getTableBorders = (minimal) => {
180209
if (minimal) {
181210
return {
182-
'top': '', 'top-mid': '', 'top-left': '', 'top-right': '',
183-
'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': '',
184-
'left': '', 'left-mid': '', 'mid': '', 'mid-mid': '',
185-
'right': '', 'right-mid': '', 'middle': ' '
211+
top: '',
212+
'top-mid': '',
213+
'top-left': '',
214+
'top-right': '',
215+
bottom: '',
216+
'bottom-mid': '',
217+
'bottom-left': '',
218+
'bottom-right': '',
219+
left: '',
220+
'left-mid': '',
221+
mid: '',
222+
'mid-mid': '',
223+
right: '',
224+
'right-mid': '',
225+
middle: ' ',
186226
};
187227
}
188228

189229
return {
190-
'top': '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗',
191-
'bottom': '═', 'bottom-mid': '╧', 'bottom-left': '╚', 'bottom-right': '╝',
192-
'left': '║', 'left-mid': '╟', 'mid': '─', 'mid-mid': '┼',
193-
'right': '║', 'right-mid': '╢', 'middle': '│',
230+
top: '═',
231+
'top-mid': '╤',
232+
'top-left': '╔',
233+
'top-right': '╗',
234+
bottom: '═',
235+
'bottom-mid': '╧',
236+
'bottom-left': '╚',
237+
'bottom-right': '╝',
238+
left: '║',
239+
'left-mid': '╟',
240+
mid: '─',
241+
'mid-mid': '┼',
242+
right: '║',
243+
'right-mid': '╢',
244+
middle: '│',
194245
};
195246
};
196247

197-
e.getTableStyles = minimal => {
248+
e.getTableStyles = (minimal) => {
198249
if (minimal) {
199250
return { 'padding-left': 0, 'padding-right': 0 };
200251
}
@@ -231,7 +282,7 @@ e.getTableHeadersV2 = (emojis, secondColumnName) => {
231282
return head;
232283
};
233284
e.extraStats = (dataArr) => {
234-
return dataArr.map(obj => {
285+
return dataArr.map((obj) => {
235286
return {
236287
...obj,
237288
mortalityPer: e.calMortalityPer(obj),
@@ -302,4 +353,4 @@ exports.cFormatter = (content, chalkFn, alignment, humanize, extra = '') => {
302353
};
303354
}
304355
return content;
305-
};
356+
};

0 commit comments

Comments
 (0)