@exodus/feature-control

中文文档
2.5.0发布于 2026/10/10MITES Module近 30 天下载 1.1万

This library abstracts and simplifies handling and use of feature flags and other feature controls.

原始使用文档
文档目录13 节
  1. Install
  2. Usage
  3. API
  4. createFeatureControl(options, enabledModules?)
  5. createFeatureControlSelectors(options, enabledModules?)
  6. Common scenarios
  7. I'm developing a new feature that is not working and using …
  8. I'm developing a new feature that is not working, but doesn…
  9. I'm developing a new feature that is working, but is not re…
  10. I have developed a new feature that is ready for production…
  11. I have developed a new feature that is ready for production…
  12. I have a working feature shipped to production, but somethi…
  13. Development

feature-control

Simplify feature availability handling

Install

$ npm install @exodus/feature-control

Usage

You can find more usage examples in common scenarios.

import { createFeatureControl } from '@exodus/feature-control'

const unicornFeatureControl = createFeatureControl(
  {
    enabled: true,
    ready: true,
    versionSemver: '1.0.0',
    geolocation: {
      countryCode: 'US',
      regionCode: 'TX',
    },
  },
  {
    enabledOverride: true,
    geolocation: true,
    shutdownSemver: true,
  }
)

unicornFeatureControl.getIsOn() //=> true
unicornFeatureControl.getIsOn({ enabled: false }) //=> false
unicornFeatureControl.getIsOn({ shutdownSemver: '1.x' }) //=> false
unicornFeatureControl.getIsOn({ shutdownSemver: '0.x' }) //=> true
unicornFeatureControl.getIsOn({ shutdownSemver: '1.x', enabled: true }) //=> false
unicornFeatureControl.getIsOn({ geolocation: { countries: 'all' } }) //=> true
unicornFeatureControl.getIsOn({
  geolocation: { countries: 'all', disabledCountries: { US: 'United States of America' } },
}) //=> false
unicornFeatureControl.getIsOn({ geolocation: { countries: { US: 'United States of America' } } }) //=> true
unicornFeatureControl.getIsOn({
  geolocation: { countries: 'all', disabledRegions: { US: { TX: 'Texas' } } },
}) //=> false

unicornFeatureControl.getUnavailableStatus({ error: 'Unicorn is disabled!', enabled: true }) //=> 'Unicorn is disabled!'
unicornFeatureControl.getUnavailableStatus({
  unavailableStatus: 'Unicorn is disabled!',
  enabled: false,
}) //=> 'Unicorn is disabled!'

This can also be used with selectors:

import { useSelector } from 'react-redux'
import createFeatureControlSelectors from '@exodus/feature-control'

const unicornFeatureControl = createFeatureControlSelectors(
  {
    optsSelector: () => ({
      enabled: true,
      ready: true,
      versionSemver: '1.0.0',
      geolocation: {
        countryCode: 'US',
        regionCode: 'TX',
      },
    }),
    featureConfigSelector: (state) => state?.remoteConfig?.dapps?.unicorn,
  },
  {
    enabledOverride: true,
    geolocation: true,
    shutdownSemver: true,
  }
)

const Unicorn = () => {
  const isOn = useSelector(unicornFeatureControl.isOnSelector)
  const unAvailableStatus = useSelector(unicornFeatureControl.unavailableStatusSelector)

  return (
    <>
      <div>Unicorn is {isOn ? 'enabled' : 'disabled'}</div>
      {!isOn && <div>{unAvailableStatus}</div>}
    </>
  )
}

export default Unicorn

API

createFeatureControl(options, enabledModules?)

Create and configure feature control instance. Returns an instance with the following methods:

.getIsOn(featureConfig)

Returns a boolean for whether the feature is available or not.

.getUnavailableStatus(featureConfig)

Returns an unavailable status to be shown when the feature is unavailable. Can be present even if the feature is available.

featureConfig

Type: object

Configure the enabled modules.

enabled

Type: boolean

Override the default enabled option.

geolocation

Type: object

Enable or disable the feature in certain jurisdictions. Expects an object with the following signature:

{
  countries: object<string, string> | string
  disabledCountries: object<string, string>
  disabledRegions: object<string, object<string, string>>
  enabledRegions: object<string, object<string, string>>
}

Enable the feature for certain countries by setting countries to an object with their country codes as keys and country names as values. Set it to all to enable it for all countries.

Blacklist rules take precedence over whitelist rules. If a country or region is listed in disabledCountries or disabledRegions, the feature will be disabled even if it is allowed by countries or enabledRegions.

To disable the feature for certain countries, set disabledCountries to an object with their country codes as keys and country names as values.

E.g.

const disabledCountries = {
  US: 'United States of America',
}

To disable the feature for certain regions, set disabledRegions to a per-country object with their region codes as keys and region names as values.

E.g.

const disabledRegions = {
  US: {
    TX: 'Texas',
  },
}

