@yar.ua/numerals
Version:
Number to text - Inflector for Ukrainian numerals
17 lines (16 loc) • 746 B
JavaScript
import { DummySyntaxNode } from "./syntax/node.js";
import * as fractionals from "./fractionals.js";
export function inflect(whole, decimal, form, insert_ones = false, strict_range = false) {
const root = new DummySyntaxNode(form);
const obj = new DummySyntaxNode({});
build_tree(root, obj, whole, decimal, insert_ones, strict_range);
root.agree();
return root.text();
}
export function build_tree(root, obj, whole, decimal, insert_ones = false, strict_range = false) {
const magnitude = get_decimal_fraction_magnitude(decimal);
fractionals.build_tree(root, obj, whole, decimal, magnitude, insert_ones, strict_range);
}
function get_decimal_fraction_magnitude(decimal) {
return "1" + "0".repeat(decimal.length);
}