Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/intl/src/format/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ export function datetime(
/**
* Creates a locale-aware date/time formatter with a fallback value.
* @param fallback - Value used when the input is `undefined` or `null`.
* @param options - `Intl.DateTimeFormat` options.
* @param options - `Intl.DateTimeFormat` options, or `{}` for the defaults.
* @returns Formatter that returns a formatted string or `undefined`.
*/
export function datetime(
fallback: Date | number | string,
options?: Intl.DateTimeFormatOptions
options: Intl.DateTimeFormatOptions
): Format<Date | number | string | undefined, string | undefined>

/**
Expand All @@ -59,9 +59,9 @@ export function datetime(
* @returns Formatter that returns a formatted string or `undefined`.
*/
export function datetime<I = Date | number | string>(
optionsOrFallback?: Intl.DateTimeFormatOptions | false | I,
maybeOptions?: Intl.DateTimeFormatOptions | false,
format?: IntlFormatFn<Intl.DateTimeFormat, I, Intl.DateTimeFormatOptions>
optionsOrFallback: Intl.DateTimeFormatOptions | false | I | undefined,
maybeOptions: Intl.DateTimeFormatOptions | false | undefined,
format: IntlFormatFn<Intl.DateTimeFormat, I, Intl.DateTimeFormatOptions>
): Format<I | undefined, string | undefined>

/* @__NO_SIDE_EFFECTS__ */
Expand Down
4 changes: 2 additions & 2 deletions packages/intl/src/format/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export function duration(
/**
* Creates a locale-aware duration formatter with a fallback value.
* @param fallback - Value used when the input is `undefined` or `null`.
* @param options - `Intl.DurationFormat` options.
* @param options - `Intl.DurationFormat` options, or `{}` for the defaults.
* @returns Formatter that returns a formatted string or `undefined`.
*/
export function duration(
fallback: Duration,
options?: Intl.DurationFormatOptions
options: Intl.DurationFormatOptions
): Format<Duration | undefined, string | undefined>

/* @__NO_SIDE_EFFECTS__ */
Expand Down
4 changes: 2 additions & 2 deletions packages/intl/src/format/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export function list(
/**
* Creates a locale-aware list formatter with a fallback value.
* @param fallback - Value used when the input is `undefined` or `null`.
* @param options - `Intl.ListFormat` options.
* @param options - `Intl.ListFormat` options, or `{}` for the defaults.
* @returns Formatter that returns a formatted string or `undefined`.
*/
export function list(
fallback: Iterable<string>,
options?: Intl.ListFormatOptions
options: Intl.ListFormatOptions
): Format<Iterable<string> | undefined, string | undefined>

/* @__NO_SIDE_EFFECTS__ */
Expand Down
10 changes: 5 additions & 5 deletions packages/intl/src/format/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export function number(
/**
* Creates a locale-aware number formatter with a fallback value.
* @param fallback - Value used when the input is `undefined` or `null`.
* @param options - `Intl.NumberFormat` options.
* @param options - `Intl.NumberFormat` options, or `{}` for the defaults.
* @returns Formatter that returns a formatted string or `undefined`.
*/
export function number(
fallback: number | bigint | string,
options?: Intl.NumberFormatOptions
options: Intl.NumberFormatOptions
): Format<number | bigint | string | undefined, string | undefined>

/**
Expand All @@ -53,9 +53,9 @@ export function number(
* @returns Formatter that returns a formatted string or `undefined`.
*/
export function number(
optionsOrFallback?: Intl.NumberFormatOptions | false | number | bigint | string,
maybeOptions?: Intl.NumberFormatOptions | false,
format?: IntlFormatFn<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions>
optionsOrFallback: Intl.NumberFormatOptions | false | number | bigint | string | undefined,
maybeOptions: Intl.NumberFormatOptions | false | undefined,
format: IntlFormatFn<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions>
): Format<number | bigint | string | undefined, string | undefined>

/* @__NO_SIDE_EFFECTS__ */
Expand Down
10 changes: 5 additions & 5 deletions packages/intl/src/format/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type {
type RangeInput<I> = readonly [from: I, to: I]

type RangeFrom<F extends IntlFormatRange<I>, I, O, R> = (
optionsOrFallback?: O | false | I,
maybeOptions?: O | false,
format?: IntlFormatFn<F, I, O>
optionsOrFallback: O | false | I | undefined,
maybeOptions: O | false | undefined,
format: IntlFormatFn<F, I, O>
) => Format<I | undefined, R | undefined>

function rangeFormat(
Expand Down Expand Up @@ -58,13 +58,13 @@ export function range<F extends IntlFormatRange<I>, I, O, R>(
* Creates a locale-aware range formatter with a fallback range.
* @param format - Formatter factory that supports a custom range formatting function.
* @param fallback - Range used when the input is `undefined` or `null`.
* @param options - Formatter options.
* @param options - Formatter options, or `{}` for the defaults.
* @returns Formatter that returns a formatted range string or `undefined`.
*/
export function range<F extends IntlFormatRange<I>, I, O, R>(
format: RangeFrom<F, I, O, R>,
fallback: RangeInput<I>,
options?: O
options: O
): Format<RangeInput<I> | undefined, string | undefined>

/* @__NO_SIDE_EFFECTS__ */
Expand Down
4 changes: 2 additions & 2 deletions packages/intl/src/format/relativetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function relativetime(
* @returns Formatter that returns a formatted string or `undefined`.
*/
export function relativetime(
options?: RelativeTimeOptions
options: RelativeTimeOptions
): Format<number | undefined, string | undefined>

/**
Expand All @@ -50,7 +50,7 @@ export function relativetime(
*/
export function relativetime(
fallback: number,
options?: RelativeTimeOptions
options: RelativeTimeOptions
): Format<number | undefined, string | undefined>

/* @__NO_SIDE_EFFECTS__ */
Expand Down
2 changes: 2 additions & 0 deletions website/src/content/docs/intl/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ This is useful for dates, numbers, and other UI values that come from app state.

Intl formats can be used inside `params(...)` for translated templates, or wrapped with `format(...)` when the value comes from runtime state, API data, or a database.

A fallback is always passed together with options, for example `number(0, {})` or `datetime(fallback, false)`: a lone argument is always read as options.

### `number(fallback?, options?)`

Formats numbers with `Intl.NumberFormat`.
Expand Down