-
Notifications
You must be signed in to change notification settings - Fork 0
/
defn.js
35 lines (34 loc) · 893 Bytes
/
defn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const program = require('commander');
const services = require('./service');
program
.version('0.0.1')
.parse(process.argv)
var word = program.args[0];
const defintions = function(word,console_data=1) {
api_path="definitions"
return new Promise((resolve, reject) => {
services.getDictService(word,api_path).then((data) => {
if(data.status == 200){
data = data.body ? data.body : [];
for(var k in data) {
if(console_data == 0)
break;
console.log("Definition ",(parseInt(k)+1),":", data[k].text);
}
if(!data.length){
console.log("No Defitions Found!")
}
resolve(data);
}else
console.log(data.body.error ? data.body.error : "Internal Error");
}).catch(err=>{
console.log(err);
console.log("Server Error");
});
});
}
if(word != undefined)
defintions(word);
module.exports = {
defintions: defintions
};