# simple-feature-flag

> Simple Feature Flag

Latest version **0.0.3** (published 2021-10-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install simple-feature-flag
pnpm add simple-feature-flag
yarn add simple-feature-flag
bun add simple-feature-flag
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-10-13 |
| First published | 2021-10-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ashish K. Poudel |
| Maintainers | routeasis |
| Keywords | feature-flag, feature-toggle |

## Links

- npm: https://www.npmjs.com/package/simple-feature-flag
- npm.io page: https://npm.io/package/simple-feature-flag

## Recent versions

- 0.0.3 (latest) — 2021-10-13
- 0.0.2 — 2021-10-13
- 0.0.1 — 2021-10-12

## README

# 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](https://github.com/ashishkpoudel)
- [All Contributors](../../contributors)

---
_Source: https://npm.io/package/simple-feature-flag · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
