@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.
32 lines (31 loc) • 1.11 kB
JavaScript
import { deepFreeze } from "../../helpers/deep-freeze.js";
import { applyStress, countVowelForms } from "../../helpers/stress.js";
/** A Zod validator matching Slot X stresses. */
export const ALL_SLOT_X_STRESSES = /* @__PURE__ */ deepFreeze(["UNF/C", "UNF/K", "FRM"]);
/**
* Applies Slot X stress to an Ithkuilic word.
*
* @param word The word to apply stress to.
* @param stress The stress type to apply.
* @returns Romanized Ithkuilic text representing the full formative, including
* the stress, marked with an accent mark or circumflex.
*/
export function applySlotXStress(word, stress) {
const vowelFormCount = countVowelForms(word);
if (stress == "UNF/C") {
if (vowelFormCount >= 2) {
return word;
}
throw new Error(`The formative '${word}' cannot be marked nominal.`);
}
if (stress == "UNF/K") {
if (vowelFormCount == 1) {
return word;
}
return applyStress(word, -1);
}
if (stress == "FRM") {
return applyStress(word, -3);
}
throw new Error("Invalid stress type '" + stress + "'.");
}