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.

58 lines (57 loc) 1.71 kB
import { attachConstructor, Secondary, textToSecondaries, } from "../index.js"; import { Numeral } from "./index.js"; /** * Converts a numeric adjunct into numeral characters. * * @param number The number to be converted. * @param handwritten Whether the outputted characters should be handwritten. * @returns A series of constructable characters. */ export function numericAdjunctToNumerals(number, handwritten) { if (typeof number == "number") { number = Math.floor(number); if (!Number.isSafeInteger(number)) { number = 0; } } let value = BigInt(number); if (value < 0n) { value = 0n; } const output = []; while (value) { const amount = value % 10000n; value = value / 10000n; output.unshift({ construct: Numeral, value: Number(amount), handwritten, }); } if (output.length == 0) { output.push({ construct: Numeral, value: 0, handwritten, }); } return output; } /** * Converts a numeric Cs or Cr form into secondary characters. * * @param value The numeric value to write. * @param getCx Gets the Cs or Cr form corresponding to a given numeric value. * @param handwritten Whether or not to use the handwritten script. * @returns An array of secondary characters, or undefined if impossible. */ export function numericCxToSecondaries(value, getCx, handwritten) { const cx = getCx(value); if (cx == null) { return; } return textToSecondaries(cx, { forcePlaceholderCharacters: true, handwritten, }).map((x) => attachConstructor(x, Secondary)); }