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.

91 lines (90 loc) 3 kB
import { getIntegerCs } from "../../data/affixes-map.js"; import { caToIthkuil } from "../ca/index.js"; import { ALL_CASES, CASE_AFFIX_TO_CS_MAP, caseToIthkuil, } from "../formative/slot-9/case.js"; import { deepFreeze } from "../helpers/deep-freeze.js"; import { STANDARD_VOWEL_TABLE } from "../helpers/vowel-table.js"; import { IA_UÄ, IE_UË, IO_ÜÄ, IÖ_ÜË, UA_IÄ, UE_IË, UO_ÖÄ, UÖ_ÖË, WithWYAlternative, } from "../helpers/with-wy-alternative.js"; import { referentialAffixToIthkuil, } from "../referential/referent/index.js"; import {} from "./degree.js"; import {} from "./type.js"; export * from "./affixes.js"; export * from "./degree.js"; export * from "./type.js"; /** An array containing all referential affix cases. */ export const ALL_REFERENTIAL_AFFIX_CASES = /* @__PURE__ */ deepFreeze([ "THM", "INS", "ABS", "AFF", "STM", "EFF", "ERG", "DAT", "IND", "POS", "PRP", "GEN", "ATT", "PDC", "ITP", "OGN", "IDP", "PAR", ]); /** * An object mapping from referential affix cases to their Ithkuilic * translations. */ const REFERENTIAL_AFFIX_CASE_TO_ITHKUIL_MAP = /* @__PURE__ */ deepFreeze({ THM: "ao", INS: "aö", ABS: "eo", AFF: "eö", STM: "oë", EFF: "öe", ERG: "oe", DAT: "öa", IND: "oa", POS: IA_UÄ, PRP: IE_UË, GEN: IO_ÜÄ, ATT: IÖ_ÜË, PDC: "eë", ITP: UÖ_ÖË, OGN: UO_ÖÄ, IDP: UE_IË, PAR: UA_IÄ, }); /** * Converts an affix into Ithkuil. * * @param affix The affix to be converted. * @param metadata Metadata about the affix. * @returns Romanized Ithkuilic text representing the affix. */ export function affixToIthkuil(affix, metadata) { let vowel = WithWYAlternative.of("ca" in affix && affix.ca ? "üö" : "referents" in affix && affix.referents ? REFERENTIAL_AFFIX_CASE_TO_ITHKUIL_MAP[affix.case ?? "THM"] : "case" in affix && affix.case ? caseToIthkuil(affix.case, false, true) : STANDARD_VOWEL_TABLE[affix.type][affix.degree]); if (metadata.insertGlottalStop) { vowel = vowel.insertGlottalStop(metadata.isGlottalStopWordFinal ?? false); } const consonant = "ca" in affix && affix.ca ? caToIthkuil(affix.ca) : "referents" in affix && affix.referents ? referentialAffixToIthkuil(affix.referents, affix.perspective ?? "M") : "case" in affix && affix.case ? ("type" in affix && affix.type ? CASE_AFFIX_TO_CS_MAP[`${affix.isInverse}`][affix.type] : "l") + (ALL_CASES.indexOf(affix.case) >= 36 ? "y" : "w") : ((typeof affix.cs == "number" || typeof affix.cs == "bigint") && getIntegerCs(affix.cs)) || "" + affix.cs; if (metadata.reversed) { return WithWYAlternative.of(consonant + vowel.withPreviousText(consonant)); } else { return vowel.add(consonant); } }