aboutsummaryrefslogtreecommitdiff
path: root/src/lib/grammar.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/grammar.js')
-rw-r--r--src/lib/grammar.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/grammar.js b/src/lib/grammar.js
new file mode 100644
index 0000000..4831240
--- /dev/null
+++ b/src/lib/grammar.js
@@ -0,0 +1,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$/, '');
+ }
+
+};