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.4 kB
TypeScript
/**
* Vietnamese (Vietnam) language converter
*
* CLDR: vi-VN | Vietnamese as used in Vietnam
*
* Vietnamese-specific rules:
* - Special pronunciation: "lăm" for 5 in tens position, "mốt" for final 1
* - "Lẻ" (odd/extra) marker when tens place is zero after hundreds/scales
* - Short scale system with Vietnamese words (nghìn, triệu, tỷ)
*/
export declare const cardinalMax: bigint;
export declare const ordinalMax: bigint;
export declare const currencyMax: bigint;
/**
* Converts a numeric value to Vietnamese 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 Vietnamese words
* @throws {TypeError} If value is not a valid numeric type
* @throws {Error} If value is not a valid number format
* @example
* toCardinal(42) // 'bốn mươi hai'
* toCardinal(101) // 'một trăm lẻ một'
* toCardinal(1000000) // 'một triệu'
*/
declare function toCardinal(value: number | string | bigint): string;
/**
* Converts a numeric value to Vietnamese ordinal words.
* @param {number | string | bigint} value - The numeric value to convert (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) // 'thứ nhất'
* toOrdinal(2) // 'thứ hai'
* toOrdinal(10) // 'thứ mười'
*/
declare function toOrdinal(value: number | string | bigint): string;
/**
* Converts a numeric value to Vietnamese currency words (Dong).
*
* Vietnamese Dong has no subunit in modern usage (xu are historical).
* Amounts are rounded to whole đồng.
* @param {number | string | bigint} value - The currency amount to convert
* @returns {string} The amount in Vietnamese 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) // 'bốn mươi hai đồng'
* toCurrency(1000) // 'một nghìn đồng'
* toCurrency(-5) // 'âm năm đồng'
*/
declare function toCurrency(value: number | string | bigint): string;
export { toCardinal, toOrdinal, toCurrency };