Skip to content

Commit f35cf99

Browse files
committed
🐛 FIX: Sort + API Outcome
1 parent 5e54736 commit f35cf99

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

utils/getAll.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ const { sortKeys, sortOrders } = require("./table.js");
66
module.exports = async (spinner, table, states, country, options) => {
77
if (!country && !states) {
88
const api = await axios.get(`https://corona.lmao.ninja/countries`);
9-
let all = api.data.map(one => Object.values(one));
9+
let allCountries = api.data.map(country => Object.values(country));
1010

1111
const sortIndex = sortKeys.indexOf(options.sort);
1212

1313
if (sortIndex != -1) {
1414
const dir = sortOrders[sortIndex];
15-
all = all.sort((a, b) => (a[sortIndex] > b[sortIndex] ? dir : -dir));
15+
allCountries = allCountries.sort((a, b) =>
16+
a[sortIndex] > b[sortIndex] ? dir : -dir
17+
);
1618
}
1719

18-
all.map(one => {
19-
one = one.map(d => comma(d));
20-
return table.push(one);
20+
allCountries.map((oneCountry, count) => {
21+
oneCountry = [oneCountry[0], ...oneCountry.slice(2, oneCountry.length)];
22+
oneCountry = oneCountry.map(stat => comma(stat));
23+
return table.push([count + 1, ...oneCountry]);
2124
});
2225
spinner.stopAndPersist();
2326
spinner.info(`${chalk.cyan(`Sorted by:`)} ${options.sort}`);

utils/getCountry.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ module.exports = async (spinner, table, states, country) => {
1919
);
2020
process.exit(0);
2121
}
22-
let data = Object.values(api.data);
23-
data = data.map(d => comma(d));
24-
table.push(data);
22+
let dataPerCountry = Object.values(api.data);
23+
dataPerCountry = [
24+
dataPerCountry[0],
25+
...dataPerCountry.slice(2, dataPerCountry.length)
26+
];
27+
dataPerCountry = dataPerCountry.map(stat => comma(stat));
28+
table.push([`—`, ...dataPerCountry]);
2529
spinner.stopAndPersist();
2630
console.log(table.toString());
2731
}

utils/getStates.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ const { sortStateKeys, sortStateOrders } = require("./table.js");
66
module.exports = async (spinner, table, states, options) => {
77
if (states) {
88
const api = await axios.get(`https://corona.lmao.ninja/states`);
9-
let all = api.data.map(one => Object.values(one));
9+
let allStates = api.data.map(one => Object.values(one));
1010

1111
const sortIndex = sortStateKeys.indexOf(options.sort);
1212

1313
if (sortIndex != -1) {
1414
const dir = sortStateOrders[sortIndex];
15-
all = all.sort((a, b) => (a[sortIndex] > b[sortIndex] ? dir : -dir));
15+
allStates = allStates.sort((a, b) =>
16+
a[sortIndex] > b[sortIndex] ? dir : -dir
17+
);
1618
}
1719

18-
all.map(one => {
19-
one = one.map(d => comma(d));
20-
return table.push(one);
20+
allStates.map((oneState, count) => {
21+
oneState = oneState.map(d => comma(d));
22+
return table.push([count + 1, ...oneState]);
2123
});
2224

2325
spinner.stopAndPersist();

utils/getWorldwide.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = async (table, states) => {
77
let data = Object.values(all.data);
88
data = data.map(d => comma(d));
99
table.push([
10+
`—`,
1011
`Worldwide`,
1112
data[0],
1213
`—`,

utils/table.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const dim = chalk.dim;
55

66
module.exports = {
77
single: [
8+
`#`,
89
`Country`,
910
`Cases`,
1011
`Cases ${dim(`(today)`)}`,
@@ -16,6 +17,7 @@ module.exports = {
1617
`Per Million`
1718
],
1819
colored: [
20+
`#`,
1921
`Country`,
2022
`Cases`,
2123
`Cases ${dim(`(today)`)}`,
@@ -28,6 +30,7 @@ module.exports = {
2830
],
2931
sortKeys: [
3032
`country`,
33+
`country-info`,
3134
`cases`,
3235
`cases-today`,
3336
`deaths`,
@@ -38,6 +41,7 @@ module.exports = {
3841
`per-million`
3942
],
4043
singleStates: [
44+
`#`,
4145
`State`,
4246
`Cases`,
4347
`Cases ${dim(`(today)`)}`,
@@ -47,6 +51,7 @@ module.exports = {
4751
`Active`
4852
],
4953
coloredStates: [
54+
`#`,
5055
`State`,
5156
`Cases`,
5257
`Cases ${dim(`(today)`)}`,
@@ -64,7 +69,7 @@ module.exports = {
6469
`recovered`,
6570
`active`
6671
],
67-
sortOrders: [1, -1, -1, -1, -1, -1, -1, -1, -1],
72+
sortOrders: [1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
6873
sortStateOrders: [1, -1, -1, -1, -1, -1, -1],
6974
style: { head: ["cyan"] }
7075
};

0 commit comments

Comments
 (0)