Intl.Locale.prototype.caseFirst - JavaScript 编辑

The Intl.Locale.prototype.caseFirst property is an accessor property that returns whether case is taken into account for the locale's collation rules.

Description

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 Locale's caseFirst property.

There are 3 values that the caseFirst property can have, outlined in the table below.

caseFirst values

ValueDescription
upperUpper case to be sorted before lower case.
lowerLower case to be sorted before upper case.
falseNo special case ordering.

Examples

Setting the caseFirst value via the locale string

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 inital 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.

let caseFirstStr = new Intl.Locale("fr-Latn-FR-u-kf-upper");
console.log(caseFirstStr.caseFirst); // Prints "upper"

Setting the caseFirst value via the configuration object argument

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.

let caseFirstObj= new Intl.Locale("en-Latn-US", {caseFirst: "lower"});
console.log(us12hour.caseFirst); // Prints "lower"

Specifications

Specification
ECMAScript Internationalization API (ECMA-402)

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:89 次

字数:4818

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文