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.

74 lines (73 loc) 2.84 kB
import { has } from "../../helpers/has.js"; import { EMPTY, WithWYAlternative } from "../../helpers/with-wy-alternative.js"; import { ALL_ASPECTS, aspectToIthkuil } from "./aspect.js"; import { caseScopeToIthkuil } from "./case-scope.js"; import { ALL_EFFECTS, effectToIthkuil } from "./effect.js"; import { ALL_LEVELS, levelToIthkuil } from "./level.js"; import { FAC_CCN, MoodOrCaseScope } from "./mood-or-case-scope.js"; import { ALL_MOODS, moodToIthkuil } from "./mood.js"; import { ALL_PHASES, phaseToIthkuil } from "./phase.js"; import { ALL_VALENCES, valenceToIthkuil } from "./valence.js"; export * from "./aspect.js"; export * from "./case-scope.js"; export * from "./effect.js"; export * from "./level.js"; export * from "./mood.js"; export * from "./phase.js"; export * from "./valence.js"; export * from "./vn-type.js"; /** * Converts a Vn form into Ithkuil. * * @param vn The Vn form to be converted. * @param omitDefaultValence Whether default MNO valence should be omitted. * @returns Romanized Ithkuilic text representing the Vn form. */ export function vnToIthkuil(vn, omitDefaultValence) { return (has(ALL_VALENCES, vn) ? valenceToIthkuil(vn, omitDefaultValence) : has(ALL_PHASES, vn) ? phaseToIthkuil(vn) : has(ALL_EFFECTS, vn) ? effectToIthkuil(vn) : has(ALL_LEVELS, vn) ? levelToIthkuil(vn) : aspectToIthkuil(vn)); } /** * Converts a Cn form into Ithkuil. * * @param cn The Cn form to be converted. * @param vnType The contents of Slot 8. Use "aspect" when Slot 8 contains an * aspect, "non-aspect" when it contains a non-aspect, and "empty" when Slot 8 * has been elided due to the use of MNO valence. * @returns Romanized Ithkuilic text representing the Cn form. */ export function cnToIthkuil(cn, vnType) { return (cn instanceof MoodOrCaseScope ? vnType == "empty" && cn == FAC_CCN ? "" : vnType == "aspect" ? cn.aspectualValue : cn.nonAspectualValue : has(ALL_MOODS, cn) ? moodToIthkuil(cn, vnType) : caseScopeToIthkuil(cn, vnType)); } /** * Converts Slot VIII into Ithkuil * * @param slot The Vn and Cn forms of the formative. * @param metadata Additional information relevant to Slot VIII. * @returns A `WithWYAlternative` containing romanized Ithkuilic text * representing Slot VIII. */ export function slotVIIIToIthkuil(slot, metadata) { if (metadata.omitDefault && slot.vn == "MNO" && (slot.cn == "CCN" || slot.cn == "FAC")) { return EMPTY; } const vn = vnToIthkuil(slot.vn, false); const vnType = has(ALL_ASPECTS, slot.vn) ? "aspect" : "non-aspect"; const cn = cnToIthkuil(slot.cn, vnType); if (typeof vn == "string") { return WithWYAlternative.of(vn + cn); } else { return vn.add(cn); } }