n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
78 lines (77 loc) • 3.23 kB
TypeScript
/**
* German (Germany) language converter
*
* CLDR: de-DE | German as used in Germany
*
* Key features:
* - Inverted tens-ones order: "einundzwanzig" (one-and-twenty) for 21-99
* - Compound words without spaces below million level
* - Three forms of 1: "eins" (standalone), "ein" (before hundert/tausend), "eine" (before Million+)
* - Scale pluralization: Million → Millionen, Milliarde → Milliarden
* - Spaces only around million+ scale words
* - BigInt modulo for efficient segment extraction
*/
export declare const cardinalMax: bigint;
export declare const ordinalMax: bigint;
export declare const currencyMax: bigint;
/**
* Converts a numeric value to German 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 German words
* @throws {TypeError} If value is not a valid numeric type
* @throws {Error} If value is not a valid number format
* @example
* toCardinal(21) // 'einundzwanzig'
* toCardinal(1000) // 'eintausend'
* toCardinal(1000000) // 'eine Million'
*/
declare function toCardinal(value: number | string | bigint): string;
/**
* Converts a numeric value to German ordinal words.
*
* German ordinals add -te for 1-19 and -ste for 20+.
* Irregular forms: erste (1st), dritte (3rd), siebte (7th), achte (8th).
* @param {number | string | bigint} value - The numeric value to convert (positive integer)
* @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) // 'erste'
* toOrdinal(2) // 'zweite'
* toOrdinal(3) // 'dritte'
* toOrdinal(21) // 'einundzwanzigste'
* toOrdinal(100) // 'einhundertste'
* toOrdinal(1000) // 'eintausendste'
*/
declare function toOrdinal(value: number | string | bigint): string;
export type CurrencyOptions = {
/**
* - Use "und" between euros and cents
*/
and?: boolean;
};
/**
* @typedef {object} CurrencyOptions
* @property {boolean} [and] - Use "und" between euros and cents
*/
/** @type {Required<CurrencyOptions>} */
export declare const currencyDefaults: Required<CurrencyOptions>;
/**
* Converts a numeric value to German currency words (Euro).
* @param {number | string | bigint} value - The currency amount to convert
* @param {CurrencyOptions} [options] - Optional configuration
* @returns {string} The amount in German 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) // 'zweiundvierzig Euro und fünfzig Cent'
* toCurrency(1) // 'ein Euro'
* toCurrency(0.99) // 'neunundneunzig Cent'
* toCurrency(0.01) // 'ein Cent'
* toCurrency(42.50, { and: false }) // 'zweiundvierzig Euro fünfzig Cent'
*/
declare function toCurrency(value: number | string | bigint, options?: CurrencyOptions): string;
export { toCardinal, toOrdinal, toCurrency };