ListFormat
t
type tlistType
type listType = [#conjunction | #disjunction | #unit]style
type style = [#long | #narrow | #short]options
type options = {
localeMatcher?: Intl_Common.localeMatcher,
\"type"?: listType,
style?: style,
}listPartComponentType
type listPartComponentType = [#element | #literal]listPart
type listPart = {
\"type": listPartComponentType,
value: string,
}resolvedOptions
type resolvedOptions = {
locale: string,
style: style,
\"type": listType,
}supportedLocalesOptions
type supportedLocalesOptions = {
localeMatcher: Intl_Common.localeMatcher,
}make
let make: (~locales: array<string>=?, ~options: options=?) => tCreates a new Intl.ListFormat instance for formatting lists.
See Intl.ListFormat on MDN.
Examples
RESCRIPTlet formatter = Intl.ListFormat.make(~locales=["en"], ~options={\"type": #conjunction})
formatter->Intl.ListFormat.format(["apples", "bananas", "cherries"]) == "apples, bananas, and cherries"
supportedLocalesOf
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
RESCRIPTIntl.ListFormat.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]
resolvedOptions
let resolvedOptions: t => resolvedOptionsresolvedOptions(formatter) returns the actual options being used.
See Intl.ListFormat.prototype.resolvedOptions on MDN.
Examples
RESCRIPTlet formatter = Intl.ListFormat.make(~locales=["en"])
Intl.ListFormat.resolvedOptions(formatter).locale == "en"
format
let format: (t, array<string>) => stringformat(formatter, items) returns the formatted list string.
Examples
RESCRIPTlet formatter = Intl.ListFormat.make(~locales=["en"])
formatter->Intl.ListFormat.format(["a", "b"]) == "a and b"
formatToParts
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
RESCRIPTlet formatter = Intl.ListFormat.make(~locales=["en"])
formatter->Intl.ListFormat.formatToParts(["a", "b"])->Array.length > 0
ignore
let ignore: t => unitignore(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.