Intl.Locale.prototype.caseFirst

Baseline 已广泛支持

此功能已成熟,并可在许多设备和浏览器版本上使用。自 2020 年 9 月起,所有浏览器均已提供此功能。

Intl.Locale 实例的 caseFirst 访问器属性返回是否在当前区域设置的排序规则中考虑了大小写。

描述

区域设置的排序规则用于确定字符串在该区域设置中的排序方式。某些区域设置在排序过程中会使用字符的大小写(大写或小写)。此附加规则可以在 Intl.Locale 对象的 caseFirst 属性中表示。caseFirst 属性有 3 种可能的值,在下表中概述。

描述
upper 大写字母排在小写字母之前。
lower 小写字母排在大写字母之前。
false 不考虑大小写排序。

caseFirst 属性的值在构造时设置,通过区域设置标识符的 kf 键,或通过 Intl.Locale() 构造函数的 caseFirst 选项。如果两者都存在,后者具有更高的优先级;如果两者都不存在,该属性的值为 undefined

caseFirst 的设置访问器为 undefined。您不能直接更改此属性。

示例

与其他区域设置子标签一样,可以通过区域设置字符串或构造函数的配置对象参数将 caseFirst 值添加到 Intl.Locale 对象中。

通过区域设置字符串添加 caseFirst 值

Unicode 区域设置字符串规范中,caseFirst 是一个“扩展子标签”。这些子标签提供有关区域设置的附加数据,并通过 -u 扩展键添加到区域设置标识符中。要将 caseFirst 值添加到传递到 Intl.Locale() 构造函数的初始区域设置标识符字符串,请先添加 -u 扩展键(如果它不存在)。然后,添加 -kf 扩展以指示您正在为 caseFirst 添加值。最后,添加 caseFirst 值。

js
const locale = new Intl.Locale("fr-Latn-FR-u-kf-upper");
console.log(locale.caseFirst); // "upper"

通过配置对象参数添加 caseFirst 值

Intl.Locale() 构造函数有一个可选的配置对象参数,其中可以包含多种扩展类型,包括 caseFirst。将配置对象的 caseFirst 属性设置为您想要的 caseFirst 值,然后将其传递到构造函数中。

js
const locale = new Intl.Locale("en-Latn-US", { caseFirst: "lower" });
console.log(locale.caseFirst); // "lower"

规范

规范
ECMAScript® 2026 国际化 API 规范
# sec-Intl.Locale.prototype.caseFirst

浏览器兼容性

另见