feature-toggle-api 4.1.1 → 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.
- package/README.md +14 -16
- package/dist/feature-toggle.js +227 -385
- package/dist/feature-toggle.js.map +1 -0
- package/dist/featureToggle.d.ts +3 -0
- package/dist/html-plugin.js +42 -0
- package/dist/html-plugin.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/plugins/htmlplugin/plugin-html.d.ts +15 -0
- package/dist/plugins/urlplugin/plugin-url.d.ts +14 -0
- package/{src/types.ts → dist/types.d.ts} +44 -64
- package/dist/url-plugin.js +40 -0
- package/dist/url-plugin.js.map +1 -0
- package/dist/vite.config.d.ts +2 -0
- package/package.json +26 -11
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
- package/dist/feature-toggle.d.ts +0 -130
- package/dist/feature-toggle.min.cjs +0 -2
- package/dist/feature-toggle.min.cjs.map +0 -1
- package/dist/feature-toggle.min.js +0 -2
- package/dist/feature-toggle.min.js.map +0 -1
- package/dist/feature-toggle.umd.min.js +0 -2
- package/dist/feature-toggle.umd.min.js.map +0 -1
- package/dist/html-plugin.umd.min.js +0 -2
- package/dist/html-plugin.umd.min.js.map +0 -1
- package/dist/url-plugin.umd.min.js +0 -2
- package/dist/url-plugin.umd.min.js.map +0 -1
- package/docs/_config.yml +0 -1
- package/docs/example-intro.html +0 -75
- package/docs/example-setup.html +0 -55
- package/docs/example-visibility-basic.html +0 -144
- package/docs/readme.md +0 -628
- package/docs/vue-feature-toggle.min.js +0 -902
- package/examples/01_basic_esmodule.js +0 -10
- package/examples/02_basic_cjsmodule.cjs +0 -6
- package/examples/03_basic_scripttag.html +0 -24
- package/examples/04_example-htmlplugin.html +0 -35
- package/examples/05_example-urlplugin.html +0 -25
- package/examples/06_withListener.html +0 -21
- package/rollup.config.js +0 -107
- package/src/featureToggle.ts +0 -352
- package/src/index.ts +0 -13
- package/src/plugins/htmlplugin/plugin-html.ts +0 -83
- package/src/plugins/htmlplugin/readme.md +0 -221
- package/src/plugins/urlplugin/plugin-url.ts +0 -90
- package/src/plugins/urlplugin/readme.md +0 -92
- package/tests/featuretoggle.test.ts +0 -450
- package/tests/polyfills.ts +0 -20
- package/tsconfig.cjs.json +0 -12
- package/tsconfig.json +0 -12
package/dist/feature-toggle.js
CHANGED
|
@@ -1,397 +1,239 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
//#region src/plugins/urlplugin/plugin-url.ts
|
|
2
|
+
function e() {
|
|
3
|
+
return {
|
|
4
|
+
isMocked: !0,
|
|
5
|
+
decodeURIComponent: function(e) {
|
|
6
|
+
return e;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
8
9
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
return true;
|
|
12
|
-
return false;
|
|
10
|
+
function t(e) {
|
|
11
|
+
return e === "true";
|
|
13
12
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const parts = urlparts[1].split('&');
|
|
23
|
-
parts.forEach(function (part) {
|
|
24
|
-
var pair = part.split('=');
|
|
25
|
-
pair[0] = window.decodeURIComponent(pair[0]);
|
|
26
|
-
pair[1] = parseValue(window.decodeURIComponent(pair[1]));
|
|
27
|
-
params[pair[0]] = (pair[1] !== 'undefined') ?
|
|
28
|
-
pair[1] : true;
|
|
29
|
-
});
|
|
30
|
-
return params;
|
|
13
|
+
function n(e, n) {
|
|
14
|
+
var r = {};
|
|
15
|
+
if (!e) return [];
|
|
16
|
+
var i = e.split("?");
|
|
17
|
+
return i.length < 2 ? [] : (i[1].split("&").forEach(function(e) {
|
|
18
|
+
var i = e.split("=");
|
|
19
|
+
i[0] = n.decodeURIComponent(i[0]), i[1] = t(n.decodeURIComponent(i[1])), r[i[0]] = i[1] === "undefined" || i[1];
|
|
20
|
+
}), r);
|
|
31
21
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Object.keys(urlparams).forEach(key => {
|
|
47
|
-
if (!key.startsWith(prefix))
|
|
48
|
-
return;
|
|
49
|
-
const keyWithoutPrefix = key.replace(prefix, "");
|
|
50
|
-
api.visibility(keyWithoutPrefix, urlparams[key]);
|
|
51
|
-
});
|
|
52
|
-
return { name: 'urlplugin' };
|
|
53
|
-
};
|
|
22
|
+
function r(t = {}) {
|
|
23
|
+
let r;
|
|
24
|
+
return r = t.useMockedWindow ? e() : window, t = Object.assign({}, {
|
|
25
|
+
url: r.isMocked ? "" : r.location.href,
|
|
26
|
+
prefix: ""
|
|
27
|
+
}, t), function(e) {
|
|
28
|
+
e.url = t.url;
|
|
29
|
+
let i = n(t.url, r), a = t.prefix;
|
|
30
|
+
return Object.keys(i).forEach((t) => {
|
|
31
|
+
if (!t.startsWith(a)) return;
|
|
32
|
+
let n = t.replace(a, "");
|
|
33
|
+
e.visibility(n, i[t]);
|
|
34
|
+
}), { name: "urlplugin" };
|
|
35
|
+
};
|
|
54
36
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const defaultparams = {
|
|
67
|
-
renderedTag: 'div',
|
|
68
|
-
featureTagName: 'feature',
|
|
69
|
-
tagAttributeName: 'tag',
|
|
70
|
-
nameAttributeName: 'name',
|
|
71
|
-
variantAttributeName: 'variant',
|
|
72
|
-
dataAttributeName: 'data',
|
|
73
|
-
displayAttributeName: 'display',
|
|
74
|
-
defaultDisplay: 'block',
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/plugins/htmlplugin/plugin-html.ts
|
|
39
|
+
var i = {
|
|
40
|
+
renderedTag: "div",
|
|
41
|
+
featureTagName: "feature",
|
|
42
|
+
tagAttributeName: "tag",
|
|
43
|
+
nameAttributeName: "name",
|
|
44
|
+
variantAttributeName: "variant",
|
|
45
|
+
dataAttributeName: "data",
|
|
46
|
+
displayAttributeName: "display",
|
|
47
|
+
defaultDisplay: "block"
|
|
75
48
|
};
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return parseFloat(attrAsString);
|
|
83
|
-
return attrAsString;
|
|
84
|
-
}
|
|
49
|
+
function a(e) {
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(e);
|
|
52
|
+
} catch {
|
|
53
|
+
return isNaN(parseFloat(e)) ? e : parseFloat(e);
|
|
54
|
+
}
|
|
85
55
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
var elements = document.querySelectorAll(selector);
|
|
106
|
-
elements.forEach(elem => {
|
|
107
|
-
const dataAsString = elem.getAttribute(config.dataAttributeName);
|
|
108
|
-
const data = parseDataAttribute(dataAsString);
|
|
109
|
-
const isVisible = api.isVisible(event.name, event.variant, data);
|
|
110
|
-
renderFeatureTag(elem, isVisible);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
return { name: 'htmlplugin' };
|
|
114
|
-
};
|
|
56
|
+
function o(e = {}) {
|
|
57
|
+
e = Object.assign({}, i, e);
|
|
58
|
+
function t(t, n) {
|
|
59
|
+
let r = t.getAttribute(e.tagAttributeName) || e.renderedTag, i = Array.from(t.attributes), a = "";
|
|
60
|
+
i.forEach((e) => {
|
|
61
|
+
a += ` ${e.nodeName}="${e.nodeValue.replace(/"/g, """)}"`;
|
|
62
|
+
}), t.outerHTML = `<${r} style="display:${n ? t.getAttribute(e.displayAttributeName) || e.defaultDisplay : "none"}" _feature="true" ${a}>${t.innerHTML}</${r}>`;
|
|
63
|
+
}
|
|
64
|
+
return function(n) {
|
|
65
|
+
return window.document.querySelectorAll(e.featureTagName).forEach((e) => {
|
|
66
|
+
t(e, !1);
|
|
67
|
+
}), n.on("visibilityrule", function(r) {
|
|
68
|
+
var i = `[_feature][${e.nameAttributeName}="${r.name}"]`;
|
|
69
|
+
r.variant && (i += `[${e.variantAttributeName}="${r.variant}"]`), document.querySelectorAll(i).forEach((i) => {
|
|
70
|
+
let o = a(i.getAttribute(e.dataAttributeName));
|
|
71
|
+
t(i, n.isVisible(r.name, r.variant, o));
|
|
72
|
+
});
|
|
73
|
+
}), { name: "htmlplugin" };
|
|
74
|
+
};
|
|
115
75
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/featureToggle.ts
|
|
78
|
+
function s(e) {
|
|
79
|
+
return typeof e == "boolean" ? function() {
|
|
80
|
+
return e;
|
|
81
|
+
} : e;
|
|
121
82
|
}
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
_name += "#" + variant.toLowerCase();
|
|
126
|
-
}
|
|
127
|
-
return _name;
|
|
83
|
+
function c(e, t) {
|
|
84
|
+
let n = e.toLowerCase();
|
|
85
|
+
return t && typeof t == "string" && (n += `#${t.toLowerCase()}`), n;
|
|
128
86
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
returnVisibilities[getKey(key)] = parseToFn(visibilities[key]);
|
|
135
|
-
});
|
|
136
|
-
return returnVisibilities;
|
|
87
|
+
function l(e = {}) {
|
|
88
|
+
let t = {};
|
|
89
|
+
return Object.entries(e).forEach(([e, n]) => {
|
|
90
|
+
e.startsWith("_") || e.startsWith("$") || (t[c(e)] = s(n));
|
|
91
|
+
}), t;
|
|
137
92
|
}
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
var requiredFnExists = visibilities['_required'] != null;
|
|
281
|
-
var requiredFnResult = getVisibility(requiredFn, 'requiredVisibility', name, variant, data);
|
|
282
|
-
var visibilityFnKey = getKey(name, variant);
|
|
283
|
-
var visibilityFn = visibilities[visibilityFnKey];
|
|
284
|
-
var visibilityFnExists = visibilities[visibilityFnKey] != null;
|
|
285
|
-
var visibilityFnResult = getVisibility(visibilityFn, 'visibility function', name, variant, data);
|
|
286
|
-
var variantExists = variant != null;
|
|
287
|
-
var visibilityOnlyNameFnKey = getKey(name, null);
|
|
288
|
-
var visibilityOnlyNameFn = visibilities[visibilityOnlyNameFnKey];
|
|
289
|
-
var visibilityOnlyNameFnResult = getVisibility(visibilityOnlyNameFn, 'visibility function (only name)', name, variant, data);
|
|
290
|
-
var defaultFn = visibilities['_default'];
|
|
291
|
-
var defaultFnExists = visibilities['_default'] != null;
|
|
292
|
-
var defaultFnResult = getVisibility(defaultFn, 'defaultVisibility', name, variant, data);
|
|
293
|
-
if (!requiredFnExists)
|
|
294
|
-
log("No requiredVisibility rule specified for this feature.");
|
|
295
|
-
else if (requiredFnExists && requiredFnResult === true)
|
|
296
|
-
log("The requiredVisibility rule returns true. This feature will be shown when no other rule rejects it.");
|
|
297
|
-
else if (requiredFnExists && requiredFnResult === false)
|
|
298
|
-
return logAndReturn(false, "The requiredVisibility rule returns false. This feature will be hidden.");
|
|
299
|
-
if (visibilityFnExists)
|
|
300
|
-
return logAndReturn(visibilityFnResult, `The visibility rule returns ${visibilityFnResult}. This feature will be ${visibilityFnResult ? 'visible' : 'hidden'}.`);
|
|
301
|
-
log('No visibility rule found matching name and variant.');
|
|
302
|
-
if (variantExists && typeof visibilityOnlyNameFnResult == 'boolean')
|
|
303
|
-
return logAndReturn(visibilityOnlyNameFnResult, `Found a visibility rule for name ${name} without variants. The rule returns ${visibilityOnlyNameFnResult}. => This feature will be ${visibilityOnlyNameFnResult ? 'visible' : 'hidden'}.`);
|
|
304
|
-
else if (variantExists)
|
|
305
|
-
log(`No rules found for name ${name} without variants.`);
|
|
306
|
-
if (defaultFnExists)
|
|
307
|
-
return logAndReturn(defaultFnResult, `Found a defaultVisibility rule. The rule returns ${defaultFnResult}. => This feature will be ${defaultFnResult ? 'visible' : 'hidden'}.`);
|
|
308
|
-
log(`No default rule found.`);
|
|
309
|
-
if (requiredFnExists)
|
|
310
|
-
return logAndReturn(true, `Only the requiredVisibility rule was found. This returned true. => This feature will be visible.`);
|
|
311
|
-
return logAndReturn(false, 'No rules were found. This feature will be hidden.');
|
|
312
|
-
}
|
|
313
|
-
const api = {
|
|
314
|
-
name: 'feature-toggle-api',
|
|
315
|
-
setData: function (nameParam, variantOrDataParam, dataParam) {
|
|
316
|
-
if (nameParam == undefined)
|
|
317
|
-
throw new Error('setData(): The name must of the feature must be defined, but ist undefined');
|
|
318
|
-
const variant = (dataParam != undefined ? variantOrDataParam : undefined);
|
|
319
|
-
const data = dataParam || variantOrDataParam;
|
|
320
|
-
const event = getEvent(nameParam, variant, data);
|
|
321
|
-
globals.datas[event.key] = event.data;
|
|
322
|
-
triggerEvent('visibilityrule', event);
|
|
323
|
-
},
|
|
324
|
-
on(eventtype, fn, config) {
|
|
325
|
-
globals.listeners[eventtype] = globals.listeners[eventtype] || [];
|
|
326
|
-
globals.listeners[eventtype].push(fn);
|
|
327
|
-
triggerEvent('registerEvent', {
|
|
328
|
-
type: eventtype
|
|
329
|
-
});
|
|
330
|
-
if (config != undefined && config.ignorePreviousRules)
|
|
331
|
-
return;
|
|
332
|
-
Object.keys(globals.visibilities).forEach(key => {
|
|
333
|
-
const event = parseKey(key);
|
|
334
|
-
const rule = globals.visibilities[key];
|
|
335
|
-
event.result = rule(event);
|
|
336
|
-
fn(event);
|
|
337
|
-
});
|
|
338
|
-
},
|
|
339
|
-
trigger: triggerEvent,
|
|
340
|
-
showLogs: function (showLogs) {
|
|
341
|
-
globals.showLogs = showLogs == undefined ? true : showLogs;
|
|
342
|
-
},
|
|
343
|
-
isVisible(name, variant, data) {
|
|
344
|
-
console.log('featureToggle.isVisible is deprecated. use featureToggle.isActive instead. This function will be removed in one of the next major versions.');
|
|
345
|
-
return isActive(name, variant, data);
|
|
346
|
-
},
|
|
347
|
-
isActive,
|
|
348
|
-
/**
|
|
349
|
-
the following function calls are possible:
|
|
350
|
-
visibility(name,result);
|
|
351
|
-
visibility(name,variant,result);
|
|
352
|
-
visibility(name,variant,data,result);
|
|
353
|
-
*/
|
|
354
|
-
setFlag(name, resultOrVariant, resultOrData, result) {
|
|
355
|
-
const params = visibilityFnParams(name, resultOrVariant, resultOrData, result);
|
|
356
|
-
const event = getEvent(params.name, params.variant, params.data, params.result);
|
|
357
|
-
globals.visibilities[event.key] = event.visibilityFunction;
|
|
358
|
-
globals.datas[event.key] = event.data;
|
|
359
|
-
triggerEvent('visibilityrule', event);
|
|
360
|
-
},
|
|
361
|
-
visibility: function (name, resultOrVariant, resultOrData, result) {
|
|
362
|
-
console.log('featureToggle.visibility is deprecated. use featureToggle.setVisibility instead. This function will be removed in one of the next major versions.');
|
|
363
|
-
api.setFlag(name, resultOrVariant, resultOrData, result);
|
|
364
|
-
},
|
|
365
|
-
requiredVisibility: function (fn) {
|
|
366
|
-
console.log('featureToggle.requiredVisibility is deprecated. use featureToggle.setRequiredFlag instead. This function will be removed in one of the next major versions.');
|
|
367
|
-
api.setRequiredFlag(fn);
|
|
368
|
-
},
|
|
369
|
-
defaultVisibility: function (fn) {
|
|
370
|
-
console.log('featureToggle.requiredVisibility is deprecated. use featureToggle.setRequiredFlag instead. This function will be removed in one of the next major versions.');
|
|
371
|
-
api.setDefaultFlag(fn);
|
|
372
|
-
},
|
|
373
|
-
setRequiredFlag(fn) {
|
|
374
|
-
if (typeof fn != "function")
|
|
375
|
-
throw new Error('feature.setRequiredFlag(): 1st parameter must be a function, but is ' + typeof fn);
|
|
376
|
-
globals.visibilities['_required'] = parseToFn(fn);
|
|
377
|
-
},
|
|
378
|
-
setDefaultFlag(fn) {
|
|
379
|
-
if (typeof fn != "function")
|
|
380
|
-
throw new Error('feature.defaultVisibility(): 1st parameter must be a function, but is ' + typeof fn);
|
|
381
|
-
globals.visibilities['_default'] = parseToFn(fn);
|
|
382
|
-
},
|
|
383
|
-
addPlugin: function (plugin) {
|
|
384
|
-
if (globals.usedPlugins.includes(plugin))
|
|
385
|
-
return;
|
|
386
|
-
const newPlugin = plugin(api);
|
|
387
|
-
for (let _key of Object.keys(newPlugin)) {
|
|
388
|
-
api[_key] = newPlugin[_key];
|
|
389
|
-
}
|
|
390
|
-
globals.usedPlugins.push(plugin);
|
|
391
|
-
},
|
|
392
|
-
};
|
|
393
|
-
init(api);
|
|
394
|
-
return api;
|
|
93
|
+
function u(e = {}) {
|
|
94
|
+
let t = {
|
|
95
|
+
datas: {},
|
|
96
|
+
listeners: {},
|
|
97
|
+
visibilities: l(e),
|
|
98
|
+
showLogs: !1,
|
|
99
|
+
usedPlugins: []
|
|
100
|
+
};
|
|
101
|
+
function n(t) {
|
|
102
|
+
e.$default && t.setDefaultFlag(e.$default), e.$required && t.setRequiredFlag(e.$required);
|
|
103
|
+
let n = e._plugins || [], i = [...e.$plugins || [], ...n];
|
|
104
|
+
n.length && console.log("useFeatureToggle({_plugins:[]}): Key _plugins is deprecated. Use $plugins instead. This attribute will be removed in one of the next major versions."), i.length && i.forEach((e) => {
|
|
105
|
+
if (typeof e != "function") throw Error("featuretoggleapi()-constructor: config.plugins needs functions as entries, not " + typeof e + ".");
|
|
106
|
+
t.addPlugin(e);
|
|
107
|
+
}), r("init");
|
|
108
|
+
}
|
|
109
|
+
function r(e, n) {
|
|
110
|
+
(t.listeners[e] || []).forEach((e) => {
|
|
111
|
+
e(n);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
let i = function(e) {
|
|
115
|
+
if (!t.showLogs) return;
|
|
116
|
+
if (globalThis.window === void 0) {
|
|
117
|
+
let t = e.replaceAll("<b>", "");
|
|
118
|
+
console.log(t);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
let n = e.includes("<b>"), r = e.includes("visible"), i = e.includes("hidden"), a = e.replaceAll("visible", "%cvisible");
|
|
122
|
+
a = a.replaceAll("hidden", "%chidden"), r ? console.log(a, "color:green;font-weight:bold;") : i ? console.log(a, "color:red;font-weight:bold;") : n ? (a = a.replace("<b>", "%c"), console.log(a, "font-weight:bold;")) : console.log(e);
|
|
123
|
+
}, a = function(e, t) {
|
|
124
|
+
return i(t), i(""), e;
|
|
125
|
+
}, o = function(e, t, n, r, i) {
|
|
126
|
+
if (e == null) return;
|
|
127
|
+
let o = e({
|
|
128
|
+
name: n,
|
|
129
|
+
variant: r ?? void 0,
|
|
130
|
+
data: i
|
|
131
|
+
});
|
|
132
|
+
return typeof o == "boolean" ? o : a(!1, `The ${t} returns ${o}. => Please return true or false. This result (and all non-boolean results) will return false.`);
|
|
133
|
+
};
|
|
134
|
+
function u(e) {
|
|
135
|
+
let n = e.split("#");
|
|
136
|
+
return {
|
|
137
|
+
name: n[0],
|
|
138
|
+
variant: n.length > 1 ? n[1] : void 0,
|
|
139
|
+
data: t.datas[e]
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
let d = function(e, t, n, r) {
|
|
143
|
+
if (e === void 0) throw Error("feature.visibility(): 1st parameter name must be defined");
|
|
144
|
+
if (arguments.length === 1) throw Error("feature.visibility(): 2nd parameter name must be a boolean or function, but is empty");
|
|
145
|
+
let i = e, a = null, o = null, s;
|
|
146
|
+
return n === void 0 && r === void 0 ? s = t : r === void 0 ? (a = t, s = n) : (a = t, o = n, s = r), {
|
|
147
|
+
name: i,
|
|
148
|
+
variant: a,
|
|
149
|
+
data: o,
|
|
150
|
+
result: s
|
|
151
|
+
};
|
|
152
|
+
}, f = (e, t, n, r) => {
|
|
153
|
+
let i = {
|
|
154
|
+
name: e,
|
|
155
|
+
variant: t ?? void 0,
|
|
156
|
+
data: n
|
|
157
|
+
};
|
|
158
|
+
return i.key = c(i.name, i.variant), r == null ? i : (i.visibilityFunction = s(r), i.result = i.visibilityFunction({
|
|
159
|
+
name: i.name,
|
|
160
|
+
variant: i.variant,
|
|
161
|
+
data: i.data || {},
|
|
162
|
+
_internalCall: !0,
|
|
163
|
+
description: "When attaching a function, the result must be calculated internally. You can filter this out with the _internalCall:true -Flag."
|
|
164
|
+
}), i);
|
|
165
|
+
};
|
|
166
|
+
function p(e, n, r) {
|
|
167
|
+
let s = t.visibilities, l = r ? ` with data ${JSON.stringify(r)}` : "";
|
|
168
|
+
if (i(`\nCheck Visibility of <b>Feature "${e}", variant "${n ?? ""}"${l}.`), e === void 0) throw Error("The attribute \"name\" is required for tag <feature></feature>. Example: <feature name=\"aname\"></feature>");
|
|
169
|
+
let u = s._required, d = u != null, f = o(u, "requiredVisibility", e, n, r);
|
|
170
|
+
if (!d) i("No requiredVisibility rule specified for this feature.");
|
|
171
|
+
else if (f === !0) i("The requiredVisibility rule returns true. This feature will be shown when no other rule rejects it.");
|
|
172
|
+
else return a(!1, "The requiredVisibility rule returns false. This feature will be hidden.");
|
|
173
|
+
let p = s[c(e, n)], h = p != null, g = o(p, "visibility function", e, n, r);
|
|
174
|
+
if (h) return a(g ?? !1, `The visibility rule returns ${g}. This feature will be ${g ? "visible" : "hidden"}.`);
|
|
175
|
+
i("No visibility rule found matching name and variant.");
|
|
176
|
+
let _ = n != null, v = s[c(e)], y = o(v, "visibility function (only name)", e, n, r);
|
|
177
|
+
if (_ && typeof y == "boolean") return a(y, `Found a visibility rule for name ${e} without variants. The rule returns ${y}. => This feature will be ${y ? "visible" : "hidden"}.`);
|
|
178
|
+
_ && i(`No rules found for name ${e} without variants.`);
|
|
179
|
+
let b = s._default;
|
|
180
|
+
return m(d, _, y, b != null, o(b, "defaultVisibility", e, n, r), e);
|
|
181
|
+
}
|
|
182
|
+
function m(e, t, n, r, o, s) {
|
|
183
|
+
return t && typeof n == "boolean" ? a(n, `Found a visibility rule for name ${s} without variants. The rule returns ${n}. => This feature will be ${n ? "visible" : "hidden"}.`) : (t && i(`No rules found for name ${s} without variants.`), r ? a(o ?? !1, `Found a defaultVisibility rule. The rule returns ${o}. => This feature will be ${o ? "visible" : "hidden"}.`) : (i("No default rule found."), e ? a(!0, "Only the requiredVisibility rule was found. This returned true. => This feature will be visible.") : a(!1, "No rules were found. This feature will be hidden.")));
|
|
184
|
+
}
|
|
185
|
+
let h = {
|
|
186
|
+
name: "feature-toggle-api",
|
|
187
|
+
setData: function(e, n, i) {
|
|
188
|
+
if (e === void 0) throw Error("setData(): The name of the feature must be defined, but is undefined");
|
|
189
|
+
let a = f(e, i === void 0 ? void 0 : n, i === void 0 ? n : i);
|
|
190
|
+
t.datas[a.key] = a.data, r("visibilityrule", a);
|
|
191
|
+
},
|
|
192
|
+
on(e, n, i) {
|
|
193
|
+
t.listeners[e] = t.listeners[e] || [], t.listeners[e].push(n), r("registerEvent", { type: e }), !i?.ignorePreviousRules && Object.keys(t.visibilities).forEach((e) => {
|
|
194
|
+
let r = u(e), i = t.visibilities[e];
|
|
195
|
+
r.result = i(r), n(r);
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
trigger: r,
|
|
199
|
+
showLogs: function(e) {
|
|
200
|
+
t.showLogs = e ?? !0;
|
|
201
|
+
},
|
|
202
|
+
isVisible(e, t, n) {
|
|
203
|
+
return console.log("featureToggle.isVisible is deprecated. use featureToggle.isActive instead. This function will be removed in one of the next major versions."), p(e, t, n);
|
|
204
|
+
},
|
|
205
|
+
isActive: p,
|
|
206
|
+
setFlag(e, n, i, a) {
|
|
207
|
+
let o = d(e, n, i, a), s = f(o.name, o.variant, o.data, o.result);
|
|
208
|
+
t.visibilities[s.key] = s.visibilityFunction, t.datas[s.key] = s.data, r("visibilityrule", s);
|
|
209
|
+
},
|
|
210
|
+
visibility: function(e, t, n, r) {
|
|
211
|
+
console.log("featureToggle.visibility is deprecated. use featureToggle.setVisibility instead. This function will be removed in one of the next major versions."), h.setFlag(e, t, n, r);
|
|
212
|
+
},
|
|
213
|
+
requiredVisibility: function(e) {
|
|
214
|
+
console.log("featureToggle.requiredVisibility is deprecated. use featureToggle.setRequiredFlag instead. This function will be removed in one of the next major versions."), h.setRequiredFlag(e);
|
|
215
|
+
},
|
|
216
|
+
defaultVisibility: function(e) {
|
|
217
|
+
console.log("featureToggle.requiredVisibility is deprecated. use featureToggle.setRequiredFlag instead. This function will be removed in one of the next major versions."), h.setDefaultFlag(e);
|
|
218
|
+
},
|
|
219
|
+
setRequiredFlag(e) {
|
|
220
|
+
if (typeof e != "function") throw Error("feature.setRequiredFlag(): 1st parameter must be a function, but is " + typeof e);
|
|
221
|
+
t.visibilities._required = s(e);
|
|
222
|
+
},
|
|
223
|
+
setDefaultFlag(e) {
|
|
224
|
+
if (typeof e != "function") throw Error("feature.defaultVisibility(): 1st parameter must be a function, but is " + typeof e);
|
|
225
|
+
t.visibilities._default = s(e);
|
|
226
|
+
},
|
|
227
|
+
addPlugin: function(e) {
|
|
228
|
+
if (t.usedPlugins.includes(e)) return;
|
|
229
|
+
let n = e(h);
|
|
230
|
+
for (let e of Object.keys(n)) h[e] = n[e];
|
|
231
|
+
t.usedPlugins.push(e);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
return n(h), h;
|
|
395
235
|
}
|
|
236
|
+
//#endregion
|
|
237
|
+
export { o as htmlPlugin, r as urlPlugin, u as useFeatureToggle };
|
|
396
238
|
|
|
397
|
-
|
|
239
|
+
//# sourceMappingURL=feature-toggle.js.map
|