n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
65 lines (64 loc) • 2.62 kB
TypeScript
/**
* English (Australia) language converter
*
* CLDR: en-AU | English as used in Australia
*
* Key features:
* - Western numbering system (short scale: billion = 10^9)
* - British-style "and" after hundreds
* - Australian Dollar currency (AUD)
*/
export declare const cardinalMax: bigint;
export declare const ordinalMax: bigint;
export declare const currencyMax: bigint;
/**
* Converts a numeric value to Australian English words.
* @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(101) // 'one hundred and one'
* toCardinal(1000000) // 'one million'
*/
declare function toCardinal(value: number | string | bigint): string;
/**
* Converts a numeric value to Australian 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
* @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(42) // 'forty-second'
* toOrdinal(100) // 'one hundredth'
*/
declare function toOrdinal(value: number | string | bigint): string;
export type CurrencyOptions = {
/**
* - Use "and" between dollars and cents
*/
and?: boolean;
};
/**
* @typedef {object} CurrencyOptions
* @property {boolean} [and] - Use "and" between dollars and cents
*/
/** @type {Required<CurrencyOptions>} */
export declare const currencyDefaults: Required<CurrencyOptions>;
/**
* Converts a numeric value to Australian English currency words.
* @param {number | string | bigint} value - The currency amount to convert
* @param {CurrencyOptions} [options] - Optional configuration
* @returns {string} The amount in Australian 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 dollars and fifty cents'
* toCurrency(1) // 'one dollar'
* toCurrency(0.99) // 'ninety-nine cents'
* toCurrency(42.50, { and: false }) // 'forty-two dollars fifty cents'
*/
declare function toCurrency(value: number | string | bigint, options?: CurrencyOptions): string;
export { toCardinal, toOrdinal, toCurrency };