@carbon/feature-flags 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/index.js CHANGED
@@ -5,109 +5,189 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- const enabled = {};
8
+ const enabled$1 = {};
9
9
 
10
10
  try {
11
11
  if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES) {
12
12
  if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES === 'true') {
13
- enabled.enableCssCustomProperties = true;
13
+ enabled$1.enableCssCustomProperties = true;
14
14
  } else {
15
- enabled.enableCssCustomProperties = false;
15
+ enabled$1.enableCssCustomProperties = false;
16
16
  }
17
17
  } else {
18
- enabled.enableCssCustomProperties = false;
18
+ enabled$1.enableCssCustomProperties = false;
19
19
  }
20
20
 
21
21
  if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE) {
22
22
  if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE === 'true') {
23
- enabled.enableUseControlledStateWithValue = true;
23
+ enabled$1.enableUseControlledStateWithValue = true;
24
24
  } else {
25
- enabled.enableUseControlledStateWithValue = false;
25
+ enabled$1.enableUseControlledStateWithValue = false;
26
26
  }
27
27
  } else {
28
- enabled.enableUseControlledStateWithValue = false;
28
+ enabled$1.enableUseControlledStateWithValue = false;
29
+ }
30
+
31
+ if (process.env.CARBON_ENABLE_CSS_GRID) {
32
+ if (process.env.CARBON_ENABLE_CSS_GRID === 'true') {
33
+ enabled$1.enableCssGrid = true;
34
+ } else {
35
+ enabled$1.enableCssGrid = false;
36
+ }
37
+ } else {
38
+ enabled$1.enableCssGrid = false;
39
+ }
40
+
41
+ if (process.env.CARBON_ENABLE_V11_RELEASE) {
42
+ if (process.env.CARBON_ENABLE_V11_RELEASE === 'true') {
43
+ enabled$1.enableV11Release = true;
44
+ } else {
45
+ enabled$1.enableV11Release = false;
46
+ }
47
+ } else {
48
+ enabled$1.enableV11Release = false;
29
49
  }
30
50
  } catch (error) {
31
- enabled.enableCssCustomProperties = false;
32
- enabled.enableUseControlledStateWithValue = false;
51
+ enabled$1.enableCssCustomProperties = false;
52
+ enabled$1.enableUseControlledStateWithValue = false;
53
+ enabled$1.enableCssGrid = false;
54
+ enabled$1.enableV11Release = false;
33
55
  }
34
56
 
35
57
  const featureFlagInfo = [{
36
58
  name: "enable-css-custom-properties",
37
59
  description: "Describe what the flag does",
38
- enabled: enabled.enableCssCustomProperties
60
+ enabled: enabled$1.enableCssCustomProperties
39
61
  }, {
40
62
  name: "enable-use-controlled-state-with-value",
41
63
  description: "Enable components to be created in either a controlled or uncontrolled mode\n",
42
- enabled: enabled.enableUseControlledStateWithValue
64
+ enabled: enabled$1.enableUseControlledStateWithValue
65
+ }, {
66
+ name: "enable-css-grid",
67
+ description: "Enable CSS Grid Layout in the Grid and Column React components\n",
68
+ enabled: enabled$1.enableCssGrid
69
+ }, {
70
+ name: "enable-v11-release",
71
+ description: "Enable the features and functionality for the v11 Release\n",
72
+ enabled: enabled$1.enableV11Release
43
73
  }];
44
74
 
