simple-feature-flag
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Simple Feature Flag

A feature flag (also called feature toggle) makes it easier to enable or disable feature/functionality. This package will help you to implement such feature flag/toggle across your application in a easy way.

Installation

You can install the package via npm:

npm install simple-feature-flag

Usage

For every flag you create there must be at least one filter associated. Filters are classes which contains business logic. For example: IsEnabled() and IsDisabled() are two in-build filters which can be added while creating a flag. You can also create your custom filters for any customized logic.

Example

Create a file called feature-flag.ts

First step is to create flags for the feature we want to toggle. For this we're using FlagBuilder.

const oktoberfestFlag = new FlagBuilder('oktober-fest')
  .addFilters('live', new IsDisabled())
  .addFilters('staging', new IsEnabled())
  .build();

As you can see oktober-fest feature is set to be disabled in live and enabled for staging environment.

Now you just need to add created flag using FeatureFlagBuilder.

const featureFlag = new FeatureFlagBuilder()
  .setEnvironment('staging')
  .addFlag(oktoberfestFlag)
  .build();

Just use featureFlag instance in you application to check if given feature is enabled or not for specified environment.

if (featureFlag.isEnabled('oktober-fest')) {
  // code when feature is enabled
}

Testing

npm run test

Credits

Package Sidebar

Install

npm i simple-feature-flag

Weekly Downloads

0

Version

0.0.3

License

ISC

Unpacked Size

14.5 kB

Total Files

35

Last publish

Collaborators

  • routeasis