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.

39 lines (38 loc) 1.27 kB
import { ALL_DIPTHONGS } from "./dipthongs.js"; import { has } from "./has.js"; import { WithWYAlternative } from "./with-wy-alternative.js"; /** * Inserts a glottal stop into a vowel form. * * @param vowelForm The vowel form to insert a glottal stop into. * @param isAtEndOfWord Whether the finished vowel form will be at the end of a * word. * @returns The vowel form with a glottal stop inserted. */ export function insertGlottalStop(vowelForm, isAtEndOfWord) { if (isAtEndOfWord) { if (vowelForm.length == 1) { return vowelForm + "'" + vowelForm; } if (vowelForm.length == 2) { return vowelForm[0] + "'" + vowelForm[1]; } } else { if (vowelForm.length == 1 || has(ALL_DIPTHONGS, vowelForm)) { return vowelForm + "'"; } if (vowelForm.length == 2) { return vowelForm[0] + "'" + vowelForm[1]; } } throw new Error("Vowel forms may only 1 or 2 vowels."); } export function insertGlottalStopIntoPossiblyWithWYAlternative(vowelForm, isAtEndOfWord) { if (typeof vowelForm == "string") { return insertGlottalStop(vowelForm, isAtEndOfWord); } else { return vowelForm.insertGlottalStop(isAtEndOfWord); } }