UNPKG

to-words

Version:

Convert numbers to words in 132 locales with currency, ordinal, and BigInt support (TypeScript, ESM/CJS/UMD).

182 lines (181 loc) 8.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToWords = void 0; exports.toWords = toWords; exports.toOrdinal = toOrdinal; exports.toCurrency = toCurrency; const ToWordsCore_js_1 = require("../ToWordsCore.js"); class Locale { config = { currency: { name: 'Shilling', plural: 'Shillings', singular: 'Shilling', symbol: 'USh', fractionalUnit: { name: 'Cent', plural: 'Cents', singular: 'Cent', symbol: '', }, }, texts: { and: 'And', minus: 'Minus', only: 'Only', point: 'Point', }, numberWordsMapping: [ { number: 1000000000000000000000000000000000000000000000000000000000000000n, value: 'Vigintillion' }, { number: 1000000000000000000000000000000000000000000000000000000000000n, value: 'Novemdecillion' }, { number: 1000000000000000000000000000000000000000000000000000000000n, value: 'Octodecillion' }, { number: 1000000000000000000000000000000000000000000000000000000n, value: 'Septendecillion' }, { number: 1000000000000000000000000000000000000000000000000000n, value: 'Sexdecillion' }, { number: 1000000000000000000000000000000000000000000000000n, value: 'Quindecillion' }, { number: 1000000000000000000000000000000000000000000000n, value: 'Quattuordecillion' }, { number: 1000000000000000000000000000000000000000000n, value: 'Tredecillion' }, { number: 1000000000000000000000000000000000000000n, value: 'Duodecillion' }, { number: 1000000000000000000000000000000000000n, value: 'Undecillion' }, { number: 1000000000000000000000000000000000n, value: 'Decillion' }, { number: 1000000000000000000000000000000n, value: 'Nonillion' }, { number: 1000000000000000000000000000n, value: 'Octillion' }, { number: 1000000000000000000000000n, value: 'Septillion' }, { number: 1000000000000000000000n, value: 'Sextillion' }, { number: 1000000000000000000n, value: 'Quintillion' }, { number: 1000000000000000, value: 'Quadrillion' }, { number: 1000000000000, value: 'Trillion' }, { number: 1000000000, value: 'Billion' }, { number: 1000000, value: 'Million' }, { number: 1000, value: 'Thousand' }, { number: 100, value: 'Hundred' }, { number: 90, value: 'Ninety' }, { number: 80, value: 'Eighty' }, { number: 70, value: 'Seventy' }, { number: 60, value: 'Sixty' }, { number: 50, value: 'Fifty' }, { number: 40, value: 'Forty' }, { number: 30, value: 'Thirty' }, { number: 20, value: 'Twenty' }, { number: 19, value: 'Nineteen' }, { number: 18, value: 'Eighteen' }, { number: 17, value: 'Seventeen' }, { number: 16, value: 'Sixteen' }, { number: 15, value: 'Fifteen' }, { number: 14, value: 'Fourteen' }, { number: 13, value: 'Thirteen' }, { number: 12, value: 'Twelve' }, { number: 11, value: 'Eleven' }, { number: 10, value: 'Ten' }, { number: 9, value: 'Nine' }, { number: 8, value: 'Eight' }, { number: 7, value: 'Seven' }, { number: 6, value: 'Six' }, { number: 5, value: 'Five' }, { number: 4, value: 'Four' }, { number: 3, value: 'Three' }, { number: 2, value: 'Two' }, { number: 1, value: 'One' }, { number: 0, value: 'Zero' }, ], exactWordsMapping: [{ number: 100, value: 'One Hundred' }], ordinalWordsMapping: [ { number: 1000000000000000000000000000000000000000000000000000000000000000n, value: 'Vigintillionth' }, { number: 1000000000000000000000000000000000000000000000000000000000000n, value: 'Novemdecillionth' }, { number: 1000000000000000000000000000000000000000000000000000000000n, value: 'Octodecillionth' }, { number: 1000000000000000000000000000000000000000000000000000000n, value: 'Septendecillionth' }, { number: 1000000000000000000000000000000000000000000000000000n, value: 'Sexdecillionth' }, { number: 1000000000000000000000000000000000000000000000000n, value: 'Quindecillionth' }, { number: 1000000000000000000000000000000000000000000000n, value: 'Quattuordecillionth' }, { number: 1000000000000000000000000000000000000000000n, value: 'Tredecillionth' }, { number: 1000000000000000000000000000000000000000n, value: 'Duodecillionth' }, { number: 1000000000000000000000000000000000000n, value: 'Undecillionth' }, { number: 1000000000000000000000000000000000n, value: 'Decillionth' }, { number: 1000000000000000000000000000000n, value: 'Nonillionth' }, { number: 1000000000000000000000000000n, value: 'Octillionth' }, { number: 1000000000000000000000000n, value: 'Septillionth' }, { number: 1000000000000000000000n, value: 'Sextillionth' }, { number: 1000000000000000000n, value: 'Quintillionth' }, { number: 1000000000000000, value: 'Quadrillionth' }, { number: 1000000000000, value: 'Trillionth' }, { number: 1000000000, value: 'Billionth' }, { number: 1000000, value: 'Millionth' }, { number: 1000, value: 'Thousandth' }, { number: 100, value: 'Hundredth' }, { number: 90, value: 'Ninetieth' }, { number: 80, value: 'Eightieth' }, { number: 70, value: 'Seventieth' }, { number: 60, value: 'Sixtieth' }, { number: 50, value: 'Fiftieth' }, { number: 40, value: 'Fortieth' }, { number: 30, value: 'Thirtieth' }, { number: 20, value: 'Twentieth' }, { number: 19, value: 'Nineteenth' }, { number: 18, value: 'Eighteenth' }, { number: 17, value: 'Seventeenth' }, { number: 16, value: 'Sixteenth' }, { number: 15, value: 'Fifteenth' }, { number: 14, value: 'Fourteenth' }, { number: 13, value: 'Thirteenth' }, { number: 12, value: 'Twelfth' }, { number: 11, value: 'Eleventh' }, { number: 10, value: 'Tenth' }, { number: 9, value: 'Ninth' }, { number: 8, value: 'Eighth' }, { number: 7, value: 'Seventh' }, { number: 6, value: 'Sixth' }, { number: 5, value: 'Fifth' }, { number: 4, value: 'Fourth' }, { number: 3, value: 'Third' }, { number: 2, value: 'Second' }, { number: 1, value: 'First' }, { number: 0, value: 'Zeroth' }, ], ordinalExactWordsMapping: [{ number: 100, value: 'One Hundredth' }], fractionDenominatorMapping: { 1: { singular: 'Tenth', plural: 'Tenths' }, 2: { singular: 'Hundredth', plural: 'Hundredths' }, 3: { singular: 'Thousandth', plural: 'Thousandths' }, 4: { singular: 'Ten-Thousandth', plural: 'Ten-Thousandths' }, 5: { singular: 'Hundred-Thousandth', plural: 'Hundred-Thousandths' }, 6: { singular: 'Millionth', plural: 'Millionths' }, }, }; } exports.default = Locale; /** * ToWords class pre-configured for this locale. * This is a lightweight version that only bundles this specific locale. * * @example * import { ToWords } from 'to-words/en-UG'; * const tw = new ToWords(); * tw.convert(1234); */ class ToWords extends ToWordsCore_js_1.ToWordsCore { constructor(options = {}) { super(options); this.setLocale(Locale); } } exports.ToWords = ToWords; // Module-level singleton reused across calls to avoid per-call instance creation const instance = new ToWords(); /** * Convert a number to words for this locale (functional style). */ function toWords(number, options) { return instance.convert(number, options); } /** * Convert a number to ordinal words for this locale (functional style). */ function toOrdinal(number, options) { return instance.toOrdinal(number, options); } /** * Convert a number to currency words for this locale (functional style). * Shorthand for toWords(number, { currency: true, ...options }). */ function toCurrency(number, options) { return instance.convert(number, { ...options, currency: true }); }