UNPKG

@zsnout/ithkuil

Version:

A set of tools which can generate and parse romanized Ithkuil text and which can generate Ithkuil script from text and JSON data.

59 lines (58 loc) 2.32 kB
import { affixToIthkuil } from "../../affix/index.js"; import { applyStress, countVowelForms } from "../../helpers/stress.js"; import { extractAllConsonants } from "../../phonotactics/letters.js"; import { isLegalWordFinalConsonantForm } from "../../phonotactics/word-final.js"; import { isLegalWordInitialConsonantForm } from "../../phonotactics/word-initial.js"; import { affixualAdjunctScopeToIthkuil, } from "./scope.js"; export * from "./scope.js"; /** * Converts an affixual adjunct into Ithkuil. * * @example * affixualAdjunctToIthkuil({ * affixes: [{ type: 2, degree: 7, cs: "c" }], * scope: "VII:DOM", * appliesToConcatenatedStemOnly: true, * }) * // "oicé" * * @param adjunct The affixual adjunct to be converted. * @returns Romanized Ithkuilic text representing the affixual adjunct. */ export function affixualAdjunctToIthkuil(adjunct) { if (adjunct.affixes.length == 1) { const affix = affixToIthkuil(adjunct.affixes[0], { reversed: false, }).defaultValue; const scope = affixualAdjunctScopeToIthkuil(adjunct.scope ?? "V:DOM", "vs", (adjunct.appliesToConcatenatedStemOnly ?? false) && isLegalWordFinalConsonantForm(extractAllConsonants(affix))); if (adjunct.appliesToConcatenatedStemOnly) { const output = affix + scope; if (countVowelForms(output) == 1) { return output; } else { return applyStress(output, -1); } } return affix + scope; } const rawAffix1 = affixToIthkuil(adjunct.affixes[0], { reversed: true, }).defaultValue; const affix1 = isLegalWordInitialConsonantForm(extractAllConsonants(rawAffix1)) ? rawAffix1 : "ë" + rawAffix1; const cz = affixualAdjunctScopeToIthkuil(adjunct.scope ?? "V:DOM", "cz", false); const main = adjunct.affixes .slice(1) .map((affix) => affixToIthkuil(affix, { reversed: false })) .reduce((a, b) => a + b.withPreviousText(a), affix1 + cz); const scope = adjunct.scope2 ? affixualAdjunctScopeToIthkuil(adjunct.scope2, "vz", false) : "ai"; const output = main + scope; if (adjunct.appliesToConcatenatedStemOnly) { return applyStress(output, -1); } return output; }