# simple-feature-toggle

> A simple library allowing you to hide code implementation behind a feature-toggle flag. Allows for nested features and callbacks.

Latest version **1.0.1** (published 2017-01-02) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-01-02 |
| First published | 2017-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Bartosz Szczecinski |
| Maintainers | btmpl |
| Keywords | javascript, feature, toggle, flag |

## Links

- npm: https://www.npmjs.com/package/simple-feature-toggle
- Repository: https://github.com/btmpl/feature-toggle
- Issues: https://github.com/btmpl/feature-toggle/issues
- npm.io page: https://npm.io/package/simple-feature-toggle

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4

## Recent versions

- 1.0.1 (latest) — 2017-01-02
- 1.0.0 — 2017-01-02

## README

## USAGE

```js
var featureToggle = require("simple-feature-toggle");

featureToggle.set({
  root: {
    child: {
      flag1: false
    }
  }
});

if(featureToggle.isEnabled("root.child.flag1")) {
  console.log("root.child.feature1 is enabled");
}
else {
  console.log("root.child.feature1 is disabled");
}
```

## API

```js
featureToggle.set(Object flagset)
```

Load or update an existing flag set. The value should be an object with each
leaf being either a boolean or function that when evaluate returns a boolean.

Calling the function multiple time will merge the flag set using [_.merge](https://lodash.com/docs#merge)

```js
featureToggle.reset()
```

Resets the flag set to an empty set. Useful when you want to replace the current
set with a new one, and not update it.

```js
featureToggle.isEnabled(String, [param1, param2, ....])
```

Checks the flag set against an selector supplied as a `dot.string.notation`.
If the expected value is a function, you can pass additional parameters which
will be then passed to the function at runtime.

```js
featureToggle.isDisabled(String, [param1, param2, ...])
```

Returns the opposite of `isEnabled`

```js
featureToggle.data
```

Object holding the current flag set. Please use `set()` and `reset()` to alter.

```js
featureToggle.assumeEnabledByDefault
```

The value to be returned when the queries key (using `isEnabled`, `isDisabled`)
fails to find the value in the flag set. By default `true` allowing the lib to
be used to disable functionality rather than enable it.

```js
featureToggle.resolveNested
```

Decides if the app can query for whole flag objects as valid `isEnabled` and
`isDisabled` response. This can be useful to lock/unlock a whole group of
features and each individual one later on.

```js
featureToggle.resolveNested()
```

If `featureToggle.resolveNested` is enabled, decides on value to be returned when
resolving with an object. Returns `featureToggle.assumeEnabledByDefault` by
default.

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