MENU
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:
RESETRUNFULL
RESETRUNFULL
<!DOCTYPE html><html><body><script>
localeMatcherThe locale matching algorithm to use. Possible values are "lookup" and "best fit"; the default is "best fit".
</script></body><html>
<!DOCTYPE html><html><body><script>
usageWhether the comparison is for sorting or for searching for matching strings. Possible values are "sort" and "search"; the default is "sort".
</script></body><html>
<!DOCTYPE html><html><body><script>
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".
</script></body><html>
<!DOCTYPE html><html><body><script>
ignorePunctuationWhether punctuation should be ignored. Possible values are true and false; the default is false.
</script></body><html>
<!DOCTYPE html><html><body><script>
numericWhether numeric collation should be used, such that "1" < "2" < "10". Possible values are true and false; the default is false.
</script></body><html>
<!DOCTYPE html><html><body><script>
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".
</script></body><html>
RESETRUNFULL
<!DOCTYPE html><html><body><script>
var list = [ "ä", "a", "z" ]
var l10nDE = new Intl.Collator("de")
var l10nSV = new Intl.Collator("sv")
console.log(l10nDE.compare("ä", "z")); // -1
console.log(l10nSV.compare("ä", "z")); // 1
console.log(list.sort(l10nDE.compare)); // [ "a", "ä", "z" ]
console.log(list.sort(l10nSV.compare)); // [ "a", "z", "ä" ]
console.log(new Intl.Collator('de').compare('ä', 'z')); // -1
console.log(new Intl.Collator('sv').compare('ä', 'z')); // 1
console.log(new Intl.Collator('de',
{ sensitivity: 'base' }).compare('ä', 'a')); // 0
console.log(new Intl.Collator('sv',
{ sensitivity: 'base' }).compare('ä', 'a')); // 1
console.log(new Intl.Collator('sv',
{ sensitivity: 'base' }).resolvedOptions()); // Object {locale: "sv", usage: "sort", sensitivity: "base", // ignorePunctuation: false, numeric: false…
var locales = ['ban', 'id-u-co-pinyin', 'de-ID'];
var options = { localeMatcher: 'lookup' };
console.log(Intl.Collator.supportedLocalesOf(
locales, options).join(', '));// "id-u-co-pinyin, de-ID"
</script></body><html>