Collator
t
type tusage
type usage = [#search | #sort]sensitivity
type sensitivity = [#accent | #base | #case | #variant]caseFirst
type caseFirst = [#"false" | #lower | #upper]options
type options = {
localeMatcher?: Intl_Common.localeMatcher,
usage?: usage,
sensitivity?: sensitivity,
ignorePunctuation?: bool,
numeric?: bool,
caseFirst?: caseFirst,
}resolvedOptions
type resolvedOptions = {
locale: string,
usage: usage,
sensitivity: sensitivity,
ignorePunctuation: bool,
collation: [
| #compat
| #default
| #dict
| #emoji
| #eor
| #phonebk
| #phonetic
| #pinyin
| #stroke
| #trad
| #unihan
| #zhuyin
],
numeric?: bool,
caseFirst?: caseFirst,
}supportedLocalesOptions
type supportedLocalesOptions = {
localeMatcher: Intl_Common.localeMatcher,
}make
let make: (~locales: array<string>=?, ~options: options=?) => tCreates a new Intl.Collator instance that can compare strings using locale-aware rules.
See Intl.Collator on MDN.
Examples
RESCRIPTlet collator = Intl.Collator.make(~locales=["en"])
collator->Intl.Collator.compare("apple", "banana") < 0
supportedLocalesOf
let supportedLocalesOf: (
array<string>,
~options: supportedLocalesOptions=?,
) => array<string>supportedLocalesOf(locales, ~options) filters locales to those supported by the runtime for collation.
See Intl.Collator.supportedLocalesOf on MDN.
Examples
RESCRIPTIntl.Collator.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]
resolvedOptions
let resolvedOptions: t => resolvedOptionsresolvedOptions(collator) returns the locale and collation settings in use.
See Intl.Collator.prototype.resolvedOptions on MDN.
Examples
RESCRIPTlet collator = Intl.Collator.make(~locales=["en-US"])
Intl.Collator.resolvedOptions(collator).locale == "en-US"
compare
let compare: (t, string, string) => intcompare(collator, a, b) compares two strings using the rules of collator. Returns a negative number when a comes before b, 0 when equal, and a positive number otherwise.
Examples
RESCRIPTlet collator = Intl.Collator.make(~locales=["en-US"])
collator->Intl.Collator.compare("apple", "banana") < 0
ignore
let ignore: t => unitignore(collator) ignores the provided collator 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.