n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
75 lines (74 loc) • 3.18 kB
TypeScript
/**
* British English language converter
*
* CLDR: en-GB | English as used in the United Kingdom
*
* British English conventions:
* - "and" after hundreds: "one hundred and twenty-three"
* - "and" before final segment: "one million and one"
* - Hyphenated tens-ones: "twenty-one", "forty-two"
* - Western numbering system (short scale: billion = 10^9)
*/
export declare const cardinalMax: bigint;
export declare const ordinalMax: bigint;
export declare const currencyMax: bigint;
/**
* Converts a numeric value to English words.
*
* This is the main public API. It accepts any valid numeric input
* (number, string, or bigint) and handles parsing internally.
* @param {number | string | bigint} value - The numeric value to convert
* @returns {string} The number in English words
* @throws {TypeError} If value is not a valid numeric type
* @throws {Error} If value is not a valid number format
* @example
* toCardinal(42) // 'forty-two'
* toCardinal(-3.14) // 'minus three point fourteen'
* toCardinal('1000000') // 'one million'
*/
declare function toCardinal(value: number | string | bigint): string;
/**
* Converts a numeric value to British English ordinal words.
* @param {number | string | bigint} value - The numeric value to convert (must be a positive integer)
* @returns {string} The number as ordinal words (e.g., "first", "forty-second")
* @throws {TypeError} If value is not a valid numeric type
* @throws {RangeError} If value is negative, zero, or has a decimal part
* @example
* toOrdinal(1) // 'first'
* toOrdinal(2) // 'second'
* toOrdinal(3) // 'third'
* toOrdinal(21) // 'twenty-first'
* toOrdinal(42) // 'forty-second'
* toOrdinal(100) // 'one hundredth'
* toOrdinal(101) // 'one hundred first'
* toOrdinal(1000) // 'one thousandth'
*/
declare function toOrdinal(value: number | string | bigint): string;
export type CurrencyOptions = {
/**
* - Use "and" between pounds and pence (e.g., "one pound and fifty pence")
*/
and?: boolean;
};
/**
* @typedef {object} CurrencyOptions
* @property {boolean} [and] - Use "and" between pounds and pence (e.g., "one pound and fifty pence")
*/
/** @type {Required<CurrencyOptions>} */
export declare const currencyDefaults: Required<CurrencyOptions>;
/**
* Converts a numeric value to British English currency words.
* @param {number | string | bigint} value - The currency amount to convert
* @param {CurrencyOptions} [options] - Optional configuration
* @returns {string} The amount in British English currency words
* @throws {TypeError} If value is not a valid numeric type
* @throws {Error} If value is not a valid number format
* @example
* toCurrency(42.50) // 'forty-two pounds and fifty pence'
* toCurrency(1) // 'one pound'
* toCurrency(0.99) // 'ninety-nine pence'
* toCurrency(0.01) // 'one penny'
* toCurrency(42.50, { and: false }) // 'forty-two pounds fifty pence'
*/
declare function toCurrency(value: number | string | bigint, options?: CurrencyOptions): string;
export { toCardinal, toOrdinal, toCurrency };