/** * The options for the `useNumberFormatter` hook. */ export interface UseNumberFormatterOptions { /** * The numeric value to be formatted. */ value?: number | string | null | undefined; /** * Locale to be used in formatting. */ locale?: string; /** * The locale matching algorithm to use. Possible values are 'lookup' and 'best fit'. * @default 'best fit' */ localeMatcher?: 'lookup' | 'best fit'; /** * Defines the behavior of the component. * @default 'decimal' */ mode?: 'decimal' | 'currency'; /** * The currency to use in currency formatting (ISO 4217 currency codes). */ currency?: string; /** * How to display the currency in currency formatting. */ currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name'; /** * Whether to use grouping separators, such as thousands separators. * @default true */ useGrouping?: boolean; /** * The minimum number of fraction digits to use. */ minFractionDigits?: number; /** * The maximum number of fraction digits to use. */ maxFractionDigits?: number; /** * How decimals should be rounded. */ roundingMode?: 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfCeil' | 'halfFloor' | 'halfExpand' | 'halfTrunc' | 'halfEven'; /** * Text to display before the value. */ prefix?: string; /** * Text to display after the value. */ suffix?: string; /** * Minimum boundary value (used to determine if minus sign is allowed). */ min?: number; /** * Whether to format the value. * @default true */ format?: boolean; } /** * The exposes for the `useNumberFormatter` hook. */ export interface UseNumberFormatterExposes { /** * The formatted value based on the provided value and options. */ formattedValue: string; /** * Formats a numeric value to a localized string. * @param value - The value to format * @returns The formatted string */ formatValue: (value: number | string | null | undefined) => string; /** * Parses a formatted string back to a numeric value. * @param text - The text to parse * @returns The parsed number, '-' for minus sign only, or null if invalid */ parseValue: (text: string) => number | string | null; /** * Adds two numbers with floating-point precision handling. * @param base - The base number * @param increment - The increment to add * @returns The sum with proper precision */ addWithPrecision: (base: number, increment: number) => number; /** * Checks if the mode is decimal. * @returns True if mode is 'decimal' */ isDecimalMode: () => boolean; /** * Checks if a character is a numeral character (digit, decimal, group separator, or minus sign). * @param char - The character to check * @returns True if the character is a numeral character */ isNumeralChar: (char: string) => boolean; /** * Checks if a character is a minus sign. * @param char - The character to check * @returns True if the character is a minus sign */ isMinusSign: (char: string) => boolean; /** * Checks if a character is a decimal sign. * @param char - The character to check * @returns True if the character is a decimal sign */ isDecimalSign: (char: string) => boolean; /** * Checks if minus sign is allowed based on min value. * @returns True if minus sign is allowed */ allowMinusSign: () => boolean; /** * Gets the decimal character indexes in a value string. * @param val - The value string to analyze * @returns Object with decimalCharIndex and decimalCharIndexWithoutPrefix */ getDecimalCharIndexes: (val: string) => { decimalCharIndex: number; decimalCharIndexWithoutPrefix: number; }; /** * Gets various character indexes (decimal, minus, suffix, currency) in a value string. * @param val - The value string to analyze * @returns Object with character indexes */ getCharIndexes: (val: string) => { decimalCharIndex: number; minusCharIndex: number; suffixCharIndex: number; currencyCharIndex: number; }; /** * Gets the length of decimal part in a formatted value. * @param value - The formatted value string * @returns The decimal length */ getDecimalLength: (value: string) => number; /** * Concatenates two value strings, handling decimal positions. * @param val1 - The first value * @param val2 - The second value * @returns The concatenated result */ concatValues: (val1: string, val2: string) => string; /** * The group character used for thousands separator. */ groupChar: string | null; /** * The prefix character/string. */ prefixChar: string | null; /** * The suffix character/string. */ suffixChar: string | null; /** * The resolved Intl.NumberFormat options. */ resolvedOptions: () => Intl.ResolvedNumberFormatOptions | undefined; /** * Reinitializes the parser (call when options change). */ constructParser: () => void; } /** * useNumberFormatter hook is used to format and parse numbers using Intl.NumberFormat. * * @param {UseNumberFormatterOptions} options - The options for the number formatter. * @returns {UseNumberFormatterExposes} - The exposed methods for the number formatter. * * @example * ```tsx * const formatter = useNumberFormatter({ * value: 1234.56, * locale: 'en-US', * mode: 'currency', * currency: 'USD' * }); * * const formatted = formatter.formatValue(1234.56); // "$1,234.56" * const parsed = formatter.parseValue("$1,234.56"); // 1234.56 * ``` */ export declare function useNumberFormatter(options?: UseNumberFormatterOptions): UseNumberFormatterExposes;