# @salmonui/core/format API reference

> 18 exported symbols of @salmonui/core/format: 9 functions, 5 interfaces and 4 types.

Canonical: https://salmonui.dev/docs/reference/core/format

```ts
import { … } from '@salmonui/core/format';
```

## Functions

### createFormatter

Kind: function

Page: https://salmonui.dev/docs/reference/core/format/createFormatter

```ts
function createFormatter(options?: FormatterOptions): Formatter;
```

A formatter for one locale; compiled formats and `Intl` objects are cached on the instance.

### createValueFormatter

Kind: function

Page: https://salmonui.dev/docs/reference/core/format/createValueFormatter

```ts
function createValueFormatter(descriptor: FormatDescriptor | null, type: ColumnType, env: FormatEnvironment): (value: unknown) => string;
```

Builds the value → display string function for a column.

### describeFormat

Kind: function

Page: https://salmonui.dev/docs/reference/core/format/describeFormat

```ts
function describeFormat(format: string | FormatOptions | undefined, type: ColumnType, warn: Warn, columnId: string): FormatDescriptor | null;
```

Normalizes `column.format` for a column of the given type. Returns null for no format.

### formatValue

Kind: function

Page: https://salmonui.dev/docs/reference/core/format/formatValue

```ts
function formatValue(value: unknown, format?: string | FormatOptions, options?: FormatterOptions & {
    readonly type?: ColumnType;
}): string;
```

Formats a value like a column format would (template helper). Formatters are shared per (locale, currency, time zone).

### getCollator

Kind: function

Page: https://salmonui.dev/docs/reference/core/format/getCollator

```ts
function getCollator(env: FormatEnvironment): Intl.Collator;
```

Locale-aware comparer used as the default `sortComparer` for string columns.

### isRtlLocale

Kind: function

Page: https://salmonui.dev/docs/reference/core/format/isRtlLocale

```ts
function isRtlLocale(locale: string): boolean;
```

True for right-to-left locales (`ar`, `he-IL`, `fa`, `ur-PK`, `az-Arab`, ...). Invalid locales are LTR.

### parseNumber

Kind: function

Page: https://salmonui.dev/docs/reference/core/format/parseNumber

```ts
function parseNumber(text: string, options?: ParseNumberOptions): number | null;
```

Parses localized number text: `'1.234,5'` in `de-DE` is `1234.5`. Accepts
the locale's digits, group, decimal and minus symbols (and ASCII `-`, and
`.` when it is not the group symbol), currency and percent signs, and
parentheses for accounting negatives. Returns `null` for empty text and
`NaN` when the text is not a number.

### skeletonToOptions

Kind: function

Page: https://salmonui.dev/docs/reference/core/format/skeletonToOptions

```ts
function skeletonToOptions(skeleton: string): Intl.DateTimeFormatOptions;
```

Converts a CLDR skeleton (`yMMMd`, `Hm`, `EEEE`) into `Intl.DateTimeFormat` options.

### toDate

Kind: function

Page: https://salmonui.dev/docs/reference/core/format/toDate

```ts
function toDate(value: unknown): Date | null;
```

## Interfaces

### FormatEnvironment

Kind: interface

Page: https://salmonui.dev/docs/reference/core/format/FormatEnvironment

```ts
interface FormatEnvironment {
    getLocale(): string;
    readonly timeZone: string | undefined;
    readonly currency: string;
    readonly cache: Map<string, Intl.NumberFormat | Intl.DateTimeFormat | Intl.Collator>;
    readonly warn: Warn;
}
```

Value formatting backed by the platform `Intl` API. Formatter instances are
created once per (locale, options) pair and cached per engine.

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `getLocale` | `getLocale(): string;` |  |  |
| `timeZone` | `readonly timeZone: string \| undefined;` |  |  |
| `currency` | `readonly currency: string;` |  |  |
| `cache` | `readonly cache: Map<string, Intl.NumberFormat \| Intl.DateTimeFormat \| Intl.Collator>;` |  |  |
| `warn` | `readonly warn: Warn;` |  |  |

### FormatOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/core/format/FormatOptions

```ts
interface FormatOptions {
    readonly type?: 'number' | 'date' | 'datetime';
    readonly format?: string;
    readonly skeleton?: string;
    readonly currency?: string;
    readonly minimumFractionDigits?: number;
    readonly maximumFractionDigits?: number;
    readonly useGrouping?: boolean;
    readonly timeZone?: string;
}
```

Number presets (`N2`, `C`, `P1`), custom number patterns (`#,##0.00`), date skeletons (`yMMMd`, `short`), or custom date patterns (`dd/MM/yyyy HH:mm`).

