@carbon/feature-flags

中文文档
1.12.0发布于 2026/11/04Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 83.5万

以 C碳 特性标记构建

中文使用文档
文档目录6 节
  1. 开始
  2. 使用量
  3. 管理专题旗帜
  4. 捐款
  5. 许可证
  6. IBM 遥测

@ 碳/地平线旗

以 C碳 特性标记构建

开始

要安装 @carbon/feature-flags 在您的项目中,您需要运行 根据命令使用 无数字 :

npm install -S @carbon/feature-flags

如果你喜欢 雅伦,使用以下命令 相反:

yarn add @carbon/feature-flags

使用量

这个 @carbon/feature-flags 提供基于运行时的特性旗系统 可以用来启用或禁用来自Carbon或你自己的预览功能 代码.

要检查是否启用了特性旗, 您可以使用 enabled 函数在 Java 脚本 :

import { enabled } from '@carbon/feature-flags';

enabled('feature-flag-name');

在萨斯,你会使用 enabled 函数或混合:

@use '@carbon/feature-flags';

// Return true if the flag is enabled
@if feature-flags.enabled('feature-flag-name') {
  //
}

@include enabled('feature-flag-name') {
  // only include contents if the flag is enabled
}

管理专题旗帜

您可以更改是否启用了特性旗 。 在JavaScript中,您可以使用 enable, (中文(简体) ), disable,以及 merge 实现此目标的功能.

import { enable, disable, merge } from '@carbon/feature-flags';

// Enable `feature-flag-a`
enable('feature-flag-a');

// Disable `feature-flag-a`
disable('feature-flag-a');

// Set a variety of feature flags to a specific value
merge({
  'feature-flag-a': true,
  'feature-flag-b': false,
  'feature-flag-c': true,
});

在 Sass 中,您可以在包含时配置功能旗是否被启用 模块或通过使用 enable, (中文(简体) ), disable,以及 merge。 。 。 .

@use '@carbon/feature-flags' with (
  $feature-flags: (
    'feature-flag-a': false,
    'feature-flag-b': true,
  )
);

// Enable `feature-flag-a`
@include feature-flags.enable('feature-flag-a');

// Disable `feature-flag-b`
@include feature-flags.disable('feature-flag-b');

// Set a variety of feature flags to a specific value
@include feature-flags.merge(
  (
    'feature-flag-a': true,
    'feature-flag-b': true,
  )
);

捐款

我们总是寻找贡献者 帮助我们修复错误, 建立新的特性, 或者帮助我们改进项目文件。 如果你有兴趣,肯定 看看我们 贡献指南!

许可证

凭 Apache 2.0 许可证。 。 。 .

IBM Telemetry IBM 遥测

本套件使用 IBM 遥测来收集去识别和匿名的度量衡 数据。 通过安装此包作为依赖, 您同意远程测量 藏书。 选择退出,看 选择退出IBM遥测数据收集。 。 。 . 有关所收集数据的更多信息,请参见: IBM 遥测文档。 。 。 .

版本与发布记录

@carbon/feature-flags 共发布 94 个版本,首次发布于 2021/03/03;过去 12 个月发布了 27 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.12.0latest2026/11/044 天前
1.12.0-rc.0next2026/11/035 天前
2.0.0-alpha.2v12-alpha2026/10/2218 天前
1.11.02026/10/2119 天前
1.11.0-rc.02026/10/2020 天前
2.0.0-alpha.12026/10/011 个月前

其他发布通道:v10-next → 0.7.3,v12-alpha → 2.0.0-alpha.2,next → 1.12.0-rc.0。

关于 @carbon/feature-flags 的常见问题

@carbon/feature-flags 是什么?

以 C碳 特性标记构建

如何安装 @carbon/feature-flags?

在项目目录运行 npm install @carbon/feature-flags,或使用 pnpm add / yarn add / bun add。

@carbon/feature-flags 支持 TypeScript 吗?

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

@carbon/feature-flags 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@carbon/feature-flags 可以商用吗?

@carbon/feature-flags 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@carbon/feature-flags 的下载量有多少?

根据 npm 官方下载统计,@carbon/feature-flags 在 2026/10/09 – 2026/11/07 这 30 天内被下载 834,739 次,日均约 27,825 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@carbon/feature-flags 还在维护吗?

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