To enable the feature only for certain regions within an allowed country, set enabledRegions to a per-country object with their region codes as keys and region names as values.

E.g.

const enabledRegions = {
  US: {
    TX: 'Texas',
  },
  EE: {
    37: 'Harjumaa',
  },
}
rollout

Type: number

Integer from 0 to 100. The feature is on only when the rolloutBucket option is less than rollout. Any other value disables the feature.

shutdownSemver

Type: string

SemVer range for which the feature is disabled.

unavailableStatus

Type: string

Status to be returned when running .getUnavailableStatus(featureConfig).

options

Type: object

enabled

Type: boolean
Default: true

Toggle feature availability. Can be overriden when calling .getIsOn(featureConfig) and .getUnavailableStatus(featureConfig).

ready

Type: boolean
Default: false

Toggle feature readiness. If set to false, .getIsOn(featureConfig) will always return false. Mainly used in development when the feature is not ready to ship yet.

versionSemver

Type: string

SemVer version of the application. Can be used in conjunction with shutdownSemver to disable the feature for certain versions.

geolocation

Type: object<string, string>

Geolocation to use when enabling or disabling the application in certain jurisdictions. Expects an object with the following signature:

{
  countryName: string
  countryCode: string
  regionName: string
  regionCode: string
}
rolloutBucket

Type: number

Integer from 0 to 99 that is stable for each user and feature. Used with rollout for a gradual rollout. If it is not set, the feature is off unless rollout is 100.

enabledModules?

Type: object<string, boolean>

Specify which modules to use. Available modules sorted by priority in which the feature determines it's availability are:

  • enabledOverride
  • rollout
  • geolocation
  • shutdownSemver

createFeatureControlSelectors(options, enabledModules?)

Create and configure feature control instance. Returns an instance with the following methods:

.isOnSelector(state)

Returns a boolean for whether the feature is available or not.

.unavailableStatusSelector(state)

Returns an unavailable status to be shown when the feature is unavailable. Can be present even if the feature is available.

options

Type: object

optsSelector

Type: function

Set options on the feature control instance. Expects a selector function that takes a state and returns a options object.

featureConfigSelector

Type: function

Set feature config on the feature control instance. Expects a selector function that takes a state and returns a feature config object.

enabledModules?

See this.

Common scenarios

I'm developing a new feature that is not working and using it incorrectly might lose funds

The usage below can be used without impacting users in production and QA environments assuming the flag is set to false for those environments.

createFeatureControl({
  enabled: true,
  ready: process.env.NEW_FEATURE_ENABLED,
})

I'm developing a new feature that is not working, but doesn't risk losing funds or breaking the application

The usage below can be used without impacting users in the production environment. This allows QA and other users within the team to test the feature and follow the latest progress.

createFeatureControl({
  enabled: true,
  ready: isDev || isGenesis || isEden,
})

I'm developing a new feature that is working, but is not ready for production yet

The usage below can be used without impacting users in the production environment. This allows QA and other users within the team to test the feature before giving their final feedback.

createFeatureControl({
  enabled: true,
  ready: isDev || isGenesis || isEden,
})

I have developed a new feature that is ready for production and is expected to ship next the release

The usage below will make the feature available by default.

createFeatureControl({
  enabled: true,
  ready: true,
})

I have developed a new feature that is ready for production and is expected to ship the next release. But it cannot be enabled before a certain date

The feature can be toggled on at the expected date by using a remote config override for enabled. Once that date is passed we can switch enabled back to true in the client code.

createFeatureControl({
  enabled: false,
  ready: true,
})

I have a working feature shipped to production, but something is broken because the blockchain forked

Turn off the feature by setting enabled to false with a remote config override.

createFeatureControl({
  enabled: false,
  ready: true,
})

You can also disable it using shutdownSemver that targets affected versions.

const featureControl = createFeatureControl({
  enabled: true,
  ready: true,
  versionSemver: '1.0.0',
})

featureControl.getIsOn({ shutdownSemver: '1.x' })
//=> false

Development

bun install
bun test

版本与发布记录

@exodus/feature-control 共发布 17 个版本,首次发布于 2021/12/13;过去 12 个月发布了 4 个版本。

版本发布日期距今
2.5.0latest2026/10/101 个月前
2.4.12026/05/056 个月前
2.4.02025/12/2910 个月前
2.3.02025/12/2310 个月前
2.2.42025/05/131.5 年前
2.2.32025/02/171.7 年前

关于 @exodus/feature-control 的常见问题

@exodus/feature-control 是什么?

This library abstracts and simplifies handling and use of feature flags and other feature controls.

如何安装 @exodus/feature-control?

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

@exodus/feature-control 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/exodus__feature-control 是否存在。

@exodus/feature-control 支持 ESM 还是 CommonJS?

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

@exodus/feature-control 可以商用吗?

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

@exodus/feature-control 的下载量有多少?

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

@exodus/feature-control 还在维护吗?

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