@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.
58 lines (57 loc) • 2.19 kB
JavaScript
import { ALL_AFFILIATIONS, ALL_CONFIGURATIONS, ALL_ESSENCES, ALL_EXTENSIONS, ALL_PERSPECTIVES, caToIthkuil, geminatedCAToIthkuil, } from "../../generate/ca/index.js";
function makeCaForms() {
const ALL_CA_FORMS = new Map();
const ALL_GEMINATED_CA_FORMS = new Map();
for (const affiliation of ALL_AFFILIATIONS) {
for (const configuration of ALL_CONFIGURATIONS) {
for (const extension of ALL_EXTENSIONS) {
for (const perspective of ALL_PERSPECTIVES) {
for (const essence of ALL_ESSENCES) {
const ca = {};
if (affiliation != "CSL")
ca.affiliation = affiliation;
if (configuration != "UPX")
ca.configuration = configuration;
if (extension != "DEL")
ca.extension = extension;
if (perspective != "M")
ca.perspective = perspective;
if (essence != "NRM")
ca.essence = essence;
ALL_CA_FORMS.set(caToIthkuil(ca), ca);
ALL_GEMINATED_CA_FORMS.set(geminatedCAToIthkuil(ca), ca);
}
}
}
}
}
return [ALL_CA_FORMS, ALL_GEMINATED_CA_FORMS];
}
const CA_FORMS = /* @__PURE__ */ makeCaForms();
/**
* Parses a non-geminated Ca form into an object.
*
* @param ca The Ca form to be parsed.
* @returns A `PartialCA` object containing the details of the Ca form.
*/
export function parseCa(ca) {
const form = CA_FORMS[0].get(ca);
if (form != null) {
return form;
}
console.error(new Error().stack);
throw new Error("Invalid Ca form: " + form + ".");
}
/**
* Parses a geminated Ca form into an object.
*
* @param ca The Ca form to be parsed.
* @returns A `PartialCA` object containing the details of the Ca form.
*/
export function parseGeminatedCa(ca) {
const form = CA_FORMS[1].get(ca);
if (form != null) {
return form;
}
throw new Error("Invalid geminated Ca form: " + form + ".");
}