The caseFirst
accessor property of Intl.Locale
instances returns whether case is taken into account for this locale's collation rules.
The caseFirst
accessor property of Intl.Locale
instances returns whether case is taken into account for this locale's collation rules.
A locale's collation rules are used to determine how strings are ordered in that locale. Certain locales use a character's case (UPPERCASE or lowercase) in the collation process. This additional rule can be expressed in a Intl.Locale
object's caseFirst
property.
There are 3 values that the caseFirst
property can have, outlined in the table below.
caseFirst
valuesValue | Description |
---|---|
upper | Upper case to be sorted before lower case. |
lower | Lower case to be sorted before upper case. |
false | No special case ordering. |
In the Unicode locale string spec, the values that caseFirst
represents correspond to the key kf
. kf
is treated as a locale string "extension subtag". These subtags add additional data about the locale, and are added to locale identifiers by using the -u
extension key. Thus, the caseFirst
value can be added to the initial locale identifier string that is passed into the Locale
constructor. To add the caseFirst
value, first add the -u
extension key to the string. Next, add the -kf
extension key to indicate that you are adding a value for caseFirst
. Finally, add the caseFirst
value to the string.
const locale = new Intl.Locale("fr-Latn-FR-u-kf-upper"); console.log(locale.caseFirst); // Prints "upper"
The Intl.Locale()
constructor has an optional configuration object argument, which can be used to pass extension types. Set the caseFirst
property of the configuration object to your desired caseFirst
value, and then pass it into the constructor.
const locale = new Intl.Locale("en-Latn-US", { caseFirst: "lower" }); console.log(locale.caseFirst); // Prints "lower"
Specification |
---|
ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.caseFirst |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
caseFirst |
74 | 79 | 75 | 62 | 14 | 74 | 79 | 53 | 14 | 11.0 | 74 | 1.8 | 12.0.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst