https://github.com/dipunm/smart-feature-toggles
A smart feature toggle library with housekeeping and dependency features
https://github.com/dipunm/smart-feature-toggles
alerting expiration feature-flags feature-toggles housekeeping multi-source
Last synced: 3 months ago
JSON representation
A smart feature toggle library with housekeeping and dependency features
- Host: GitHub
- URL: https://github.com/dipunm/smart-feature-toggles
- Owner: dipunm
- License: mit
- Created: 2018-07-13T21:37:26.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-24T12:31:15.000Z (almost 7 years ago)
- Last Synced: 2025-02-22T14:37:18.862Z (3 months ago)
- Topics: alerting, expiration, feature-flags, feature-toggles, housekeeping, multi-source
- Language: JavaScript
- Homepage:
- Size: 189 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Smart feature toggles
[](https://travis-ci.com/dipunm/smart-feature-toggles)  
_Client sizes are based on a webpack bundle using the lite version of the library. (See [Lite Client](#lite-client))_
## Contents
- [Installation](#installation)
- [Defining toggles](#defining-toggles)
- [Usage](#usage)
- [Features](#features)## Installation
```bash
npm install smart-feature-toggles
```## Defining toggles
- A feature toggle may only be `active` or `inactive`.
- Feature toggles can be scoped (eg. to a http request, or to an
application context).
- A feature toggle _should not_ change value between calls\*.
- A feature toggle cannot be given arguments when being queried. All
[dependencies](#dependencies) should be defined and ready before a toggle
is queried.
- A feature toggle can be set up to alert developers when it is becoming
old.\*Smart feature toggles will cache the calculated value based on this
assumption, but the [auto reset feature](#auto-resets) exists to satisfy
more dynamic toggles.## Usage
#### Require `smart-feature-toggles`:
```js
const FeatureToggles = require('smart-feature-toggles');
```#### Set up alert handling: (see: [Housekeeping](#housekeeping))
```js
FeatureToggles.onHealthAlert((name, alert) => console.log(name, alert));
```#### Name and configure your features:
```js
const features = [
{
name: 'my-feature',dependencies: ['request'],
test: request => request.query.test_mode,
health: () => {
// If the toggle is getting old, return an alert
if (new Date().getFullYear() > 2018) {
return 'my-feature toggle is getting old!';
}
},
},
];
```#### Create your toggle client:
```js
const toggles = FeatureToggles.create(features);
```#### Define your dependencies: (see: [Dependencies](#dependencies))
```js
const request = { query: { test_mode: true } };
toggles.defineDependency('request', request);
```#### Use your feature toggle:
```js
if (toggles.get('my-feature')) { // true
...
}// alternative syntax.
toggles.values['my-feature']; // true// once evaluated, the toggle will
// always return it's original value
request.query.test_mode = false;
toggles.get('my-feature'); // true
```#### Toggles _can_ be set up to auto update (see: [Auto Resets](#auto-resets))
# Features
### Scoping:
Read about [Scoping](docs/features/SCOPING.md)
### Housekeeping:
Read about [Housekeeping](docs/features/HOUSEKEEPING.md)
### Dependencies:
Read about [Dependencies](docs/features/DEPENDENCIES.md)
### Serialization:
Read about [Serialization](docs/features/SERIALIZATION.md)
### Auto Resets:
Read about [Auto Resets](docs/features/AUTO_RESETS.md)
### Browser Compatibility:
Read about the [Browser Compatibility](docs/features/BROWSER_COMPATIBILITY.md)
### Lite Client:
Read about the [Lite Client](docs/features/LITE_CLIENT.md)
# API
see the [API docs](#api). (coming soon)