Collator

The declaration of a Collator has the form:

new Intl.Collator([locales[, options]])

'locales' is a locale tag conforming to the BCP47 language. The '-u' extension may be included to specify one or more Unicode extensions '-co', '-kn' or '-kf'.
-co : Variant collations for certain locales, which can be "big5han", "dict", "direct", "ducet", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan".eg. "language-region-u-co-value"
-kn : Whether numeric collation should be used, such that "1" < "2" < "10". Possible values are "true" and "false". eg.  "language-region-u-kn-true|false"
-kf : Whether upper case or lower case should sort first. Possible values are "upper", "lower", or "false" (use the locale's default). eg. "language-region-u-kf-upper|lower|false"
'options' is an object with some or all of the following properties:
localeMatcherThe locale matching algorithm to use. Possible values are "lookup" and "best fit"; the default is "best fit".

usageWhether the comparison is for sorting or for searching for matching strings. Possible values are "sort" and "search"; the default is "sort".

sensitivityWhich differences in the strings should lead to non-zero result values. Possible values are:"base": Only strings that differ in base letters compare as unequal. Examples: a ≠ b, a = á, a = A."accent": Only strings that differ in base letters or accents and other diacritic marks compare as unequal. Examples: a ≠ b, a ≠ á, a = A."case": Only strings that differ in base letters or case compare as unequal. Examples: a ≠ b, a = á, a ≠ A."variant": Strings that differ in base letters, accents and other diacritic marks, or case compare as unequal. Other differences may also be taken into consideration. Examples: a ≠ b, a ≠ á, a ≠ A.The default is "variant" for usage "sort"; it's locale-dependent for usage "search".

ignorePunctuationWhether punctuation should be ignored. Possible values are true and false; the default is false.

numericWhether numeric collation should be used, such that "1" < "2" < "10". Possible values are true and false; the default is false.

caseFirstWhether upper case or lower case should sort first. Possible values are "upper", "lower", or "false" (use the locale's default); the default is "false".


var list = ["ä", "a", "z"];
var l10nDE = new Intl.Collator("de");
var l10nSV = new Intl.Collator("sv");

console.log(l10nDE.compare("ä", "z"));
console.log(l10nSV.compare("ä", "z"));
console.log(list.sort(l10nDE.compare));
console.log(list.sort(l10nSV.compare));

console.log(new Intl.Collator('de').compare('ä', 'z'));
console.log(new Intl.Collator('sv').compare('ä', 'z'));

console.log(new Intl.Collator('de', { sensitivity: 'base' }).compare('ä', 'a'));
console.log(new Intl.Collator('sv', { sensitivity: 'base' }).compare('ä', 'a'));

console.log(new Intl.Collator('sv', { sensitivity: 'base' }).resolvedOptions());

var locales = ['ban', 'id-u-co-pinyin', 'de-ID'];
var options = { localeMatcher: 'lookup' };

console.log(Intl.Collator.supportedLocalesOf(locales, options).join(', '));

-1 1 [ "a", "ä", "z" ] [ "a", "z", "ä" ] -1 1 0 1 Object {locale: "sv", usage: "sort", sensitivity: "base", ignorePunctuation: false, numeric: false… "id-u-co-pinyin, de-ID"