@html-validate/w3c-data

中文文档
1.20261101.0发布于 2026/11/01MITTypeScriptES Module零依赖构建来源已验证

Machine readable data scraped from W3C specifications

原始使用文档
文档目录6 节
  1. WAI-ARIA
  2. Usage
  3. Available versions
  4. Data structure
  5. Helper functions and types
  6. Versioning

HTML-Validate W3C data

This project contains scraped data from W3C specifications:

  • WAI-ARIA

This package is not meant for public consumption and breaking changes can occur between any version. Use at your own risk!

WAI-ARIA

The package provides machine-readable data about WAI-ARIA roles, properties, and states scraped from the W3C specification.

Usage

You can access ARIA data in two ways.

Use the factory function to get ARIA data for a specific version:

import { getAriaData } from "@html-validate/w3c-data/aria";

// Get data for a specific version
const { getRoleData } = getAriaData("latest"); // "latest", "1.3" or "1.2"

// Use the data
const alert = getRoleData("alert");
console.log(alert?.category); // "live"

Or import specific ARIA versions directly for better tree-shaking:

// Import latest ARIA data
import { getRoleData } from "@html-validate/w3c-data/aria-latest";
// Or import specific versions
import { getRoleData } from "@html-validate/w3c-data/aria-1.3";

Available versions

Data structure

The getRoleData() helper returns a NormalizedRole object:

const alert = getRoleData("alert");
console.log(alert?.category); // "live"
console.log(alert?.superclasses); // ["section"]
console.log(alert?.properties["aria-atomic"]); // { inherited: true, required: false, deprecated: false, default: "true" }

Each role contains:

  • role - Role name
  • category - Role category (abstract, widget, structure, landmark, live, or window)
  • superclasses - List of roles this role inherits from
  • subclasses - List of roles that inherit from this role
  • properties - Available ARIA properties for this role
  • states - Available ARIA states for this role
  • name - Accessible name requirements
    • fromAuthor - Name can be set from author
    • fromContents - Name can be set from content
    • prohibited - Name must not be set
    • required - Name is required
  • requiredParent - List of required parent roles
  • allowedChildren - List of allowed child roles
  • childrenPresentational - Whether DOM descendants are presentational

Each property and state in the properties and states objects contains:

  • inherited (boolean) - Whether the attribute is inherited from a superclass role
  • required (boolean) - Whether the attribute is required for this role
  • deprecated (boolean) - Whether the attribute is deprecated
  • default (string | undefined) - The default value of the attribute, if any

Note: All property and state keys include the aria- prefix (e.g., "aria-atomic", "aria-expanded").

Helper functions and types

The package provides helper functions and types for working with ARIA roles:

  • isValidRole(role: string): role is AriaRole: checks if a string is a valid ARIA role name.
  • getRoleData(role: AriaRole): NormalizedRole: get ARIA role metadata for given role.
  • getRoleData(role: string): NormalizedRole | null: get ARIA role metadata for given role.

Versioning

This package does not follow semantic versioning but rather the date of the last time it was scraped. Breaking changes can occur between any changes.

版本与发布记录

@html-validate/w3c-data 共发布 33 个版本,首次发布于 2026/02/08;过去 12 个月发布了 33 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.20261101.0latest2026/11/012 天前
1.20261025.02026/10/259 天前
1.20261018.02026/10/1816 天前
1.20261011.02026/10/1123 天前
1.20261004.02026/10/0430 天前
1.20260927.02026/09/271 个月前

关于 @html-validate/w3c-data 的常见问题

@html-validate/w3c-data 是什么?

从W3C规范中抓取的机器可读数据

如何安装 @html-validate/w3c-data?

在项目目录运行 npm install @html-validate/w3c-data,或使用 pnpm add / yarn add / bun add。

@html-validate/w3c-data 支持 TypeScript 吗?

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

@html-validate/w3c-data 支持 ESM 还是 CommonJS?

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

@html-validate/w3c-data 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.16.0 || >= 24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@html-validate/w3c-data 可以商用吗?

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

@html-validate/w3c-data 还在维护吗?

最新版本 1.20261101.0 发布于 2026/11/01(2 天前);至今共发布 33 个版本,其中过去 12 个月发布了 33 个;首次发布于 2026/02/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。