ListFormat

format

RESCRIPT
let format: (t, array<string>) => string

format(formatter, items) returns the formatted list string.

Examples

RESCRIPT
let formatter = Intl.ListFormat.make(~locales=["en"]) formatter->Intl.ListFormat.format(["a", "b"]) == "a and b"

formatToParts

RESCRIPT
let formatToParts: (t, array<string>) => array<listPart>

formatToParts(formatter, items) returns the list as an array of parts describing how it would be rendered.

See Intl.ListFormat.prototype.formatToParts on MDN.

Examples

RESCRIPT
let formatter = Intl.ListFormat.make(~locales=["en"]) formatter->Intl.ListFormat.formatToParts(["a", "b"])->Array.length > 0

ignore

RESCRIPT
let ignore: t => unit

ignore(listFormat) ignores the provided listFormat and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.

listPart

RESCRIPT
type listPart = { \"type": listPartComponentType, value: string, }

listPartComponentType

RESCRIPT
type listPartComponentType = [#element | #literal]

listType

RESCRIPT
type listType = [#conjunction | #disjunction | #unit]

make

RESCRIPT
let make: (~locales: array<string>=?, ~options: options=?) => t

Creates a new Intl.ListFormat instance for formatting lists.

See Intl.ListFormat on MDN.

Examples

RESCRIPT
let formatter = Intl.ListFormat.make(~locales=["en"], ~options={\"type": #conjunction}) formatter->Intl.ListFormat.format(["apples", "bananas", "cherries"]) == "apples, bananas, and cherries"

options

RESCRIPT
type options = { localeMatcher?: Intl_Common.localeMatcher, \"type"?: listType, style?: style, }

resolvedOptions

RESCRIPT
type resolvedOptions = { locale: string, style: style, \"type": listType, }

resolvedOptions

RESCRIPT
let resolvedOptions: t => resolvedOptions

resolvedOptions(formatter) returns the actual options being used.

See Intl.ListFormat.prototype.resolvedOptions on MDN.

Examples

RESCRIPT
let formatter = Intl.ListFormat.make(~locales=["en"]) Intl.ListFormat.resolvedOptions(formatter).locale == "en"

style

RESCRIPT
type style = [#long | #narrow | #short]

supportedLocalesOf

RESCRIPT
let supportedLocalesOf: ( array<string>, ~options: supportedLocalesOptions=?, ) => array<string>

supportedLocalesOf(locales, ~options) filters locales to those supported for list formatting.

See Intl.ListFormat.supportedLocalesOf on MDN.

Examples

RESCRIPT
Intl.ListFormat.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]

supportedLocalesOptions

RESCRIPT
type supportedLocalesOptions = { localeMatcher: Intl_Common.localeMatcher, }

t

RESCRIPT
type t