UNPKG

@yar.ua/numerals

Version:

Number to text - Inflector for Ukrainian numerals

37 lines (36 loc) 1.41 kB
import cardinal from "./cardinal.js"; import ordinal from "./ordinal.js"; import cardinal_stem from "./cardinal_stem.js"; import misc from "./misc.js"; import { ParadigmLexeme, CompoundOrdinalLexeme } from "../paradigm.js"; import { InternalDataError } from "../../errors.js"; export class NumeralLexeme { static cardinal(value) { if (!(value in cardinal)) { throw new InternalDataError(); } const [table, form] = cardinal[value]; return new ParadigmLexeme(value, table, form); } static ordinal(value) { if (!(value in ordinal)) { throw new InternalDataError(); } const [table, form] = ordinal[value]; return new ParadigmLexeme(value, table, form); } static ordinal_compound(cardinals_, ordinal_) { // const prefixes = [cardinal_stem.data[v][0][0][1] for v in cardinals_] const prefixes = cardinals_.map(v => cardinal_stem[v][0][0][1]); const [table, form] = ordinal[ordinal_]; const value = [...cardinals_, ordinal_].reduce((acc, x) => (acc + Number.parseInt(x)), 0); return new CompoundOrdinalLexeme(value.toString(), prefixes, table, form); } static misc(value) { if (!(value in misc)) { throw new InternalDataError(); } const [table, form] = misc[value]; return new ParadigmLexeme(value, table, form); } }