n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
57 lines (56 loc) • 2.25 kB
TypeScript
/**
* Malaysian English language converter
*
* CLDR: en-MY | English as used in Malaysia
*
* Exports:
* - toCardinal(value) - Cardinal numbers: 42 → "forty-two"
* - toOrdinal(value) - Ordinal numbers: 42 → "forty-second"
* - toCurrency(value, options?) - Currency: 42.50 → "forty-two ringgit and fifty sen"
*
* Malaysian English conventions:
* - Follows British English style
* - "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)
* - Currency: Malaysian Ringgit (MYR) - ringgit (invariable), sen (invariable)
*
* Note: Both "ringgit" and "sen" are typically invariable (same for singular and plural)
* in Malaysian English.
*/
export declare const cardinalMax: bigint;
export declare const ordinalMax: bigint;
export declare const currencyMax: bigint;
/**
* Converts a numeric value to Malaysian 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
*/
declare function toCardinal(value: number | string | bigint): string;
/**
* @param {number | string | bigint} value The numeric value to convert.
* @returns {string} The number as an ordinal in English words.
*/
declare function toOrdinal(value: number | string | bigint): string;
export type CurrencyOptions = {
/**
* - Use "and" between ringgit and sen
*/
and?: boolean;
};
/**
* @typedef {object} CurrencyOptions
* @property {boolean} [and] - Use "and" between ringgit and sen
*/
/** @type {Required<CurrencyOptions>} */
export declare const currencyDefaults: Required<CurrencyOptions>;
/**
* @param {number | string | bigint} value The numeric value to convert.
* @param {CurrencyOptions} [options] - Optional configuration
* @returns {string} The amount in Malaysian ringgit and sen in English words.
*/
declare function toCurrency(value: number | string | bigint, options?: CurrencyOptions): string;
export { toCardinal, toOrdinal, toCurrency };