feature-toggle-api 4.1.0 → 5.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.
Files changed (53) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +14 -16
  3. package/dist/feature-toggle.js +227 -385
  4. package/dist/feature-toggle.js.map +1 -0
  5. package/dist/featureToggle.d.ts +3 -0
  6. package/dist/html-plugin.js +42 -0
  7. package/dist/html-plugin.js.map +1 -0
  8. package/dist/index.d.ts +5 -0
  9. package/dist/plugins/htmlplugin/plugin-html.d.ts +15 -0
  10. package/dist/plugins/urlplugin/plugin-url.d.ts +14 -0
  11. package/dist/{feature-toggle.d.ts → types.d.ts} +17 -54
  12. package/dist/url-plugin.js +40 -0
  13. package/dist/url-plugin.js.map +1 -0
  14. package/dist/vite.config.d.ts +2 -0
  15. package/package.json +26 -11
  16. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
  17. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
  18. package/dist/feature-toggle.min.cjs +0 -2
  19. package/dist/feature-toggle.min.cjs.map +0 -1
  20. package/dist/feature-toggle.min.js +0 -2
  21. package/dist/feature-toggle.min.js.map +0 -1
  22. package/dist/feature-toggle.umd.min.js +0 -2
  23. package/dist/feature-toggle.umd.min.js.map +0 -1
  24. package/dist/html-plugin.umd.min.js +0 -2
  25. package/dist/html-plugin.umd.min.js.map +0 -1
  26. package/dist/url-plugin.umd.min.js +0 -2
  27. package/dist/url-plugin.umd.min.js.map +0 -1
  28. package/docs/_config.yml +0 -1
  29. package/docs/example-intro.html +0 -75
  30. package/docs/example-setup.html +0 -55
  31. package/docs/example-visibility-basic.html +0 -144
  32. package/docs/readme.md +0 -628
  33. package/docs/vue-feature-toggle.min.js +0 -902
  34. package/examples/01_basic_esmodule.js +0 -10
  35. package/examples/02_basic_cjsmodule.cjs +0 -6
  36. package/examples/03_basic_scripttag.html +0 -24
  37. package/examples/04_example-htmlplugin.html +0 -35
  38. package/examples/05_example-urlplugin.html +0 -25
  39. package/examples/06_withListener.html +0 -21
  40. package/gulpfile.js +0 -65
  41. package/plugin-html.js +0 -1
  42. package/plugin-url.js +0 -1
  43. package/rollup.config.js +0 -107
  44. package/src/featureToggle.ts +0 -466
  45. package/src/index.ts +0 -10
  46. package/src/plugins/htmlplugin/plugin-html.ts +0 -83
  47. package/src/plugins/htmlplugin/readme.md +0 -221
  48. package/src/plugins/urlplugin/plugin-url.ts +0 -90
  49. package/src/plugins/urlplugin/readme.md +0 -92
  50. package/tests/featuretoggle.test.ts +0 -450
  51. package/tests/polyfills.ts +0 -20
  52. package/tsconfig.cjs.json +0 -12
  53. package/tsconfig.json +0 -12
