feature-toggle-api 3.4.0 → 3.4.2
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/feature-toggle-api.js +10 -40
- package/feature-toggle-api.min.js +1 -1
- package/feature-toggle-api.module.js +10 -40
- package/gulpfile.js +0 -10
- package/package.json +15 -11
- package/plugin-html.js +1 -1
- package/plugin-url.js +1 -1
package/feature-toggle-api.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
4
|
-
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
5
4
|
var parseToFn = function parseToFn(fnOrBool) {
|
|
6
5
|
if (typeof fnOrBool == 'boolean') return function () {
|
|
7
6
|
return fnOrBool;
|
|
8
7
|
};
|
|
9
8
|
return fnOrBool;
|
|
10
9
|
};
|
|
11
|
-
|
|
12
10
|
var getKey = function getKey(name, variant) {
|
|
13
11
|
var _name = name.toLowerCase();
|
|
14
|
-
|
|
15
12
|
if (typeof variant == 'string') {
|
|
16
13
|
_name += "#" + variant.toLowerCase();
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
return _name;
|
|
20
16
|
};
|
|
21
|
-
|
|
22
17
|
function initVisibilities() {
|
|
23
18
|
var visibilities = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
19
|
var returnVisibilities = {};
|
|
@@ -28,7 +23,6 @@ function initVisibilities() {
|
|
|
28
23
|
});
|
|
29
24
|
return returnVisibilities;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
function featuretoggleapi() {
|
|
33
27
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
34
28
|
var globals = {
|
|
@@ -38,47 +32,38 @@ function featuretoggleapi() {
|
|
|
38
32
|
showLogs: false,
|
|
39
33
|
usedPlugins: []
|
|
40
34
|
};
|
|
41
|
-
|
|
42
35
|
function init(api) {
|
|
43
36
|
if (config._plugins) {
|
|
44
37
|
if (!Array.isArray(config._plugins)) throw new Error('featuretoggleapi()-constructor: config.plugins must be an array.');
|
|
45
|
-
|
|
46
38
|
config._plugins.forEach(function (plugin) {
|
|
47
39
|
if (typeof plugin !== 'function') throw new Error('featuretoggleapi()-constructor: config.plugins needs functions as entries, not ' + _typeof(plugin) + '.');
|
|
48
|
-
|
|
49
40
|
_addPlugin(plugin, api);
|
|
50
41
|
});
|
|
51
42
|
}
|
|
52
|
-
|
|
53
43
|
triggerEvent('init');
|
|
54
44
|
}
|
|
55
|
-
|
|
56
45
|
function _addPlugin(plugin, api) {
|
|
57
46
|
plugin(api);
|
|
58
47
|
}
|
|
59
|
-
|
|
60
48
|
function triggerEvent(eventtype, param) {
|
|
61
49
|
(globals.listeners[eventtype] || []).forEach(function (listener) {
|
|
62
50
|
listener(param);
|
|
63
51
|
});
|
|
64
52
|
}
|
|
65
|
-
|
|
66
53
|
var log = function log(message) {
|
|
67
|
-
if (!globals.showLogs) return;
|
|
68
|
-
//die styletags raus
|
|
54
|
+
if (!globals.showLogs) return;
|
|
69
55
|
|
|
56
|
+
//Nur Browser können Syntaxhighlighting die anderen geben die Nachricht einfach aus und schneiden
|
|
57
|
+
//die styletags raus
|
|
70
58
|
if (typeof window === 'undefined') {
|
|
71
59
|
var loggedMessage = message.replace(/<b>/g, "");
|
|
72
60
|
console.log(loggedMessage);
|
|
73
61
|
return;
|
|
74
62
|
}
|
|
75
|
-
|
|
76
63
|
var hasBoldTag = message.indexOf('<b>') != -1;
|
|
77
64
|
var hasVisibleKeyword = message.indexOf('visible') != -1;
|
|
78
65
|
var hasHiddenKeyword = message.indexOf('hidden') != -1;
|
|
79
|
-
|
|
80
66
|
var _message = message.replace('visible', '%cvisible');
|
|
81
|
-
|
|
82
67
|
_message = _message.replace('hidden', '%chidden');
|
|
83
68
|
if (hasVisibleKeyword) console.log(_message, "color:green;font-weight:bold;");else if (hasHiddenKeyword) console.log(_message, "color:red;font-weight:bold;");else if (hasBoldTag) {
|
|
84
69
|
_message = _message.replace('<b>', '%c');
|
|
@@ -86,13 +71,11 @@ function featuretoggleapi() {
|
|
|
86
71
|
console.log.apply(null, parts);
|
|
87
72
|
} else console.log(message);
|
|
88
73
|
};
|
|
89
|
-
|
|
90
74
|
var logAndReturn = function logAndReturn(returnValue, message) {
|
|
91
75
|
log(message);
|
|
92
76
|
log('');
|
|
93
77
|
return returnValue;
|
|
94
78
|
};
|
|
95
|
-
|
|
96
79
|
var getVisibility = function getVisibility(visibilityFn, functionname, name, variant, data) {
|
|
97
80
|
if (visibilityFn == null) return undefined;
|
|
98
81
|
var calculatedVisibility = visibilityFn({
|
|
@@ -100,14 +83,11 @@ function featuretoggleapi() {
|
|
|
100
83
|
variant: variant,
|
|
101
84
|
data: data
|
|
102
85
|
});
|
|
103
|
-
|
|
104
86
|
if (typeof calculatedVisibility == 'boolean') {
|
|
105
87
|
return calculatedVisibility;
|
|
106
88
|
}
|
|
107
|
-
|
|
108
89
|
return logAndReturn(false, "The ".concat(functionname, " returns ").concat(calculatedVisibility, ". => Please return true or false. This result (and all non-boolean results) will return false."));
|
|
109
90
|
};
|
|
110
|
-
|
|
111
91
|
function parseKey(key) {
|
|
112
92
|
var parts = key.split('#');
|
|
113
93
|
return {
|
|
@@ -116,6 +96,7 @@ function featuretoggleapi() {
|
|
|
116
96
|
data: globals.datas[key]
|
|
117
97
|
};
|
|
118
98
|
}
|
|
99
|
+
|
|
119
100
|
/*
|
|
120
101
|
the following calls are possible:
|
|
121
102
|
visibility(name,result);
|
|
@@ -128,17 +109,14 @@ function featuretoggleapi() {
|
|
|
128
109
|
param3: result || data
|
|
129
110
|
param4: result
|
|
130
111
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
112
|
function visibilityFnParams(param1, param2, param3, param4) {
|
|
134
113
|
//name must always be set
|
|
135
114
|
if (param1 == undefined) throw new Error('feature.visibility(): 1st parameter name must be defined');
|
|
136
115
|
if (arguments.length == 1) throw new Error('feature.visibility(): 2nd parameter name must be a boolean or function, but is empty');
|
|
137
116
|
var name = param1,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
117
|
+
variant = null,
|
|
118
|
+
data = null,
|
|
119
|
+
result = null;
|
|
142
120
|
if (param3 == undefined && param4 == undefined) {
|
|
143
121
|
result = param2;
|
|
144
122
|
} else if (param4 == undefined) {
|
|
@@ -149,7 +127,6 @@ function featuretoggleapi() {
|
|
|
149
127
|
data = param3;
|
|
150
128
|
result = param4;
|
|
151
129
|
}
|
|
152
|
-
|
|
153
130
|
return {
|
|
154
131
|
name: name,
|
|
155
132
|
variant: variant,
|
|
@@ -157,7 +134,6 @@ function featuretoggleapi() {
|
|
|
157
134
|
result: result
|
|
158
135
|
};
|
|
159
136
|
}
|
|
160
|
-
|
|
161
137
|
function getEvent(name, variant, data, result) {
|
|
162
138
|
var event;
|
|
163
139
|
event = {
|
|
@@ -177,7 +153,6 @@ function featuretoggleapi() {
|
|
|
177
153
|
});
|
|
178
154
|
return event;
|
|
179
155
|
}
|
|
180
|
-
|
|
181
156
|
function isVisible(name, variant, data) {
|
|
182
157
|
var visibilities = globals.visibilities;
|
|
183
158
|
log("\nCheck Visibility of <b>Feature \"".concat(name, "\", variant \"").concat(variant == undefined ? '' : variant, "\"").concat(data ? " with data " + JSON.stringify(data) : "", "."));
|
|
@@ -192,7 +167,7 @@ function featuretoggleapi() {
|
|
|
192
167
|
var variantExists = variant != null;
|
|
193
168
|
var visibilityOnlyNameFnKey = getKey(name, null);
|
|
194
169
|
var visibilityOnlyNameFn = visibilities[visibilityOnlyNameFnKey];
|
|
195
|
-
|
|
170
|
+
visibilities[visibilityOnlyNameFnKey] != null;
|
|
196
171
|
var visibilityOnlyNameFnResult = getVisibility(visibilityOnlyNameFn, 'visibility function (only name)', name, variant, data);
|
|
197
172
|
var defaultFn = visibilities['_default'];
|
|
198
173
|
var defaultFnExists = visibilities['_default'] != null;
|
|
@@ -206,7 +181,6 @@ function featuretoggleapi() {
|
|
|
206
181
|
if (requiredFnExists) return logAndReturn(true, "Only the requiredVisibility rule was found. This returned true. => This feature will be visible.");
|
|
207
182
|
return logAndReturn(false, 'No rules were found. This feature will be hidden.');
|
|
208
183
|
}
|
|
209
|
-
|
|
210
184
|
var api = {
|
|
211
185
|
name: 'feature-toggle-api',
|
|
212
186
|
setData: function setData(nameParam, variantOrDataParam, dataParam) {
|
|
@@ -225,7 +199,7 @@ function featuretoggleapi() {
|
|
|
225
199
|
});
|
|
226
200
|
if (config != undefined && config.ignorePreviousRules) return;
|
|
227
201
|
Object.keys(globals.visibilities).forEach(function (key) {
|
|
228
|
-
var event = parseKey(key
|
|
202
|
+
var event = parseKey(key);
|
|
229
203
|
var rule = globals.visibilities[key];
|
|
230
204
|
event.result = rule(event);
|
|
231
205
|
fn(event);
|
|
@@ -236,7 +210,6 @@ function featuretoggleapi() {
|
|
|
236
210
|
globals.showLogs = _showLogs == undefined ? true : _showLogs;
|
|
237
211
|
},
|
|
238
212
|
isVisible: isVisible,
|
|
239
|
-
|
|
240
213
|
/*
|
|
241
214
|
the following function calls are possible:
|
|
242
215
|
visibility(name,result);
|
|
@@ -260,14 +233,11 @@ function featuretoggleapi() {
|
|
|
260
233
|
},
|
|
261
234
|
addPlugin: function addPlugin(plugin) {
|
|
262
235
|
if (globals.usedPlugins.includes(plugin)) return;
|
|
263
|
-
|
|
264
236
|
_addPlugin(plugin, api);
|
|
265
|
-
|
|
266
237
|
globals.usedPlugins.push(plugin);
|
|
267
238
|
}
|
|
268
239
|
};
|
|
269
240
|
init(api);
|
|
270
241
|
return api;
|
|
271
242
|
}
|
|
272
|
-
|
|
273
243
|
window.featureToggleApi = featuretoggleapi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function _typeof(
|
|
1
|
+
"use strict";function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}var parseToFn=function parseToFn(fnOrBool){if(typeof fnOrBool=="boolean")return function(){return fnOrBool};return fnOrBool};var getKey=function getKey(name,variant){var _name=name.toLowerCase();if(typeof variant=="string"){_name+="#"+variant.toLowerCase()}return _name};function initVisibilities(){var visibilities=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var returnVisibilities={};Object.keys(visibilities).forEach(function(key){if(key.startsWith("_"))return;returnVisibilities[getKey(key)]=parseToFn(visibilities[key])});return returnVisibilities}function featuretoggleapi(){var config=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var globals={datas:{},listeners:{},visibilities:initVisibilities(config),showLogs:false,usedPlugins:[]};function init(api){if(config._plugins){if(!Array.isArray(config._plugins))throw new Error("featuretoggleapi()-constructor: config.plugins must be an array.");config._plugins.forEach(function(plugin){if(typeof plugin!=="function")throw new Error("featuretoggleapi()-constructor: config.plugins needs functions as entries, not "+_typeof(plugin)+".");_addPlugin(plugin,api)})}triggerEvent("init")}function _addPlugin(plugin,api){plugin(api)}function triggerEvent(eventtype,param){(globals.listeners[eventtype]||[]).forEach(function(listener){listener(param)})}var log=function log(message){if(!globals.showLogs)return;if(typeof window==="undefined"){var loggedMessage=message.replace(/<b>/g,"");console.log(loggedMessage);return}var hasBoldTag=message.indexOf("<b>")!=-1;var hasVisibleKeyword=message.indexOf("visible")!=-1;var hasHiddenKeyword=message.indexOf("hidden")!=-1;var _message=message.replace("visible","%cvisible");_message=_message.replace("hidden","%chidden");if(hasVisibleKeyword)console.log(_message,"color:green;font-weight:bold;");else if(hasHiddenKeyword)console.log(_message,"color:red;font-weight:bold;");else if(hasBoldTag){_message=_message.replace("<b>","%c");var parts=[_message,"font-weight:bold;"];console.log.apply(null,parts)}else console.log(message)};var logAndReturn=function logAndReturn(returnValue,message){log(message);log("");return returnValue};var getVisibility=function getVisibility(visibilityFn,functionname,name,variant,data){if(visibilityFn==null)return undefined;var calculatedVisibility=visibilityFn({name:name,variant:variant,data:data});if(typeof calculatedVisibility=="boolean"){return calculatedVisibility}return logAndReturn(false,"The ".concat(functionname," returns ").concat(calculatedVisibility,". => Please return true or false. This result (and all non-boolean results) will return false."))};function parseKey(key){var parts=key.split("#");return{name:parts[0],variant:parts.length>1?parts[1]:undefined,data:globals.datas[key]}}function visibilityFnParams(param1,param2,param3,param4){if(param1==undefined)throw new Error("feature.visibility(): 1st parameter name must be defined");if(arguments.length==1)throw new Error("feature.visibility(): 2nd parameter name must be a boolean or function, but is empty");var name=param1,variant=null,data=null,result=null;if(param3==undefined&¶m4==undefined){result=param2}else if(param4==undefined){variant=param2;result=param3}else{variant=param2;data=param3;result=param4}return{name:name,variant:variant,data:data,result:result}}function getEvent(name,variant,data,result){var event;event={name:name,variant:variant,data:data};event.key=getKey(event.name,event.variant);if(result==null)return event;event.visibilityFunction=parseToFn(result);event.result=event.visibilityFunction({name:event.name,variant:event.variant,data:event.data||{},_internalCall:true,description:"When attaching a function, the result must be calculated internally. You can filter this out with the _internalCall:true -Flag."});return event}function isVisible(name,variant,data){var visibilities=globals.visibilities;log('\nCheck Visibility of <b>Feature "'.concat(name,'", variant "').concat(variant==undefined?"":variant,'"').concat(data?" with data "+JSON.stringify(data):"","."));if(name==undefined)throw new Error('The attribute "name" is required for tag <feature></feature>. Example: <feature name="aname"></feature>');var requiredFn=visibilities["_required"];var requiredFnExists=visibilities["_required"]!=null;var requiredFnResult=getVisibility(requiredFn,"requiredVisibility",name,variant,data);var visibilityFnKey=getKey(name,variant);var visibilityFn=visibilities[visibilityFnKey];var visibilityFnExists=visibilities[visibilityFnKey]!=null;var visibilityFnResult=getVisibility(visibilityFn,"visibility function",name,variant,data);var variantExists=variant!=null;var visibilityOnlyNameFnKey=getKey(name,null);var visibilityOnlyNameFn=visibilities[visibilityOnlyNameFnKey];visibilities[visibilityOnlyNameFnKey]!=null;var visibilityOnlyNameFnResult=getVisibility(visibilityOnlyNameFn,"visibility function (only name)",name,variant,data);var defaultFn=visibilities["_default"];var defaultFnExists=visibilities["_default"]!=null;var defaultFnResult=getVisibility(defaultFn,"defaultVisibility",name,variant,data);if(!requiredFnExists)log("No requiredVisibility rule specified for this feature.");else if(requiredFnExists&&requiredFnResult===true)log("The requiredVisibility rule returns true. This feature will be shown when no other rule rejects it.");else if(requiredFnExists&&requiredFnResult===false)return logAndReturn(false,"The requiredVisibility rule returns false. This feature will be hidden.");if(visibilityFnExists)return logAndReturn(visibilityFnResult,"The visibility rule returns ".concat(visibilityFnResult,". This feature will be ").concat(visibilityFnResult?"visible":"hidden","."));log("No visibility rule found matching name and variant.");if(variantExists&&typeof visibilityOnlyNameFnResult=="boolean")return logAndReturn(visibilityOnlyNameFnResult,"Found a visibility rule for name ".concat(name," without variants. The rule returns ").concat(visibilityOnlyNameFnResult,". => This feature will be ").concat(visibilityOnlyNameFnResult?"visible":"hidden","."));else if(variantExists)log("No rules found for name ".concat(name," without variants."));if(defaultFnExists)return logAndReturn(defaultFnResult,"Found a defaultVisibility rule. The rule returns ".concat(defaultFnResult,". => This feature will be ").concat(defaultFnResult?"visible":"hidden","."));log("No default rule found.");if(requiredFnExists)return logAndReturn(true,"Only the requiredVisibility rule was found. This returned true. => This feature will be visible.");return logAndReturn(false,"No rules were found. This feature will be hidden.")}var api={name:"feature-toggle-api",setData:function setData(nameParam,variantOrDataParam,dataParam){if(nameParam==undefined)throw new Error("setData(): The name must of the feature must be defined, but ist undefined");var variant=dataParam!=undefined?variantOrDataParam:undefined;var data=dataParam||variantOrDataParam;var event=getEvent(nameParam,variant,data);globals.datas[event.key]=event.data;triggerEvent("visibilityrule",event)},on:function on(eventtype,fn,config){globals.listeners[eventtype]=globals.listeners[eventtype]||[];globals.listeners[eventtype].push(fn);triggerEvent("registerEvent",{type:eventtype});if(config!=undefined&&config.ignorePreviousRules)return;Object.keys(globals.visibilities).forEach(function(key){var event=parseKey(key);var rule=globals.visibilities[key];event.result=rule(event);fn(event)})},trigger:triggerEvent,showLogs:function showLogs(_showLogs){globals.showLogs=_showLogs==undefined?true:_showLogs},isVisible:isVisible,visibility:function visibility(param1,param2,param3,param4){var params=visibilityFnParams(param1,param2,param3,param4);var event=getEvent(params.name,params.variant,params.data,params.result);globals.visibilities[event.key]=event.visibilityFunction;globals.datas[event.key]=event.data;triggerEvent("visibilityrule",event)},requiredVisibility:function requiredVisibility(fn){if(typeof fn!="function")throw new Error("feature.requiredVisibility(): 1st parameter must be a function, but is "+_typeof(fn));globals.visibilities["_required"]=parseToFn(fn)},defaultVisibility:function defaultVisibility(fn){if(typeof fn!="function")throw new Error("feature.defaultVisibility(): 1st parameter must be a function, but is "+_typeof(fn));globals.visibilities["_default"]=parseToFn(fn)},addPlugin:function addPlugin(plugin){if(globals.usedPlugins.includes(plugin))return;_addPlugin(plugin,api);globals.usedPlugins.push(plugin)}};init(api);return api}window.featureToggleApi=featuretoggleapi;
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
4
|
-
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
5
4
|
var parseToFn = function parseToFn(fnOrBool) {
|
|
6
5
|
if (typeof fnOrBool == 'boolean') return function () {
|
|
7
6
|
return fnOrBool;
|
|
8
7
|
};
|
|
9
8
|
return fnOrBool;
|
|
10
9
|
};
|
|
11
|
-
|
|
12
10
|
var getKey = function getKey(name, variant) {
|
|
13
11
|
var _name = name.toLowerCase();
|
|
14
|
-
|
|
15
12
|
if (typeof variant == 'string') {
|
|
16
13
|
_name += "#" + variant.toLowerCase();
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
return _name;
|
|
20
16
|
};
|
|
21
|
-
|
|
22
17
|
function initVisibilities() {
|
|
23
18
|
var visibilities = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
19
|
var returnVisibilities = {};
|
|
@@ -28,7 +23,6 @@ function initVisibilities() {
|
|
|
28
23
|
});
|
|
29
24
|
return returnVisibilities;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
function featuretoggleapi() {
|
|
33
27
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
34
28
|
var globals = {
|
|
@@ -38,47 +32,38 @@ function featuretoggleapi() {
|
|
|
38
32
|
showLogs: false,
|
|
39
33
|
usedPlugins: []
|
|
40
34
|
};
|
|
41
|
-
|
|
42
35
|
function init(api) {
|
|
43
36
|
if (config._plugins) {
|
|
44
37
|
if (!Array.isArray(config._plugins)) throw new Error('featuretoggleapi()-constructor: config.plugins must be an array.');
|
|
45
|
-
|
|
46
38
|
config._plugins.forEach(function (plugin) {
|
|
47
39
|
if (typeof plugin !== 'function') throw new Error('featuretoggleapi()-constructor: config.plugins needs functions as entries, not ' + _typeof(plugin) + '.');
|
|
48
|
-
|
|
49
40
|
_addPlugin(plugin, api);
|
|
50
41
|
});
|
|
51
42
|
}
|
|
52
|
-
|
|
53
43
|
triggerEvent('init');
|
|
54
44
|
}
|
|
55
|
-
|
|
56
45
|
function _addPlugin(plugin, api) {
|
|
57
46
|
plugin(api);
|
|
58
47
|
}
|
|
59
|
-
|
|
60
48
|
function triggerEvent(eventtype, param) {
|
|
61
49
|
(globals.listeners[eventtype] || []).forEach(function (listener) {
|
|
62
50
|
listener(param);
|
|
63
51
|
});
|
|
64
52
|
}
|
|
65
|
-
|
|
66
53
|
var log = function log(message) {
|
|
67
|
-
if (!globals.showLogs) return;
|
|
68
|
-
//die styletags raus
|
|
54
|
+
if (!globals.showLogs) return;
|
|
69
55
|
|
|
56
|
+
//Nur Browser können Syntaxhighlighting die anderen geben die Nachricht einfach aus und schneiden
|
|
57
|
+
//die styletags raus
|
|
70
58
|
if (typeof window === 'undefined') {
|
|
71
59
|
var loggedMessage = message.replace(/<b>/g, "");
|
|
72
60
|
console.log(loggedMessage);
|
|
73
61
|
return;
|
|
74
62
|
}
|
|
75
|
-
|
|
76
63
|
var hasBoldTag = message.indexOf('<b>') != -1;
|
|
77
64
|
var hasVisibleKeyword = message.indexOf('visible') != -1;
|
|
78
65
|
var hasHiddenKeyword = message.indexOf('hidden') != -1;
|
|
79
|
-
|
|
80
66
|
var _message = message.replace('visible', '%cvisible');
|
|
81
|
-
|
|
82
67
|
_message = _message.replace('hidden', '%chidden');
|
|
83
68
|
if (hasVisibleKeyword) console.log(_message, "color:green;font-weight:bold;");else if (hasHiddenKeyword) console.log(_message, "color:red;font-weight:bold;");else if (hasBoldTag) {
|
|
84
69
|
_message = _message.replace('<b>', '%c');
|
|
@@ -86,13 +71,11 @@ function featuretoggleapi() {
|
|
|
86
71
|
console.log.apply(null, parts);
|
|
87
72
|
} else console.log(message);
|
|
88
73
|
};
|
|
89
|
-
|
|
90
74
|
var logAndReturn = function logAndReturn(returnValue, message) {
|
|
91
75
|
log(message);
|
|
92
76
|
log('');
|
|
93
77
|
return returnValue;
|
|
94
78
|
};
|
|
95
|
-
|
|
96
79
|
var getVisibility = function getVisibility(visibilityFn, functionname, name, variant, data) {
|
|
97
80
|
if (visibilityFn == null) return undefined;
|
|
98
81
|
var calculatedVisibility = visibilityFn({
|
|
@@ -100,14 +83,11 @@ function featuretoggleapi() {
|
|
|
100
83
|
variant: variant,
|
|
101
84
|
data: data
|
|
102
85
|
});
|
|
103
|
-
|
|
104
86
|
if (typeof calculatedVisibility == 'boolean') {
|
|
105
87
|
return calculatedVisibility;
|
|
106
88
|
}
|
|
107
|
-
|
|
108
89
|
return logAndReturn(false, "The ".concat(functionname, " returns ").concat(calculatedVisibility, ". => Please return true or false. This result (and all non-boolean results) will return false."));
|
|
109
90
|
};
|
|
110
|
-
|
|
111
91
|
function parseKey(key) {
|
|
112
92
|
var parts = key.split('#');
|
|
113
93
|
return {
|
|
@@ -116,6 +96,7 @@ function featuretoggleapi() {
|
|
|
116
96
|
data: globals.datas[key]
|
|
117
97
|
};
|
|
118
98
|
}
|
|
99
|
+
|
|
119
100
|
/*
|
|
120
101
|
the following calls are possible:
|
|
121
102
|
visibility(name,result);
|
|
@@ -128,17 +109,14 @@ function featuretoggleapi() {
|
|
|
128
109
|
param3: result || data
|
|
129
110
|
param4: result
|
|
130
111
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
112
|
function visibilityFnParams(param1, param2, param3, param4) {
|
|
134
113
|
//name must always be set
|
|
135
114
|
if (param1 == undefined) throw new Error('feature.visibility(): 1st parameter name must be defined');
|
|
136
115
|
if (arguments.length == 1) throw new Error('feature.visibility(): 2nd parameter name must be a boolean or function, but is empty');
|
|
137
116
|
var name = param1,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
117
|
+
variant = null,
|
|
118
|
+
data = null,
|
|
119
|
+
result = null;
|
|
142
120
|
if (param3 == undefined && param4 == undefined) {
|
|
143
121
|
result = param2;
|
|
144
122
|
} else if (param4 == undefined) {
|
|
@@ -149,7 +127,6 @@ function featuretoggleapi() {
|
|
|
149
127
|
data = param3;
|
|
150
128
|
result = param4;
|
|
151
129
|
}
|
|
152
|
-
|
|
153
130
|
return {
|
|
154
131
|
name: name,
|
|
155
132
|
variant: variant,
|
|
@@ -157,7 +134,6 @@ function featuretoggleapi() {
|
|
|
157
134
|
result: result
|
|
158
135
|
};
|
|
159
136
|
}
|
|
160
|
-
|
|
161
137
|
function getEvent(name, variant, data, result) {
|
|
162
138
|
var event;
|
|
163
139
|
event = {
|
|
@@ -177,7 +153,6 @@ function featuretoggleapi() {
|
|
|
177
153
|
});
|
|
178
154
|
return event;
|
|
179
155
|
}
|
|
180
|
-
|
|
181
156
|
function isVisible(name, variant, data) {
|
|
182
157
|
var visibilities = globals.visibilities;
|
|
183
158
|
log("\nCheck Visibility of <b>Feature \"".concat(name, "\", variant \"").concat(variant == undefined ? '' : variant, "\"").concat(data ? " with data " + JSON.stringify(data) : "", "."));
|
|
@@ -192,7 +167,7 @@ function featuretoggleapi() {
|
|
|
192
167
|
var variantExists = variant != null;
|
|
193
168
|
var visibilityOnlyNameFnKey = getKey(name, null);
|
|
194
169
|
var visibilityOnlyNameFn = visibilities[visibilityOnlyNameFnKey];
|
|
195
|
-
|
|
170
|
+
visibilities[visibilityOnlyNameFnKey] != null;
|
|
196
171
|
var visibilityOnlyNameFnResult = getVisibility(visibilityOnlyNameFn, 'visibility function (only name)', name, variant, data);
|
|
197
172
|
var defaultFn = visibilities['_default'];
|
|
198
173
|
var defaultFnExists = visibilities['_default'] != null;
|
|
@@ -206,7 +181,6 @@ function featuretoggleapi() {
|
|
|
206
181
|
if (requiredFnExists) return logAndReturn(true, "Only the requiredVisibility rule was found. This returned true. => This feature will be visible.");
|
|
207
182
|
return logAndReturn(false, 'No rules were found. This feature will be hidden.');
|
|
208
183
|
}
|
|
209
|
-
|
|
210
184
|
var api = {
|
|
211
185
|
name: 'feature-toggle-api',
|
|
212
186
|
setData: function setData(nameParam, variantOrDataParam, dataParam) {
|
|
@@ -225,7 +199,7 @@ function featuretoggleapi() {
|
|
|
225
199
|
});
|
|
226
200
|
if (config != undefined && config.ignorePreviousRules) return;
|
|
227
201
|
Object.keys(globals.visibilities).forEach(function (key) {
|
|
228
|
-
var event = parseKey(key
|
|
202
|
+
var event = parseKey(key);
|
|
229
203
|
var rule = globals.visibilities[key];
|
|
230
204
|
event.result = rule(event);
|
|
231
205
|
fn(event);
|
|
@@ -236,7 +210,6 @@ function featuretoggleapi() {
|
|
|
236
210
|
globals.showLogs = _showLogs == undefined ? true : _showLogs;
|
|
237
211
|
},
|
|
238
212
|
isVisible: isVisible,
|
|
239
|
-
|
|
240
213
|
/*
|
|
241
214
|
the following function calls are possible:
|
|
242
215
|
visibility(name,result);
|
|
@@ -260,14 +233,11 @@ function featuretoggleapi() {
|
|
|
260
233
|
},
|
|
261
234
|
addPlugin: function addPlugin(plugin) {
|
|
262
235
|
if (globals.usedPlugins.includes(plugin)) return;
|
|
263
|
-
|
|
264
236
|
_addPlugin(plugin, api);
|
|
265
|
-
|
|
266
237
|
globals.usedPlugins.push(plugin);
|
|
267
238
|
}
|
|
268
239
|
};
|
|
269
240
|
init(api);
|
|
270
241
|
return api;
|
|
271
242
|
}
|
|
272
|
-
|
|
273
243
|
module.exports = featuretoggleapi;
|
package/gulpfile.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const { series, src, dest } = require('gulp');
|
|
2
|
-
const sourcemaps = require('gulp-sourcemaps');
|
|
3
2
|
const concat = require('gulp-concat');
|
|
4
3
|
const uglify = require('gulp-uglify');
|
|
5
4
|
const babel = require('gulp-babel');
|
|
@@ -7,7 +6,6 @@ const rollup = require('gulp-rollup');
|
|
|
7
6
|
|
|
8
7
|
function build_module() {
|
|
9
8
|
return src('src/index.js')
|
|
10
|
-
// .pipe(sourcemaps.init())
|
|
11
9
|
.pipe(rollup({
|
|
12
10
|
// any option supported by Rollup can be set here.
|
|
13
11
|
input: './src/index.js',
|
|
@@ -19,13 +17,11 @@ function build_module() {
|
|
|
19
17
|
presets: ["@babel/preset-env"]
|
|
20
18
|
}))
|
|
21
19
|
.pipe(concat('feature-toggle-api.module.js'))
|
|
22
|
-
// .pipe(sourcemaps.write())
|
|
23
20
|
.pipe(dest('./'));
|
|
24
21
|
};
|
|
25
22
|
|
|
26
23
|
function build_raw() {
|
|
27
24
|
return src('src/*.js')
|
|
28
|
-
// .pipe(sourcemaps.init())
|
|
29
25
|
.pipe(rollup({
|
|
30
26
|
// any option supported by Rollup can be set here.
|
|
31
27
|
input: './src/index.cjs.js',
|
|
@@ -37,13 +33,11 @@ function build_raw() {
|
|
|
37
33
|
presets: ["@babel/preset-env"]
|
|
38
34
|
}))
|
|
39
35
|
.pipe(concat('feature-toggle-api.js'))
|
|
40
|
-
// .pipe(sourcemaps.write())
|
|
41
36
|
.pipe(dest('./'));
|
|
42
37
|
};
|
|
43
38
|
|
|
44
39
|
function build_min() {
|
|
45
40
|
return src('src/*.js')
|
|
46
|
-
// .pipe(sourcemaps.init())
|
|
47
41
|
.pipe(rollup({
|
|
48
42
|
// any option supported by Rollup can be set here.
|
|
49
43
|
input: './src/index.cjs.js',
|
|
@@ -56,19 +50,15 @@ function build_min() {
|
|
|
56
50
|
}))
|
|
57
51
|
.pipe(uglify())
|
|
58
52
|
.pipe(concat('feature-toggle-api.min.js'))
|
|
59
|
-
// .pipe(sourcemaps.write())
|
|
60
53
|
.pipe(dest('./'));
|
|
61
54
|
};
|
|
62
55
|
|
|
63
56
|
function build_plugins() {
|
|
64
57
|
return src(['src/plugins/htmlplugin/plugin-html.js', 'src/plugins/urlplugin/plugin-url.js'])
|
|
65
|
-
// .pipe(sourcemaps.init())
|
|
66
58
|
.pipe(babel({
|
|
67
59
|
presets: ["@babel/preset-env"]
|
|
68
60
|
}))
|
|
69
61
|
.pipe(uglify())
|
|
70
|
-
//.pipe(concat('feature-toggle-api.min.js'))
|
|
71
|
-
// .pipe(sourcemaps.write())
|
|
72
62
|
.pipe(dest('./'));
|
|
73
63
|
};
|
|
74
64
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feature-toggle-api",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2",
|
|
4
4
|
"description": "Gives you advanced feature-toggle for any Framework",
|
|
5
5
|
"main": "feature-toggle-api.module.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"pretest": "
|
|
7
|
+
"pretest": "npm run build",
|
|
8
8
|
"test": "jasmine",
|
|
9
|
-
"build": "
|
|
9
|
+
"build": "npm-run-all build:rollup-* build:babel-files build:minify-*",
|
|
10
|
+
"build:rollup-file1": "rollup src/index.js --file feature-toggle-api.module.js --format cjs",
|
|
11
|
+
"build:rollup-file2": "rollup src/index.cjs.js --file feature-toggle-api.js --format cjs",
|
|
12
|
+
"build:rollup-file3": "rollup src/index.cjs.js --file feature-toggle-api.min.js --format cjs",
|
|
13
|
+
"build:babel-files": "npx babel feature-toggle-api.module.js feature-toggle-api.js feature-toggle-api.min.js src/plugins/htmlplugin/plugin-html.js src/plugins/urlplugin/plugin-url.js --out-dir ./ --presets @babel/preset-env",
|
|
14
|
+
"build:minify-file1": "uglifyjs feature-toggle-api.min.js --output feature-toggle-api.min.js",
|
|
15
|
+
"build:minify-file2": "uglifyjs plugin-html.js --output plugin-html.js --mangle",
|
|
16
|
+
"build:minify-file3": "uglifyjs plugin-url.js --output plugin-url.js --mangle"
|
|
10
17
|
},
|
|
11
18
|
"author": "Manuel Gelsen",
|
|
12
19
|
"license": "MIT",
|
|
@@ -26,15 +33,12 @@
|
|
|
26
33
|
"url": "https://github.com/bassdman/feature-toggle-api.git/issues"
|
|
27
34
|
},
|
|
28
35
|
"devDependencies": {
|
|
36
|
+
"@babel/cli": "^7.16.0",
|
|
29
37
|
"@babel/core": "^7.14.3",
|
|
30
38
|
"@babel/preset-env": "^7.14.4",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"gulp-rollup": "^2.17.0",
|
|
36
|
-
"gulp-sourcemaps": "^2.6.5",
|
|
37
|
-
"gulp-uglify": "^3.0.2",
|
|
38
|
-
"jasmine": "^3.6.1"
|
|
39
|
+
"jasmine": "^3.6.1",
|
|
40
|
+
"npm-run-all": "^4.1.5",
|
|
41
|
+
"rollup": "^2.61.0",
|
|
42
|
+
"uglify-js": "^3.14.4"
|
|
39
43
|
}
|
|
40
44
|
}
|
package/plugin-html.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var defaultparams={renderedTag:"div",featureTagName:"feature",tagAttributeName:"tag",nameAttributeName:"name",variantAttributeName:"variant",dataAttributeName:"data",displayAttributeName:"display",defaultDisplay:"block"};function parseDataAttribute(a){try{return JSON.parse(a)}catch(t){
|
|
1
|
+
"use strict";var defaultparams={renderedTag:"div",featureTagName:"feature",tagAttributeName:"tag",nameAttributeName:"name",variantAttributeName:"variant",dataAttributeName:"data",displayAttributeName:"display",defaultDisplay:"block"};function parseDataAttribute(a){try{return JSON.parse(a)}catch(t){if(!isNaN(parseFloat(a)))return parseFloat(a);return a}}function htmlplugin(){var u=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};u=Object.assign({},defaultparams,u);function o(t,a){var e=t.getAttribute(u.tagAttributeName)||u.renderedTag;var r=Array.from(t.attributes);var n="";r.forEach(function(t){n+=" ".concat(t.nodeName,'="').concat(t.nodeValue.replace(/"/g,"""),'"')});var i=a?t.getAttribute(u.displayAttributeName)||u.defaultDisplay:"none";t.outerHTML="<".concat(e,' style="display:').concat(i,'" _feature="true" ').concat(n,">").concat(t.innerHTML,"</").concat(e,">")}return function(i){var t=window.document.querySelectorAll(u.featureTagName);t.forEach(function(t){o(t,false)});i.on("visibilityrule",function(n){var t="[_feature][".concat(u.nameAttributeName,'="').concat(n.name,'"]');if(n.variant)t+="[".concat(u.variantAttributeName,'="').concat(n.variant,'"]');var a=document.querySelectorAll(t);a.forEach(function(t){var a=t.getAttribute(u.dataAttributeName);var e=parseDataAttribute(a);var r=i.isVisible(n.name,n.variant,e);o(t,r)})});return{name:"htmlplugin"}}}if(typeof window!=="undefined")window.htmlplugin=htmlplugin;if(typeof module!=="undefined")module.exports=htmlplugin;
|
package/plugin-url.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function parseValue(
|
|
1
|
+
"use strict";function parseValue(e){if(e==="true")return true;return false}function getParams(e,r){var i={};if(!e)return[];var n=e.split("?");if(n.length<2)return[];var u=n[1].split("&");u.forEach(function(e){var n=e.split("=");n[0]=r.decodeURIComponent(n[0]);n[1]=parseValue(r.decodeURIComponent(n[1]));i[n[0]]=n[1]!=="undefined"?n[1]:true});return i}function urlplugin(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};if(e.window)window=e.window;e=Object.assign({},{url:window.isMocked?"":window.location.href,prefix:""},e);return function(r){r.url=e.url;var i=getParams(e.url,window);var u=e.prefix;Object.keys(i).forEach(function(e){if(!e.startsWith(u))return;var n=e.replace(u,"");r.visibility(n,i[e])});return{name:"urlplugin"}}}if(typeof window!=="undefined")window.urlplugin=urlplugin;if(typeof module!=="undefined")module.exports=urlplugin;
|