blob: 48312407f6a29afed4fc4a1bdaef1f7523ce9fc9 (
plain)
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
36
37
38
39
40
41
42
43
44
|
import { Conjugator } from '@jirimracek/conjugate-esp';
const internals = {
kVowels: ['a', 'e', 'i', 'o', 'u'],
};
export const pluralize = function (noun) {
const lastLetter = noun[noun.length - 1];
if (lastLetter === 's') {
return noun;
}
if (internals.kVowels.indexOf(lastLetter) >= 0) {
return noun + 's'
}
return noun + 'es';
};
export const conjugate = async function(verb) {
const conjugator = new Conjugator();
try {
const conjugation = await conjugator.conjugate(verb);
if (!conjugation || conjugation.length === 0) {
console.error('Could not conjugate: ', verb);
throw new Error(`Could not conjugate: ${verb}`)
}
const presentIndicative = conjugation[0]
.conjugation
.Indicativo
.Presente[2];
return presentIndicative;
}
catch (err) {
return verb.replace(/r$/, '');
}
};
|