n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
92 lines (91 loc) • 3.48 kB
TypeScript
/**
* Traditional Chinese (Taiwan) language converter
*
* CLDR: zh-Hant-TW | Traditional Chinese as used in Taiwan
*
* Key features:
* - Myriad-based (萬, 億) grouping - 4 digits
* - Formal (financial) vs common numerals
* - Zero insertion for skipped positions
* - No word separators (concatenated format)
*
* Differences from Simplified:
* - Different character forms (e.g., 負/负, 點/点, 億/亿, 萬/万)
* - Some formal numerals differ (參/叁, 貳/贰, 陸/陆)
*/
export declare const cardinalMax: bigint;
export declare const ordinalMax: bigint;
export declare const currencyMax: bigint;
export type CardinalOptions = {
/**
* - Use formal/financial numerals
*/
formal?: boolean;
};
/**
* @typedef {object} CardinalOptions
* @property {boolean} [formal] - Use formal/financial numerals
*/
/** @type {Required<CardinalOptions>} */
export declare const cardinalDefaults: Required<CardinalOptions>;
/**
* Converts a numeric value to Traditional Chinese words.
* @param {number | string | bigint} value - The numeric value to convert
* @param {CardinalOptions} [options] - Optional configuration
* @returns {string} The number in Traditional Chinese words
*/
declare function toCardinal(value: number | string | bigint, options?: CardinalOptions): string;
export type OrdinalOptions = {
/**
* - Use formal/financial numerals
*/
formal?: boolean;
};
/**
* @typedef {object} OrdinalOptions
* @property {boolean} [formal] - Use formal/financial numerals
*/
/** @type {Required<OrdinalOptions>} */
export declare const ordinalDefaults: Required<OrdinalOptions>;
/**
* Converts a numeric value to Traditional Chinese ordinal words.
* @param {number | string | bigint} value - The numeric value to convert (positive integer)
* @param {OrdinalOptions} [options] - Optional configuration
* @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) // '第壹'
* toOrdinal(2) // '第貳'
* toOrdinal(1, { formal: false }) // '第一'
*/
declare function toOrdinal(value: number | string | bigint, options?: OrdinalOptions): string;
export type CurrencyOptions = {
/**
* - Use formal/financial numerals
*/
formal?: boolean;
};
/**
* @typedef {object} CurrencyOptions
* @property {boolean} [formal] - Use formal/financial numerals
*/
/** @type {Required<CurrencyOptions>} */
export declare const currencyDefaults: Required<CurrencyOptions>;
/**
* Converts a numeric value to Traditional Chinese currency words (New Taiwan Dollar).
*
* Uses 圓 (yuan), 角 (jiao, 1/10), 分 (fen, 1/100).
* Formal writing adds 整 (zheng) for whole amounts.
* @param {number | string | bigint} value - The currency amount to convert
* @param {CurrencyOptions} [options] - Optional configuration
* @returns {string} The amount in Traditional Chinese 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) // '肆拾貳圓整'
* toCurrency(1.50) // '壹圓伍角整'
* toCurrency(42, { formal: false }) // '四十二元整'
*/
declare function toCurrency(value: number | string | bigint, options?: CurrencyOptions): string;
export { toCardinal, toOrdinal, toCurrency };