]>
Commit | Line | Data |
---|---|---|
c0d27c05 RBR |
1 | import { Conjugator } from '@jirimracek/conjugate-esp'; |
2 | ||
3 | const internals = { | |
4 | kVowels: ['a', 'e', 'i', 'o', 'u'], | |
5 | }; | |
6 | ||
7 | export const pluralize = function (noun) { | |
8 | ||
9 | const lastLetter = noun[noun.length - 1]; | |
10 | ||
11 | if (lastLetter === 's') { | |
12 | return noun; | |
13 | } | |
14 | ||
15 | if (internals.kVowels.indexOf(lastLetter) >= 0) { | |
16 | return noun + 's' | |
17 | } | |
18 | ||
19 | return noun + 'es'; | |
20 | }; | |
21 | ||
22 | export const conjugate = async function(verb) { | |
23 | ||
24 | const conjugator = new Conjugator(); | |
25 | try { | |
26 | const conjugation = await conjugator.conjugate(verb); | |
27 | ||
28 | if (!conjugation || conjugation.length === 0) { | |
29 | console.error('Could not conjugate: ', verb); | |
30 | throw new Error(`Could not conjugate: ${verb}`) | |
31 | } | |
32 | ||
33 | const presentIndicative = conjugation[0] | |
34 | .conjugation | |
35 | .Indicativo | |
36 | .Presente[2]; | |
37 | ||
38 | return presentIndicative; | |
39 | } | |
40 | catch (err) { | |
41 | return verb.replace(/r$/, ''); | |
42 | } | |
43 | ||
44 | }; |