n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
65 lines (64 loc) • 2.44 kB
TypeScript
/**
* Portuguese (Portugal) language converter
*
* CLDR: pt-PT | European Portuguese as used in Portugal
*
* Portuguese-specific rules:
* - "e" conjunction everywhere: vinte e um, cento e um, mil e um
* - "cem" for exact 100, "cento" for 100+ remainder
* - Irregular hundreds: duzentos, trezentos, quatrocentos, etc.
* - Long scale: milhão (10^6), mil milhões (10^9), biliã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.
*
* 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 Portuguese words
* @throws {TypeError} If value is not a valid numeric type
* @throws {Error} If value is not a valid number format
* @example
* toCardinal(21) // 'vinte e um'
* toCardinal(100) // 'cem'
* toCardinal(1000000) // 'um milhão'
*/
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
* @example
* toOrdinal(1) // 'primeiro'
* toOrdinal(21) // 'vigésimo primeiro'
* toOrdinal(100) // 'centésimo'
*/
declare function toOrdinal(value: number | string | bigint): string;
export type CurrencyOptions = {
/**
* - Include "e" between euros and cents
*/
and?: boolean;
};
/**
* @typedef {object} CurrencyOptions
* @property {boolean} [and] - Include "e" between euros and cents
*/
/** @type {Required<CurrencyOptions>} */
export declare const currencyDefaults: Required<CurrencyOptions>;
/**
* Converts a number to Portuguese currency words (Euro).
* @param {number | string | bigint} value - The amount to convert
* @param {CurrencyOptions} [options] Currency formatting options
* @returns {string} Portuguese currency words
* @example
* toCurrency(42.50) // 'quarenta e dois euros e cinquenta cêntimos'
* toCurrency(1) // 'um euro'
* toCurrency(0.01) // 'um cêntimo'
*/
declare function toCurrency(value: number | string | bigint, options?: CurrencyOptions): string;
export { toCardinal, toOrdinal, toCurrency };