JavaScripture
Contribute via GitHub Feedback

Collator : Object

Collator provides language aware comparison of Strings for sorting and searching. Available through Intl.Collator.

Collator([locales : Array<String>, [options : Object]]) : Collator

Constructors

new Collator([locales : Array<String>, [options : Object]]) : Collator
options : {
caseFirst :Boolean
ignorePunctuation :Boolean
localeMatcher :StringOne of 'basic' or 'best fit'.
numeric :Boolean
sensitivity :StringOne of 'base', 'accent', 'case', or 'variant'.
usage :StringOne of 'sort' or 'search'
}

Example:

Run

Results:

 

Instance Methods

compare(value1 : String, value2 : String) : Number

Compares two string values to determine which should come first if they were sorted alphabetically according to the locales of the Collator. Returns 0 if value1 is the same as value2, a negative value if value1 should come before value2, and a positive value if value1 should come after value2. Can be passed to Array.sort() to sort a list of strings.

Example:

Run

Results:

 

resolvedOptions() : Object
return : {
caseFirst :Boolean
collation :String
ignorePunctuation :Boolean
locale :String
numeric :Boolean
sensitivity :String
usage :String
}

Example:

Run

Results:

 

Collator Methods

supportedLocalesOf(locales : Array<String>, [options : Object]) : Array<String>
options : {
localeMatcher :StringOne of 'basic' or 'best fit'.
}

Example:

Run

Results: