# @formatjs/intl-supportedvaluesof 中文文档

规范地址：https://npmcn.com/package/%40formatjs/intl-supportedvaluesof/

版本：3\.0\.1
npm 元数据更新时间：2026-11-08T22:17:30.779Z
中文译文更新时间：2026-11-15T08:31:57.550Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40formatjs/intl-supportedvaluesof
原文对照：https://npmcn.com/package/%40formatjs/intl-supportedvaluesof/?lang=original
项目主页：https://github.com/formatjs/formatjs#readme
源码仓库：https://github.com/formatjs/formatjs

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：410 kB，16 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2026-01-15T15:55:14.557Z
- 最新版本发布：2026-11-08T22:17:30.493Z
- 近 30 天下载量：3197270（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 20 个）

## 中文简介

内置支持的多填充值

## 安装

```sh
npm install @formatjs/intl-supportedvaluesof
```

也可以使用：`pnpm add @formatjs/intl-supportedvaluesof`、`yarn add @formatjs/intl-supportedvaluesof`、`bun add @formatjs/intl-supportedvaluesof`

## README

# @formatjs/intl-支持值f

多元填充 [`Intl.supportedValuesOf()`](https://tc39.es/ecma402/#sec-intl.supportedvaluesof)

[![npm Version](https://img.shields.io/npm/v/@formatjs/intl-supportedvaluesof.svg?style=flat-square)](https://www.npmjs.org/package/@formatjs/intl-supportedvaluesof)

## ECMA-402 光谱遵守

此套件执行 ECMA-402 `Intl.supportedValuesOf()` 规格 :

-   **光谱科**数字 : [8.3.2 支持的Intl.ValuesOf(钥匙)](https://tc39.es/ecma402/#sec-intl.supportedvaluesof)
-   **回返**: 国际化密钥的支持值
-   **完全符合规格**: 没有可选参数, 匹配本地浏览器行为

## 安装

```bash
npm install @formatjs/intl-supportedvaluesof
```

## 使用量

### 作为多填充

导入多填充器 `Intl.supportedValuesOf` 全球现有:

```javascript
import '@formatjs/intl-supportedvaluesof/polyfill'

// Now available on the global Intl object
const calendars = Intl.supportedValuesOf('calendar')
// ['buddhist', 'chinese', 'coptic', 'dangi', 'ethioaa', 'ethiopic', 'gregory', ...]

const currencies = Intl.supportedValuesOf('currency')
// ['AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', ...]

const timeZones = Intl.supportedValuesOf('timeZone')
// ['Africa/Abidjan', 'Africa/Accra', ..., 'Pacific/Wallis']
```

### 直接导入

直接导入函数而不修改全局命名空间 :

```javascript
import {supportedValuesOf} from '@formatjs/intl-supportedvaluesof'

const numberingSystems = supportedValuesOf('numberingSystem')
// ['adlm', 'ahom', 'arab', 'arabext', 'bali', 'beng', 'bhks', ...]

const units = supportedValuesOf('unit')
// ['acre', 'bit', 'byte', 'celsius', 'centimeter', 'day', 'degree', ...]
```

## 支持的密钥

该函数接受六个字符串密钥中的一个并返回一系列支持的值:

| 密钥 | 回返 | 示例数值 |
| --- | --- | --- |
| `'calendar'` | 支持的日历系统 | `'gregory'`, (中文(简体) ), `'islamic'`, (中文(简体) ), `'buddhist'`, (中文(简体) ), `'chinese'` |
| `'collation'` | 支持的整理算法 | `'emoji'`, (中文(简体) ), `'eor'`, (中文(简体) ), `'phonebk'`, (中文(简体) ), `'search'` |
| `'currency'` | 支持的 ISO 4217 货币代码 | `'USD'`, (中文(简体) ), `'EUR'`, (中文(简体) ), `'JPY'`, (中文(简体) ), `'GBP'` |
| `'numberingSystem'` | 支持的编号系统 | `'arab'`, (中文(简体) ), `'latn'`, (中文(简体) ), `'hanidec'`, (中文(简体) ), `'thai'` |
| `'timeZone'` | 支持的IANA时区 | `'America/New_York'`, (中文(简体) ), `'Europe/London'`, (中文(简体) ), `'Asia/Tokyo'` |
| `'unit'` | 支助的计量单位 | `'meter'`, (中文(简体) ), `'celsius'`, (中文(简体) ), `'liter'`, (中文(简体) ), `'acre'` |

## API 密码

### `supportedValuesOf(key: string): string[]`

返回给定密钥的一系列支持值.

**参数:**

-   `key` - 一个: `'calendar'`, (中文(简体) ), `'collation'`, (中文(简体) ), `'currency'`, (中文(简体) ), `'numberingSystem'`, (中文(简体) ), `'timeZone'`, (中文(简体) ), `'unit'`

**回返情况:**

-   排序的独有字符串值阵列

**掷出 :**

-   `RangeError` - 如果密钥不是支持的值之一

**示例**

```javascript
import {supportedValuesOf} from '@formatjs/intl-supportedvaluesof'

// Valid usage
const calendars = supportedValuesOf('calendar')
console.log(calendars) // ['buddhist', 'chinese', 'coptic', ...]

// Invalid key throws RangeError
try {
  supportedValuesOf('invalid')
} catch (e) {
  console.error(e) // RangeError: Invalid key: invalid
}
```

## 执行细节

这种多填充 **动态验证** 候选人数值与实际 `Intl` 而不是维持静态清单。 这种办法确保:

-   **准确性**: 结果匹配您的 JavaScript 运行时间
-   **特定运行时间**: 不同的引擎( V8, JavaScriptCore, SpiderMonkey) 可能支持不同的值
-   **最新数据**: 引擎添加新值时不需要手动更新列表

### 如何运作

每一类别的执行情况:

1.  **装入候选值** 出自QQR( Unicode 通用地块数据存储器)
2.  **测试每个值** 试图创建适当的 `Intl` 用于含有该值的事项
3.  **验证接受** 检查是否实际使用请求的值
4.  **返回过滤列表** 只有通过验证的值

### 示例:日历验证

```javascript
// Implementation tests if a calendar is supported:
function isSupportedCalendar(calendar) {
  try {
    // Attempt to create DateTimeFormat with this calendar
    const formatter = new Intl.DateTimeFormat(`en-u-ca-${calendar}`)
    // Verify the calendar was actually accepted
    const resolvedOptions = formatter.resolvedOptions()
    return resolvedOptions.calendar === calendar
  } catch {
    return false
  }
}
```

这只保证日历 **实际支持** 由您的运行时间返回,而不仅仅是一个静态列表.

## 类型脚本支持

此包包括了TypeScript类型定义. 当使用多填充时,全局 `Intl` 命名空间自动增强 :

```typescript
import '@formatjs/intl-supportedvaluesof/polyfill'

// TypeScript knows about Intl.supportedValuesOf
const calendars: string[] = Intl.supportedValuesOf('calendar')

// TypeScript will error on invalid keys
Intl.supportedValuesOf('invalid') // Error: Argument of type '"invalid"' is not assignable...
```

## 浏览器支持

这种多填充只针对没有本地支持的更老浏览器 `Intl.supportedValuesOf()`土著支助有:

-   99克罗姆克
-   边缘99+
-   Firefox 93+ (英语)
-   萨法里15.4+

混合填充需要下列条件: `Intl` 可用的 API :

-   `Intl.DateTimeFormat` (计: `calendar`, (中文(简体) ), `timeZone`, (中文(简体) ), `numberingSystem`(中文(简体) )
-   `Intl.NumberFormat` (计: `currency`, (中文(简体) ), `unit`, (中文(简体) ), `numberingSystem`(中文(简体) )
-   `Intl.Collator` (计: `collation`(中文(简体) )

## 正在突破 v3. 0 的更改

### 删除:非标准 `locale` 参数

**v2.x 及更早时** 有非标准选项 `locale` 按语言过滤结果的参数。 这是 **删除** 与ECMA-402规格相匹配.

```javascript
// ❌ v2.x (non-standard, no longer works)
const calendars = supportedValuesOf('calendar', 'en-US')

// ✅ v3.0 (spec-compliant)
const calendars = supportedValuesOf('calendar')
```

函数现在总是返回 **全体** 支持的值,匹配本地浏览器行为.

### 移徙指南

如果您在 v3. 0+ 中需要指定本地端过滤, 请自行执行 :

```javascript
import {supportedValuesOf} from '@formatjs/intl-supportedvaluesof'

// Get all supported calendars
const allCalendars = supportedValuesOf('calendar')

// Filter by what a specific locale actually uses/accepts
const enUSCalendars = allCalendars.filter(calendar => {
  try {
    const formatter = new Intl.DateTimeFormat('en-US', {calendar})
    return formatter.resolvedOptions().calendar === calendar
  } catch {
    return false
  }
})
```

然而,请注意,大多数使用案例不需要特定本地化过滤,因为光谱的设计返回了所有值 **任意** 当地人可以使用.

## 实例

### 检查是否支持日历

```javascript
import {supportedValuesOf} from '@formatjs/intl-supportedvaluesof'

const calendars = supportedValuesOf('calendar')

if (calendars.includes('islamic')) {
  console.log('Islamic calendar is supported')
  const formatter = new Intl.DateTimeFormat('en-US', {calendar: 'islamic'})
  console.log(formatter.format(new Date()))
}
```

### 显示所有支持的货币

```javascript
import {supportedValuesOf} from '@formatjs/intl-supportedvaluesof'

const currencies = supportedValuesOf('currency')

console.log(`This runtime supports ${currencies.length} currencies:`)
currencies.forEach(currency => {
  const formatter = new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency,
  })
  console.log(`${currency}: ${formatter.format(100)}`)
})
```

### 验证用户输入

```javascript
import {supportedValuesOf} from '@formatjs/intl-supportedvaluesof'

function isValidTimeZone(timeZone) {
  const supportedTimeZones = supportedValuesOf('timeZone')
  return supportedTimeZones.includes(timeZone)
}

console.log(isValidTimeZone('America/New_York')) // true
console.log(isValidTimeZone('Invalid/TimeZone')) // false
```

## 许可证

麻省理工学院

## 相关软件包

-   [@formatjs/intl (中文(简体) )](https://www.npmjs.com/package/@formatjs/intl) - 完整格式JS国际化套件
-   [@formatjs/intl-date-timeformat (中文(简体) )](https://www.npmjs.com/package/@formatjs/intl-datetimeformat) -内特 日期时间格式多填充
-   [@formatjs/intl-numberformat (中文(简体) )](https://www.npmjs.com/package/@formatjs/intl-numberformat) -内特 数字格式多填充
-   [@formatjs/intl-pluralrules (英语)](https://www.npmjs.com/package/@formatjs/intl-pluralrules) -内特 多规则多填充

## 资源

-   [ECMA-402 规格](https://tc39.es/ecma402/)
-   [MDN: 已支持的 ValuesOf ()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
-   [Unicode-%R 密码](https://cldr.unicode.org/)
-   [格式JS 文档](https://formatjs.io/)

## 常见问题

### @formatjs/intl-supportedvaluesof 是什么？

内置支持的多填充值

### 如何安装 @formatjs/intl-supportedvaluesof？

在项目目录运行 npm install @formatjs/intl-supportedvaluesof，或使用 pnpm add / yarn add / bun add。

### @formatjs/intl-supportedvaluesof 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @formatjs/intl-supportedvaluesof 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @formatjs/intl-supportedvaluesof 可以商用吗？

@formatjs/intl-supportedvaluesof 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @formatjs/intl-supportedvaluesof 的下载量有多少？

根据 npm 官方下载统计，@formatjs/intl-supportedvaluesof 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,197,270 次，日均约 106,576 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @formatjs/intl-supportedvaluesof 还在维护吗？

最新版本 3\.0\.1 发布于 2026/11/09（7 天前）；至今共发布 20 个版本，其中过去 12 个月发布了 20 个；首次发布于 2026/01/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

