word-def 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/index.js +50 -0
- package/package.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# word-def
|
|
2
|
+
|
|
3
|
+
CLI tool to find definitions of any English word using the Free Dictionary API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g word-def
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
word-def <word>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Example:
|
|
18
|
+
```bash
|
|
19
|
+
$ word-def hello
|
|
20
|
+
|
|
21
|
+
š hello
|
|
22
|
+
|
|
23
|
+
[noun]
|
|
24
|
+
1. a greeting used when meeting someone
|
|
25
|
+
ā "hello, how are you?"
|
|
26
|
+
2. an expression of surprise
|
|
27
|
+
|
|
28
|
+
[verb]
|
|
29
|
+
1. to say "hello" to someone
|
|
30
|
+
ā "he helloed the crowd"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- Fetches definitions from Free Dictionary API
|
|
36
|
+
- Shows part of speech
|
|
37
|
+
- Displays up to 3 definitions per part of speech
|
|
38
|
+
- Shows example sentences when available
|
|
39
|
+
- Works offline? No, requires internet
|
package/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const https = require('https');
|
|
4
|
+
|
|
5
|
+
const word = process.argv[2];
|
|
6
|
+
|
|
7
|
+
if (!word) {
|
|
8
|
+
console.error('Usage: word-def <word>');
|
|
9
|
+
console.error('Example: word-def hello');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const url = `https://api.dictionaryapi.dev/api/v2/entries/en/${encodeURIComponent(word)}`;
|
|
14
|
+
|
|
15
|
+
https.get(url, (res) => {
|
|
16
|
+
let data = '';
|
|
17
|
+
|
|
18
|
+
res.on('data', chunk => data += chunk);
|
|
19
|
+
res.on('end', () => {
|
|
20
|
+
try {
|
|
21
|
+
const parsed = JSON.parse(data);
|
|
22
|
+
|
|
23
|
+
if (res.statusCode === 404) {
|
|
24
|
+
console.log(`ā No definition found for "${word}"`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const entry = parsed[0];
|
|
29
|
+
console.log(`\nš ${entry.word}\n`);
|
|
30
|
+
|
|
31
|
+
entry.meanings.forEach((meaning, i) => {
|
|
32
|
+
console.log(`[${meaning.partOfSpeech}]`);
|
|
33
|
+
meaning.definitions.slice(0, 3).forEach((def, j) => {
|
|
34
|
+
console.log(` ${j + 1}. ${def.definition}`);
|
|
35
|
+
if (def.example) {
|
|
36
|
+
console.log(` ā "${def.example}"`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
console.log('');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.log(`ā Error parsing response for "${word}"`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}).on('error', () => {
|
|
48
|
+
console.log('ā Network error - check your connection');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "word-def",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI tool to find definitions of any English word",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"word-def": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"No tests yet\" && exit 0"
|
|
11
|
+
},
|
|
12
|
+
"keywords": ["dictionary", "cli", "definition", "english"],
|
|
13
|
+
"author": "Oscar Roberts",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/oskibobby13/word-def.git"
|
|
18
|
+
}
|
|
19
|
+
}
|