45
- const featureFlags = new Map();
75
+ class FeatureFlagScope {
76
+ constructor(flags) {
77
+ this.flags = new Map();
78
+
79
+ if (flags) {
80
+ Object.keys(flags).forEach((key) => {
81
+ this.flags.set(key, flags[key]);
82
+ });
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Check to see if a flag exists
88
+ * @param {string} name
89
+ */
90
+ checkForFlag(name) {
91
+ if (!this.flags.has(name)) {
92
+ throw new Error(
93
+ `Unable to find a feature flag with the name: \`${name}\``
94
+ );
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Add a feature flag
100
+ * @param {string} name
101
+ * @param {boolean} enabled
102
+ */
103
+ add(name, enabled) {
104
+ if (this.flags.has(name)) {
105
+ throw new Error(`The feature flag: ${name} already exists`);
106
+ }
107
+ this.flags.set(name, enabled);
108
+ }
109
+
110
+ /**
111
+ * Enable a feature flag
112
+ * @param {string} name
113
+ */
114
+ enable(name) {
115
+ this.checkForFlag(name);
116
+ this.flags.set(name, true);
117
+ }
118
+
119
+ /**
120
+ * Disable a feature flag
121
+ * @param {string} name
122
+ */
123
+ disable(name) {
124
+ this.checkForFlag(name);
125
+ this.flags.set(name, false);
126
+ }
127
+
128
+ /**
129
+ * Merge the given feature flags with the current set of feature flags.
130
+ * Duplicate keys will be set to the value in the given feature flags.
131
+ * @param {object} flags
132
+ */
133
+ merge(flags) {
134
+ Object.keys(flags).forEach((key) => {
135
+ this.flags.set(key, flags[key]);
136
+ });
137
+ }
138
+
139
+ /**
140
+ * @param {FeatureFlagScope} scope
141
+ */
142
+ mergeWithScope(scope) {
143
+ for (const [key, value] of scope.flags) {
144
+ if (this.flags.has(key)) {
145
+ continue;
146
+ }
147
+ this.flags.set(key, value);
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Check if a feature flag is enabled
153
+ * @param {string} name
154
+ * @returns {boolean}
155
+ */
156
+ enabled(name) {
157
+ this.checkForFlag(name);
158
+ return this.flags.get(name);
159
+ }
160
+ }
161
+
162
+ const FeatureFlags = createScope();
46
163
 
47
164
  for (let i = 0; i < featureFlagInfo.length; i++) {
48
165
  const featureFlag = featureFlagInfo[i];
49
- featureFlags.set(featureFlag.name, featureFlag.enabled);
166
+ FeatureFlags.add(featureFlag.name, featureFlag.enabled);
50
167
  }
51
168
 
52
- /**
53
- * Check to see if a flag exists
54
- * @param {string} name
55
- */
56
- function checkForFlag(name) {
57
- if (!featureFlags.has(name)) {
58
- throw new Error(`Unable to find a feature flag with the name \`${name}\``);
59
- }
169
+ function createScope(flags) {
170
+ return new FeatureFlagScope(flags);
60
171
  }
61
172
 
62
- /**
63
- * Add a feature flag
64
- * @param {string} name
65
- * @param {boolean} enabled
66
- */
67
- function add(name, enabled) {
68
- if (featureFlags.has(name)) {
69
- throw new Error(`The feature flag: ${name} already exists`);
70
- }
71
- featureFlags.set(name, enabled);
173
+ function add(...args) {
174
+ return FeatureFlags.add(...args);
72
175
  }
73
176
 
74
- /**
75
- * Enable a feature flag
76
- * @param {string} name
77
- */
78
- function enable(name) {
79
- checkForFlag(name);
80
- featureFlags.set(name, true);
177
+ function enable(...args) {
178
+ return FeatureFlags.enable(...args);
81
179
  }
82
180
 
83
- /**
84
- * Disable a feature flag
85
- * @param {string} name
86
- */
87
- function disable(name) {
88
- checkForFlag(name);
89
- featureFlags.set(name, false);
181
+ function disable(...args) {
182
+ return FeatureFlags.disable(...args);
90
183
  }
91
184
 
92
- /**
93
- * Merge the given feature flags with the current set of feature flags.
94
- * Duplicate keys will be set to the value in the given feature flags.
95
- * @param {object} flags
96
- */
97
- function merge(flags) {
98
- Object.keys(flags).forEach((key) => {
99
- featureFlags.set(key, flags[key]);
100
- });
185
+ function enabled(...args) {
186
+ return FeatureFlags.enabled(...args);
101
187
  }
102
188
 
103
- /**
104
- * Check if a feature flag is enabled
105
- * @param {string} name
106
- * @returns {boolean}
107
- */
108
- function enabled$1(name) {
109
- checkForFlag(name);
110
- return featureFlags.get(name);
189
+ function merge(...args) {
190
+ return FeatureFlags.merge(...args);
111
191
  }
112
192
 
113
- export { add, disable, enable, enabled$1 as enabled, merge, featureFlagInfo as unstable_featureFlagInfo };
193
+ export { FeatureFlags, add, createScope, disable, enable, enabled, merge };
package/lib/index.js CHANGED
@@ -9,114 +9,195 @@
9
9
 
10
10
  Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
- const enabled = {};
12
+ const enabled$1 = {};
13
13
 
14
14
  try {
15
15
  if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES) {
16
16
  if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES === 'true') {
17
- enabled.enableCssCustomProperties = true;
17
+ enabled$1.enableCssCustomProperties = true;
18
18
  } else {
19
- enabled.enableCssCustomProperties = false;
19
+ enabled$1.enableCssCustomProperties = false;
20
20
  }
21
21
  } else {
22
- enabled.enableCssCustomProperties = false;
22
+ enabled$1.enableCssCustomProperties = false;
23
23
  }
24
24
 
25
25
  if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE) {
26
26
  if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE === 'true') {
27
- enabled.enableUseControlledStateWithValue = true;
27
+ enabled$1.enableUseControlledStateWithValue = true;
28
28
  } else {
29
- enabled.enableUseControlledStateWithValue = false;
29
+ enabled$1.enableUseControlledStateWithValue = false;
30
30
  }
31
31
  } else {
32
- enabled.enableUseControlledStateWithValue = false;
32
+ enabled$1.enableUseControlledStateWithValue = false;
33
+ }
34
+
35
+ if (process.env.CARBON_ENABLE_CSS_GRID) {
36
+ if (process.env.CARBON_ENABLE_CSS_GRID === 'true') {
37
+ enabled$1.enableCssGrid = true;
38
+ } else {
39
+ enabled$1.enableCssGrid = false;
40
+ }
41
+ } else {
42
+ enabled$1.enableCssGrid = false;
43
+ }
44
+
45
+ if (process.env.CARBON_ENABLE_V11_RELEASE) {
46
+ if (process.env.CARBON_ENABLE_V11_RELEASE === 'true') {
47
+ enabled$1.enableV11Release = true;
48
+ } else {
49
+ enabled$1.enableV11Release = false;
50
+ }
51
+ } else {
52
+ enabled$1.enableV11Release = false;
33
53
  }
34
54
  } catch (error) {
35
- enabled.enableCssCustomProperties = false;
36
- enabled.enableUseControlledStateWithValue = false;
55
+ enabled$1.enableCssCustomProperties = false;
56
+ enabled$1.enableUseControlledStateWithValue = false;
57
+ enabled$1.enableCssGrid = false;
58
+ enabled$1.enableV11Release = false;
37
59
  }
38
60
 
39
61
  const featureFlagInfo = [{
40
62
  name: "enable-css-custom-properties",
41
63
  description: "Describe what the flag does",
42
- enabled: enabled.enableCssCustomProperties
64
+ enabled: enabled$1.enableCssCustomProperties
43
65
  }, {
44
66
  name: "enable-use-controlled-state-with-value",
45
67
  description: "Enable components to be created in either a controlled or uncontrolled mode\n",
46
- enabled: enabled.enableUseControlledStateWithValue
68
+ enabled: enabled$1.enableUseControlledStateWithValue
69
+ }, {
70
+ name: "enable-css-grid",
71
+ description: "Enable CSS Grid Layout in the Grid and Column React components\n",
72
+ enabled: enabled$1.enableCssGrid
73
+ }, {
74
+ name: "enable-v11-release",
75
+ description: "Enable the features and functionality for the v11 Release\n",
76
+ enabled: enabled$1.enableV11Release
47
77
  }];
48
78
 
49
- const featureFlags = new Map();
79
+ class FeatureFlagScope {
80
+ constructor(flags) {
81
+ this.flags = new Map();
82
+
83
+ if (flags) {
84
+ Object.keys(flags).forEach((key) => {
85
+ this.flags.set(key, flags[key]);
86
+ });
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Check to see if a flag exists
92
+ * @param {string} name
93
+ */
94
+ checkForFlag(name) {
95
+ if (!this.flags.has(name)) {
96
+ throw new Error(
97
+ `Unable to find a feature flag with the name: \`${name}\``
98
+ );
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Add a feature flag
104
+ * @param {string} name
105
+ * @param {boolean} enabled
106
+ */
107
+ add(name, enabled) {
108
+ if (this.flags.has(name)) {
109
+ throw new Error(`The feature flag: ${name} already exists`);
110
+ }
111
+ this.flags.set(name, enabled);
112
+ }
113
+
114
+ /**
115
+ * Enable a feature flag
116
+ * @param {string} name
117
+ */
118
+ enable(name) {
119
+ this.checkForFlag(name);
120
+ this.flags.set(name, true);
121
+ }
122
+
123
+ /**
124
+ * Disable a feature flag
125
+ * @param {string} name
126
+ */
127
+ disable(name) {
128
+ this.checkForFlag(name);
129
+ this.flags.set(name, false);
130
+ }
131
+
132
+ /**
133
+ * Merge the given feature flags with the current set of feature flags.
134
+ * Duplicate keys will be set to the value in the given feature flags.
135
+ * @param {object} flags
136
+ */
137
+ merge(flags) {
138
+ Object.keys(flags).forEach((key) => {
139
+ this.flags.set(key, flags[key]);
140
+ });
141
+ }
142
+
143
+ /**
144
+ * @param {FeatureFlagScope} scope
145
+ */
146
+ mergeWithScope(scope) {
147
+ for (const [key, value] of scope.flags) {
148
+ if (this.flags.has(key)) {
149
+ continue;
150
+ }
151
+ this.flags.set(key, value);
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Check if a feature flag is enabled
157
+ * @param {string} name
158
+ * @returns {boolean}
159
+ */
160
+ enabled(name) {
161
+ this.checkForFlag(name);
162
+ return this.flags.get(name);
163
+ }
164
+ }
165
+
166
+ const FeatureFlags = createScope();
50
167
 
51
168
  for (let i = 0; i < featureFlagInfo.length; i++) {
52
169
  const featureFlag = featureFlagInfo[i];
53
- featureFlags.set(featureFlag.name, featureFlag.enabled);
170
+ FeatureFlags.add(featureFlag.name, featureFlag.enabled);
54
171
  }
55
172
 
56
- /**
57
- * Check to see if a flag exists
58
- * @param {string} name
59
- */
60
- function checkForFlag(name) {
61
- if (!featureFlags.has(name)) {
62
- throw new Error(`Unable to find a feature flag with the name \`${name}\``);
63
- }
173
+ function createScope(flags) {
174
+ return new FeatureFlagScope(flags);
64
175
  }
65
176
 
66
- /**
67
- * Add a feature flag
68
- * @param {string} name
69
- * @param {boolean} enabled
70
- */
71
- function add(name, enabled) {
72
- if (featureFlags.has(name)) {
73
- throw new Error(`The feature flag: ${name} already exists`);
74
- }
75
- featureFlags.set(name, enabled);
177
+ function add(...args) {
178
+ return FeatureFlags.add(...args);
76
179
  }
77
180
 
78
- /**
79
- * Enable a feature flag
80
- * @param {string} name
81
- */
82
- function enable(name) {
83
- checkForFlag(name);
84
- featureFlags.set(name, true);
181
+ function enable(...args) {
182
+ return FeatureFlags.enable(...args);
85
183
  }
86
184
 
87
- /**
88
- * Disable a feature flag
89
- * @param {string} name
90
- */
91
- function disable(name) {
92
- checkForFlag(name);
93
- featureFlags.set(name, false);
185
+ function disable(...args) {
186
+ return FeatureFlags.disable(...args);
94
187
  }
95
188
 
96
- /**
97
- * Merge the given feature flags with the current set of feature flags.
98
- * Duplicate keys will be set to the value in the given feature flags.
99
- * @param {object} flags
100
- */
101
- function merge(flags) {
102
- Object.keys(flags).forEach((key) => {
103
- featureFlags.set(key, flags[key]);
104
- });
189
+ function enabled(...args) {
190
+ return FeatureFlags.enabled(...args);
105
191
  }
106
192
 
107
- /**
108
- * Check if a feature flag is enabled
109
- * @param {string} name
110
- * @returns {boolean}
111
- */
112
- function enabled$1(name) {
113
- checkForFlag(name);
114
- return featureFlags.get(name);
193
+ function merge(...args) {
194
+ return FeatureFlags.merge(...args);
115
195
  }
116
196
 
197
+ exports.FeatureFlags = FeatureFlags;
117
198
  exports.add = add;
199
+ exports.createScope = createScope;
118
200
  exports.disable = disable;
119
201
  exports.enable = enable;
120
- exports.enabled = enabled$1;
202
+ exports.enabled = enabled;
121
203
  exports.merge = merge;
122
- exports.unstable_featureFlagInfo = featureFlagInfo;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/feature-flags",
3
3
  "description": "Build with feature flags in Carbon",
4
- "version": "0.2.0",
4
+ "version": "0.4.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -11,6 +11,12 @@
11
11
  "directory": "packages/feature-flags"
12
12
  },
13
13
  "bugs": "https://github.com/carbon-design-system/carbon/issues",
14
+ "files": [
15
+ "es",
16
+ "lib",
17
+ "scss",
18
+ "index.scss"
19
+ ],
14
20
  "keywords": [
15
21
  "ibm",
16
22
  "carbon",
@@ -27,17 +33,17 @@
27
33
  "watch": "yarn clean && node tasks/build.js && rollup -c -w"
28
34
  },
29
35
  "devDependencies": {
30
- "@babel/generator": "^7.10.2",
36
+ "@babel/generator": "^7.14.0",
31
37
  "@babel/template": "^7.12.13",
32
- "@babel/types": "^7.10.2",
38
+ "@babel/types": "^7.14.0",
33
39
  "@carbon/scss-generator": "^10.13.0",
34
40
  "change-case": "^4.1.2",
35
41
  "fs-extra": "^9.0.1",
36
42
  "js-yaml": "^3.14.0",
37
43
  "rimraf": "^3.0.2",
38
- "rollup": "^2.38.0",
44
+ "rollup": "^2.46.0",
39
45
  "rollup-plugin-strip-banner": "^2.0.0"
40
46
  },
41
47
  "sideEffects": false,
42
- "gitHead": "9d5ddba624d9cc7afe54717fd430228349c043e3"
48
+ "gitHead": "b00113e8d4cb273a80d9c71f12b741ae6ac360a6"
43
49
  }
@@ -9,4 +9,6 @@
9
9
  $generated-feature-flags: (
10
10
  'enable-css-custom-properties': false,
11
11
  'enable-use-controlled-state-with-value': false,
12
+ 'enable-css-grid': false,
13
+ 'enable-v11-release': false,
12
14
  );
package/feature-flags.yml DELETED
@@ -1,16 +0,0 @@
1
- #
2
- # Copyright IBM Corp. 2015, 2020
3
- #
4
- # This source code is licensed under the Apache-2.0 license found in the
5
- # LICENSE file in the root directory of this source tree.
6
- #
7
-
8
- feature-flags:
9
- - name: enable-css-custom-properties
10
- description: Describe what the flag does
11
- enabled: false
12
- - name: enable-use-controlled-state-with-value
13
- description: >
14
- Enable components to be created in either a controlled or uncontrolled
15
- mode
16
- enabled: false
package/rollup.config.js DELETED
@@ -1,48 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2015, 2020
3
- *
4
- * This source code is licensed under the Apache-2.0 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import path from 'path';
9
- import stripBanner from 'rollup-plugin-strip-banner';
10
-
11
- const BANNER = `/**
12
- * Copyright IBM Corp. 2015, 2020
13
- *
14
- * This source code is licensed under the Apache-2.0 license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- */
17
- `;
18
-
19
- const baseConfig = {
20
- external: [],
21
- plugins: [
22
- stripBanner(),
23
- {
24
- renderChunk(code) {
25
- return `${BANNER}\n${code}`;
26
- },
27
- },
28
- ],
29
- };
30
-
31
- export default [
32
- {
33
- ...baseConfig,
34
- input: path.join(__dirname, './src/index.js'),
35
- output: {
36
- file: 'es/index.js',
37
- format: 'esm',
38
- },
39
- },
40
- {
41
- ...baseConfig,
42
- input: path.join(__dirname, './src/index.js'),
43
- output: {
44
- file: 'lib/index.js',
45
- format: 'commonjs',
46
- },
47
- },
48
- ];
@@ -1,44 +0,0 @@
1
- /**
2
- * Code generated by @carbon/feature-flags. DO NOT EDIT.
3
- *
4
- * Copyright IBM Corp. 2015, 2020
5
- *
6
- * This source code is licensed under the Apache-2.0 license found in the
7
- * LICENSE file in the root directory of this source tree.
8
- */
9
- const enabled = {};
10
-
11
- try {
12
- if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES) {
13
- if (process.env.CARBON_ENABLE_CSS_CUSTOM_PROPERTIES === 'true') {
14
- enabled.enableCssCustomProperties = true;
15
- } else {
16
- enabled.enableCssCustomProperties = false;
17
- }
18
- } else {
19
- enabled.enableCssCustomProperties = false;
20
- }
21
-
22
- if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE) {
23
- if (process.env.CARBON_ENABLE_USE_CONTROLLED_STATE_WITH_VALUE === 'true') {
24
- enabled.enableUseControlledStateWithValue = true;
25
- } else {
26
- enabled.enableUseControlledStateWithValue = false;
27
- }
28
- } else {
29
- enabled.enableUseControlledStateWithValue = false;
30
- }
31
- } catch (error) {
32
- enabled.enableCssCustomProperties = false;
33
- enabled.enableUseControlledStateWithValue = false;
34
- }
35
-
36
- export const featureFlagInfo = [{
37
- name: "enable-css-custom-properties",
38
- description: "Describe what the flag does",
39
- enabled: enabled.enableCssCustomProperties
40
- }, {
41
- name: "enable-use-controlled-state-with-value",
42
- description: "Enable components to be created in either a controlled or uncontrolled mode\n",
43
- enabled: enabled.enableUseControlledStateWithValue
44
- }];
package/src/index.js DELETED
@@ -1,78 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2015, 2020
3
- *
4
- * This source code is licensed under the Apache-2.0 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import { featureFlagInfo } from './generated/feature-flags';
9
-
10
- const featureFlags = new Map();
11
-
12
- for (let i = 0; i < featureFlagInfo.length; i++) {
13
- const featureFlag = featureFlagInfo[i];
14
- featureFlags.set(featureFlag.name, featureFlag.enabled);
15
- }
16
-
17
- /**
18
- * Check to see if a flag exists
19
- * @param {string} name
20
- */
21
- function checkForFlag(name) {
22
- if (!featureFlags.has(name)) {
23
- throw new Error(`Unable to find a feature flag with the name \`${name}\``);
24
- }
25
- }
26
-
27
- /**
28
- * Add a feature flag
29
- * @param {string} name
30
- * @param {boolean} enabled
31
- */
32
- export function add(name, enabled) {
33
- if (featureFlags.has(name)) {
34
- throw new Error(`The feature flag: ${name} already exists`);
35
- }
36
- featureFlags.set(name, enabled);
37
- }
38
-
39
- /**
40
- * Enable a feature flag
41
- * @param {string} name
42
- */
43
- export function enable(name) {
44
- checkForFlag(name);
45
- featureFlags.set(name, true);
46
- }
47
-
48
- /**
49
- * Disable a feature flag
50
- * @param {string} name
51
- */
52
- export function disable(name) {
53
- checkForFlag(name);
54
- featureFlags.set(name, false);
55
- }
56
-
57
- /**
58
- * Merge the given feature flags with the current set of feature flags.
59
- * Duplicate keys will be set to the value in the given feature flags.
60
- * @param {object} flags
61
- */
62
- export function merge(flags) {
63
- Object.keys(flags).forEach((key) => {
64
- featureFlags.set(key, flags[key]);
65
- });
66
- }
67
-
68
- /**
69
- * Check if a feature flag is enabled
70
- * @param {string} name
71
- * @returns {boolean}
72
- */
73
- export function enabled(name) {
74
- checkForFlag(name);
75
- return featureFlags.get(name);
76
- }
77
-
78
- export { featureFlagInfo as unstable_featureFlagInfo };