https://github.com/solirius/feature-toggle-decorator
JavaScript feature toggle decorator
https://github.com/solirius/feature-toggle-decorator
Last synced: 8 months ago
JSON representation
JavaScript feature toggle decorator
- Host: GitHub
- URL: https://github.com/solirius/feature-toggle-decorator
- Owner: Solirius
- License: gpl-3.0
- Created: 2019-09-19T16:22:14.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T18:41:39.000Z (over 3 years ago)
- Last Synced: 2025-01-16T13:19:14.704Z (over 1 year ago)
- Language: TypeScript
- Size: 89.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Feature Toggle Decorator
=========================
[](https://travis-ci.org/solirius/feature-toggle-decorator)  
A decorator that will only execute the wrapped function if it is given a truthy parameter, and optionally call a fallback method if the feature is not enabled.
## Installation
```shell script
npm install --save feature-toggle-decorator
```
## Usage
```javascript
import { isEnabled } from "feature-toggle-decorator";
const features = {
FEATURE_1: true,
FEATURE_2: false,
FEATURE_3: false
};
class Example {
@isEnabled(features.FEATURE_1)
public test1() {
// will be called
}
@isEnabled(features.FEATURE_2)
public test2() {
// will not be called
}
@isEnabled(features.FEATURE_3, "fallbackMethod")
public test3(...args) {
// will not be called
}
public fallbackMethod() {
// will be called instead of test3
}
}
```
Note that any arguments sent to a disabled method with a fallback will be passed on to the fallback.
## Limitations
- The decorator parameters are evaluated at compile time so it is not possible to dynamically toggle features
- Fallback methods must be specified by string name
## Contributing
Issues and PRs are very welcome. To get the project set up run:
```
git clone git@github.com:solirius/feature-toggle-decorator
npm install --dev
npm test
```
If you would like to send a pull request please write your contribution in TypeScript and if possible, add a test.
## License
This software is licensed under [GNU GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html).