]> git.r.bdr.sh - rbdr/generador-de-insultos/blame - src/lib/grammar.js
Remove old binary
[rbdr/generador-de-insultos] / src / lib / grammar.js
CommitLineData
c0d27c05
RBR
1import { Conjugator } from '@jirimracek/conjugate-esp';
2
3const internals = {
4 kVowels: ['a', 'e', 'i', 'o', 'u'],
5};
6
7export 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
22export 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};