n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
80 lines (79 loc) • 3.27 kB
TypeScript
/**
* Italian (Italy) language converter
*
* CLDR: it-IT | Italian as used in Italy
*
* Italian-specific rules:
* - Concatenation without spaces within segments ("ventotto" not "venti otto")
* - Phonetic vowel elision: "venti" + "otto" → "ventotto"
* - Accent on final "tre" in compounds: "ventitré"
* - mille/mila alternation for thousands
* - Scale words: milione/milioni, miliardo/miliardi, etc.
* - "e" connector before simple final remainder
*/
export declare const cardinalMax: bigint;
export declare const ordinalMax: bigint;
export declare const currencyMax: bigint;
/**
* Converts a numeric value to Italian 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 Italian words
* @throws {TypeError} If value is not a valid numeric type
* @throws {Error} If value is not a valid number format
* @example
* toCardinal(28) // 'ventotto'
* toCardinal(23) // 'ventitré'
* toCardinal(1000) // 'mille'
* toCardinal(2000) // 'duemila'
* toCardinal(1000000) // 'un milione'
*/
declare function toCardinal(value: number | string | bigint): string;
/**
* Converts a numeric value to Italian ordinal words.
*
* Italian ordinals: primo, secondo, terzo... (1-10 irregular)
* For 11+: cardinal word (drop final vowel) + -esimo
* @param {number | string | bigint} value - The numeric value to convert (positive integer)
* @returns {string} The number as ordinal words (masculine form)
* @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) // 'primo'
* toOrdinal(2) // 'secondo'
* toOrdinal(11) // 'undicesimo'
* toOrdinal(21) // 'ventunesimo'
* toOrdinal(100) // 'centesimo'
* toOrdinal(1000) // 'millesimo'
*/
declare function toOrdinal(value: number | string | bigint): string;
export type CurrencyOptions = {
/**
* - Use "e" between euros and centesimi
*/
and?: boolean;
};
/**
* @typedef {object} CurrencyOptions
* @property {boolean} [and] - Use "e" between euros and centesimi
*/
/** @type {Required<CurrencyOptions>} */
export declare const currencyDefaults: Required<CurrencyOptions>;
/**
* Converts a numeric value to Italian currency words (Euro).
* @param {number | string | bigint} value - The currency amount to convert
* @param {CurrencyOptions} [options] - Optional configuration
* @returns {string} The amount in Italian 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) // 'quarantadue euro e cinquanta centesimi'
* toCurrency(1) // 'un euro'
* toCurrency(0.99) // 'novantanove centesimi'
* toCurrency(0.01) // 'un centesimo'
* toCurrency(42.50, { and: false }) // 'quarantadue euro cinquanta centesimi'
*/
declare function toCurrency(value: number | string | bigint, options?: CurrencyOptions): string;
export { toCardinal, toOrdinal, toCurrency };