package/docs/readme.md DELETED
@@ -1,628 +0,0 @@
1
- # The interactive feature-toggle-api demo
2
-
3
- > Gives you advanced feature-toggle for any Framework - test it with live examples
4
-
5
- [![npm version](https://img.shields.io/npm/v/feature-toggle-api.svg)](https://www.npmjs.com/package/feature-toggle-api)
6
- [![npm downloads](https://img.shields.io/npm/dt/feature-toggle-api.svg)](https://www.npmjs.com/package/feature-toggle-api)
7
- [![npm downloads](https://img.shields.io/github/license/mashape/apistatus.svg)](https://www.npmjs.com/package/feature-toggle-api)
8
-
9
- ## Live example
10
- Try many interactive examples - so you won't take long to understand the api.
11
-
12
- <iframe src="https://bassdman.github.io/feature-toggle-api/example-intro.html" width="700" height="310"> </iframe>
13
-
14
-
15
- ## Install
16
-
17
- ``` shell
18
- npm install feature-toggle-api --save
19
- ```
20
-
21
- - [Quicklink to the API](#api-description)
22
- - [Quicklink to the HTML-Plugin](https://github.com/bassdman/feature-toggle-api/blob/master/src/plugins/htmlplugin/readme.md)
23
- - [Quicklink to the URL-Plugin](https://github.com/bassdman/feature-toggle-api/blob/master/src/plugins/urlplugin/readme.md)
24
- - [Quicklink to the vue-Plugin (package vue-feature-toggle)](https://github.com/bassdman/vue-feature-toggle)
25
-
26
- ## The Problem
27
- Imagine you have an onlineshop with an testmode and in multiple languages.
28
- One part uses a html-template that looks like this:
29
- ``` html
30
- <content-area>
31
- <!-- Show important debugging information for testmode -->
32
- <testmode-nav onload="showIf(testmode)"></testmode-nav>
33
-
34
- <!-- That's the old one, in a few days the new one, commented out here will be released
35
- <left-nav-new></left-nav-new>
36
- -->
37
- <left-nav></left-nav>
38
-
39
- <!-- Every shop has a slider with amazing foodinfo on the startpage-->
40
- <div id="startpage-slider-de" ref="food/bratwurst" onload="showIf(shop=='de')">...</div>
41
- <div id="startpage-slider-en" ref="food/fishnchips" onload="showIf(shop=='en')">...</div>
42
- <div id="startpage-slider-fr" ref="food/croissant" onload="showIf(shop=='fr')">...</div>
43
-
44
- <footer-new></footer-new>
45
- <!--
46
- New footer just went live. When there are some problems, we rollback and comment out the new footer and uncomment the old one
47
- <footer-old></footer-old> -->
48
- </content-area>
49
- ```
50
- It's generally a bad idea to have visibility rules in the template. Of course, by refactoring the template a little bit the code will look better.
51
- But that's not the point. The problem is: The view-logic is spread in .html and .js files and if the viewlogic changes, you have to change at least them. And all visibility rules are spread over the whole system.
52
- That's not good.
53
-
54
- ## The solution
55
- Feature-toggle. All View-Logic is placed in one place. This can be a config file, a webservice or a tool with a User Interface.
56
- When you want to change a visibility rule, for example "Show feature XYZ also in the french shop", you just have to update the config or add this info in an UI. And no developer is needed for it.
57
-
58
- <a href="https://martinfowler.com/articles/feature-toggles.html">Read the article from Martin Fowler about feature toggle for a better understanding.</a>
59
-
60
- ### Setup
61
- We will initialize the api in two ways. In both ways we will have it initialized with one feature.
62
- <iframe src="https://bassdman.github.io/feature-toggle-api/example-setup.html" width="700" height="210"> </iframe>
63
-
64
- Create a new project, type
65
- ``` shell
66
- npm install feature-toggle-api --save
67
- ```
68
- You want to include it as a scripttag? Here's a sample HTML-File.
69
- ``` html
70
- <!DOCTYPE html>
71
- <html lang="en">
72
- <head>
73
- <meta charset="UTF-8">
74
- <title>Basic Feature-Toggle-API-Test</title>
75
- <script src="../feature-toggle-api.min.js"></script>
76
- </head>
77
- <body>
78
- <div class="feature1">This is text from feature1</div>
79
- <div class="feature2">This is text from feature2</div>
80
- <script>
81
- var api = featuretoggleapi({
82
- feature1: true
83
- });
84
- var feature1Visible = api.isVisible('feature1');
85
- var feature2Visible = api.isVisible('feature2');
86
-
87
- //here we could also use jquery or any other library,... The api has done its job.
88
- if(!feature1Visible) document.querySelector(".feature1").style.display = 'none';
89
- if(!feature2Visible) document.querySelector(".feature2").style.display = 'none';
90
- </script>
91
- </body>
92
- </html>
93
- ```
94
- You have a node-module? Nothing is easier then that:
95
- ``` javascript
96
- var featuretoggleapi = require('feature-toggle-api');
97
- var api = featuretoggleapi({
98
- feature1: true
99
- });
100
- var feature1Visible = api.isVisible('feature1');
101
- var feature2Visible = api.isVisible('feature2');
102
-
103
- //now you can do sth with the visibilities
104
- ```
105
-
106
-
107
- ### Initialisation
108
- Initialisation is very simple
109
- ```javascript
110
- //This api has already initialized some visiblity rules:
111
- var api = new featuretoggleapi({
112
- feature1: true, //feature1 will be shown
113
- feature2: false, //feature2 won't be shown,
114
- // a rule can also be a function. important: it must return a boolean value; feature 3 would be shown
115
- feature3: function(rule){return true;},
116
- feature4: true,
117
- "feature4:new": false, //feature 4 will be shown - but if variant is new, it won't be.
118
- });
119
-
120
- //You could also write it like this:
121
- var api = new featuretoggleapi();
122
- api.visibility('feature1',true);
123
- api.visibility('feature2',false);
124
- api.visibility('feature3',function(rule){return true});
125
- api.visibility('feature4',true);
126
- api.visibility('feature4','new',false);
127
- //only possible via functioncall: pass some data; maybe necessary in the listener
128
- api.visibility('feature4','new',"some custom data",false);
129
- ```
130
-
131
- Important: A visibilityrule mustn't start with an underscore. Attributes starting with an underscore are reserved for configuration settings.
132
- ```javascript
133
- //This api has already initialized some visiblity rules:
134
- var api = new featuretoggleapi({
135
- feature1: true, //visibilityrule feature1 -> true
136
- plugins: true, //visibilityrule plugins -> true
137
- _feature1: true, //_ is reserved for configuration -> this attribute does nothing
138
- _plugins: [], //_ is reserved for configuration -> add plugins
139
- });
140
- ```
141
-
142
- ### Features
143
- For the next examples we will imagine, the properties are mapped to the visibility rules. (Btw, the [html-plugin](https://github.com/bassdman/feature-toggle-api/blob/master/src/plugins/htmlplugin/readme.md) does this for you ;)
144
- Here's an live example:
145
- <iframe src="https://bassdman.github.io/feature-toggle-api/example-visibility-basic.html" width="700" height="900"> </iframe>
146
-
147
- ```html
148
- <div id="app">
149
- <!-- Just imagine, the properties are matched to the visibility rules -->
150
- <feature name="feature1">This is "Feature1"</feature>
151
- <feature name="feature2">This is "Feature2"</feature>
152
- <feature name="feature2" variant="new">This is "Feature2" with variant "new"</feature>
153
- <feature name="feature2" variant="old">This "Feature2" with variant "old"</feature>
154
- <feature name="feature2" variant="grumpfel">This "Feature2" with variant "grumpfel"</feature>
155
-
156
- <feature name="feature3" variant="old" data="grumpfel">This "Feature3" with variant "old" has some Data.</feature>
157
- <feature name="feature3" variant="new" data="{'text':'grumpfel'}">This "Feature3" with variant "old" has some Data.</feature>
158
- </div>
159
- ```
160
- #### Basic visibility
161
- ```javascript
162
- // shows Feature1
163
- //Feature2 is not configured, so it will be hidden
164
- api.visibility('feature1',true);
165
-
166
- //Remember: you can also wrap it in functions - but the example above is better to read
167
- api.visibility('feature1',function ( rule) {
168
- //here would be some more complex logic, in this example we keep it simple
169
- return true;
170
- });
171
- ```
172
- ```javascript
173
- /*
174
- shows all features with name feature2, in this case:
175
- api.isVisible('feature1') -> return false
176
- api.isVisible('feature2') -> return true
177
- api.isVisible('feature2','new') -> return true
178
- api.isVisible('feature2','old') -> return true
179
- api.isVisible('feature2','grumpfel') -> return true
180
-
181
- */
182
- api.visibility('feature2', true);
183
-
184
- /*
185
- This overwrites the rule above for "feature2", variant "new"
186
- api.isVisible('feature1') -> return false
187
- api.isVisible('feature2') -> return true - because of rule above
188
- api.isVisible('feature2','new') -> return false
189
- api.isVisible('feature2','old') -> return true
190
- api.isVisible('feature2','grumpfel') -> return true
191
- */
192
- api.visibility('feature2','new', false);
193
- ```
194
- ```javascript
195
- /*
196
- feature.isVisible('feature3','new','grumpfel'); //returns true
197
- feature.isVisible('feature3','new','grumpfelbu'); //returns false
198
- */
199
- api.visibility('feature3','new', function (rule) {
200
- //rule.data could also be an object or whatever you want
201
- //you could also use rule.name, rule.variant,...
202
- return rule.data == "grumpfel";
203
- });
204
- ```
205
- #### Default Visibility
206
- Bored of writing the same visibility rule again and again? Use defaultVisibility. This is the default-rule and will be overwritten by feature.visibility() - rules.
207
- ``` javascript
208
- feature.defaultVisibility(function(rule){
209
- return true;
210
- });
211
-
212
- feature.visibility('feature2', 'new', function(rule){
213
- return false;
214
- });
215
- /*
216
- "Feature2", variant "new" is overwritten, all other features have the defaultVisibility
217
- api.isVisible('feature1') -> return true
218
- api.isVisible('feature2') -> return true
219
- api.isVisible('feature2','new') -> return false
220
- api.isVisible('feature2','old') -> return true
221
- api.isVisible('feature2','grumpfel') -> return true
222
- */
223
- ```
224
- You already want to initialize it in the constructor? No Problem.
225
- ```javascript
226
- var api = new featuretoggleapi({
227
- _default: true, //default visibility always returns true; again: this could also be a function
228
- });
229
- ```
230
-
231
- #### Required Visibility
232
- This rule is always executed, before the other rules. When it returns false, the other rules are ignored.
233
- ``` javascript
234
- /*
235
- Imagine a config that is loaded via ajax. When the name is in the config, it returns true.
236
- And this config looks like this:
237
- var globalConfig = { "feature2" : true }
238
- */
239
-
240
- feature.requiredVisibility(function(rule){
241
- //In this case it returns true, when name == 'feture2'
242
- return globalConfig[rule.name] === true;
243
- });
244
-
245
- /*
246
- feature2, variant "new" returns false, but requiredConfig returns true. Both rules must match, so it will be hidden
247
- */
248
- feature.visibility('feature2','new',function(rule){
249
- return false;
250
- });
251
-
252
- /*
253
- feature3 returns true, but requiredConfig returns false. Both rules must match, so Feature3 is hidden
254
- */
255
- feature.visibility('feature3',function(rule){
256
- return true;
257
- });
258
-
259
- /*
260
- api.isVisible('feature2') -> return true
261
- api.isVisible('feature2','new') -> return false
262
- api.isVisible('feature2','old') -> return true
263
- api.isVisible('feature2','grumpfel') -> return true
264
-
265
- api.isVisible('feature3','new') -> return false
266
- api.isVisible('feature3','old') -> return false
267
- */
268
- ```
269
- You already want to initialize it in the constructor? No Problem.
270
- ```javascript
271
- var api = new featuretoggleapi({
272
- _required: true, //default visibility always returns true; again: this could also be a function
273
- });
274
- ```
275
-
276
- #### Function isVisible
277
- Example for this function:
278
- ```javascript
279
- // prooves if feature2 is visible
280
- var isVisible = feature.isVisible('feature2');
281
-
282
- // prooves if tag feature "feature2", variant "new" is visible
283
- var isVisible_new = feature.isVisible('feature2','new');
284
-
285
- // prooves if tag feature "feature2", variant "new" with data "grumpfl" is visible
286
- var isVisible_data = feature.isVisible('feature2','new','grumpfl');
287
-
288
- // prooves if tag feature "feature2" with data "grumpfl" is visible
289
- var isVisible_data_onlyname = feature.isVisible('feature2',null,'grumpfl');
290
- ```
291
-
292
- #### Function setData
293
- if you want to update the data without updating the whole visibilityrule, use the setData-Function.
294
- ```javascript
295
- api.setData('featurename','variantname','anydata'); //will set the data for featurename#variantnam -> anydata
296
- //or
297
- api.setData('featurename','anydata2'); // will set the data for featurename -> anydata2
298
-
299
- //api.setData() calls the listener.
300
- api.on('visibilityrule', function (rule) {
301
- console.log(rule.data);
302
- });
303
-
304
- api.visibility('feature', 'variant','gruempfel',true); // logs 'gruempfel'
305
- api.setData('feature','variant','newgruempfel'); // logs 'newgruempfel'
306
- api.visibility('feature2', null,'gruempfel2',true); // logs 'gruempfel2'
307
- api.setData('feature2','newgruempfel2'); // logs 'newgruempfel2'
308
- ```
309
-
310
- #### Listeners
311
- If you want to 'watch' every initialisation of a visibility rule, you can append a watcher on it.
312
- ```javascript
313
- var api = new featureToggleApi({feature: true});
314
- api.visibility("feature2","variant","data",true);
315
-
316
- //Calling the listener will also regard already added visibility rules
317
- //The result:
318
- //true, 'feature', undefined, undefined
319
- //true, 'feature2, 'variant', "data"
320
- api.on('visibilityrule', function (event) {
321
- console.log(event.result+","+event.name+","+event.variant+","+event.data);
322
- })
323
- ```
324
-
325
- You can also add custom events and triggers whenever you want.
326
- ```javascript
327
- var api = new featureToggleApi();
328
- api.on('customevent', function (param) {
329
- console.log("customevent " + param);
330
- });
331
-
332
- api.trigger('customevent','fired');
333
- //logs "customevent fired"
334
- ```
335
-
336
- #### Plugins
337
- You can add more functionality to the feature-toggle-api with plugins. Imagine you want an api that watches url-parameters - then you can add a plugin that implemented this logic. Or (if it does not exist) write a custom one.
338
-
339
- ##### Use existing plugins
340
- The feature toggle api already implemented some Plugins that can be used without installing other packages.
341
- Some plugins are included within this package:
342
-
343
- ###### HTML-Plugin
344
- You can use the api with <feature> tags
345
- ```html
346
- <feature name="feature1">
347
- <!-- Will be shown because feature1 is visible -->
348
- </feature>
349
- ```
350
- [Read more about this plugin here.](https://github.com/bassdman/feature-toggle-api/blob/master/src/plugins/htmlplugin/readme.md)
351
-
352
- ###### URL-Plugin
353
- The api sets the features according to the url-parameters.
354
-
355
- Example:
356
- URL: https://anydomain.de?feature1=true&feature2=false
357
- -> sets feature1=true and feature2=false
358
-
359
- [Read more about this plugin here.](https://github.com/bassdman/feature-toggle-api/blob/master/src/plugins/urlplugin/readme.md)
360
-
361
-
362
- ##### Write a custom plugin
363
- A plugin is just a function with a parameter. You can add it with the .addPlugin()-Function.
364
- Calling addPlugin() prevents you from from adding a plugin multiple times, so if you do this, the plugin will only be executed once.
365
- ```javascript
366
- function customFunctionPlugin(api){
367
- //adds function customFunction to your api
368
- api.customFunction = function(){console.log('custom function created')}
369
- }
370
-
371
- //1st option: via constructor
372
- //Important: don't forget the _ in the property _plugins!!!
373
- const api = featuretoggleapi({_plugins:[customFunctionPlugin]});
374
-
375
- //2nd option: via function
376
- api.addPlugin(customFunctionPlugin);
377
-
378
- //-> now api.customFunction() logs "custom function created"
379
- ```
380
-
381
- Here's the way, how to add parameters to your plugin
382
- ```javascript
383
- function pluginWithParams(param1)
384
- {
385
- return function (api){
386
- //adds function customFunction to your api
387
- api.customFunction = function(){console.log('Hello ' + param1)}
388
- }
389
- }
390
-
391
- //1st option: via constructor
392
- //Important: don't forget the _ in the property _plugins!!!
393
- const api = featuretoggleapi({_plugins:[pluginWithParams('Peter')]});
394
-
395
- //2nd option: via function
396
- api.addPlugin(pluginWithParams('Peter'));
397
-
398
- //-> now api.customFunction() logs "Hello Peter"
399
- ```
400
-
401
- #### ShowLogs
402
- Imagine this following html-snippet:
403
- ```javascript
404
- /* Why is this ******* feature hidden? I checked the visibilityrule. It should be visible... */
405
- api.isVisible('anamazingFeature') //returns false, but should return true... wtf???
406
- ```
407
- 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.
408
- ```javascript
409
- feature.showLogs(); //or feature.showLogs(true);
410
- ```
411
- This returns a log like the following:
412
- ```html
413
- Check Visibility of Feature "anAmazingFeature".
414
- The requiredVisibility rule returns false. This feature will be hidden.
415
-
416
- Check Visibility of Feature "anotherAmazingFeature", variant "new" with data {"id":"bla"}.
417
- The requiredVisibility rule returns true. This feature will be shown when no other rule rejects it.
418
- No visibility rule found matching name and variant.
419
- No rules found for name anotherAmazingFeature without variants.
420
- No default rule found.
421
- Only the requiredVisibility rule was found. This returned true. => This feature will be visible.
422
- ```
423
- With this you don't have to waste your time with debugging the visibility state.
424
-
425
-
426
- ## API-Description
427
- ### Constructor
428
- - 1 paramter; must be an object; optional;
429
- - all parameters _not_ starting with an _ are visibilityrules
430
- - all parameters starting with an _ are _not_ visibilityrules, but configuration for the api
431
- - possible configuration settings:
432
- - _plugins: Adds a plugin; Array of functions; optional
433
-
434
- ```javascript
435
- //initializes a visibilityrule and adds a plugin
436
- var api = new featuretoggleapi({
437
- feature1: true,
438
- _plugins: []
439
- })
440
- ```
441
-
442
- ### Visibility
443
- Adds a visibility rule.
444
-
445
- Parameters:
446
- - name: name of the feature; required; type string
447
- - variant: variant of the feature; optional; type string
448
- - data: corresp. data for the feature; optional; type any
449
- - result: result for this feature; required; boolean or function that returns boolean
450
-
451
- Returns:
452
- nothing
453
- ```javascript
454
- //possible parameters
455
- api.visibility(name,result);
456
- api.visibility(name,variant,result);
457
- api.visibility(name,variant,data,result);
458
- ```
459
- Example:
460
- ```javascript
461
- //possible parameters
462
- api.visibility('name',true);
463
- api.visibility('name','variant',true);
464
- api.visibility('name','variant','data',true);
465
-
466
- //if result is a function
467
- api.visibility('name',function(rule){
468
- /*
469
- rule has the following parameters
470
- name: Name of the feature,
471
- variant: Variant: Variant of the feature
472
- data: Data of the feature
473
- }
474
- */
475
- return true
476
- });
477
- ```
478
-
479
- ### isVisible
480
- Prooves if a function is visible.
481
-
482
- Parameters:
483
- - name: name of the feature; required; type string
484
- - variant: variant of the feature; optional; type string
485
- - data: corresp. data for the feature; optional; type any
486
-
487
- Returns:
488
- boolean: weather the feature is visible or not
489
-
490
- ```javascript
491
- //possible parameters
492
- api.isVisible(name);
493
- api.isVisible(name,variant);
494
- api.isVisible(name,variant,data);
495
- ```
496
-
497
- ### on
498
- A listener that is executed, everytime a function visibility rule is added or changed. Is also executed for rules that are passed via constructor.
499
-
500
- Parameters:
501
- - eventname: name of event; required; type string;
502
- - eventfunction: function that is executed when a rule changes; required; type function
503
-
504
- Events:
505
- - visibilityrule: executed, everytime a function visibility rule is added or changed. Is also executed for rules that are passed via constructor.
506
-
507
- Returns
508
- Nothing
509
-
510
- ```javascript
511
- api.on('visibilityrule', function (event) {
512
- /*
513
- Parameters:
514
- event.name,
515
- event.variant,
516
- event.data,
517
- event.result
518
- */
519
- })
520
- ```
521
-
522
- ### trigger
523
- triggers an Event
524
- Parameters:
525
- - eventname: name of event; required; type string;
526
- - parameter: optional; will be passed to the event as 1st parameter
527
-
528
- Returns
529
- Nothing
530
-
531
- ```javascript
532
- api.on('eventname', function (event) {
533
- console.log('doSth');
534
- })
535
- api.trigger('eventname'); //triggers event eventname
536
- api.trigger('eventname','parameter');
537
- ```
538
-
539
- ### setData
540
- Sets the data for the corresp. feature;
541
- Also triggers listener "visibilityrule".
542
-
543
- Parameters:
544
- - name: name of the feature; required; type string
545
- - variant: variant of the feature; optional; type string
546
- - data: corresp. data for the feature; required; type any
547
-
548
- Returns
549
- nothing
550
-
551
- ```javascript
552
- api.setData(name,data);
553
- api.setData(name,variant,data);
554
- ```
555
-
556
- ### requiredVisibility
557
- Sets the function for the required visibility.
558
-
559
- Parameters:
560
- - requiredVisibilityFunction
561
-
562
- Returns:
563
- - nothing
564
-
565
- ```javascript
566
- //possible parameters
567
- api.requiredVisibility(function(rule){
568
- //do sth
569
- /* Parameters:
570
- event.name,
571
- event.variant,
572
- event.data,
573
- */
574
- });
575
- ```
576
-
577
- ### defaultVisibility
578
- Sets the function for the default visibility.
579
-
580
- Parameters:
581
- - defaultVisibilityFunction
582
-
583
- Returns:
584
- - nothing
585
-
586
- ```javascript
587
- //possible parameters
588
- api.defaultVisibility(function(rule){
589
- //do sth
590
- /* Parameters:
591
- event.name,
592
- event.variant,
593
- event.data,
594
- */
595
- });
596
- ```
597
-
598
- ### addPlugin
599
- Adds a plugin to the api. A plugin will only be executed once, even if the function is called multiple times.
600
-
601
- Parameters:
602
- - plugin: required -> adds a plugin to the api
603
-
604
- Returns:
605
- - nothing
606
-
607
- ```javascript
608
- api.addPlugin(plugin);
609
- ```
610
-
611
- ### showLogs
612
- Shows the Logs of a visibilityrule when function is called or listener is triggered.
613
-
614
- Parameters:
615
- - showLogs: should logs be shown or not?; optional; type boolean; default: true
616
-
617
- Returns
618
- nothing
619
-
620
- ```javascript
621
- api.showLogs();
622
- //is the same as
623
- api.showLogs(true);
624
- ```
625
-
626
- ## License
627
- <a href="https://opensource.org/licenses/MIT">MIT</a>.
628
- Copyright (c) 2018 Manuel Gelsen