From 44156694a293d4f6e45cf4709f2f1d88c774f4b4 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 12 Sep 2021 02:07:29 -0700 Subject: [PATCH] More types --- .eslintrc.js | 3 +- package.json | 3 +- src/saimiar_morphology.ts | 163 ++++++++++++++++++++------------------ 3 files changed, 91 insertions(+), 78 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 734c2b8..aeb0276 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -20,6 +20,7 @@ module.exports = { "@typescript-eslint" ], rules: { - "arrow-parens": ["error", "always"] + "arrow-parens": ["error", "always"], + "indent": ["error", 4] }, }; diff --git a/package.json b/package.json index c14040d..9dad55f 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "build": "parcel build index.html --no-source-maps", "prebuild": "yarn run typecheck", "typecheck": "tsc --noEmit", - "lint": "eslint src/*" + "lint": "eslint src/*", + "lint-fix": "eslint src/* --fix" }, "devDependencies": { "@parcel/transformer-image": "2.0.0-rc.0", diff --git a/src/saimiar_morphology.ts b/src/saimiar_morphology.ts index ec992a5..75de8cf 100644 --- a/src/saimiar_morphology.ts +++ b/src/saimiar_morphology.ts @@ -1,99 +1,110 @@ const rootEndingPair = (str) => ({root: str.slice(0, -1), ending: str.slice(-1)}); -function declineSaimiar(entry) { - const split = entry.sai.split(' '); - const sai = split.at(-1); - const morph = entry.morph_type; +type SaimiarDeclension = { + abs: string; + erg: string; + adp: string; + all: string; + loc: string; + ell: string; + inst: string; + rel: string; +}; - if (morph === '-V') { - return vowelDeclension(sai); - } +function declineSaimiar(entry): SaimiarDeclension { + const split = entry.sai.split(' '); + const sai = split.at(-1); + const morph = entry.morph_type; - if (morph === '-a/i') { - return aiDeclension(sai); - } + if (morph === '-V') { + return vowelDeclension(sai); + } - if (morph === 'e-') { - return initalDeclension(sai); - } + if (morph === '-a/i') { + return aiDeclension(sai); + } - if (morph === '-C') { - return consonantDeclension(sai); - } + if (morph === 'e-') { + return initalDeclension(sai); + } - console.warn(`Can't decline entry '${entry.sai}'`); - console.log(entry); - return null; + if (morph === '-C') { + return consonantDeclension(sai); + } + + console.warn(`Can't decline entry '${entry.sai}'`); + console.log(entry); + return null; } -function vowelDeclension(sai: string) { - const {root, ending} = rootEndingPair(sai); - const adpEnding = ending === 'u' ? 'ys' : `${ending}s`; +function vowelDeclension(sai: string): SaimiarDeclension { + const {root, ending} = rootEndingPair(sai); + const adpEnding = ending === 'u' ? 'ys' : `${ending}s`; - return { - abs: `${root}${ending}`, - erg: `${root}${ending}na`, - adp: `${root}${adpEnding}`, - all: `so${root}${adpEnding}`, - loc: `${root}${ending}xa`, - ell: `tlê${root}${adpEnding}`, - inst: `${root}${ending}ŕa`, - rel: `${root}${ending}źi`, - }; + return { + abs: `${root}${ending}`, + erg: `${root}${ending}na`, + adp: `${root}${adpEnding}`, + all: `so${root}${adpEnding}`, + loc: `${root}${ending}xa`, + ell: `tlê${root}${adpEnding}`, + inst: `${root}${ending}ŕa`, + rel: `${root}${ending}źi`, + }; } -function aiDeclension(sai: string) { - const {root, ending} = rootEndingPair(sai); - return { - abs: `${root}${ending}`, - erg: `${root}iad`, - adp: `${root}i`, - all: `so${root}i`, - loc: `${root}iath`, - ell: `tlê${root}i`, - inst: `${root}iar`, - rel: `${root}iai`, - }; +function aiDeclension(sai: string): SaimiarDeclension { + const {root, ending} = rootEndingPair(sai); + return { + abs: `${root}${ending}`, + erg: `${root}iad`, + adp: `${root}i`, + all: `so${root}i`, + loc: `${root}iath`, + ell: `tlê${root}i`, + inst: `${root}iar`, + rel: `${root}iai`, + }; } -function consonantDeclension(sai: string) { - const split = rootEndingPair(sai); - const root = split.ending === 'ø' ? split.root : sai; - const absFinal = split.ending === 'ø' ? 'ø' : ''; +function consonantDeclension(sai: string): SaimiarDeclension { + const split = rootEndingPair(sai); + const root = split.ending === 'ø' ? split.root : sai; + const absFinal = split.ending === 'ø' ? 'ø' : ''; - return { - abs: `${root}${absFinal}`, - erg: `${root}ad`, - adp: `${root}e`, - all: `so${root}i`, - loc: `${root}ak`, - ell: `tlê${root}i`, - inst: `${root}ar`, - rel: `${root}ai`, - }; + return { + abs: `${root}${absFinal}`, + erg: `${root}ad`, + adp: `${root}e`, + all: `so${root}i`, + loc: `${root}ak`, + ell: `tlê${root}i`, + inst: `${root}ar`, + rel: `${root}ai`, + }; } const vowels = ['a', 'e', 'ê', 'i', 'o', 'ô', 'u', 'y']; -function initalDeclension(sai: string) { - const initial = sai.slice(0, 1); - const root = sai.slice(1); +function initalDeclension(sai: string): SaimiarDeclension { + const initial = sai.slice(0, 1); + const root = sai.slice(1); - const finalRootSound = root.slice(-1); - const finalVowel = vowels.includes(finalRootSound); - const instEnding = finalVowel ? 'ŕø' : 'ar'; - const relEnding = finalVowel ? 'źi' : 'ai'; + const finalRootSound = root.slice(-1); + const finalVowel = vowels.includes(finalRootSound); + const instEnding = finalVowel ? 'ŕø' : 'ar'; + const relEnding = finalVowel ? 'źi' : 'ai'; - return { - abs: `${initial}${root}`, - erg: `da${root}`, - adp: `i${root}`, - all: `so${root}`, - loc: `xa${root}`, - ell: `tlê${root}`, - inst: `i${root}${instEnding}`, - rel: `${initial}${root}${relEnding}`, - }; + return { + abs: `${initial}${root}`, + erg: `da${root}`, + adp: `i${root}`, + all: `so${root}`, + loc: `xa${root}`, + ell: `tlê${root}`, + inst: `i${root}${instEnding}`, + rel: `${initial}${root}${relEnding}`, + }; } -export {declineSaimiar}; +export {declineSaimiar, SaimiarDeclension};