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.

65 lines (64 loc) 3.21 kB
import { suppletiveAdjunctTypeToIthkuil, } from "../adjunct/index.js"; import { affixToIthkuil } from "../affix/index.js"; import {} from "../ca/index.js"; import { caseToIthkuil, } from "../formative/index.js"; import { countVowelForms } from "../helpers/stress.js"; import { WithWYAlternative } from "../helpers/with-wy-alternative.js"; import { isLegalWordFinalConsonantForm } from "../phonotactics/index.js"; import { fillInDefaultReferentialSlots } from "./default.js"; import { applyReferentialEssence } from "./essence.js"; import { referentListToIthkuil } from "./referent/list.js"; import { referentialSpecificationToIthkuil } from "./specification.js"; /** * Converts a referential into Ithkuil. * * @param referential The referential to convert. * @returns Romanized Ithkuilic text representing the referential. */ function completeReferentialToIthkuil(referential) { const slot1 = referential.referents ? referentListToIthkuil(referential.referents, referential.perspective, false) : (referential.specification && referential.affixes ? "a" : "üo") + suppletiveAdjunctTypeToIthkuil(referential.type); const slot2 = WithWYAlternative.of(caseToIthkuil(referential.case, false, false)).withPreviousText(slot1); if (referential.specification && referential.affixes) { const slot3 = referentialSpecificationToIthkuil(referential.specification); const slot4 = referential.affixes.length ? referential.affixes .map((affix) => affixToIthkuil(affix, { reversed: false })) .reduce((a, b) => a.add(b)) .withPreviousText(slot1 + slot2 + slot3) : ""; const slot5 = referential.case2 ? referential.case2 == "THM" ? "üa" : WithWYAlternative.of(caseToIthkuil(referential.case2, false, false)).withPreviousText(slot1 + slot2 + slot3 + slot4) : (referential.essence == "NRM" || countVowelForms(slot1 + slot2 + slot3 + slot4) >= 2) ? "" : "a"; const word = slot1 + slot2 + slot3 + slot4 + slot5; return applyReferentialEssence(word, referential.essence); } if (referential.case2 || referential.perspective2 || referential.referents2) { const slot3 = "w" + WithWYAlternative.of(caseToIthkuil(referential.case2 || "THM", false, false)).valueAfterW; let slot4 = ""; if (referential.referents2) { const referentList = referentListToIthkuil(referential.referents2, referential.perspective2, true); slot4 = isLegalWordFinalConsonantForm(referentList) ? referentList : (referentList + "ë"); } return applyReferentialEssence(slot1 + slot2 + slot3 + slot4, referential.essence); } return applyReferentialEssence(slot1 + slot2, referential.essence); } /** * Converts a referential into Ithkuil. * * @param referential The referential to convert. * @returns Romanized Ithkuilic text representing the referential. */ export function referentialToIthkuil(referential) { return completeReferentialToIthkuil(fillInDefaultReferentialSlots(referential)); }