Members (8):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `type` | `readonly type?: 'number' \| 'date' \| 'datetime';` | optional |  |
| `format` | `readonly format?: string;` | optional | Preset or custom pattern. |
| `skeleton` | `readonly skeleton?: string;` | optional | Date skeleton such as `yMd`, `yMMMEd`, `Hm`, or a style: `short` \| `medium` \| `long` \| `full`. |
| `currency` | `readonly currency?: string;` | optional | ISO 4217 code for currency formats. Defaults to the grid `currency` option. |
| `minimumFractionDigits` | `readonly minimumFractionDigits?: number;` | optional |  |
| `maximumFractionDigits` | `readonly maximumFractionDigits?: number;` | optional |  |
| `useGrouping` | `readonly useGrouping?: boolean;` | optional |  |
| `timeZone` | `readonly timeZone?: string;` | optional | IANA time zone. Defaults to the grid `timeZone` option. Set it for deterministic SSR output. |

### Formatter

Kind: interface

Page: https://salmonui.dev/docs/reference/core/format/Formatter

```ts
interface Formatter {
    readonly locale: string;
    readonly currency: string;
    readonly timeZone: string | undefined;
    format(value: unknown, format?: string | FormatOptions, type?: ColumnType): string;
    number(value: unknown, format?: string | FormatOptions): string;
    date(value: unknown, format?: string | FormatOptions): string;
    dateTime(value: unknown, format?: string | FormatOptions): string;
    money(value: unknown, fractionDigits?: number, currency?: string): string;
    percent(value: unknown, fractionDigits?: number): string;
}
```

Members (9):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `locale` | `readonly locale: string;` |  |  |
| `currency` | `readonly currency: string;` |  |  |
| `timeZone` | `readonly timeZone: string \| undefined;` |  |  |
| `format` | `format(value: unknown, format?: string \| FormatOptions, type?: ColumnType): string;` |  | Formats like a column `format`: number presets (`N2`, `C`, `P1`), number patterns (`#,##0.00`), date skeletons (`yMMMd`) and styles (`short`), date patterns (`dd/MM/yyyy HH:mm`), or `FormatOptions`. `type` defaults to `date` for `Date` values and `number` for numbers. |
| `number` | `number(value: unknown, format?: string \| FormatOptions): string;` |  |  |
| `date` | `date(value: unknown, format?: string \| FormatOptions): string;` |  |  |
| `dateTime` | `dateTime(value: unknown, format?: string \| FormatOptions): string;` |  |  |
| `money` | `money(value: unknown, fractionDigits?: number, currency?: string): string;` |  |  |
| `percent` | `percent(value: unknown, fractionDigits?: number): string;` |  |  |

### FormatterOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/core/format/FormatterOptions

```ts
interface FormatterOptions {
    readonly locale?: string;
    readonly currency?: string;
    readonly timeZone?: string;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `locale` | `readonly locale?: string;` | optional | BCP 47 locale. Default `en-US`. |
| `currency` | `readonly currency?: string;` | optional | ISO 4217 code for currency formats. Default `USD`. |
| `timeZone` | `readonly timeZone?: string;` | optional | IANA time zone for dates. Default: the runtime zone (set it for deterministic SSR output). |

### ParseNumberOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/core/format/ParseNumberOptions

```ts
interface ParseNumberOptions {
    readonly locale?: string | undefined;
    readonly formatOptions?: Intl.NumberFormatOptions | undefined;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `locale` | `readonly locale?: string \| undefined;` | optional | BCP 47 locale. Default `en-US`. |
| `formatOptions` | `readonly formatOptions?: Intl.NumberFormatOptions \| undefined;` | optional | The options the text was formatted with (percent formats divide by 100). |

## Types

### ColumnType

Kind: type

Page: https://salmonui.dev/docs/reference/core/format/ColumnType

```ts
type ColumnType = 'string' | 'number' | 'boolean' | 'date' | 'datetime' | 'selection' | 'rowNumber';
```

`selection`: the row selection checkbox column; `rowNumber`: the 1-based row number column (no value, rendered from the row position).

### FormatDescriptor

Kind: type

Page: https://salmonui.dev/docs/reference/core/format/FormatDescriptor

```ts
type FormatDescriptor = {
    readonly kind: 'number';
    readonly style: 'decimal' | 'currency' | 'percent';
    readonly pattern: string | null;
    readonly options: FormatOptions;
} | {
    readonly kind: 'date';
    readonly skeleton: string | null;
    readonly pattern: string | null;
    readonly options: FormatOptions;
};
```

Normalized `column.format`.

### LocaleMessage

Kind: type

Page: https://salmonui.dev/docs/reference/core/format/LocaleMessage

```ts
type LocaleMessage = string | {
    readonly zero?: string;
    readonly one?: string;
    readonly two?: string;
    readonly few?: string;
    readonly many?: string;
    readonly other: string;
};
```

A message: a `{param}` template, or plural forms chosen by `Intl.PluralRules` for `count` (`other` is required).

### Warn

Kind: type

Page: https://salmonui.dev/docs/reference/core/format/Warn

```ts
type Warn = (code: string, message: string) => void;
```

Development warning sink: `(code, message)`.
