Automatic formatting @localizer/format 1.0.1
autoFormat (
value
: any )
value
- The value to format. Can be any JavaScript value.
This formatter transforms any value into a locale-aware Localizable
by leveraging preconfigured formatters. By default, it applies the following formatter based on the value's type:
Type | Default Formatter |
---|---|
number , bigint , Number | Decimal formatter |
Date | Date formatter |
Array | List formatter, applies autoFormat to each entry |
Localizable | Returned as-is |
undefined , null | Empty value |
string , boolean | Stringification formatter |
Other | Stringification formatter |
You can customize the behavior of autoFormat
by configuring the DefaultFormatters
settings. This allows you to specify which formatters should be applied to different value types.
typescript
configure(
{ DefaultFormatters },
{
DefaultFormatters: {
number: decimal,
date: date,
array: list,
boolean: stringify,
string: stringify,
default: stringify,
},
},
);
WARNING
Use autoFormat
carefully. It handles various value types but lacks strict type safety and customization options.
Examples: