More types

This commit is contained in:
Greg Shuflin 2021-09-12 02:07:29 -07:00
parent a9703a9529
commit 44156694a2
3 changed files with 91 additions and 78 deletions

View File

@ -20,6 +20,7 @@ module.exports = {
"@typescript-eslint"
],
rules: {
"arrow-parens": ["error", "always"]
"arrow-parens": ["error", "always"],
"indent": ["error", 4]
},
};

View File

@ -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",

View File

@ -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};