3 const Cheerio
= require('cheerio');
4 const Fetch
= require('node-fetch');
7 kBaseUrl: 'http://www.spanishdict.com/conjugate/',
8 kSelector: 'table .ex-tip',
9 kThirdPersonPresentPosition: 10,
15 node
.children
.forEach(function (child
) {
17 if (child
.type
=== 'text') {
20 word
+= internals
.extractWord(child
);
24 word
= word
.split(',')[0]; // multiple conjugations, take 1
26 const components
= word
.split(' '); // some special cases have two words
27 // use the last, why not
29 return components
[components
.length
- 1];
34 async
conjugate(verb
) {
36 console
.debug(`Conjugating ${verb}`);
38 const response
= await
Fetch(internals
.kBaseUrl
+ verb
);
39 const body
= await response
.text();
41 const $ = Cheerio
.load(body
);
42 const result
= $(internals
.kSelector
)[internals
.kThirdPersonPresentPosition
];
45 console
.error('Verb not found: ', verb
);
46 throw new Error('Not a valid verb');
49 const plainTextVerb
= internals
.extractWord(result
);
50 console
.debug(verb
, plainTextVerb
);