n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
56 lines (55 loc) • 2.21 kB
TypeScript
/**
* Portuguese (Brazil) language converter
*
* CLDR: pt-BR | Brazilian Portuguese as used in Brazil
*
* Portuguese-specific rules:
* - "e" conjunction between units, tens and hundreds: vinte e um, cento e um
* - "cem" for exact 100, "cento" for 100+ remainder
* - Irregular hundreds: duzentos, trezentos, quatrocentos, etc.
* - Short scale: milhão (10^6), bilhão (10^9), trilhão (10^12)
* - Omit "um" before "mil"
*/
export declare const cardinalMax: bigint;
export declare const ordinalMax: bigint;
export declare const currencyMax: bigint;
/**
* Converts a numeric value to Portuguese words.
* @param {number | string | bigint} value - The numeric value to convert
* @returns {string} The number in Portuguese words
*/
declare function toCardinal(value: number | string | bigint): string;
/**
* Converts a number to Portuguese ordinal words.
* @param {number | string | bigint} value - The number to convert
* @returns {string} Portuguese ordinal words
*/
declare function toOrdinal(value: number | string | bigint): string;
export type CurrencyOptions = {
/**
* - Include "e" between major and minor units
*/
and?: boolean;
/**
* - Currency code (e.g., 'BRL', 'USD'); empty means auto-detect for pt-BR
*/
currency?: string;
};
/**
* @typedef {object} CurrencyOptions
* @property {boolean} [and] - Include "e" between major and minor units
* @property {string} [currency] - Currency code (e.g., 'BRL', 'USD'); empty means auto-detect for pt-BR
*/
/** @type {Required<CurrencyOptions>} */
export declare const currencyDefaults: Required<CurrencyOptions>;
/**
* Converts a number to Brazilian Portuguese currency words.
* @param {number | string | bigint} value - The amount to convert
* @param {CurrencyOptions} [options] Currency formatting options
* @returns {string} Brazilian Portuguese currency words
* @example
* toCurrency(42.50) // 'quarenta e dois reais e cinquenta centavos'
* toCurrency(42.50, {currency: 'USD'}) // 'quarenta e dois dólares e cinquenta centavos'
*/
declare function toCurrency(value: number | string | bigint, options?: CurrencyOptions): string;
export { toCardinal, toOrdinal, toCurrency };