@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.
104 lines (103 loc) • 3.7 kB
JavaScript
import { deepFreeze } from "../helpers/deep-freeze.js";
import { fillDefaults } from "../helpers/fill-defaults.js";
import { affiliationToIthkuil } from "./affiliation.js";
import { configurationToIthkuil } from "./configuration.js";
import {} from "./essence.js";
import { extensionToIthkuil } from "./extension.js";
import { attemptGemination } from "./geminate.js";
import { perspectiveAndEssenceToIthkuil } from "./perspective-and-essence.js";
import {} from "./perspective.js";
export * from "./affiliation.js";
export * from "./configuration.js";
export * from "./essence.js";
export * from "./extension.js";
export * from "./geminate.js";
export * from "./perspective-and-essence.js";
export * from "./perspective.js";
/**
* Makes allomorphic substitutions within Ca forms to make the pronounceble and
* conform to Ithkuil's phonotactic rules.
*
* @param ca The Ca form which will have substitutions made in it.
* @returns Romanized Ithkuilic text representing the finalized Ca form.
*/
export function makeCAAllomorphicSubstitutions(ca) {
return ca
.replace(/pp/g, "mp")
.replace(/tt/g, "nt")
.replace(/kk/g, "nk")
.replace(/ll/g, "pļ")
.replace(/pb/g, "mb")
.replace(/kg/g, "ng")
.replace(/çy/g, "nd")
.replace(/rr/g, "ns")
.replace(/rř/g, "nš")
.replace(/řr/g, "ňs")
.replace(/řř/g, "ňš")
.replace(/(.)gm/g, "$1x")
.replace(/(.)gn/g, "$1ň")
.replace(/nň/g, "ňn")
.replace(/(.)çx/g, "$1xw")
.replace(/(.)bm/g, "$1v")
.replace(/(.)bn/g, "$1ḑ")
.replace(/fv/g, "vw")
.replace(/ţḑ/g, "ḑy");
}
/**
* Converts a Ca form into Ithkuil.
*
* @param ca The Ca form to be converted.
* @returns Romanized Ithkuilic text representing the Ca form.
*/
export function caToIthkuil(ca) {
const ca2 = fillInDefaultCAValues(ca);
const configuration = configurationToIthkuil(ca2.configuration);
const extension = extensionToIthkuil(ca2.extension, ca2.configuration == "UPX");
const affiliation = affiliationToIthkuil(ca2.affiliation, configuration == "" &&
extension == "" &&
ca2.perspective == "M" &&
ca2.essence == "NRM");
const perspectiveAndEssence = perspectiveAndEssenceToIthkuil(ca2.perspective, ca2.essence, affiliation == "" && configuration == "" && extension == "", !!(affiliation + configuration + extension).match(/[kpt]$/));
const core = affiliation + configuration + extension + perspectiveAndEssence;
return makeCAAllomorphicSubstitutions(core);
}
/**
* Geminates an ungeminated Ca form.
*
* @param ca The Ca form to be geminated.
* @returns Romanized Ithkuilic text representing the geminated Ca form.
*/
export function geminateCa(ca) {
const geminate = attemptGemination(ca);
if (ca == geminate) {
return geminate[0] + geminate;
}
return geminate;
}
/**
* Converts a Ca form into Ithkuil, geminating the form throughout the process.
*
* @param ca The Ca form to be converted.
* @returns Romanized Ithkuilic text representing the geminated Ca form.
*/
export function geminatedCAToIthkuil(ca) {
return geminateCa(caToIthkuil(ca));
}
/** The default Ca form. */
export const DEFAULT_CA = /* @__PURE__ */ deepFreeze({
affiliation: "CSL",
configuration: "UPX",
extension: "DEL",
perspective: "M",
essence: "NRM",
});
/**
* Fills a Ca form with default values (CSL, UPX, DEL, M, and NRM) in its empty
* slots.
*
* @param ca The Ca form to be filled.
* @returns A completed Ca form with no empty slots.
*/
export function fillInDefaultCAValues(ca) {
return fillDefaults(DEFAULT_CA, ca);
}