n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
86 lines (85 loc) • 3.25 kB
TypeScript
/**
* Simplified Chinese (China) language converter
*
* CLDR: zh-Hans-CN | Simplified Chinese as used in China
*
* Key features:
* - Myriad-based (万, 亿) grouping - 4 digits
* - Formal (financial) vs common numerals
* - Zero insertion for skipped positions
* - No word separators (concatenated format)
*/
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 Simplified Chinese words.
* @param {number | string | bigint} value - The numeric value to convert
* @param {CardinalOptions} [options] - Optional configuration
* @returns {string} The number in Simplified 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 Simplified 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(1, { formal: false }) // '第一'
* toOrdinal(10) // '第壹拾'
*/
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 Simplified Chinese currency words (Yuan/Renminbi).
* @param {number | string | bigint} value - The currency amount to convert
* @param {CurrencyOptions} [options] - Optional configuration
* @returns {string} The amount in Simplified 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.50) // '肆拾贰圆伍角整'
* toCurrency(1) // '壹圆整'
* toCurrency(0.05) // '伍分'
* toCurrency(42.50, { formal: false }) // '四十二元五角整'
*/
declare function toCurrency(value: number | string | bigint, options?: CurrencyOptions): string;
export { toCardinal, toOrdinal, toCurrency };