@react-input/number-format
Version:
React input component for formatted number input with locale-specific.
26 lines (25 loc) • 1.39 kB
TypeScript
import type { NumberFormatOptions } from './types';
/**
* Formats the value using the specified locales and options (see "[Utils](https://github.com/GoncharukOrg/react-input/tree/main/packages/number-format#format)").
*
* The result is exactly the same as the value received from the input.
* Useful when you want to get a formatted value without raising an input event.
*
* Since `InputNumberFormat` works exactly like the `input` element, `InputNumberFormat`
* will not change the value outside of an input event, so you may end up in a situation
* where the `input` element has a value that does not match the format, such as when
* initializing a value received from the backend.
*
* `format(123456.78, 'en-IN', { format: "currency", currency: "USD" })` → "$1,23,456.78"
*/
export declare function format(value: number | bigint | string, { locales, ...options }?: NumberFormatOptions & {
locales?: Intl.LocalesArgument;
}): string;
/**
* Unformats the value using the specified locales (see «[Utils](https://github.com/GoncharukOrg/react-input/tree/main/packages/number-format#unformat)»).
*
* Returns a string as the numeric equivalent of the formatted value. Essentially does the opposite of the `format` utility.
*
* `unformat('$1,23,456.78', 'en-IN')` → "123456.78"
*/
export declare function unformat(value: string, locales?: Intl.LocalesArgument): string;