@runespoorstack/feature-toggles-imperative
v0.0.6
Published
Imperative feature toggles as code for JavaScript and TypeScript.
Downloads
38
Maintainers
Readme
Table of Contents
- Table of Contents
- Context
- ✨ Features
- 🦾 Installation
- ♾️ Usage
- 🛠️ Contributing
- 💕 Special Thanks
- ❤️ Support or Donate
Context
This package implement something that is called Release Feature Toggles. It is the simplest way to manage feature toggles - as code.
✨ Features
- Convenient way to define feature toggles in code.
- Validate feature toggles configuration.
- Feature toggles history (via VSC).
- Zero dependencies.
🦾 Installation
npm i @runespoorstack/feature-toggles-imperative
♾️ Usage
List app environments:
const ENVS = ['dev', 'qa', 'prod'] as const;
Use env variable name to get the current environment (vite example). You can use NODE_ENV or set your own variable:
const ENVS = ['dev', 'qa', 'prod'] as const;
const ENV_NAME = import.meta.env.VITE_ENV_NAME;
Define feature toggles configuration:
const FEATURE_TOGGLES = {
feature1: {
meta: {
description: 'Feature 1',
createdAt: '2023-01-01',
createdBy: 'John Doe'
},
enabled: {
dev: true,
qa: false,
prod: false
},
},
feature2: {
meta: {
description: 'Feature 2',
createdAt: '2023-01-02',
createdBy: 'Jane Doe'
},
enabled: {
dev: false,
qa: false,
prod: true
},
value: {
dev: 'value4',
qa: 'value5',
prod: 'value6'
}
}
} as const;
Create feature toggles:
import { createFeatureToggles } from '@runespoorstack/feature-toggles-imperative';
const { getFeatureToggle } = createFeatureToggles({
featureToggles: FEATURE_TOGGLES,
envs: ENVS,
env: ENV_NAME
});
Use feature toggles:
const feature1 = getFeatureToggle('feature2');
console.log(feature1);
// {
// meta: {
// description: 'Feature 1',
// createdAt: '2023-01-01',
// createdBy: 'John Doe'
// },
// enabled: true,
// value: 'value6'
// }
🛠️ Contributing
See the CONTRIBUTING.md document.
💕 Special Thanks
- I want to say thank you to the best woman in the world, my wife Diana for her love, daily support, motivation and inspiration.
❤️ Support or Donate
If you are enjoying this work and feel extra appreciative, you could buy me a book 📖 or 3 📖📖📖.