Skip to content

Commit

Permalink
Merge pull request #28 from 5-gwoap/release/0.3.0
Browse files Browse the repository at this point in the history
Release/0.3.0
  • Loading branch information
rainrivas authored Feb 5, 2018
2 parents 271bd3a + 4ec6fe0 commit db8a479
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
38 changes: 29 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ const chalk = require('chalk');
const program = require('commander');
const request = require('request');

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

program
.version('0.2.0')
.version('0.3.0')
.arguments('<phrase>')
.action((slng) => {
var options = {
Expand All @@ -24,21 +28,37 @@ program
if (err) throw new Error(err);
var trimRes;
var results = JSON.parse(body).list;
if (results.length === 0 ) {
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);
} else {
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()));
}
});
}
});
})
.parse(process.argv);
});

program.on('--help', function () {
console.log('');
console.log(' Examples:');
console.log(' $ slng gucci');
console.log(' $ slng \'square up\'');
console.log('');
});

program.parse(process.argv);
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slng",
"version": "0.2.0",
"version": "0.3.0",
"description": "Get hip or die trying",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit db8a479

Please sign in to comment.