feature-toggle-api 3.4.2 → 4.0.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/README.md +115 -96
- package/dist/feature-toggle.d.ts +120 -0
- package/dist/feature-toggle.js +388 -0
- package/dist/feature-toggle.min.cjs +2 -0
- package/dist/feature-toggle.min.cjs.map +1 -0
- package/dist/feature-toggle.min.js +2 -0
- package/dist/feature-toggle.min.js.map +1 -0
- package/dist/feature-toggle.umd.min.js +2 -0
- package/dist/feature-toggle.umd.min.js.map +1 -0
- package/dist/html-plugin.umd.min.js +2 -0
- package/dist/html-plugin.umd.min.js.map +1 -0
- package/dist/url-plugin.umd.min.js +2 -0
- package/dist/url-plugin.umd.min.js.map +1 -0
- package/examples/01_basic_esmodule.js +10 -0
- package/examples/02_basic_cjsmodule.cjs +6 -0
- package/examples/{basic.html → 03_basic_scripttag.html} +3 -2
- package/examples/{example-htmlplugin.html → 04_example-htmlplugin.html} +2 -2
- package/examples/{example-urlplugin.html → 05_example-urlplugin.html} +2 -2
- package/examples/{withListener.html → 06_withListener.html} +1 -1
- package/package.json +32 -43
- package/rollup.config.js +107 -0
- package/src/{index.js → featureToggle.ts} +172 -51
- package/src/index.ts +10 -0
- package/src/plugins/htmlplugin/{plugin-html.js → plugin-html.ts} +22 -10
- package/src/plugins/urlplugin/{plugin-url.js → plugin-url.ts} +36 -10
- package/tests/featuretoggle.test.ts +407 -0
- package/tests/polyfills.ts +20 -0
- package/tsconfig.cjs.json +12 -0
- package/tsconfig.json +12 -0
- package/feature-toggle-api.js +0 -243
- package/feature-toggle-api.min.js +0 -1
- package/feature-toggle-api.module.js +0 -243
- package/spec/support/index.spec.js +0 -378
- package/spec/support/jasmine.json +0 -11
- package/spec/support/polyfills.js +0 -6
- package/src/index.cjs.js +0 -8
package/README.md
CHANGED
|
@@ -58,24 +58,52 @@ Create a new project, type
|
|
|
58
58
|
``` shell
|
|
59
59
|
npm install feature-toggle-api --save
|
|
60
60
|
```
|
|
61
|
-
|
|
61
|
+
|
|
62
|
+
Use it in your script
|
|
63
|
+
``` javascript
|
|
64
|
+
import { useFeatureToggle } from "feature-toggle-api";
|
|
65
|
+
|
|
66
|
+
//initialize it with your feature-flags
|
|
67
|
+
const feature = useFeatureToggle({
|
|
68
|
+
a:true,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
console.log(feature.isActive('a')); //true
|
|
72
|
+
console.log(feature.isActive('c')); //false
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
You use commonjs-scripts? Here we go:
|
|
76
|
+
``` javascript
|
|
77
|
+
const { useFeatureToggle } = require("feature-toggle-api/dist/feature-toggle.cjs");
|
|
78
|
+
|
|
79
|
+
//initialize it with your feature-flags
|
|
80
|
+
const feature = useFeatureToggle({
|
|
81
|
+
a:true,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
console.log(feature.isActive('a')); //true
|
|
85
|
+
console.log(feature.isActive('c')); //false
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
Or you want to include it as a scripttag? Here's a sample HTML-File.
|
|
62
90
|
``` html
|
|
63
91
|
<!DOCTYPE html>
|
|
64
92
|
<html lang="en">
|
|
65
93
|
<head>
|
|
66
94
|
<meta charset="UTF-8">
|
|
67
95
|
<title>Basic Feature-Toggle-API-Test</title>
|
|
68
|
-
<script src="
|
|
96
|
+
<script src="path/to/feature-toggle-api/dist/feature-toggle.umd.min.js"></script>
|
|
69
97
|
</head>
|
|
70
98
|
<body>
|
|
71
99
|
<div class="feature1">This is text from feature1</div>
|
|
72
100
|
<div class="feature2">This is text from feature2</div>
|
|
73
101
|
<script>
|
|
74
|
-
var api =
|
|
102
|
+
var api = useFeatureToggle({
|
|
75
103
|
feature1: true
|
|
76
104
|
});
|
|
77
|
-
var feature1Visible = api.
|
|
78
|
-
var feature2Visible = api.
|
|
105
|
+
var feature1Visible = api.isActive('feature1');
|
|
106
|
+
var feature2Visible = api.isActive('feature2');
|
|
79
107
|
|
|
80
108
|
//here we could also use jquery or any other library,... The api has done its job.
|
|
81
109
|
if(!feature1Visible) document.querySelector(".feature1").style.display = 'none';
|
|
@@ -84,23 +112,13 @@ You want to include it as a scripttag? Here's a sample HTML-File.
|
|
|
84
112
|
</body>
|
|
85
113
|
</html>
|
|
86
114
|
```
|
|
87
|
-
You have a node-module? Nothing is easier then that:
|
|
88
|
-
``` javascript
|
|
89
|
-
var featuretoggleapi = require('feature-toggle-api');
|
|
90
|
-
var api = featuretoggleapi({
|
|
91
|
-
feature1: true
|
|
92
|
-
});
|
|
93
|
-
var feature1Visible = api.isVisible('feature1');
|
|
94
|
-
var feature2Visible = api.isVisible('feature2');
|
|
95
115
|
|
|
96
|
-
//now you can do sth with the visibilities
|
|
97
|
-
```
|
|
98
116
|
|
|
99
117
|
### Initialisation
|
|
100
118
|
Initialisation is very simple
|
|
101
119
|
```javascript
|
|
102
120
|
//This api has already initialized some visiblity rules:
|
|
103
|
-
var api =
|
|
121
|
+
var api = useFeatureToggle({
|
|
104
122
|
feature1: true, //feature1 will be shown
|
|
105
123
|
feature2: false, //feature2 won't be shown,
|
|
106
124
|
// a rule can also be a function. important: it must return a boolean value; feature 3 would be shown
|
|
@@ -110,20 +128,20 @@ var api = new featuretoggleapi({
|
|
|
110
128
|
});
|
|
111
129
|
|
|
112
130
|
//You could also write it like this:
|
|
113
|
-
var api =
|
|
114
|
-
api.
|
|
115
|
-
api.
|
|
116
|
-
api.
|
|
117
|
-
api.
|
|
118
|
-
api.
|
|
131
|
+
var api = useFeatureToggle();
|
|
132
|
+
api.setFlag('feature1',true);
|
|
133
|
+
api.setFlag('feature2',false);
|
|
134
|
+
api.setFlag('feature3',function(rule){return true});
|
|
135
|
+
api.setFlag('feature4',true);
|
|
136
|
+
api.setFlag('feature4','new',false);
|
|
119
137
|
//only possible via functioncall: pass some data; maybe necessary in the listener
|
|
120
|
-
api.
|
|
138
|
+
api.setFlag('feature4','new',"some custom data",false);
|
|
121
139
|
```
|
|
122
140
|
|
|
123
141
|
Important: A visibilityrule mustn't start with an underscore. Attributes starting with an underscore are reserved for configuration settings.
|
|
124
142
|
```javascript
|
|
125
143
|
//This api has already initialized some visiblity rules:
|
|
126
|
-
var api =
|
|
144
|
+
var api = useFeatureToggle({
|
|
127
145
|
feature1: true, //visibilityrule feature1 -> true
|
|
128
146
|
plugins: true, //visibilityrule plugins -> true
|
|
129
147
|
_feature1: true, //_ is reserved for configuration -> this attribute does nothing
|
|
@@ -150,10 +168,10 @@ For the next examples we will imagine, the properties are mapped to the visibili
|
|
|
150
168
|
```javascript
|
|
151
169
|
// shows Feature1
|
|
152
170
|
//Feature2 is not configured, so it will be hidden
|
|
153
|
-
api.
|
|
171
|
+
api.setFlag('feature1',true);
|
|
154
172
|
|
|
155
173
|
//Remember: you can also wrap it in functions - but the example above is better to read
|
|
156
|
-
api.
|
|
174
|
+
api.setFlag('feature1',function ( rule) {
|
|
157
175
|
//here would be some more complex logic, in this example we keep it simple
|
|
158
176
|
return true;
|
|
159
177
|
});
|
|
@@ -161,58 +179,58 @@ api.visibility('feature1',function ( rule) {
|
|
|
161
179
|
```javascript
|
|
162
180
|
/*
|
|
163
181
|
shows all features with name feature2, in this case:
|
|
164
|
-
api.
|
|
165
|
-
api.
|
|
166
|
-
api.
|
|
167
|
-
api.
|
|
168
|
-
api.
|
|
182
|
+
api.isActive('feature1') -> return false
|
|
183
|
+
api.isActive('feature2') -> return true
|
|
184
|
+
api.isActive('feature2','new') -> return true
|
|
185
|
+
api.isActive('feature2','old') -> return true
|
|
186
|
+
api.isActive('feature2','grumpfel') -> return true
|
|
169
187
|
|
|
170
188
|
*/
|
|
171
|
-
api.
|
|
189
|
+
api.setFlag('feature2', true);
|
|
172
190
|
|
|
173
191
|
/*
|
|
174
192
|
This overwrites the rule above for "feature2", variant "new"
|
|
175
|
-
api.
|
|
176
|
-
api.
|
|
177
|
-
api.
|
|
178
|
-
api.
|
|
179
|
-
api.
|
|
193
|
+
api.isActive('feature1') -> return false
|
|
194
|
+
api.isActive('feature2') -> return true - because of rule above
|
|
195
|
+
api.isActive('feature2','new') -> return false
|
|
196
|
+
api.isActive('feature2','old') -> return true
|
|
197
|
+
api.isActive('feature2','grumpfel') -> return true
|
|
180
198
|
*/
|
|
181
|
-
api.
|
|
199
|
+
api.setFlag('feature2','new', false);
|
|
182
200
|
```
|
|
183
201
|
```javascript
|
|
184
202
|
/*
|
|
185
|
-
feature.
|
|
186
|
-
feature.
|
|
203
|
+
feature.isActive('feature3','new','grumpfel'); //returns true
|
|
204
|
+
feature.isActive('feature3','new','grumpfelbu'); //returns false
|
|
187
205
|
*/
|
|
188
|
-
api.
|
|
206
|
+
api.setFlag('feature3','new', function (rule) {
|
|
189
207
|
//rule.data could also be an object or whatever you want
|
|
190
208
|
//you could also use rule.name, rule.variant,...
|
|
191
209
|
return rule.data == "grumpfel";
|
|
192
210
|
});
|
|
193
211
|
```
|
|
194
212
|
#### Default Visibility
|
|
195
|
-
Bored of writing the same visibility rule again and again? Use
|
|
213
|
+
Bored of writing the same visibility rule again and again? Use defaultFlag. This is the default-rule and will be overwritten by feature.setFlag() - rules.
|
|
196
214
|
``` javascript
|
|
197
|
-
feature.
|
|
215
|
+
feature.setDefaultFlag(function(rule){
|
|
198
216
|
return true;
|
|
199
217
|
});
|
|
200
218
|
|
|
201
|
-
feature.
|
|
219
|
+
feature.setFlag('feature2', 'new', function(rule){
|
|
202
220
|
return false;
|
|
203
221
|
});
|
|
204
222
|
/*
|
|
205
|
-
"Feature2", variant "new" is overwritten, all other features have the
|
|
206
|
-
api.
|
|
207
|
-
api.
|
|
208
|
-
api.
|
|
209
|
-
api.
|
|
210
|
-
api.
|
|
223
|
+
"Feature2", variant "new" is overwritten, all other features have the defaultFlag
|
|
224
|
+
api.isActive('feature1') -> return true
|
|
225
|
+
api.isActive('feature2') -> return true
|
|
226
|
+
api.isActive('feature2','new') -> return false
|
|
227
|
+
api.isActive('feature2','old') -> return true
|
|
228
|
+
api.isActive('feature2','grumpfel') -> return true
|
|
211
229
|
*/
|
|
212
230
|
```
|
|
213
231
|
You already want to initialize it in the constructor? No Problem.
|
|
214
232
|
```javascript
|
|
215
|
-
var api =
|
|
233
|
+
var api = useFeatureToggle({
|
|
216
234
|
_default: true, //default visibility always returns true; again: this could also be a function
|
|
217
235
|
});
|
|
218
236
|
```
|
|
@@ -226,7 +244,7 @@ This rule is always executed, before the other rules. When it returns false, the
|
|
|
226
244
|
var globalConfig = { "feature2" : true }
|
|
227
245
|
*/
|
|
228
246
|
|
|
229
|
-
feature.
|
|
247
|
+
feature.setRequiredFlag(function(rule){
|
|
230
248
|
//In this case it returns true, when name == 'feture2'
|
|
231
249
|
return globalConfig[rule.name] === true;
|
|
232
250
|
});
|
|
@@ -234,48 +252,48 @@ feature.requiredVisibility(function(rule){
|
|
|
234
252
|
/*
|
|
235
253
|
feature2, variant "new" returns false, but requiredConfig returns true. Both rules must match, so it will be hidden
|
|
236
254
|
*/
|
|
237
|
-
feature.
|
|
255
|
+
feature.setFlag('feature2','new',function(rule){
|
|
238
256
|
return false;
|
|
239
257
|
});
|
|
240
258
|
|
|
241
259
|
/*
|
|
242
260
|
feature3 returns true, but requiredConfig returns false. Both rules must match, so Feature3 is hidden
|
|
243
261
|
*/
|
|
244
|
-
feature.
|
|
262
|
+
feature.setFlag('feature3',function(rule){
|
|
245
263
|
return true;
|
|
246
264
|
});
|
|
247
265
|
|
|
248
266
|
/*
|
|
249
|
-
api.
|
|
250
|
-
api.
|
|
251
|
-
api.
|
|
252
|
-
api.
|
|
267
|
+
api.isActive('feature2') -> return true
|
|
268
|
+
api.isActive('feature2','new') -> return false
|
|
269
|
+
api.isActive('feature2','old') -> return true
|
|
270
|
+
api.isActive('feature2','grumpfel') -> return true
|
|
253
271
|
|
|
254
|
-
api.
|
|
255
|
-
api.
|
|
272
|
+
api.isActive('feature3','new') -> return false
|
|
273
|
+
api.isActive('feature3','old') -> return false
|
|
256
274
|
*/
|
|
257
275
|
```
|
|
258
276
|
You already want to initialize it in the constructor? No Problem.
|
|
259
277
|
```javascript
|
|
260
|
-
var api =
|
|
278
|
+
var api = useFeatureToggle({
|
|
261
279
|
_required: true, //default visibility always returns true; again: this could also be a function
|
|
262
280
|
});
|
|
263
281
|
```
|
|
264
282
|
|
|
265
|
-
#### Function
|
|
283
|
+
#### Function isActive
|
|
266
284
|
Example for this function:
|
|
267
285
|
```javascript
|
|
268
286
|
// prooves if feature2 is visible
|
|
269
|
-
var
|
|
287
|
+
var isActive = feature.isActive('feature2');
|
|
270
288
|
|
|
271
289
|
// prooves if tag feature "feature2", variant "new" is visible
|
|
272
|
-
var
|
|
290
|
+
var isActive_new = feature.isActive('feature2','new');
|
|
273
291
|
|
|
274
292
|
// prooves if tag feature "feature2", variant "new" with data "grumpfl" is visible
|
|
275
|
-
var
|
|
293
|
+
var isActive_data = feature.isActive('feature2','new','grumpfl');
|
|
276
294
|
|
|
277
295
|
// prooves if tag feature "feature2" with data "grumpfl" is visible
|
|
278
|
-
var
|
|
296
|
+
var isActive_data_onlyname = feature.isActive('feature2',null,'grumpfl');
|
|
279
297
|
```
|
|
280
298
|
|
|
281
299
|
#### Function setData
|
|
@@ -290,17 +308,17 @@ if you want to update the data without updating the whole visibilityrule, use th
|
|
|
290
308
|
console.log(rule.data);
|
|
291
309
|
});
|
|
292
310
|
|
|
293
|
-
api.
|
|
311
|
+
api.setFlag('feature', 'variant','gruempfel',true); // logs 'gruempfel'
|
|
294
312
|
api.setData('feature','variant','newgruempfel'); // logs 'newgruempfel'
|
|
295
|
-
api.
|
|
313
|
+
api.setFlag('feature2', null,'gruempfel2',true); // logs 'gruempfel2'
|
|
296
314
|
api.setData('feature2','newgruempfel2'); // logs 'newgruempfel2'
|
|
297
315
|
```
|
|
298
316
|
|
|
299
317
|
#### Listeners
|
|
300
318
|
If you want to 'watch' every initialisation of a visibility rule, you can append a watcher on it.
|
|
301
319
|
```javascript
|
|
302
|
-
var api =
|
|
303
|
-
api.
|
|
320
|
+
var api = useFeatureToggle({feature: true});
|
|
321
|
+
api.setFlag("feature2","variant","data",true);
|
|
304
322
|
|
|
305
323
|
//Calling the listener will also regard already added visibility rules
|
|
306
324
|
//The result:
|
|
@@ -313,7 +331,7 @@ If you want to 'watch' every initialisation of a visibility rule, you can append
|
|
|
313
331
|
|
|
314
332
|
You can also add custom events and triggers whenever you want.
|
|
315
333
|
```javascript
|
|
316
|
-
var api =
|
|
334
|
+
var api = useFeatureToggle();
|
|
317
335
|
api.on('customevent', function (param) {
|
|
318
336
|
console.log("customevent " + param);
|
|
319
337
|
});
|
|
@@ -359,7 +377,7 @@ Calling addPlugin() prevents you from from adding a plugin multiple times, so if
|
|
|
359
377
|
|
|
360
378
|
//1st option: via constructor
|
|
361
379
|
//Important: don't forget the _ in the property _plugins!!!
|
|
362
|
-
const api =
|
|
380
|
+
const api = useFeatureToggle({_plugins:[customFunctionPlugin]});
|
|
363
381
|
|
|
364
382
|
//2nd option: via function
|
|
365
383
|
api.addPlugin(customFunctionPlugin);
|
|
@@ -379,7 +397,7 @@ Here's the way, how to add parameters to your plugin
|
|
|
379
397
|
|
|
380
398
|
//1st option: via constructor
|
|
381
399
|
//Important: don't forget the _ in the property _plugins!!!
|
|
382
|
-
const api =
|
|
400
|
+
const api = useFeatureToggle({_plugins:[pluginWithParams('Peter')]});
|
|
383
401
|
|
|
384
402
|
//2nd option: via function
|
|
385
403
|
api.addPlugin(pluginWithParams('Peter'));
|
|
@@ -391,7 +409,7 @@ Here's the way, how to add parameters to your plugin
|
|
|
391
409
|
Imagine this following html-snippet:
|
|
392
410
|
```javascript
|
|
393
411
|
/* Why is this ******* feature hidden? I checked the visibilityrule. It should be visible... */
|
|
394
|
-
api.
|
|
412
|
+
api.isActive('anamazingFeature') //returns false, but should return true... wtf???
|
|
395
413
|
```
|
|
396
414
|
All developers of the world agree with you, debugging sth like this is horrible. But don't worry, we have a perfect solution for it. And it's just one line of code.
|
|
397
415
|
```javascript
|
|
@@ -400,14 +418,14 @@ feature.showLogs(); //or feature.showLogs(true);
|
|
|
400
418
|
This returns a log like the following:
|
|
401
419
|
```html
|
|
402
420
|
Check Visibility of Feature "anAmazingFeature".
|
|
403
|
-
The
|
|
421
|
+
The requiredFlag rule returns false. This feature will be hidden.
|
|
404
422
|
|
|
405
423
|
Check Visibility of Feature "anotherAmazingFeature", variant "new" with data {"id":"bla"}.
|
|
406
|
-
The
|
|
424
|
+
The requiredFlag rule returns true. This feature will be shown when no other rule rejects it.
|
|
407
425
|
No visibility rule found matching name and variant.
|
|
408
426
|
No rules found for name anotherAmazingFeature without variants.
|
|
409
427
|
No default rule found.
|
|
410
|
-
Only the
|
|
428
|
+
Only the requiredFlag rule was found. This returned true. => This feature will be visible.
|
|
411
429
|
```
|
|
412
430
|
With this you don't have to waste your time with debugging the visibility state.
|
|
413
431
|
|
|
@@ -422,9 +440,10 @@ With this you don't have to waste your time with debugging the visibility state.
|
|
|
422
440
|
|
|
423
441
|
```javascript
|
|
424
442
|
//initializes a visibilityrule and adds a plugin
|
|
425
|
-
var api =
|
|
443
|
+
var api = useFeatureToggle({
|
|
426
444
|
feature1: true,
|
|
427
|
-
|
|
445
|
+
},{
|
|
446
|
+
plugins:[]
|
|
428
447
|
})
|
|
429
448
|
```
|
|
430
449
|
|
|
@@ -441,19 +460,19 @@ Returns:
|
|
|
441
460
|
nothing
|
|
442
461
|
```javascript
|
|
443
462
|
//possible parameters
|
|
444
|
-
api.
|
|
445
|
-
api.
|
|
446
|
-
api.
|
|
463
|
+
api.setFlag(name,result);
|
|
464
|
+
api.setFlag(name,variant,result);
|
|
465
|
+
api.setFlag(name,variant,data,result);
|
|
447
466
|
```
|
|
448
467
|
Example:
|
|
449
468
|
```javascript
|
|
450
469
|
//possible parameters
|
|
451
|
-
api.
|
|
452
|
-
api.
|
|
453
|
-
api.
|
|
470
|
+
api.setFlag('name',true);
|
|
471
|
+
api.setFlag('name','variant',true);
|
|
472
|
+
api.setFlag('name','variant','data',true);
|
|
454
473
|
|
|
455
474
|
//if result is a function
|
|
456
|
-
api.
|
|
475
|
+
api.setFlag('name',function(rule){
|
|
457
476
|
/*
|
|
458
477
|
rule has the following parameters
|
|
459
478
|
name: Name of the feature,
|
|
@@ -465,7 +484,7 @@ api.visibility('name',function(rule){
|
|
|
465
484
|
});
|
|
466
485
|
```
|
|
467
486
|
|
|
468
|
-
###
|
|
487
|
+
### isActive
|
|
469
488
|
Prooves if a function is visible.
|
|
470
489
|
|
|
471
490
|
Parameters:
|
|
@@ -478,9 +497,9 @@ Returns:
|
|
|
478
497
|
|
|
479
498
|
```javascript
|
|
480
499
|
//possible parameters
|
|
481
|
-
api.
|
|
482
|
-
api.
|
|
483
|
-
api.
|
|
500
|
+
api.isActive(name);
|
|
501
|
+
api.isActive(name,variant);
|
|
502
|
+
api.isActive(name,variant,data);
|
|
484
503
|
```
|
|
485
504
|
|
|
486
505
|
### on
|
|
@@ -542,18 +561,18 @@ Returns
|
|
|
542
561
|
api.setData(name,variant,data);
|
|
543
562
|
```
|
|
544
563
|
|
|
545
|
-
###
|
|
564
|
+
### requiredFlag
|
|
546
565
|
Sets the function for the required visibility.
|
|
547
566
|
|
|
548
567
|
Parameters:
|
|
549
|
-
-
|
|
568
|
+
- requiredFlagFunction
|
|
550
569
|
|
|
551
570
|
Returns:
|
|
552
571
|
- nothing
|
|
553
572
|
|
|
554
573
|
```javascript
|
|
555
574
|
//possible parameters
|
|
556
|
-
api.
|
|
575
|
+
api.setRequiredFlag(function(rule){
|
|
557
576
|
//do sth
|
|
558
577
|
/* Parameters:
|
|
559
578
|
event.name,
|
|
@@ -563,18 +582,18 @@ api.requiredVisibility(function(rule){
|
|
|
563
582
|
});
|
|
564
583
|
```
|
|
565
584
|
|
|
566
|
-
###
|
|
585
|
+
### defaultFlag
|
|
567
586
|
Sets the function for the default visibility.
|
|
568
587
|
|
|
569
588
|
Parameters:
|
|
570
|
-
-
|
|
589
|
+
- defaultFlagFunction
|
|
571
590
|
|
|
572
591
|
Returns:
|
|
573
592
|
- nothing
|
|
574
593
|
|
|
575
594
|
```javascript
|
|
576
595
|
//possible parameters
|
|
577
|
-
api.
|
|
596
|
+
api.setDefaultFlag(function(rule){
|
|
578
597
|
//do sth
|
|
579
598
|
/* Parameters:
|
|
580
599
|
event.name,
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
interface URLPluginConfig {
|
|
2
|
+
useMockedWindow?: boolean;
|
|
3
|
+
url?: string;
|
|
4
|
+
prefix?: string;
|
|
5
|
+
}
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
isMocked: boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
declare function urlPlugin(config?: URLPluginConfig): (api: any) => {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type Display = 'block' | 'inline-block' | 'inline' | 'flex' | 'inline-flex' | 'grid' | 'inline-grid';
|
|
16
|
+
interface HtmlPluginConfig {
|
|
17
|
+
renderedTag?: string;
|
|
18
|
+
featureTagName?: string;
|
|
19
|
+
tagAttributeName?: string;
|
|
20
|
+
nameAttributeName?: string;
|
|
21
|
+
variantAttributeName?: string;
|
|
22
|
+
dataAttributeName?: string;
|
|
23
|
+
displayAttributeName?: string;
|
|
24
|
+
defaultDisplay?: Display;
|
|
25
|
+
}
|
|
26
|
+
declare function htmlPlugin(config?: HtmlPluginConfig): (api: any) => {
|
|
27
|
+
name: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
interface OnConfiguration {
|
|
31
|
+
ignorePreviousRules: boolean;
|
|
32
|
+
}
|
|
33
|
+
type Plugin = (api: any) => void;
|
|
34
|
+
interface OnEvent {
|
|
35
|
+
name: string;
|
|
36
|
+
variant: string;
|
|
37
|
+
data: any;
|
|
38
|
+
result?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type FirstCharOfFeatureFlagKey = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' |
|
|
42
|
+
'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
|
|
43
|
+
|
|
44
|
+
type FeatureFlagKey = `${FirstCharOfFeatureFlagKey}${string}`;
|
|
45
|
+
|
|
46
|
+
interface FeatureToggleConfig {
|
|
47
|
+
[key: FeatureFlagKey]: boolean | (() => boolean);
|
|
48
|
+
$plugins?: Plugin[];
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use key`$plugins` instead.
|
|
51
|
+
*/
|
|
52
|
+
_plugins?: Plugin[];
|
|
53
|
+
}
|
|
54
|
+
interface Rule {
|
|
55
|
+
name: string;
|
|
56
|
+
variant: string;
|
|
57
|
+
data: any;
|
|
58
|
+
_internalCall?: true;
|
|
59
|
+
description?: string;
|
|
60
|
+
}
|
|
61
|
+
interface FeatureToggleApi {
|
|
62
|
+
name: string;
|
|
63
|
+
setData(name: string, dataParam?: any): void;
|
|
64
|
+
setData(name: string, variant: string, dataParam?: any): void;
|
|
65
|
+
setData(nameParam: string, variantOrDataParam: string | {
|
|
66
|
+
[key: string]: any;
|
|
67
|
+
}, dataParam?: any): void;
|
|
68
|
+
on(eventType: string, fn: (event: OnEvent) => void, config?: OnConfiguration): void;
|
|
69
|
+
trigger(eventtype: string, param?: any): any;
|
|
70
|
+
showLogs(showLogs?: boolean): void;
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use `featureToggle.isActive` instead.
|
|
73
|
+
*/
|
|
74
|
+
isVisible(name: string, variant?: string, data?: any): boolean;
|
|
75
|
+
isActive(name: string, variant?: string, data?: any): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated Use `featureToggle.setFlag` instead.
|
|
78
|
+
*/
|
|
79
|
+
visibility(name: string, result: boolean | ((rule: Rule) => boolean)): void;
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated Use `featureToggle.setFlag` instead.
|
|
82
|
+
*/
|
|
83
|
+
visibility(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void;
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated Use `featureToggle.setFlag` instead.
|
|
86
|
+
*/
|
|
87
|
+
visibility(name: string, variant: string | null, data: any, result: boolean | ((rule: Rule) => boolean)): void;
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use `featureToggle.setFlag` instead.
|
|
90
|
+
*/
|
|
91
|
+
visibility(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | (() => boolean)): void;
|
|
92
|
+
setFlag(name: string, result: boolean | ((rule: Rule) => boolean)): void;
|
|
93
|
+
setFlag(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void;
|
|
94
|
+
setFlag(name: string, variant: string | null, data: any, result: boolean | ((rule: Rule) => boolean)): void;
|
|
95
|
+
setFlag(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | (() => boolean)): void;
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use `featureToggle.setRequiredFlag` instead.
|
|
98
|
+
*/
|
|
99
|
+
requiredVisibility(fn: boolean | ((result: Rule) => boolean)): void;
|
|
100
|
+
/**
|
|
101
|
+
* @deprecated Use `featureToggle.setDefaultFlag` instead.
|
|
102
|
+
*/
|
|
103
|
+
defaultVisibility(fn: boolean | ((result: Rule) => boolean)): void;
|
|
104
|
+
/**
|
|
105
|
+
* This rule will run first and only if it is true, the feature.setFlag() - rules apply.
|
|
106
|
+
* In other words: if the required-rule returns false, all feature.setFlag-rules return false - regardless of its normal result.
|
|
107
|
+
* @param fn
|
|
108
|
+
*/
|
|
109
|
+
setRequiredFlag(fn: boolean | ((result: Rule) => boolean)): void;
|
|
110
|
+
/**
|
|
111
|
+
* This is the default-rule and will be overwritten by feature.setFlag() - rules.
|
|
112
|
+
* In other words: If feature.setFlag == false, the result of the defaultRule applies.
|
|
113
|
+
* @param fn DefaultRule
|
|
114
|
+
*/
|
|
115
|
+
setDefaultFlag(fn: boolean | ((result: Rule) => boolean)): void;
|
|
116
|
+
addPlugin(plugin: Plugin): any;
|
|
117
|
+
}
|
|
118
|
+
declare function useFeatureToggle(config?: FeatureToggleConfig): FeatureToggleApi;
|
|
119
|
+
|
|
120
|
+
export { htmlPlugin, urlPlugin, useFeatureToggle };
|