Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api features to console logs for extra results information #23

Merged
merged 3 commits into from
Feb 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const chalk = require('chalk');
const program = require('commander');
const request = require('request');

const consoleWidth = () => {
return parseInt(process.stdout.columns)
}

program
.version('0.2.0')
.arguments('<phrase>')
Expand All @@ -24,17 +28,25 @@ program
if (err) throw new Error(err);
var trimRes;
var results = JSON.parse(body).list;
var resultsToDisplay = 3;

console.log('='.repeat(consoleWidth()));

if (results.length === 0) {
console.log(chalk.red('No results were found, please try another phrase'));
} else {
if (results.length > 3) {
trimRes = results.slice(0, 3);
if (results.length > resultsToDisplay) {
trimRes = results.slice(0, resultsToDisplay);
} else {
trimRes = results;
}
trimRes.forEach((result) => {
if (typeof (result.definition) !== undefined) {
console.log(chalk.bold.cyan('=======================\n') + result.definition);
console.log(chalk.bold.cyan('Word: ') + result.word);
console.log(chalk.bold.cyan('Definition: ') + result.definition);
console.log(chalk.bold.cyan('Score: ') + (result.thumbs_up - result.thumbs_down));
console.log(chalk.bold.green('Ayys: ') + result.thumbs_up + ' | ' + chalk.bold.red('Nayys: ') + result.thumbs_down);
console.log('='.repeat(consoleWidth()));
}
});
}
Expand Down