Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

simple-feature-flag

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-feature-flag

Simple Feature Flag

latest
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

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

  • Ashish K. Poudel
  • All Contributors

Keywords

feature-flag

FAQs

Package last updated on 13 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts