-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
34 lines (29 loc) · 810 Bytes
/
example.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
//To run:
// $ node example.js [your-merriam-webster-api-key] [word]
var Dictionary = require('./dictionary'),
//pass the constructor a config object with your key
dict = new Dictionary({
key: process.argv[2]
});
//sample method
dict.define(process.argv[3], function(error, result){
if (error == null) {
for(var i=0; i<result.length; i++){
console.log(i+'.');
console.log('Part of speech: '+result[i].partOfSpeech);
console.log('Definitions: '+result[i].definition);
console.log(result[i].definition)
}
}
else if (error === "suggestions"){
console.log(process.argv[3] + ' not found in dictionary. Possible suggestions:');
for (var i=0; i<result.length; i++){
console.log(result[i]);
}
}
else console.log(error);
});
//test words
// charlatan
// patutukis
// doodle