Skip to content

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:

TypeDefault Formatter
number, bigint, NumberDecimal formatter
DateDate formatter
ArrayList formatter, applies autoFormat to each entry
LocalizableReturned as-is
undefined, nullEmpty value
string, booleanStringification formatter
OtherStringification 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: