├── .gitignore ├── .prettierrc ├── LICENSE ├── bin └── describe ├── cmds ├── antonyms.js ├── definitions.js ├── help.js ├── synonyms.js └── version.js ├── config.js ├── index.js ├── media └── describe.png ├── package.json ├── readme.md └── utils ├── error.js └── query.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": true 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Pavan Jadhaw 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bin/describe: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('../')(); 3 | -------------------------------------------------------------------------------- /cmds/antonyms.js: -------------------------------------------------------------------------------- 1 | const ora = require('ora'); 2 | const getWord = require('../utils/query'); 3 | const handleError = require('../utils/error'); 4 | 5 | module.exports = async args => { 6 | const spinner = ora().start(); 7 | 8 | try { 9 | const path = '/entries/en/' + args.a.toLowerCase() + '/antonyms'; 10 | const result = await getWord(path); 11 | 12 | spinner.stop(); 13 | 14 | const ant = result.lexicalEntries[0].entries[0].senses[0].antonyms; 15 | 16 | ant.forEach(element => { 17 | console.log(element.text); 18 | }); 19 | } catch (error) { 20 | spinner.stop(); 21 | handleError(error.response.status); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /cmds/definitions.js: -------------------------------------------------------------------------------- 1 | const ora = require('ora'); 2 | const getWord = require('../utils/query'); 3 | const handleError = require('../utils/error'); 4 | 5 | module.exports = async args => { 6 | for (let i = 0; i < args._.length; i++) { 7 | const spinner = ora().start(); 8 | 9 | try { 10 | const path = '/entries/en/' + args._[i].toLowerCase(); 11 | const result = await getWord(path); 12 | 13 | spinner.stop(); 14 | 15 | const definition = 16 | result.lexicalEntries[0].entries[0].senses[0].definitions[0]; 17 | 18 | console.log(`${args._[i]} is ${definition}`); 19 | } catch (error) { 20 | spinner.stop(); 21 | handleError(error.response.status); 22 | } 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /cmds/help.js: -------------------------------------------------------------------------------- 1 | const menus = { 2 | main: ` 3 | describe [command] 4 | 5 | commands: 6 | -d ................ show defination 7 | -s ................ show synonyms 8 | -a ................ show antonyms 9 | 10 | -v ................ show package version 11 | -h ................ show help menu for a command 12 | `, 13 | 14 | definition: ` 15 | describe 16 | 17 | example: 18 | describe tiny 19 | 20 | tiny is very small 21 | `, 22 | 23 | synonyms: ` 24 | describe -s 25 | 26 | example: describe -s tiny 27 | `, 28 | 29 | antonyms: ` 30 | describe -a 31 | 32 | example: describe -a tiny 33 | 34 | 35 | `, 36 | }; 37 | 38 | module.exports = args => { 39 | const subCmd = args._[0] === 'help' ? args._[1] : args._[0]; 40 | 41 | console.log(menus[subCmd] || menus.main); 42 | }; 43 | -------------------------------------------------------------------------------- /cmds/synonyms.js: -------------------------------------------------------------------------------- 1 | const ora = require('ora'); 2 | const getWord = require('../utils/query'); 3 | const handleError = require('../utils/error'); 4 | 5 | module.exports = async args => { 6 | const spinner = ora().start(); 7 | 8 | try { 9 | const path = '/entries/en/' + args.s.toLowerCase() + '/synonyms'; 10 | const result = await getWord(path); 11 | 12 | spinner.stop(); 13 | 14 | const syn = result.lexicalEntries[0].entries[0].senses[0].synonyms; 15 | 16 | syn.forEach(element => { 17 | console.log(element.text); 18 | }); 19 | } catch (error) { 20 | spinner.stop(); 21 | handleError(error.response.status); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /cmds/version.js: -------------------------------------------------------------------------------- 1 | const {version} = require('../package.json'); 2 | 3 | module.exports = () => { 4 | console.log(`v${version}`); 5 | }; 6 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | appId: '', 3 | appKey: '', 4 | }; 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const minimist = require('minimist'); 2 | 3 | module.exports = () => { 4 | const args = minimist(process.argv.slice(2), { 5 | alias: { 6 | s: 'synonyms', 7 | a: 'antonyms', 8 | d: 'definition', 9 | h: 'help', 10 | v: 'version' 11 | } 12 | }); 13 | 14 | let cmd = args._[0] || 'help'; 15 | 16 | if (args.s) { 17 | cmd = 'syn'; 18 | } 19 | 20 | if (args.a) { 21 | cmd = 'ant'; 22 | } 23 | 24 | if (args.v) { 25 | cmd = 'ver'; 26 | } 27 | 28 | if (args.h) { 29 | cmd = 'help'; 30 | } 31 | 32 | switch (cmd) { 33 | case 'syn': 34 | require('./cmds/synonyms')(args); 35 | break; 36 | case 'ant': 37 | require('./cmds/antonyms')(args); 38 | break; 39 | case 'ver': 40 | require('./cmds/version')(args); 41 | break; 42 | case 'help': 43 | require('./cmds/help')(args); 44 | break; 45 | default: 46 | require('./cmds/definitions')(args); 47 | break; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /media/describe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pavanjadhaw/describe/6272a76b1f247cb73874d0aa95be4c4eb81095c7/media/describe.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "describe", 3 | "version": "0.0.1", 4 | "description": "query words from Oxford Dictionaries API", 5 | "main": "index.js", 6 | "bin": { 7 | "describe": "./bin/describe" 8 | }, 9 | "scripts": { 10 | "test": "xo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/pavanjadhaw/describe.git" 15 | }, 16 | "keywords": [ 17 | "describe", 18 | "nodejs", 19 | "cli", 20 | "oxford", 21 | "dictionaries", 22 | "dictionary", 23 | "synonyms", 24 | "antonyms" 25 | ], 26 | "author": "Pavan Jadhaw <@pavanjadhaw>", 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/pavanjadhaw/describe/issues" 30 | }, 31 | "homepage": "https://github.com/pavanjadhaw/describe#readme", 32 | "dependencies": { 33 | "axios": "^0.18.0", 34 | "minimist": "^1.2.0", 35 | "ora": "^3.0.0" 36 | }, 37 | "devDependencies": { 38 | "xo": "^0.23.0" 39 | }, 40 | "xo": { 41 | "space": true 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ![heroimage.png](./media/describe.png) 2 | >Query words from oxford dictionaries API saythanks 3 | 4 | ## Usage 5 | 6 | To query for a words definition simply pass it as an argument to the script 7 | 8 | ```bash 9 | $ describe tiny 10 | 11 | tiny is very small 12 | ``` 13 | 14 | Alternatively, you can try deriving the words meaning by its synonyms 15 | 16 | ```bash 17 | $ describe --synonyms tiny 18 | 19 | minute 20 | small-scale 21 | scaled-down 22 | mini 23 | baby 24 | toy 25 | pocket 26 | fun-size 27 | petite 28 | dwarfish 29 | knee-high 30 | miniature 31 | minuscule 32 | microscopic 33 | nanoscopic 34 | infinitesimal 35 | micro 36 | diminutive 37 | pocket-sized 38 | reduced 39 | Lilliputian 40 | ``` 41 | 42 | or its antonyms 43 | 44 | ```bash 45 | $ describe --antonyms tiny 46 | 47 | huge 48 | significant 49 | ``` 50 | 51 | [![https://asciinema.org/a/nLvdaH3DTSVgfgPMYRsW5av1b](https://asciinema.org/a/nLvdaH3DTSVgfgPMYRsW5av1b.png)](https://asciinema.org/a/nLvdaH3DTSVgfgPMYRsW5av1b) 52 | 53 | 54 | ## Installation 55 | 56 | ```bash 57 | $ git clone https://github.com/pavanjadhaw/describe 58 | 59 | $ cd describe 60 | 61 | $ npm install 62 | $ npm link 63 | ``` 64 | 65 | In order to make the script work you first have to register a (free) developer account at [Oxford Dictionaries](https://developer.oxforddictionaries.com/) to obtain an `app id` and `app key` and put them in config.js 66 | 67 | 68 | ## Requirements 69 | 70 | `nodejs` 71 | `npm` 72 | -------------------------------------------------------------------------------- /utils/error.js: -------------------------------------------------------------------------------- 1 | const config = require('../config'); 2 | 3 | module.exports = statuscode => { 4 | if (config.appId.length === 0) { 5 | console.log(`To use this app you need to request api keys from Oxford Dictionaries (https://developer.oxforddictionaries.com/) 6 | And put them in config.js`); 7 | } else if (statuscode === 404) { 8 | console.log('No entry is found matching given word'); 9 | } else if (statuscode === 500) { 10 | console.log('Internal Server Error'); 11 | } else { 12 | console.log('Unknown Error'); 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /utils/query.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const config = require('../config'); 3 | 4 | module.exports = async path => { 5 | const response = await axios({ 6 | method: 'get', 7 | url: 'https://od-api.oxforddictionaries.com/api/v1' + path, 8 | port: '443', 9 | rejectUnauthorized: false, 10 | headers: { 11 | Accept: 'application/json', 12 | app_id: config.appId, 13 | app_key: config.appKey 14 | } 15 | }); 16 | return response.data.results[0]; 17 | }; 18 | --------------------------------------------------------------------------------