UNPKG

extenso

Version:

Uma biblioteca avançada para escrever números por extenso (em português).

27 lines (26 loc) 1.83 kB
import type { ExtensoOptions } from './types'; export type { BuiltInCurrencyOptions, CurrencyCode, CurrencyDefinition, CurrencyOptions, DecimalSeparator, ExtensoGender, ExtensoLocale, ExtensoMode, ExtensoOptions, ExtensoScale, NumberOptions, } from './types'; /** * Converts a number to its written form in Portuguese * @param input - The number to convert (can be string, number, or bigint) * @param options - Configuration options for the conversion * @param options.mode - The conversion mode (ABBREVIATED, CURRENCY, DIGIT, or NUMBER) * @param options.decimalSeparator - The decimal separator to use (POINT or COMMA) * @param options.locale - The locale to use for the output (BR or PT) * @param options.scale - The number scale to use (SHORT or LONG) * @param options.removeAccents - Whether to remove accents from the output * @param options.currency - Currency configuration when mode is CURRENCY * @param options.number - Number configuration when mode is NUMBER * @param options.number.ordinal - Whether to write an integer as an ordinal * @returns The written form of the number in Portuguese * @throws {TypeError} If input is not a string, number, or bigint * @throws {Error} If the number format is invalid * @throws {Error} If the number exceeds scale limits * @throws {Error} If an invalid currency code is provided * @example * extenso(1234.56) // "mil duzentos e trinta e quatro vírgula cinquenta e seis" * extenso(1234.56, { mode: Modes.CURRENCY, currency: { code: Currencies.BRL } }) // "mil duzentos e trinta e quatro reais e cinquenta e seis centavos" * extenso("R$ 1234.56", { mode: Modes.CURRENCY }) // "mil duzentos e trinta e quatro reais e cinquenta e seis centavos" */ declare const extenso: (input: number | string | bigint, options?: ExtensoOptions) => string; export default extenso;