|
1 | | -# Project |
| 1 | +# Microsoft Feature Management for JavaScript |
2 | 2 |
|
3 | | -> This repo has been populated by an initial template to help get you started. Please |
4 | | -> make sure to update the content to build a great experience for community-building. |
| 3 | +Feature Management is a library for enabling/disabling features at runtime. |
| 4 | +Developers can use feature flags in simple use cases like conditional statement to more advanced scenarios like conditionally adding routes. |
5 | 5 |
|
6 | | -As the maintainer of this project, please make a few updates: |
| 6 | +## Getting Started |
7 | 7 |
|
8 | | -- Improving this README.MD file to provide a great experience |
9 | | -- Updating SUPPORT.MD with content about this project's support experience |
10 | | -- Understanding the security reporting process in SECURITY.MD |
11 | | -- Remove this section from the README |
| 8 | +### Prerequisites |
| 9 | + |
| 10 | +- Node.js LTS version |
| 11 | + |
| 12 | +### Usage |
| 13 | + |
| 14 | +You can use feature flags from the Azure App Configuration service, local files or any other sources. |
| 15 | + |
| 16 | +#### Use feature flags from Azure App Configuration |
| 17 | + |
| 18 | +The App Configuration JavaScript provider provides feature flags in as a `Map` object. |
| 19 | +A builtin `ConfigurationMapFeatureFlagProvider` helps to load feature flags in this case. |
| 20 | + |
| 21 | +```js |
| 22 | +const appConfig = load(connectionString, {featureFlagOptions}); // load feature flags from Azure App Configuration service |
| 23 | +const featureProvider = new ConfigurationMapFeatureFlagProvider(appConfig); |
| 24 | +const featureManager = new FeatureManager(featureProvider); |
| 25 | +const isAlphaEnabled = await featureManager.isEnabled("Alpha"); |
| 26 | +console.log("Feature Alpha is:", isAlphaEnabled); |
| 27 | +``` |
| 28 | + |
| 29 | +#### Use feature flags from a json file |
| 30 | + |
| 31 | +A sample JSON file with the following format can be used to load feature flags. |
| 32 | +The JSON file can be read and parsed as an object as a whole. |
| 33 | +A builtin `ConfigurationObjectFeatureFlagProvider` helps to load feature flags in this case. |
| 34 | + |
| 35 | +Content of `sample.json`: |
| 36 | +```json |
| 37 | +{ |
| 38 | + "feature_management": { |
| 39 | + "feature_flags": [ |
| 40 | + { |
| 41 | + "id": "Alpha", |
| 42 | + "description": "", |
| 43 | + "enabled": "true", |
| 44 | + "conditions": { |
| 45 | + "client_filters": [] |
| 46 | + } |
| 47 | + } |
| 48 | + ] |
| 49 | + } |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +Load feature flags from `sample.json` file. |
| 54 | +```js |
| 55 | +const config = JSON.parse(await fs.readFile("path/to/sample.json")); |
| 56 | +const featureProvider = new ConfigurationObjectFeatureFlagProvider(config); |
| 57 | +const featureManager = new FeatureManager(featureProvider); |
| 58 | +const isAlphaEnabled = await featureManager.isEnabled("Alpha"); |
| 59 | +console.log("Feature Alpha is:", isAlphaEnabled); |
| 60 | +``` |
12 | 61 |
|
13 | 62 | ## Contributing |
14 | 63 |
|
|
0 commit comments