UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.

49 lines 2.09 kB
import type { Numeric } from '../types/index'; /** * * Converts a numeric value into its corresponding English word representation. * @warning ***Supports numeric values up to `10e19` or `10^20` (one hundred quintillion).*** * @warning ***Decimal values are ignored; only the integer part is converted.*** * @param number - The number to convert into words. * @returns The number converted in words. */ export declare function numberToWords(num: Numeric): string; /** * * Converts a number to a Roman numeral. * @param num - The number to convert. Number must be `between 1 and 3999`. * @returns The Roman numeral representation. * * @example convertToRomanNumerals(29) → "XXIX" */ export declare const convertToRomanNumerals: (num: Numeric) => string; /** * * Converts a number, numeric string, or cardinal word string into its ordinal word representation. * * @param number - A number (e.g. `42`), numeric string (e.g. `"42"`), or cardinal word (e.g. `"forty-two"`). * @returns The ordinal word form (always in lowercase) of the input. * * @example * numberToWordsOrdinal(1); // "first" * numberToWordsOrdinal("23"); // "twenty-third" * numberToWordsOrdinal("twenty-three"); // "twenty-third" */ export declare function numberToWordsOrdinal(number: Numeric | string): string; /** * * Convert an English cardinal/ordinal word string into a number. * * - Accepts hyphenated words, "and", ordinals (first, second, etc.), negatives, and large scales (thousand, million etc.). * * @example * wordsToNumber('forty-two') // 42 * wordsToNumber('one hundred and seven') // 107 * wordsToNumber('two thousand three hundred') // 2300 * wordsToNumber('twenty-first') // 21 * wordsToNumber('negative five') // -5 * * @param word - A human readable number (cardinal or ordinal) in words * @returns Numeric value of the word or NaN if cannot parse * * @remarks * **NOTE** - *For very large numbers (e.g. more than quintillion) results may not always be correct.* */ export declare function wordsToNumber(word: string): number; //# sourceMappingURL=convert.d.ts.map