From f90cd38c0363fd54c76d5866cc59c091e90220cb Mon Sep 17 00:00:00 2001 From: inukares Date: Wed, 25 Mar 2020 15:25:01 +0000 Subject: [PATCH 01/21] NEW: Omit table rows from console output --- index.js | 16 ++++++++++++--- utils/cli.js | 7 +++++++ utils/columnsMapper.js | 45 ++++++++++++++++++++++++++++++++++++++++++ utils/deleteColumns.js | 31 +++++++++++++++++++++++++++++ utils/getCountries.js | 4 ---- utils/getCountry.js | 3 +-- utils/getStates.js | 4 ---- 7 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 utils/columnsMapper.js create mode 100644 utils/deleteColumns.js diff --git a/index.js b/index.js index e737930..ec80b4c 100755 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ process.on("unhandledRejection", err => { const ora = require("ora"); const spinner = ora({ text: "" }); const Table = require("cli-table3"); +const chalk = require("chalk"); const cli = require("./utils/cli.js"); const init = require("./utils/init.js"); const getCountries = require("./utils/getCountries.js"); @@ -19,6 +20,7 @@ const handleError = require("cli-handle-error"); const getCountry = require("./utils/getCountry.js"); const getStates = require("./utils/getStates.js"); const getWorldwide = require("./utils/getWorldwide.js"); +const deleteColumns = require('./utils/deleteColumns'); const { single, colored, @@ -29,6 +31,13 @@ const { const xcolor = cli.flags.xcolor; const sortBy = cli.flags.sort; +const consoleLogTable = (spinner, table, sortBy) => { + spinner.stopAndPersist(); + if(sortBy) spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); + console.log(table.toString()) +}; + + (async () => { // Init. init(); @@ -40,9 +49,8 @@ const sortBy = cli.flags.sort; // Table const head = xcolor ? single : colored; const headStates = xcolor ? singleStates : coloredStates; - const table = !states - ? new Table({ head, style }) - : new Table({ head: headStates, style }); + let tableHead = states ? headStates : head; + const table = new Table( { head: tableHead, style }); // Display data. spinner.start(); @@ -50,6 +58,8 @@ const sortBy = cli.flags.sort; await getCountry(spinner, table, states, country); await getStates(spinner, table, states, sortBy); await getCountries(spinner, table, states, country, sortBy); + deleteColumns(table, states, tableHead); + consoleLogTable(spinner, table, sortBy ); theEnd(lastUpdated, states); })(); diff --git a/utils/cli.js b/utils/cli.js index beef82d..5ff5cd8 100644 --- a/utils/cli.js +++ b/utils/cli.js @@ -23,6 +23,8 @@ module.exports = meow( ${green(`corona`)} ${yellow(`-x`)} ${green(`corona`)} ${yellow(`--sort`)} ${cyan(`cases-today`)} ${green(`corona`)} ${yellow(`-s`)} ${cyan(`critical`)} + ${green(`corona`)} ${yellow(`--omit`)} ${cyan(`deaths-today_cases_critical`)} + ${green(`corona`)} ${yellow(`--o`)} ${cyan(`country`)} ❯ You can also run command + option at once: ${green(`corona`)} ${cyan(`china`)} ${yellow(`-x`)} ${yellow(`-s cases`)} @@ -41,6 +43,11 @@ module.exports = meow( type: "string", default: "cases", alias: "s" + }, + 'omit': { + type: "string", + default: '', + alias: 'o' } } } diff --git a/utils/columnsMapper.js b/utils/columnsMapper.js new file mode 100644 index 0000000..68d863e --- /dev/null +++ b/utils/columnsMapper.js @@ -0,0 +1,45 @@ +module.exports = { + single: { + '#': 0, + 'country': 1, + 'cases': 2, + 'cases-today': 3, + 'deaths': 4, + 'deaths-today': 5, + 'recovered': 6, + 'active': 7, + 'critical': 8, + 'per-milion': 9 + }, + colored: { + '#': 0, + 'country': 1, + 'cases': 2, + 'cases-today': 3, + 'deaths': 4, + 'deaths-today': 5, + 'recovered': 6, + 'active': 7, + 'critical': 8, + 'per-milion': 9 + }, + singleStates: { + '#': 0, + 'state': 1, + 'cases': 2, + 'cases-today': 3, + 'deaths': 4, + 'deaths-today': 5, + 'active': 6 + }, + coloredStates : { + '#': 0, + 'state': 1, + 'cases': 2, + 'cases-today': 3, + 'deaths': 4, + 'deaths-today': 5, + 'active': 6 + }, +}; + diff --git a/utils/deleteColumns.js b/utils/deleteColumns.js new file mode 100644 index 0000000..cc21ef1 --- /dev/null +++ b/utils/deleteColumns.js @@ -0,0 +1,31 @@ +const mapper = require('./columnsMapper'); +const cli = require('./cli'); + +// returns indices of table rows which user wants to omit form output in descending order +const parseCli = (states, separator = '_') => { + const input = cli.flags.omit; + if(!input || typeof input !== 'string' || input === '') return []; + return input + .split(separator) + .reduce((accumulator, current,) => { + if(states) { + return mapper.singleStates[current] ? [...accumulator, mapper.singleStates[current]] : accumulator + } + return mapper.single[current] ? [...accumulator, mapper.single[current]] : accumulator + }, []) + .sort((a, b) => a > b ? -1 : 1) +}; + +const deleteColumns = (table, tableHead, input) => { + input.forEach(key => { + tableHead.splice(key, 1); + table.forEach(row => { + row.splice(key, 1) + }) + }) +}; + +module.exports = (table, states, tableHead) => { + const input = parseCli(states); + deleteColumns(table, tableHead, input) +}; diff --git a/utils/getCountries.js b/utils/getCountries.js index 587c85f..8585f8d 100644 --- a/utils/getCountries.js +++ b/utils/getCountries.js @@ -1,5 +1,4 @@ const axios = require("axios"); -const chalk = require("chalk"); const comma = require("comma-number"); const { sortingKeys } = require("./table.js"); const to = require("await-to-js").default; @@ -33,8 +32,5 @@ module.exports = async (spinner, table, states, countryName, sortBy) => { ]); }); - spinner.stopAndPersist(); - spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); - console.log(table.toString()); } }; diff --git a/utils/getCountry.js b/utils/getCountry.js index ac0bba4..8d9fa45 100644 --- a/utils/getCountry.js +++ b/utils/getCountry.js @@ -36,7 +36,6 @@ module.exports = async (spinner, table, states, countryName) => { comma(thisCountry.critical), comma(thisCountry.casesPerOneMillion) ]); - spinner.stopAndPersist(); - console.log(table.toString()); + } }; diff --git a/utils/getStates.js b/utils/getStates.js index 9d84828..960be92 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -1,5 +1,4 @@ const axios = require("axios"); -const chalk = require("chalk"); const comma = require("comma-number"); const { sortingStateKeys } = require("./table.js"); const to = require("await-to-js").default; @@ -30,8 +29,5 @@ module.exports = async (spinner, table, states, sortBy) => { ]); }); - spinner.stopAndPersist(); - spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); - console.log(table.toString()); } }; From a11c1a905946389b3e8f49f108921a184e58e61d Mon Sep 17 00:00:00 2001 From: Ashar Irfan Date: Wed, 25 Mar 2020 19:37:15 +0500 Subject: [PATCH 02/21] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20Reverse=20order=20o?= =?UTF-8?q?f=20output=20(#40)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * πŸ“¦ NEW: Reverse sorting flag * πŸ“¦ NEW: Reverse data sorting using reverse flag * πŸ“– DOC: Reverse sorting --- index.js | 21 ++++++--------------- readme.md | 4 ++++ utils/cli.js | 8 +++----- utils/getCountries.js | 15 +++++++++++++-- utils/getStates.js | 15 +++++++++++++-- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index ec80b4c..18bcda8 100755 --- a/index.js +++ b/index.js @@ -10,7 +10,6 @@ process.on("unhandledRejection", err => { const ora = require("ora"); const spinner = ora({ text: "" }); const Table = require("cli-table3"); -const chalk = require("chalk"); const cli = require("./utils/cli.js"); const init = require("./utils/init.js"); const getCountries = require("./utils/getCountries.js"); @@ -20,7 +19,6 @@ const handleError = require("cli-handle-error"); const getCountry = require("./utils/getCountry.js"); const getStates = require("./utils/getStates.js"); const getWorldwide = require("./utils/getWorldwide.js"); -const deleteColumns = require('./utils/deleteColumns'); const { single, colored, @@ -30,13 +28,7 @@ const { } = require("./utils/table.js"); const xcolor = cli.flags.xcolor; const sortBy = cli.flags.sort; - -const consoleLogTable = (spinner, table, sortBy) => { - spinner.stopAndPersist(); - if(sortBy) spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); - console.log(table.toString()) -}; - +const reverse = cli.flags.reverse; (async () => { // Init. @@ -49,17 +41,16 @@ const consoleLogTable = (spinner, table, sortBy) => { // Table const head = xcolor ? single : colored; const headStates = xcolor ? singleStates : coloredStates; - let tableHead = states ? headStates : head; - const table = new Table( { head: tableHead, style }); + const table = !states + ? new Table({ head, style }) + : new Table({ head: headStates, style }); // Display data. spinner.start(); const lastUpdated = await getWorldwide(table, states); await getCountry(spinner, table, states, country); - await getStates(spinner, table, states, sortBy); - await getCountries(spinner, table, states, country, sortBy); - deleteColumns(table, states, tableHead); - consoleLogTable(spinner, table, sortBy ); + await getStates(spinner, table, states, sortBy, reverse); + await getCountries(spinner, table, states, country, sortBy, reverse); theEnd(lastUpdated, states); })(); diff --git a/readme.md b/readme.md index d89c552..8d783dc 100644 --- a/readme.md +++ b/readme.md @@ -105,6 +105,10 @@ corona -s recovered corona -s active corona -s critical corona -s per-million + +# Reverse sort data +corona --sort country --reverse +corona -s country -r ``` [![πŸ“Ÿ](./.github/sort.gif)](./../../) diff --git a/utils/cli.js b/utils/cli.js index 5ff5cd8..9f26a90 100644 --- a/utils/cli.js +++ b/utils/cli.js @@ -16,6 +16,7 @@ module.exports = meow( Options ${yellow(`--xcolor`)}, ${yellow(`-x`)} Single colored output ${yellow(`--sort`)}, ${yellow(`-s`)} Sort data by type + ${yellow(`--reverse`)}, ${yellow(`-r`)} Reverse the order of sorted data Examples ${green(`corona`)} ${cyan(`china`)} @@ -23,8 +24,6 @@ module.exports = meow( ${green(`corona`)} ${yellow(`-x`)} ${green(`corona`)} ${yellow(`--sort`)} ${cyan(`cases-today`)} ${green(`corona`)} ${yellow(`-s`)} ${cyan(`critical`)} - ${green(`corona`)} ${yellow(`--omit`)} ${cyan(`deaths-today_cases_critical`)} - ${green(`corona`)} ${yellow(`--o`)} ${cyan(`country`)} ❯ You can also run command + option at once: ${green(`corona`)} ${cyan(`china`)} ${yellow(`-x`)} ${yellow(`-s cases`)} @@ -44,10 +43,9 @@ module.exports = meow( default: "cases", alias: "s" }, - 'omit': { + reverse: { type: "string", - default: '', - alias: 'o' + alias: "r" } } } diff --git a/utils/getCountries.js b/utils/getCountries.js index 8585f8d..b038aa6 100644 --- a/utils/getCountries.js +++ b/utils/getCountries.js @@ -1,11 +1,12 @@ const axios = require("axios"); +const chalk = require("chalk"); const comma = require("comma-number"); const { sortingKeys } = require("./table.js"); const to = require("await-to-js").default; const handleError = require("cli-handle-error"); const orderBy = require("lodash.orderby"); -module.exports = async (spinner, table, states, countryName, sortBy) => { +module.exports = async (spinner, table, states, countryName, sortBy, reverse) => { if (!countryName && !states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/countries`) @@ -14,7 +15,11 @@ module.exports = async (spinner, table, states, countryName, sortBy) => { let allCountries = response.data; // Sort. - allCountries = orderBy(allCountries, [sortingKeys[sortBy]], ["desc"]); + if ( reverse !== undefined ) { + allCountries = orderBy(allCountries, [sortingKeys[sortBy]], ["asc"]); + } else { + allCountries = orderBy(allCountries, [sortingKeys[sortBy]], ["desc"]); + } // Push selected data. allCountries.map((oneCountry, count) => { @@ -32,5 +37,11 @@ module.exports = async (spinner, table, states, countryName, sortBy) => { ]); }); + spinner.stopAndPersist(); + spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); + if ( reverse !== undefined ) { + spinner.info(`${chalk.cyan(`Order:`)} reverse`); + } + console.log(table.toString()); } }; diff --git a/utils/getStates.js b/utils/getStates.js index 960be92..14f02e3 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -1,11 +1,12 @@ const axios = require("axios"); +const chalk = require("chalk"); const comma = require("comma-number"); const { sortingStateKeys } = require("./table.js"); const to = require("await-to-js").default; const handleError = require("cli-handle-error"); const orderBy = require("lodash.orderby"); -module.exports = async (spinner, table, states, sortBy) => { +module.exports = async (spinner, table, states, sortBy, reverse) => { if (states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/states`) @@ -14,7 +15,11 @@ module.exports = async (spinner, table, states, sortBy) => { let allStates = response.data; // Sort. - allStates = orderBy(allStates, [sortingStateKeys[sortBy]], ["desc"]); + if ( reverse !== undefined ) { + allStates = orderBy(allStates, [sortingStateKeys[sortBy]], ["asc"]); + } else { + allStates = orderBy(allStates, [sortingStateKeys[sortBy]], ["desc"]); + } // Push selected data. allStates.map((oneState, count) => { @@ -29,5 +34,11 @@ module.exports = async (spinner, table, states, sortBy) => { ]); }); + spinner.stopAndPersist(); + spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); + if ( reverse !== undefined ) { + spinner.info(`${chalk.cyan(`Order:`)} reverse`); + } + console.log(table.toString()); } }; From 366de33886f5bd00620cd64e71c2a1af329c3d22 Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 19:50:58 +0500 Subject: [PATCH 03/21] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Reverse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierrc.json | 10 +++++----- index.js | 33 ++++++++++++++++---------------- package.json | 4 ++++ readme.md | 2 +- utils/cli.js | 25 ++++++++++++------------ utils/getCountries.js | 40 +++++++++++++++++++++++---------------- utils/getCountry.js | 16 ++++++++-------- utils/getStates.js | 27 ++++++++++++-------------- utils/getWorldwide.js | 12 ++++++------ utils/init.js | 10 +++++----- utils/showHelp.js | 5 ----- utils/table.js | 44 +++++++++++++++++++++---------------------- utils/theEnd.js | 4 ++-- 13 files changed, 118 insertions(+), 114 deletions(-) delete mode 100644 utils/showHelp.js diff --git a/.prettierrc.json b/.prettierrc.json index 308d576..77a895d 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,7 +1,7 @@ { - "prettier.printWidth": 80, - "prettier.singleQuote": true, - "prettier.useTabs": true, - "prettier.tabWidth": 4, - "prettier.semi": true + "printWidth": 80, + "singleQuote": true, + "useTabs": true, + "tabWidth": 4, + "semi": true } diff --git a/index.js b/index.js index 18bcda8..3c4b4db 100755 --- a/index.js +++ b/index.js @@ -3,29 +3,28 @@ // Makes the script crash on unhandled rejections instead of silently // ignoring them. In the future, promise rejections that are not handled will // terminate the Node.js process with a non-zero exit code. -process.on("unhandledRejection", err => { +process.on('unhandledRejection', (err) => { handleError(`UNHANDLED ERROR`, err); }); -const ora = require("ora"); -const spinner = ora({ text: "" }); -const Table = require("cli-table3"); -const cli = require("./utils/cli.js"); -const init = require("./utils/init.js"); -const getCountries = require("./utils/getCountries.js"); -const showHelp = require("./utils/showHelp.js"); -const theEnd = require("./utils/theEnd.js"); -const handleError = require("cli-handle-error"); -const getCountry = require("./utils/getCountry.js"); -const getStates = require("./utils/getStates.js"); -const getWorldwide = require("./utils/getWorldwide.js"); +const ora = require('ora'); +const spinner = ora({ text: '' }); +const Table = require('cli-table3'); +const cli = require('./utils/cli.js'); +const init = require('./utils/init.js'); +const theEnd = require('./utils/theEnd.js'); +const handleError = require('cli-handle-error'); +const getStates = require('./utils/getStates.js'); +const getCountry = require('./utils/getCountry.js'); +const getWorldwide = require('./utils/getWorldwide.js'); +const getCountries = require('./utils/getCountries.js'); const { single, colored, singleStates, coloredStates, - style -} = require("./utils/table.js"); + style, +} = require('./utils/table.js'); const xcolor = cli.flags.xcolor; const sortBy = cli.flags.sort; const reverse = cli.flags.reverse; @@ -34,8 +33,8 @@ const reverse = cli.flags.reverse; // Init. init(); const [input] = cli.input; - await showHelp(); - const states = input === "states" ? true : false; + input === 'help' && (await cli.showHelp(0)); + const states = input === 'states' ? true : false; const country = input; // Table diff --git a/package.json b/package.json index 8ab391f..1aaffee 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "ahmadawais" ], "scripts": { + "format": "prettier --write \"./**/*.{js,json}\"", "test": "node test.js" }, "dependencies": { @@ -39,5 +40,8 @@ "meow": "^6.1.0", "ora": "^4.0.3", "update-notifier": "^4.1.0" + }, + "devDependencies": { + "prettier": "^2.0.2" } } diff --git a/readme.md b/readme.md index 8d783dc..ee09e5f 100644 --- a/readme.md +++ b/readme.md @@ -19,7 +19,7 @@ Track the Coronavirus disease (COVID-19) or the Novel Coronavirus Strain. - 🀯 Active daily reporting of your country's COVID-19 statistics - πŸ‡ΊπŸ‡Έ Get US States data for Coronavirus disease reports across the US - πŸ—ƒοΈ Data: Country, Cases, Deaths, Recovered, Active, Critical, Per Million -- πŸ“Ÿ Sort: `cases`,`cases-today`,`deaths`,`deaths-today`,`recovered`,`active`,`critical`,`per-million` +- πŸ“Ÿ Sort: `cases`, `cases-today`, `deaths`, `deaths-today`, `recovered`, `active`, `critical`, `per-million`
diff --git a/utils/cli.js b/utils/cli.js index 9f26a90..289f520 100644 --- a/utils/cli.js +++ b/utils/cli.js @@ -1,5 +1,5 @@ -const meow = require("meow"); -const chalk = require("chalk"); +const meow = require('meow'); +const chalk = require('chalk'); const green = chalk.green; const yellow = chalk.yellow; const cyan = chalk.cyan; @@ -16,7 +16,7 @@ module.exports = meow( Options ${yellow(`--xcolor`)}, ${yellow(`-x`)} Single colored output ${yellow(`--sort`)}, ${yellow(`-s`)} Sort data by type - ${yellow(`--reverse`)}, ${yellow(`-r`)} Reverse the order of sorted data + ${yellow(`--reverse`)}, ${yellow(`-r`)} Reverse print order Examples ${green(`corona`)} ${cyan(`china`)} @@ -34,19 +34,20 @@ module.exports = meow( inferType: false, flags: { xcolor: { - type: "boolean", + type: 'boolean', default: false, - alias: "x" + alias: 'x', }, sort: { - type: "string", - default: "cases", - alias: "s" + type: 'string', + default: 'cases', + alias: 's', }, reverse: { - type: "string", - alias: "r" - } - } + type: 'boolean', + default: false, + alias: 'r', + }, + }, } ); diff --git a/utils/getCountries.js b/utils/getCountries.js index b038aa6..b39ebad 100644 --- a/utils/getCountries.js +++ b/utils/getCountries.js @@ -1,12 +1,19 @@ -const axios = require("axios"); -const chalk = require("chalk"); -const comma = require("comma-number"); -const { sortingKeys } = require("./table.js"); -const to = require("await-to-js").default; -const handleError = require("cli-handle-error"); -const orderBy = require("lodash.orderby"); +const axios = require('axios'); +const chalk = require('chalk'); +const comma = require('comma-number'); +const { sortingKeys } = require('./table.js'); +const to = require('await-to-js').default; +const handleError = require('cli-handle-error'); +const orderBy = require('lodash.orderby'); -module.exports = async (spinner, table, states, countryName, sortBy, reverse) => { +module.exports = async ( + spinner, + table, + states, + countryName, + sortBy, + reverse +) => { if (!countryName && !states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/countries`) @@ -14,12 +21,13 @@ module.exports = async (spinner, table, states, countryName, sortBy, reverse) => handleError(`API is down, try again later.`, err, false); let allCountries = response.data; - // Sort. - if ( reverse !== undefined ) { - allCountries = orderBy(allCountries, [sortingKeys[sortBy]], ["asc"]); - } else { - allCountries = orderBy(allCountries, [sortingKeys[sortBy]], ["desc"]); - } + // Sort & reverse. + const direction = reverse ? 'asc' : 'desc'; + allCountries = orderBy( + allCountries, + [sortingKeys[sortBy]], + [direction] + ); // Push selected data. allCountries.map((oneCountry, count) => { @@ -33,13 +41,13 @@ module.exports = async (spinner, table, states, countryName, sortBy, reverse) => comma(oneCountry.recovered), comma(oneCountry.active), comma(oneCountry.critical), - comma(oneCountry.casesPerOneMillion) + comma(oneCountry.casesPerOneMillion), ]); }); spinner.stopAndPersist(); spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); - if ( reverse !== undefined ) { + if (reverse !== undefined) { spinner.info(`${chalk.cyan(`Order:`)} reverse`); } console.log(table.toString()); diff --git a/utils/getCountry.js b/utils/getCountry.js index 8d9fa45..23cb880 100644 --- a/utils/getCountry.js +++ b/utils/getCountry.js @@ -1,10 +1,10 @@ -const chalk = require("chalk"); -const axios = require("axios"); -const sym = require("log-symbols"); -const comma = require("comma-number"); +const chalk = require('chalk'); +const axios = require('axios'); +const sym = require('log-symbols'); +const comma = require('comma-number'); const red = chalk.red; -const to = require("await-to-js").default; -const handleError = require("cli-handle-error"); +const to = require('await-to-js').default; +const handleError = require('cli-handle-error'); module.exports = async (spinner, table, states, countryName) => { if (countryName && !states) { @@ -14,7 +14,7 @@ module.exports = async (spinner, table, states, countryName) => { handleError(`API is down, try again later.`, err, false); const thisCountry = response.data; - if (response.data === "Country not found") { + if (response.data === 'Country not found') { spinner.stopAndPersist(); console.log( `${red( @@ -34,7 +34,7 @@ module.exports = async (spinner, table, states, countryName) => { comma(thisCountry.recovered), comma(thisCountry.active), comma(thisCountry.critical), - comma(thisCountry.casesPerOneMillion) + comma(thisCountry.casesPerOneMillion), ]); } diff --git a/utils/getStates.js b/utils/getStates.js index 14f02e3..704499d 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -1,10 +1,10 @@ -const axios = require("axios"); -const chalk = require("chalk"); -const comma = require("comma-number"); -const { sortingStateKeys } = require("./table.js"); -const to = require("await-to-js").default; -const handleError = require("cli-handle-error"); -const orderBy = require("lodash.orderby"); +const axios = require('axios'); +const chalk = require('chalk'); +const comma = require('comma-number'); +const { sortingStateKeys } = require('./table.js'); +const to = require('await-to-js').default; +const handleError = require('cli-handle-error'); +const orderBy = require('lodash.orderby'); module.exports = async (spinner, table, states, sortBy, reverse) => { if (states) { @@ -14,12 +14,9 @@ module.exports = async (spinner, table, states, sortBy, reverse) => { handleError(`API is down, try again later.`, err, false); let allStates = response.data; - // Sort. - if ( reverse !== undefined ) { - allStates = orderBy(allStates, [sortingStateKeys[sortBy]], ["asc"]); - } else { - allStates = orderBy(allStates, [sortingStateKeys[sortBy]], ["desc"]); - } + // Sort & reverse. + const direction = reverse ? 'asc' : 'desc'; + allStates = orderBy(allStates, [sortingStateKeys[sortBy]], [direction]); // Push selected data. allStates.map((oneState, count) => { @@ -30,13 +27,13 @@ module.exports = async (spinner, table, states, sortBy, reverse) => { comma(oneState.todayCases), comma(oneState.deaths), comma(oneState.todayDeaths), - comma(oneState.active) + comma(oneState.active), ]); }); spinner.stopAndPersist(); spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); - if ( reverse !== undefined ) { + if (reverse !== undefined) { spinner.info(`${chalk.cyan(`Order:`)} reverse`); } console.log(table.toString()); diff --git a/utils/getWorldwide.js b/utils/getWorldwide.js index 4091f80..43d0bbf 100644 --- a/utils/getWorldwide.js +++ b/utils/getWorldwide.js @@ -1,13 +1,13 @@ -const axios = require("axios"); -const comma = require("comma-number"); -const to = require("await-to-js").default; -const handleError = require("cli-handle-error"); +const axios = require('axios'); +const comma = require('comma-number'); +const to = require('await-to-js').default; +const handleError = require('cli-handle-error'); module.exports = async (table, states) => { const [err, all] = await to(axios.get(`https://corona.lmao.ninja/all`)); handleError(`API is down, try again later.`, err, false); let data = Object.values(all.data); - data = data.map(d => comma(d)); + data = data.map((d) => comma(d)); if (!states) { table.push([ @@ -20,7 +20,7 @@ module.exports = async (table, states) => { data[2], `β€”`, `β€”`, - `β€”` + `β€”`, ]); } diff --git a/utils/init.js b/utils/init.js index 7e2c161..efb018b 100644 --- a/utils/init.js +++ b/utils/init.js @@ -1,6 +1,6 @@ -const welcome = require("cli-welcome"); -const pkgJSON = require("./../package.json"); -const updateNotifier = require("update-notifier"); +const welcome = require('cli-welcome'); +const pkgJSON = require('./../package.json'); +const updateNotifier = require('update-notifier'); module.exports = async () => { welcome(`corona-cli`, `by Awais.dev\n${pkgJSON.description}`, { @@ -8,11 +8,11 @@ module.exports = async () => { color: `#FFFFFF`, bold: true, clear: true, - version: `v${pkgJSON.version}` + version: `v${pkgJSON.version}`, }); updateNotifier({ pkg: pkgJSON, shouldNotifyInNpmScript: true, - updateCheckInterval: 1000 * 60 * 60 * 24 // 24 hours. + updateCheckInterval: 1000 * 60 * 60 * 24, // 24 hours. }).notify({ isGlobal: true }); }; diff --git a/utils/showHelp.js b/utils/showHelp.js deleted file mode 100644 index f4f2218..0000000 --- a/utils/showHelp.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = async input => { - if (input === "help") { - await cli.showHelp(0); - } -}; diff --git a/utils/table.js b/utils/table.js index c9dc20d..7d8ce68 100644 --- a/utils/table.js +++ b/utils/table.js @@ -1,4 +1,4 @@ -const chalk = require("chalk"); +const chalk = require('chalk'); const green = chalk.green; const red = chalk.red; const yellow = chalk.yellow; @@ -15,7 +15,7 @@ module.exports = { `Recovered`, `Active`, `Critical`, - `Per Million` + `Per Million`, ], colored: [ `#`, @@ -27,7 +27,7 @@ module.exports = { `${green(`Recovered`)}`, `${yellow(`Active`)}`, `${red(`Critical`)}`, - `Per Million` + `Per Million`, ], singleStates: [ `#`, @@ -36,7 +36,7 @@ module.exports = { `Cases ${dim(`(today)`)}`, `Deaths`, `Deaths ${dim(`(today)`)}`, - `Active` + `Active`, ], coloredStates: [ `#`, @@ -45,26 +45,26 @@ module.exports = { `Cases ${dim(`(today)`)}`, `${red(`Deaths`)}`, `${red(`Deaths (today)`)}`, - `${yellow(`Active`)}` + `${yellow(`Active`)}`, ], - style: { head: ["cyan"] }, + style: { head: ['cyan'] }, sortingKeys: { - country: "country", - cases: "cases", - "cases-today": "todayCases", - deaths: "deaths", - "deaths-today": "todayDeaths", - recovered: "recovered", - active: "active", - critical: "critical", - "per-million": "casesPerOneMillion" + country: 'country', + cases: 'cases', + 'cases-today': 'todayCases', + deaths: 'deaths', + 'deaths-today': 'todayDeaths', + recovered: 'recovered', + active: 'active', + critical: 'critical', + 'per-million': 'casesPerOneMillion', }, sortingStateKeys: { - state: "state", - cases: "cases", - "cases-today": "todayCases", - deaths: "deaths", - "deaths-today": "todayDeaths", - active: "active" - } + state: 'state', + cases: 'cases', + 'cases-today': 'todayCases', + deaths: 'deaths', + 'deaths-today': 'todayDeaths', + active: 'active', + }, }; diff --git a/utils/theEnd.js b/utils/theEnd.js index 3aa30d0..c7bd62b 100644 --- a/utils/theEnd.js +++ b/utils/theEnd.js @@ -1,5 +1,5 @@ -const sym = require("log-symbols"); -const chalk = require("chalk"); +const sym = require('log-symbols'); +const chalk = require('chalk'); const cyan = chalk.cyan; const dim = chalk.dim; From 1b524f0de3184491101470eacdf0be1135ce1e51 Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 19:59:33 +0500 Subject: [PATCH 04/21] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Lingo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/getCountries.js | 10 +++++----- utils/getStates.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/utils/getCountries.js b/utils/getCountries.js index b39ebad..d4bcf81 100644 --- a/utils/getCountries.js +++ b/utils/getCountries.js @@ -1,5 +1,7 @@ const axios = require('axios'); const chalk = require('chalk'); +const cyan = chalk.cyan; +const dim = chalk.dim; const comma = require('comma-number'); const { sortingKeys } = require('./table.js'); const to = require('await-to-js').default; @@ -41,15 +43,13 @@ module.exports = async ( comma(oneCountry.recovered), comma(oneCountry.active), comma(oneCountry.critical), - comma(oneCountry.casesPerOneMillion), + comma(oneCountry.casesPerOneMillion) ]); }); spinner.stopAndPersist(); - spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); - if (reverse !== undefined) { - spinner.info(`${chalk.cyan(`Order:`)} reverse`); - } + const isRev = reverse ? `${dim(` & `)}${cyan(`Order`)}: reversed` : ``; + spinner.info(`${cyan(`Sorted by:`)} ${sortBy}${isRev}`); console.log(table.toString()); } }; diff --git a/utils/getStates.js b/utils/getStates.js index 704499d..e79a209 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -1,5 +1,7 @@ const axios = require('axios'); const chalk = require('chalk'); +const cyan = chalk.cyan; +const dim = chalk.dim; const comma = require('comma-number'); const { sortingStateKeys } = require('./table.js'); const to = require('await-to-js').default; @@ -27,15 +29,13 @@ module.exports = async (spinner, table, states, sortBy, reverse) => { comma(oneState.todayCases), comma(oneState.deaths), comma(oneState.todayDeaths), - comma(oneState.active), + comma(oneState.active) ]); }); spinner.stopAndPersist(); - spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); - if (reverse !== undefined) { - spinner.info(`${chalk.cyan(`Order:`)} reverse`); - } + const isRev = reverse ? `${dim(` & `)}${cyan(`Order`)}: reversed` : ``; + spinner.info(`${cyan(`Sorted by:`)} ${sortBy}${isRev}`); console.log(table.toString()); } }; From 3739ac2cb8a2a8b35234ad9d99f0e0bdd4f52303 Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 19:59:50 +0500 Subject: [PATCH 05/21] =?UTF-8?q?=F0=9F=93=96=20DOC:=20Changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 17 +++++++++++++++++ package.json | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index f33064c..e676e95 100644 --- a/changelog.md +++ b/changelog.md @@ -29,12 +29,29 @@ I have released a video course to help you become a better developer β€” +### RELEASE: [3.5.0](https://github.com/ahmadawais/corona-cli/compare/3.4.0...3.5.0) + +![πŸ‘Œ IMPROVE:](https://img.shields.io/badge/-IMPROVEMENT-gray.svg?colorB=39AA54) + +> πŸ‘Œ Reverse [`5cb3f2b`](https://github.com/ahmadawais/corona-cli/commit/5cb3f2bd85a95d0b7d33f6fdca9246c0f6bf763c)
+> πŸ‘Œ Lingo [`7f4a751`](https://github.com/ahmadawais/corona-cli/commit/7f4a751f451a6b17cb522b0d5282cdfa5d09caba)
+ +
+ +[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) + +
+ ### RELEASE: [3.4.0](https://github.com/ahmadawais/corona-cli/compare/3.3.0...3.4.0) ![πŸ‘Œ IMPROVE:](https://img.shields.io/badge/-IMPROVEMENT-gray.svg?colorB=39AA54) > πŸ‘Œ Lingo [`36d3f89`](https://github.com/ahmadawais/corona-cli/commit/36d3f89d31cf6f1f067d009c4697e52b1666b6c3)
+![πŸ“– DOC:](https://img.shields.io/badge/-DOCS-gray.svg?colorB=978CD4) + +> πŸ“– Changelog [`c318abd`](https://github.com/ahmadawais/corona-cli/commit/c318abdbfd5100ffe7206f25596532fc56a1d90f)
+
[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) diff --git a/package.json b/package.json index 1aaffee..21d42f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "corona-cli", - "version": "3.4.0", + "version": "3.5.0", "description": "Track the Coronavirus disease (COVID-19).", "license": "MIT", "repository": "ahmadawais/corona-cli", From 5e5833c638a8131d3ee7266447e96297330ad304 Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:01:53 +0500 Subject: [PATCH 06/21] =?UTF-8?q?=F0=9F=93=96=20DOC:=20Lingo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index ee09e5f..1d0f193 100644 --- a/readme.md +++ b/readme.md @@ -107,8 +107,8 @@ corona -s critical corona -s per-million # Reverse sort data -corona --sort country --reverse -corona -s country -r +corona --sort active --reverse +corona -s active -r ``` [![πŸ“Ÿ](./.github/sort.gif)](./../../) From 24e894864e0df99aded8f40a5a673910c0f8b8d2 Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:02:10 +0500 Subject: [PATCH 07/21] =?UTF-8?q?=F0=9F=93=96=20DOC:=20Changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 16 ++++++++++++++++ package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index e676e95..bd9fa70 100644 --- a/changelog.md +++ b/changelog.md @@ -29,6 +29,18 @@ I have released a video course to help you become a better developer β€”
+### RELEASE: [3.5.1](https://github.com/ahmadawais/corona-cli/compare/3.5.0...3.5.1) + +![πŸ“– DOC:](https://img.shields.io/badge/-DOCS-gray.svg?colorB=978CD4) + +> πŸ“– Lingo [`d7c8671`](https://github.com/ahmadawais/corona-cli/commit/d7c86719443356fa58eb0d901d655b89f119f5ee)
+ +
+ +[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) + +
+ ### RELEASE: [3.5.0](https://github.com/ahmadawais/corona-cli/compare/3.4.0...3.5.0) ![πŸ‘Œ IMPROVE:](https://img.shields.io/badge/-IMPROVEMENT-gray.svg?colorB=39AA54) @@ -36,6 +48,10 @@ I have released a video course to help you become a better developer β€”
πŸ‘Œ Reverse [`5cb3f2b`](https://github.com/ahmadawais/corona-cli/commit/5cb3f2bd85a95d0b7d33f6fdca9246c0f6bf763c)
> πŸ‘Œ Lingo [`7f4a751`](https://github.com/ahmadawais/corona-cli/commit/7f4a751f451a6b17cb522b0d5282cdfa5d09caba)
+![πŸ“– DOC:](https://img.shields.io/badge/-DOCS-gray.svg?colorB=978CD4) + +> πŸ“– Changelog [`e070bd2`](https://github.com/ahmadawais/corona-cli/commit/e070bd2798efa792d9dce86df28e38a66055438c)
+
[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) diff --git a/package.json b/package.json index 21d42f2..aa647f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "corona-cli", - "version": "3.5.0", + "version": "3.5.1", "description": "Track the Coronavirus disease (COVID-19).", "license": "MIT", "repository": "ahmadawais/corona-cli", From e8dfd9a6dc9609e4ed752ed269d0cbfb24cf287f Mon Sep 17 00:00:00 2001 From: Firas Dib Date: Wed, 25 Mar 2020 16:20:39 +0100 Subject: [PATCH 08/21] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20=20limit=20function?= =?UTF-8?q?ality=20to=20cli=20(#17)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Firas Dib --- index.js | 7 +++++-- readme.md | 8 ++++++++ utils/cli.js | 8 +++++++- utils/getCountries.js | 12 ++++-------- utils/getStates.js | 5 ++++- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 3c4b4db..054fa41 100755 --- a/index.js +++ b/index.js @@ -28,6 +28,9 @@ const { const xcolor = cli.flags.xcolor; const sortBy = cli.flags.sort; const reverse = cli.flags.reverse; +const limit = Math.abs(cli.flags.limit); + +const options = { sortBy, limit, reverse }; (async () => { // Init. @@ -48,8 +51,8 @@ const reverse = cli.flags.reverse; spinner.start(); const lastUpdated = await getWorldwide(table, states); await getCountry(spinner, table, states, country); - await getStates(spinner, table, states, sortBy, reverse); - await getCountries(spinner, table, states, country, sortBy, reverse); + await getStates(spinner, table, states, options); + await getCountries(spinner, table, states, country, options); theEnd(lastUpdated, states); })(); diff --git a/readme.md b/readme.md index 1d0f193..261b15b 100644 --- a/readme.md +++ b/readme.md @@ -113,6 +113,14 @@ corona -s active -r [![πŸ“Ÿ](./.github/sort.gif)](./../../) +### Limit output + +Only output the top N results (depending on your sort criteria). Defaults to showing all entries. + +````sh +corona --sort cases -n 10 +```` + #### CLI Help ```sh diff --git a/utils/cli.js b/utils/cli.js index 289f520..34e8904 100644 --- a/utils/cli.js +++ b/utils/cli.js @@ -17,6 +17,7 @@ module.exports = meow( ${yellow(`--xcolor`)}, ${yellow(`-x`)} Single colored output ${yellow(`--sort`)}, ${yellow(`-s`)} Sort data by type ${yellow(`--reverse`)}, ${yellow(`-r`)} Reverse print order + ${yellow(`--limit`)}, ${yellow(`-n`)} Limit output to N entries Examples ${green(`corona`)} ${cyan(`china`)} @@ -48,6 +49,11 @@ module.exports = meow( default: false, alias: 'r', }, - }, + limit: { + type: 'number', + default: Number.MAX_SAFE_INTEGER, + alias: 'n' + } + } } ); diff --git a/utils/getCountries.js b/utils/getCountries.js index d4bcf81..5359c50 100644 --- a/utils/getCountries.js +++ b/utils/getCountries.js @@ -8,14 +8,7 @@ const to = require('await-to-js').default; const handleError = require('cli-handle-error'); const orderBy = require('lodash.orderby'); -module.exports = async ( - spinner, - table, - states, - countryName, - sortBy, - reverse -) => { +module.exports = async (spinner, table, states, countryName, { sortBy, limit, reverse }) => { if (!countryName && !states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/countries`) @@ -31,6 +24,9 @@ module.exports = async ( [direction] ); + // Limit + allCountries = allCountries.slice(0, limit); + // Push selected data. allCountries.map((oneCountry, count) => { table.push([ diff --git a/utils/getStates.js b/utils/getStates.js index e79a209..d66a644 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -8,7 +8,7 @@ const to = require('await-to-js').default; const handleError = require('cli-handle-error'); const orderBy = require('lodash.orderby'); -module.exports = async (spinner, table, states, sortBy, reverse) => { +module.exports = async (spinner, table, states, { sortBy, limit, reverse }) => { if (states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/states`) @@ -20,6 +20,9 @@ module.exports = async (spinner, table, states, sortBy, reverse) => { const direction = reverse ? 'asc' : 'desc'; allStates = orderBy(allStates, [sortingStateKeys[sortBy]], [direction]); + // Limit + allStates = allStates.slice(0, limit); + // Push selected data. allStates.map((oneState, count) => { table.push([ From c1ccb658c3228124d8574dd3aba70ef20d401592 Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:24:57 +0500 Subject: [PATCH 09/21] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20=20Limit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 5 ++--- readme.md | 7 +++---- utils/cli.js | 8 ++++---- utils/getCountries.js | 14 ++++++++++---- utils/getStates.js | 6 +++--- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 054fa41..6527384 100755 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ // Makes the script crash on unhandled rejections instead of silently // ignoring them. In the future, promise rejections that are not handled will // terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', (err) => { +process.on('unhandledRejection', err => { handleError(`UNHANDLED ERROR`, err); }); @@ -23,13 +23,12 @@ const { colored, singleStates, coloredStates, - style, + style } = require('./utils/table.js'); const xcolor = cli.flags.xcolor; const sortBy = cli.flags.sort; const reverse = cli.flags.reverse; const limit = Math.abs(cli.flags.limit); - const options = { sortBy, limit, reverse }; (async () => { diff --git a/readme.md b/readme.md index 261b15b..523dff8 100644 --- a/readme.md +++ b/readme.md @@ -113,12 +113,11 @@ corona -s active -r [![πŸ“Ÿ](./.github/sort.gif)](./../../) -### Limit output - -Only output the top N results (depending on your sort criteria). Defaults to showing all entries. +### Limit the output ````sh -corona --sort cases -n 10 +# Print a limited number of entries to the output. +corona --limit 10 ```` #### CLI Help diff --git a/utils/cli.js b/utils/cli.js index 34e8904..83ac1d4 100644 --- a/utils/cli.js +++ b/utils/cli.js @@ -37,22 +37,22 @@ module.exports = meow( xcolor: { type: 'boolean', default: false, - alias: 'x', + alias: 'x' }, sort: { type: 'string', default: 'cases', - alias: 's', + alias: 's' }, reverse: { type: 'boolean', default: false, - alias: 'r', + alias: 'r' }, limit: { type: 'number', default: Number.MAX_SAFE_INTEGER, - alias: 'n' + alias: 'l' } } } diff --git a/utils/getCountries.js b/utils/getCountries.js index 5359c50..31cf9e5 100644 --- a/utils/getCountries.js +++ b/utils/getCountries.js @@ -8,7 +8,13 @@ const to = require('await-to-js').default; const handleError = require('cli-handle-error'); const orderBy = require('lodash.orderby'); -module.exports = async (spinner, table, states, countryName, { sortBy, limit, reverse }) => { +module.exports = async ( + spinner, + table, + states, + countryName, + { sortBy, limit, reverse } +) => { if (!countryName && !states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/countries`) @@ -16,6 +22,9 @@ module.exports = async (spinner, table, states, countryName, { sortBy, limit, re handleError(`API is down, try again later.`, err, false); let allCountries = response.data; + // Limit. + allCountries = allCountries.slice(0, limit); + // Sort & reverse. const direction = reverse ? 'asc' : 'desc'; allCountries = orderBy( @@ -24,9 +33,6 @@ module.exports = async (spinner, table, states, countryName, { sortBy, limit, re [direction] ); - // Limit - allCountries = allCountries.slice(0, limit); - // Push selected data. allCountries.map((oneCountry, count) => { table.push([ diff --git a/utils/getStates.js b/utils/getStates.js index d66a644..4eaee68 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -16,13 +16,13 @@ module.exports = async (spinner, table, states, { sortBy, limit, reverse }) => { handleError(`API is down, try again later.`, err, false); let allStates = response.data; + // Limit. + allStates = allStates.slice(0, limit); + // Sort & reverse. const direction = reverse ? 'asc' : 'desc'; allStates = orderBy(allStates, [sortingStateKeys[sortBy]], [direction]); - // Limit - allStates = allStates.slice(0, limit); - // Push selected data. allStates.map((oneState, count) => { table.push([ From d629f44fbb2fb36228f70c034e7b25f271eb0fce Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:26:29 +0500 Subject: [PATCH 10/21] =?UTF-8?q?=F0=9F=93=96=20DOC:=20Changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 13 +++++++++++++ package.json | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index bd9fa70..72e18e0 100644 --- a/changelog.md +++ b/changelog.md @@ -29,10 +29,23 @@ I have released a video course to help you become a better developer β€”
+### RELEASE: [3.6.0](https://github.com/ahmadawais/corona-cli/compare/3.5.1...3.6.0) + +![πŸ‘Œ IMPROVE:](https://img.shields.io/badge/-IMPROVEMENT-gray.svg?colorB=39AA54) + +> πŸ‘Œ Limit [`4bc3f58`](https://github.com/ahmadawais/corona-cli/commit/4bc3f5899d187ba42db742fbc1ecb99f9a676c02)
+ +
+ +[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) + +
+ ### RELEASE: [3.5.1](https://github.com/ahmadawais/corona-cli/compare/3.5.0...3.5.1) ![πŸ“– DOC:](https://img.shields.io/badge/-DOCS-gray.svg?colorB=978CD4) +> πŸ“– Changelog [`2ba122a`](https://github.com/ahmadawais/corona-cli/commit/2ba122a2e4b2e2884f50e8f2f9b8fbfa3735e195)
> πŸ“– Lingo [`d7c8671`](https://github.com/ahmadawais/corona-cli/commit/d7c86719443356fa58eb0d901d655b89f119f5ee)

diff --git a/package.json b/package.json index aa647f4..21a94f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "corona-cli", - "version": "3.5.1", + "version": "3.6.0", "description": "Track the Coronavirus disease (COVID-19).", "license": "MIT", "repository": "ahmadawais/corona-cli", From 1055dd56f48833e265f33f55a69c7700a9f8588f Mon Sep 17 00:00:00 2001 From: my99N Date: Wed, 25 Mar 2020 22:43:01 +0700 Subject: [PATCH 11/21] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20NonVerbose=20(#41)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * πŸ“¦ NEW: NonVerbose * πŸ‘Œ IMPROVE: Rename option Co-authored-by: Touch Sungkawichai Co-authored-by: Ahmad Awais ⚑️ --- index.js | 17 ++++++++++------- utils/cli.js | 17 +++++++++++------ utils/init.js | 3 ++- utils/table.js | 17 +++++++++++++++++ utils/theEnd.js | 3 ++- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 6527384..6c225de 100755 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ // Makes the script crash on unhandled rejections instead of silently // ignoring them. In the future, promise rejections that are not handled will // terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { +process.on('unhandledRejection', (err) => { handleError(`UNHANDLED ERROR`, err); }); @@ -19,21 +19,23 @@ const getCountry = require('./utils/getCountry.js'); const getWorldwide = require('./utils/getWorldwide.js'); const getCountries = require('./utils/getCountries.js'); const { + style, single, colored, singleStates, coloredStates, - style + borderless, } = require('./utils/table.js'); const xcolor = cli.flags.xcolor; const sortBy = cli.flags.sort; const reverse = cli.flags.reverse; const limit = Math.abs(cli.flags.limit); -const options = { sortBy, limit, reverse }; +const minimal = cli.flags.minimal; +const options = { sortBy, limit, reverse, minimal }; (async () => { // Init. - init(); + init(minimal); const [input] = cli.input; input === 'help' && (await cli.showHelp(0)); const states = input === 'states' ? true : false; @@ -42,9 +44,10 @@ const options = { sortBy, limit, reverse }; // Table const head = xcolor ? single : colored; const headStates = xcolor ? singleStates : coloredStates; + const border = minimal ? borderless : {}; const table = !states - ? new Table({ head, style }) - : new Table({ head: headStates, style }); + ? new Table({ head, style, chars: border }) + : new Table({ head: headStates, style, chars: border }); // Display data. spinner.start(); @@ -53,5 +56,5 @@ const options = { sortBy, limit, reverse }; await getStates(spinner, table, states, options); await getCountries(spinner, table, states, country, options); - theEnd(lastUpdated, states); + !minimal && theEnd(lastUpdated, states); })(); diff --git a/utils/cli.js b/utils/cli.js index 83ac1d4..3dcd0f3 100644 --- a/utils/cli.js +++ b/utils/cli.js @@ -37,23 +37,28 @@ module.exports = meow( xcolor: { type: 'boolean', default: false, - alias: 'x' + alias: 'x', }, sort: { type: 'string', default: 'cases', - alias: 's' + alias: 's', }, reverse: { type: 'boolean', default: false, - alias: 'r' + alias: 'r', }, limit: { type: 'number', default: Number.MAX_SAFE_INTEGER, - alias: 'l' - } - } + alias: 'l', + }, + minimal: { + type: 'boolean', + defualt: false, + alias: 'm', + }, + }, } ); diff --git a/utils/init.js b/utils/init.js index efb018b..95c334e 100644 --- a/utils/init.js +++ b/utils/init.js @@ -2,7 +2,8 @@ const welcome = require('cli-welcome'); const pkgJSON = require('./../package.json'); const updateNotifier = require('update-notifier'); -module.exports = async () => { +module.exports = async (quiet) => { + if (quiet) return welcome(`corona-cli`, `by Awais.dev\n${pkgJSON.description}`, { bgColor: `#007C91`, color: `#FFFFFF`, diff --git a/utils/table.js b/utils/table.js index 7d8ce68..0afd5fe 100644 --- a/utils/table.js +++ b/utils/table.js @@ -48,6 +48,23 @@ module.exports = { `${yellow(`Active`)}`, ], style: { head: ['cyan'] }, + borderless: { + top: '', + 'top-mid': '', + 'top-left': '', + 'top-right': '', + bottom: '', + 'bottom-mid': '', + 'bottom-left': '', + 'bottom-right': '', + left: '', + 'left-mid': '', + mid: '', + 'mid-mid': '', + right: '', + 'right-mid': '', + middle: ' ', + }, sortingKeys: { country: 'country', cases: 'cases', diff --git a/utils/theEnd.js b/utils/theEnd.js index c7bd62b..b699233 100644 --- a/utils/theEnd.js +++ b/utils/theEnd.js @@ -33,7 +33,8 @@ ${dim(`❯ `)}${cyan(`Per Million:`)} Affected patients per million `) ); -module.exports = async (lastUpdated, states) => { +module.exports = async (lastUpdated, states, quiet) => { + if (quiet) return console.log(dim(`${sym.info} ${cyan(`Last Updated:`)} ${lastUpdated}`)); states && infoStates(); !states && infoCountries(); From a1738196b7e8da09dc0eb1055eed02ef0d53954b Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:51:19 +0500 Subject: [PATCH 12/21] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Minimal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierrc.json | 3 ++- index.js | 4 ++-- utils/cli.js | 14 +++++++------- utils/getCountry.js | 2 +- utils/getWorldwide.js | 2 +- utils/init.js | 7 +++---- utils/table.js | 16 ++++++++-------- utils/theEnd.js | 4 ++-- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index 77a895d..e7bf8b7 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -3,5 +3,6 @@ "singleQuote": true, "useTabs": true, "tabWidth": 4, - "semi": true + "semi": true, + "trailingComma": "none" } diff --git a/index.js b/index.js index 6c225de..228fa0a 100755 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ const { colored, singleStates, coloredStates, - borderless, + borderless } = require('./utils/table.js'); const xcolor = cli.flags.xcolor; const sortBy = cli.flags.sort; @@ -56,5 +56,5 @@ const options = { sortBy, limit, reverse, minimal }; await getStates(spinner, table, states, options); await getCountries(spinner, table, states, country, options); - !minimal && theEnd(lastUpdated, states); + theEnd(lastUpdated, states, minimal); })(); diff --git a/utils/cli.js b/utils/cli.js index 3dcd0f3..940a702 100644 --- a/utils/cli.js +++ b/utils/cli.js @@ -37,28 +37,28 @@ module.exports = meow( xcolor: { type: 'boolean', default: false, - alias: 'x', + alias: 'x' }, sort: { type: 'string', default: 'cases', - alias: 's', + alias: 's' }, reverse: { type: 'boolean', default: false, - alias: 'r', + alias: 'r' }, limit: { type: 'number', default: Number.MAX_SAFE_INTEGER, - alias: 'l', + alias: 'l' }, minimal: { type: 'boolean', defualt: false, - alias: 'm', - }, - }, + alias: 'm' + } + } } ); diff --git a/utils/getCountry.js b/utils/getCountry.js index 23cb880..5c7811d 100644 --- a/utils/getCountry.js +++ b/utils/getCountry.js @@ -34,7 +34,7 @@ module.exports = async (spinner, table, states, countryName) => { comma(thisCountry.recovered), comma(thisCountry.active), comma(thisCountry.critical), - comma(thisCountry.casesPerOneMillion), + comma(thisCountry.casesPerOneMillion) ]); } diff --git a/utils/getWorldwide.js b/utils/getWorldwide.js index 43d0bbf..59d3355 100644 --- a/utils/getWorldwide.js +++ b/utils/getWorldwide.js @@ -20,7 +20,7 @@ module.exports = async (table, states) => { data[2], `β€”`, `β€”`, - `β€”`, + `β€”` ]); } diff --git a/utils/init.js b/utils/init.js index 95c334e..33c8034 100644 --- a/utils/init.js +++ b/utils/init.js @@ -2,18 +2,17 @@ const welcome = require('cli-welcome'); const pkgJSON = require('./../package.json'); const updateNotifier = require('update-notifier'); -module.exports = async (quiet) => { - if (quiet) return +module.exports = async () => { welcome(`corona-cli`, `by Awais.dev\n${pkgJSON.description}`, { bgColor: `#007C91`, color: `#FFFFFF`, bold: true, clear: true, - version: `v${pkgJSON.version}`, + version: `v${pkgJSON.version}` }); updateNotifier({ pkg: pkgJSON, shouldNotifyInNpmScript: true, - updateCheckInterval: 1000 * 60 * 60 * 24, // 24 hours. + updateCheckInterval: 1000 * 60 * 60 * 24 // 24 hours. }).notify({ isGlobal: true }); }; diff --git a/utils/table.js b/utils/table.js index 0afd5fe..6a410b6 100644 --- a/utils/table.js +++ b/utils/table.js @@ -15,7 +15,7 @@ module.exports = { `Recovered`, `Active`, `Critical`, - `Per Million`, + `Per Million` ], colored: [ `#`, @@ -27,7 +27,7 @@ module.exports = { `${green(`Recovered`)}`, `${yellow(`Active`)}`, `${red(`Critical`)}`, - `Per Million`, + `Per Million` ], singleStates: [ `#`, @@ -36,7 +36,7 @@ module.exports = { `Cases ${dim(`(today)`)}`, `Deaths`, `Deaths ${dim(`(today)`)}`, - `Active`, + `Active` ], coloredStates: [ `#`, @@ -45,7 +45,7 @@ module.exports = { `Cases ${dim(`(today)`)}`, `${red(`Deaths`)}`, `${red(`Deaths (today)`)}`, - `${yellow(`Active`)}`, + `${yellow(`Active`)}` ], style: { head: ['cyan'] }, borderless: { @@ -63,7 +63,7 @@ module.exports = { 'mid-mid': '', right: '', 'right-mid': '', - middle: ' ', + middle: ' ' }, sortingKeys: { country: 'country', @@ -74,7 +74,7 @@ module.exports = { recovered: 'recovered', active: 'active', critical: 'critical', - 'per-million': 'casesPerOneMillion', + 'per-million': 'casesPerOneMillion' }, sortingStateKeys: { state: 'state', @@ -82,6 +82,6 @@ module.exports = { 'cases-today': 'todayCases', deaths: 'deaths', 'deaths-today': 'todayDeaths', - active: 'active', - }, + active: 'active' + } }; diff --git a/utils/theEnd.js b/utils/theEnd.js index b699233..91c4554 100644 --- a/utils/theEnd.js +++ b/utils/theEnd.js @@ -33,8 +33,8 @@ ${dim(`❯ `)}${cyan(`Per Million:`)} Affected patients per million `) ); -module.exports = async (lastUpdated, states, quiet) => { - if (quiet) return +module.exports = async (lastUpdated, states, minimal) => { + if (minimal) return console.log(); console.log(dim(`${sym.info} ${cyan(`Last Updated:`)} ${lastUpdated}`)); states && infoStates(); !states && infoCountries(); From 1efdf2e99c895d793e32db8f5949046c8a1755ce Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:51:35 +0500 Subject: [PATCH 13/21] =?UTF-8?q?=F0=9F=93=96=20DOC:=20Changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 16 ++++++++++++++++ package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 72e18e0..07511fe 100644 --- a/changelog.md +++ b/changelog.md @@ -29,12 +29,28 @@ I have released a video course to help you become a better developer β€”
+### RELEASE: [3.7.0](https://github.com/ahmadawais/corona-cli/compare/3.6.0...3.7.0) + +![πŸ‘Œ IMPROVE:](https://img.shields.io/badge/-IMPROVEMENT-gray.svg?colorB=39AA54) + +> πŸ‘Œ Minimal [`4c2e393`](https://github.com/ahmadawais/corona-cli/commit/4c2e393ced22d517061645f999877a23a66cc274)
+ +
+ +[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) + +
+ ### RELEASE: [3.6.0](https://github.com/ahmadawais/corona-cli/compare/3.5.1...3.6.0) ![πŸ‘Œ IMPROVE:](https://img.shields.io/badge/-IMPROVEMENT-gray.svg?colorB=39AA54) > πŸ‘Œ Limit [`4bc3f58`](https://github.com/ahmadawais/corona-cli/commit/4bc3f5899d187ba42db742fbc1ecb99f9a676c02)
+![πŸ“– DOC:](https://img.shields.io/badge/-DOCS-gray.svg?colorB=978CD4) + +> πŸ“– Changelog [`0f0550f`](https://github.com/ahmadawais/corona-cli/commit/0f0550f1e4f51122166b1f556d8554807967a480)
+
[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) diff --git a/package.json b/package.json index 21a94f8..9925586 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "corona-cli", - "version": "3.6.0", + "version": "3.7.0", "description": "Track the Coronavirus disease (COVID-19).", "license": "MIT", "repository": "ahmadawais/corona-cli", From 613272f28edd95e5beb292f178773a1a0a0c03fb Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:52:50 +0500 Subject: [PATCH 14/21] =?UTF-8?q?=F0=9F=93=96=20DOC:=20Minimal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index 523dff8..2c9fac8 100644 --- a/readme.md +++ b/readme.md @@ -118,6 +118,9 @@ corona -s active -r ````sh # Print a limited number of entries to the output. corona --limit 10 + +# Print a bare bones table with no info. +corona --minimal ```` #### CLI Help From a9be0e252433f63feb50a6d2ec562c42e3272798 Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:53:06 +0500 Subject: [PATCH 15/21] =?UTF-8?q?=F0=9F=93=96=20DOC:=20Changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 16 ++++++++++++++++ package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 07511fe..9cc576d 100644 --- a/changelog.md +++ b/changelog.md @@ -29,12 +29,28 @@ I have released a video course to help you become a better developer β€”
+### RELEASE: [3.7.1](https://github.com/ahmadawais/corona-cli/compare/3.7.0...3.7.1) + +![πŸ“– DOC:](https://img.shields.io/badge/-DOCS-gray.svg?colorB=978CD4) + +> πŸ“– Minimal [`875e3bb`](https://github.com/ahmadawais/corona-cli/commit/875e3bb7a3ad2764429c5d94c68b67c8243b78e7)
+ +
+ +[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) + +
+ ### RELEASE: [3.7.0](https://github.com/ahmadawais/corona-cli/compare/3.6.0...3.7.0) ![πŸ‘Œ IMPROVE:](https://img.shields.io/badge/-IMPROVEMENT-gray.svg?colorB=39AA54) > πŸ‘Œ Minimal [`4c2e393`](https://github.com/ahmadawais/corona-cli/commit/4c2e393ced22d517061645f999877a23a66cc274)
+![πŸ“– DOC:](https://img.shields.io/badge/-DOCS-gray.svg?colorB=978CD4) + +> πŸ“– Changelog [`111d20b`](https://github.com/ahmadawais/corona-cli/commit/111d20b08baf42b8456b12611de0d63a6e425c8d)
+
[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) diff --git a/package.json b/package.json index 9925586..ce2538b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "corona-cli", - "version": "3.7.0", + "version": "3.7.1", "description": "Track the Coronavirus disease (COVID-19).", "license": "MIT", "repository": "ahmadawais/corona-cli", From a816249afe4e44ea7a1adb4f320d2822f874b6ab Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:58:00 +0500 Subject: [PATCH 16/21] =?UTF-8?q?=F0=9F=93=96=20DOC:=20Alias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 2c9fac8..f0e4874 100644 --- a/readme.md +++ b/readme.md @@ -118,9 +118,11 @@ corona -s active -r ````sh # Print a limited number of entries to the output. corona --limit 10 +corona -l 10 # Print a bare bones table with no info. corona --minimal +corona -m ```` #### CLI Help From 73bf769908f5f9df3f6ce71e6907b66500ff694c Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 20:58:16 +0500 Subject: [PATCH 17/21] =?UTF-8?q?=F0=9F=93=96=20DOC:=20Changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 13 +++++++++++++ package.json | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 9cc576d..2b002d7 100644 --- a/changelog.md +++ b/changelog.md @@ -29,10 +29,23 @@ I have released a video course to help you become a better developer β€”
+### RELEASE: [3.7.2](https://github.com/ahmadawais/corona-cli/compare/3.7.1...3.7.2) + +![πŸ“– DOC:](https://img.shields.io/badge/-DOCS-gray.svg?colorB=978CD4) + +> πŸ“– Alias [`44a9360`](https://github.com/ahmadawais/corona-cli/commit/44a9360fa47fef837a94d31174f126c39d100d60)
+ +
+ +[![hr](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/hr.png)](/) + +
+ ### RELEASE: [3.7.1](https://github.com/ahmadawais/corona-cli/compare/3.7.0...3.7.1) ![πŸ“– DOC:](https://img.shields.io/badge/-DOCS-gray.svg?colorB=978CD4) +> πŸ“– Changelog [`535cc12`](https://github.com/ahmadawais/corona-cli/commit/535cc1270673ba02cf5630720a95021fb00ca2ee)
> πŸ“– Minimal [`875e3bb`](https://github.com/ahmadawais/corona-cli/commit/875e3bb7a3ad2764429c5d94c68b67c8243b78e7)

diff --git a/package.json b/package.json index ce2538b..36dedfc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "corona-cli", - "version": "3.7.1", + "version": "3.7.2", "description": "Track the Coronavirus disease (COVID-19).", "license": "MIT", "repository": "ahmadawais/corona-cli", From a3e2b7aeb8f01dbe066df3a8ef3ccc02d5ee2584 Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Wed, 25 Mar 2020 21:30:13 +0500 Subject: [PATCH 18/21] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20Node=20Engine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 36dedfc..6f667ee 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,9 @@ "url": "https://twitter.com/MrAhmadAwais" }, "main": "index.js", + "engines": { + "node": ">=12.x" + }, "bin": { "corona": "index.js", "corona-cli": "index.js" From 8a97328dbd9e9a212a657ff0b0c87a2a23269205 Mon Sep 17 00:00:00 2001 From: inukares Date: Wed, 25 Mar 2020 15:25:01 +0000 Subject: [PATCH 19/21] NEW: Omit table rows from console output --- index.js | 13 +++++++++++++ utils/cli.js | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/index.js b/index.js index 228fa0a..035bb36 100755 --- a/index.js +++ b/index.js @@ -18,6 +18,8 @@ const getStates = require('./utils/getStates.js'); const getCountry = require('./utils/getCountry.js'); const getWorldwide = require('./utils/getWorldwide.js'); const getCountries = require('./utils/getCountries.js'); +const deleteColumns = require('./utils/deleteColumns'); + const { style, single, @@ -33,6 +35,13 @@ const limit = Math.abs(cli.flags.limit); const minimal = cli.flags.minimal; const options = { sortBy, limit, reverse, minimal }; +// const consoleLogTable = (spinner, table, sortBy) => { +// spinner.stopAndPersist(); +// if(sortBy) spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); +// console.log(table.toString()) +// }; + + (async () => { // Init. init(minimal); @@ -44,6 +53,10 @@ const options = { sortBy, limit, reverse, minimal }; // Table const head = xcolor ? single : colored; const headStates = xcolor ? singleStates : coloredStates; + + // let tableHead = states ? headStates : head; + // const table = new Table( { head: tableHead, style }); + const border = minimal ? borderless : {}; const table = !states ? new Table({ head, style, chars: border }) diff --git a/utils/cli.js b/utils/cli.js index 940a702..2d27d82 100644 --- a/utils/cli.js +++ b/utils/cli.js @@ -25,6 +25,8 @@ module.exports = meow( ${green(`corona`)} ${yellow(`-x`)} ${green(`corona`)} ${yellow(`--sort`)} ${cyan(`cases-today`)} ${green(`corona`)} ${yellow(`-s`)} ${cyan(`critical`)} + ${green(`corona`)} ${yellow(`--omit`)} ${cyan(`deaths-today_cases_critical`)} + ${green(`corona`)} ${yellow(`--o`)} ${cyan(`country`)} ❯ You can also run command + option at once: ${green(`corona`)} ${cyan(`china`)} ${yellow(`-x`)} ${yellow(`-s cases`)} @@ -58,6 +60,11 @@ module.exports = meow( type: 'boolean', defualt: false, alias: 'm' + }, + omit: { + type: 'string', + default: '', + alias: 'o' } } } From 55e2463d8f3521f04491f72cd607189fad9fc835 Mon Sep 17 00:00:00 2001 From: inukares Date: Wed, 25 Mar 2020 20:18:33 +0000 Subject: [PATCH 20/21] Merge https://github.com/ahmadawais/corona-cli --omit=cases_cases-today_wrongINput_deaths will omit all valid keys wrong keys will simply be ignored --- index.js | 24 ++++++---------------- utils/columnsMapper.js | 45 +++++++++++++++++++++--------------------- utils/deleteColumns.js | 32 +++++++++++++++++------------- utils/getCountries.js | 11 ++++++++--- utils/getCountry.js | 5 ++++- utils/getStates.js | 12 ++++++++++- 6 files changed, 69 insertions(+), 60 deletions(-) diff --git a/index.js b/index.js index 035bb36..58acea2 100755 --- a/index.js +++ b/index.js @@ -18,7 +18,6 @@ const getStates = require('./utils/getStates.js'); const getCountry = require('./utils/getCountry.js'); const getWorldwide = require('./utils/getWorldwide.js'); const getCountries = require('./utils/getCountries.js'); -const deleteColumns = require('./utils/deleteColumns'); const { style, @@ -35,39 +34,28 @@ const limit = Math.abs(cli.flags.limit); const minimal = cli.flags.minimal; const options = { sortBy, limit, reverse, minimal }; -// const consoleLogTable = (spinner, table, sortBy) => { -// spinner.stopAndPersist(); -// if(sortBy) spinner.info(`${chalk.cyan(`Sorted by:`)} ${sortBy}`); -// console.log(table.toString()) -// }; - - (async () => { // Init. init(minimal); const [input] = cli.input; input === 'help' && (await cli.showHelp(0)); - const states = input === 'states' ? true : false; + const states = input === 'states'; const country = input; // Table const head = xcolor ? single : colored; const headStates = xcolor ? singleStates : coloredStates; - // let tableHead = states ? headStates : head; - // const table = new Table( { head: tableHead, style }); - const border = minimal ? borderless : {}; - const table = !states - ? new Table({ head, style, chars: border }) - : new Table({ head: headStates, style, chars: border }); + const tableHead = states ? headStates : head; + const table = new Table({ head: tableHead, style, chars: border }); // Display data. spinner.start(); const lastUpdated = await getWorldwide(table, states); - await getCountry(spinner, table, states, country); - await getStates(spinner, table, states, options); - await getCountries(spinner, table, states, country, options); + await getCountry({ spinner, table, states, country, tableHead }); + await getStates({ spinner, table, states, options, tableHead }); + await getCountries({ spinner, table, states, country, options, tableHead }); theEnd(lastUpdated, states, minimal); })(); diff --git a/utils/columnsMapper.js b/utils/columnsMapper.js index 68d863e..0f84fe0 100644 --- a/utils/columnsMapper.js +++ b/utils/columnsMapper.js @@ -1,45 +1,44 @@ module.exports = { single: { '#': 0, - 'country': 1, - 'cases': 2, + country: 1, + cases: 2, 'cases-today': 3, - 'deaths': 4, + deaths: 4, 'deaths-today': 5, - 'recovered': 6, - 'active': 7, - 'critical': 8, + recovered: 6, + active: 7, + critical: 8, 'per-milion': 9 }, colored: { '#': 0, - 'country': 1, - 'cases': 2, + country: 1, + cases: 2, 'cases-today': 3, - 'deaths': 4, + deaths: 4, 'deaths-today': 5, - 'recovered': 6, - 'active': 7, - 'critical': 8, + recovered: 6, + active: 7, + critical: 8, 'per-milion': 9 }, singleStates: { '#': 0, - 'state': 1, - 'cases': 2, + state: 1, + cases: 2, 'cases-today': 3, - 'deaths': 4, + deaths: 4, 'deaths-today': 5, - 'active': 6 + active: 6 }, - coloredStates : { + coloredStates: { '#': 0, - 'state': 1, - 'cases': 2, + state: 1, + cases: 2, 'cases-today': 3, - 'deaths': 4, + deaths: 4, 'deaths-today': 5, - 'active': 6 - }, + active: 6 + } }; - diff --git a/utils/deleteColumns.js b/utils/deleteColumns.js index cc21ef1..e9f7fd3 100644 --- a/utils/deleteColumns.js +++ b/utils/deleteColumns.js @@ -4,28 +4,32 @@ const cli = require('./cli'); // returns indices of table rows which user wants to omit form output in descending order const parseCli = (states, separator = '_') => { const input = cli.flags.omit; - if(!input || typeof input !== 'string' || input === '') return []; + if (!input || typeof input !== 'string' || input === '') return []; return input .split(separator) - .reduce((accumulator, current,) => { - if(states) { - return mapper.singleStates[current] ? [...accumulator, mapper.singleStates[current]] : accumulator + .reduce((accumulator, current) => { + if (states) { + return mapper.singleStates[current] + ? [...accumulator, mapper.singleStates[current]] + : accumulator; } - return mapper.single[current] ? [...accumulator, mapper.single[current]] : accumulator + return mapper.single[current] + ? [...accumulator, mapper.single[current]] + : accumulator; }, []) - .sort((a, b) => a > b ? -1 : 1) + .sort((a, b) => (a > b ? -1 : 1)); }; const deleteColumns = (table, tableHead, input) => { - input.forEach(key => { + input.forEach((key) => { tableHead.splice(key, 1); - table.forEach(row => { - row.splice(key, 1) - }) - }) + table.forEach((row) => { + row.splice(key, 1); + }); + }); }; -module.exports = (table, states, tableHead) => { - const input = parseCli(states); - deleteColumns(table, tableHead, input) +module.exports = { + parseCli, + deleteColumns }; diff --git a/utils/getCountries.js b/utils/getCountries.js index 31cf9e5..3281f10 100644 --- a/utils/getCountries.js +++ b/utils/getCountries.js @@ -7,14 +7,16 @@ const { sortingKeys } = require('./table.js'); const to = require('await-to-js').default; const handleError = require('cli-handle-error'); const orderBy = require('lodash.orderby'); +const { parseCli, deleteColumns } = require('./deleteColumns'); -module.exports = async ( +module.exports = async ({ spinner, table, states, countryName, - { sortBy, limit, reverse } -) => { + options: { sortBy, limit, reverse }, + tableHead +}) => { if (!countryName && !states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/countries`) @@ -49,6 +51,9 @@ module.exports = async ( ]); }); + const input = parseCli(states); + deleteColumns(table, tableHead, input); + spinner.stopAndPersist(); const isRev = reverse ? `${dim(` & `)}${cyan(`Order`)}: reversed` : ``; spinner.info(`${cyan(`Sorted by:`)} ${sortBy}${isRev}`); diff --git a/utils/getCountry.js b/utils/getCountry.js index 5c7811d..e885d1b 100644 --- a/utils/getCountry.js +++ b/utils/getCountry.js @@ -5,8 +5,9 @@ const comma = require('comma-number'); const red = chalk.red; const to = require('await-to-js').default; const handleError = require('cli-handle-error'); +const { deleteColumns } = require('./deleteColumns'); -module.exports = async (spinner, table, states, countryName) => { +module.exports = async ({ spinner, table, states, countryName, tableHead }) => { if (countryName && !states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/countries/${countryName}`) @@ -37,5 +38,7 @@ module.exports = async (spinner, table, states, countryName) => { comma(thisCountry.casesPerOneMillion) ]); + const input = parseCli(states); + deleteColumns(table, tableHead, input); } }; diff --git a/utils/getStates.js b/utils/getStates.js index 4eaee68..102fa96 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -7,8 +7,15 @@ const { sortingStateKeys } = require('./table.js'); const to = require('await-to-js').default; const handleError = require('cli-handle-error'); const orderBy = require('lodash.orderby'); +const { deleteColumns, parseCli } = require('./deleteColumns'); -module.exports = async (spinner, table, states, { sortBy, limit, reverse }) => { +module.exports = async ({ + spinner, + table, + states, + options: { sortBy, limit, reverse }, + tableHead +}) => { if (states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/states`) @@ -36,6 +43,9 @@ module.exports = async (spinner, table, states, { sortBy, limit, reverse }) => { ]); }); + const input = parseCli(states); + deleteColumns(table, tableHead, input); + spinner.stopAndPersist(); const isRev = reverse ? `${dim(` & `)}${cyan(`Order`)}: reversed` : ``; spinner.info(`${cyan(`Sorted by:`)} ${sortBy}${isRev}`); From cea6dba9d95b8e8bb226d598cdb511f561c9038a Mon Sep 17 00:00:00 2001 From: inukares Date: Wed, 25 Mar 2020 20:43:09 +0000 Subject: [PATCH 21/21] delete unnecessary logic check --- utils/deleteColumns.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/deleteColumns.js b/utils/deleteColumns.js index e9f7fd3..7288f71 100644 --- a/utils/deleteColumns.js +++ b/utils/deleteColumns.js @@ -4,7 +4,7 @@ const cli = require('./cli'); // returns indices of table rows which user wants to omit form output in descending order const parseCli = (states, separator = '_') => { const input = cli.flags.omit; - if (!input || typeof input !== 'string' || input === '') return []; + if (!input || typeof input !== 'string') return []; return input .split(separator) .reduce((accumulator, current) => {