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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-toggle.js","names":[],"sources":["../src/plugins/urlplugin/plugin-url.ts","../src/plugins/htmlplugin/plugin-html.ts","../src/featureToggle.ts"],"sourcesContent":["interface URLPluginConfig{\n useMockedWindow?: boolean,\n url?: string,\n prefix?: string\n\n}\n\nfunction useWindowMock(){\n return {\n isMocked: true,\n decodeURIComponent:function(param1){\n return param1;\n }\n }\n}\n\ndeclare global {\n interface Window {\n isMocked: boolean\n }\n }\n\n declare var window: Window;\n\nfunction parseValue(value){\n if(value === 'true')\n return true;\n return false;\n}\n\nfunction getParams(url,window) {\n var params = {};\n if (!url) \n return [];\n \n var urlparts = url.split(\"?\");\n\n //no params available for url\n if(urlparts.length < 2)\n return [];\n\n const parts = urlparts[1].split('&');\n\n parts.forEach(function (part) {\n var pair = part.split('=');\n pair[0] = window.decodeURIComponent(pair[0]);\n pair[1] = parseValue(window.decodeURIComponent(pair[1]));\n params[pair[0]] = (pair[1] !== 'undefined') ?\n pair[1] : true;\n });\n\n return params;\n }\n\n function urlPlugin(config: URLPluginConfig={}) {\n let _window;\n\n if(config.useMockedWindow)\n _window = useWindowMock();\n else\n _window = window;\n \n config = Object.assign({},{\n url: _window.isMocked ? \"\" : _window.location.href,\n prefix: \"\"\n },config);\n\n \n\n return function(api){\n api.url = config.url;\n const urlparams = getParams(config.url,_window);\n const prefix = config.prefix;\n\n Object.keys(urlparams).forEach(key => {\n if(!key.startsWith(prefix))\n return;\n \n const keyWithoutPrefix = key.replace(prefix,\"\");\n api.visibility(keyWithoutPrefix,urlparams[key]);\n });\n\n return {name: 'urlplugin'};\n }\n\n}\n\nexport {\n urlPlugin\n}","type Display = 'block' | 'inline-block' | 'inline' | 'flex' | 'inline-flex' | 'grid' | 'inline-grid';\n\ninterface HtmlPluginConfig {\n renderedTag?: string,\n featureTagName?: string,\n tagAttributeName?: string,\n nameAttributeName?:string,\n variantAttributeName?: string,\n dataAttributeName?: string,\n displayAttributeName?: string,\n defaultDisplay?: Display,\n}\n\n/*\n creates a tag that is shown / hidden, depending on the visibility rules.\n if not configured dynamically, it looks like this:\n <feature name=\"featurename\" variant=\"variantname\" data=\"data\">content </feature>\n\n Parameter: (config)\n - config.featureTagName: name of the tag. Default: \"feature\"\n - nameAttributeName: Name of the Name-Attribute: default: \"name\"\n - variantAttributeName: Name of the Variant-Attribute: default: \"variant\"\n*/\nconst defaultparams :HtmlPluginConfig = {\n renderedTag: 'div',\n featureTagName: 'feature',\n tagAttributeName: 'tag',\n nameAttributeName:'name',\n variantAttributeName: 'variant',\n dataAttributeName: 'data',\n displayAttributeName: 'display',\n defaultDisplay: 'block',\n}\nfunction parseDataAttribute(attrAsString){\n try{\n return JSON.parse(attrAsString);\n }\n catch(e)\n {\n if(!isNaN(parseFloat(attrAsString)))\n return parseFloat(attrAsString);\n \n return attrAsString;\n }\n}\n\nfunction htmlPlugin(config :HtmlPluginConfig = {}) {\n config = Object.assign({},defaultparams,config);\n\n function renderFeatureTag(elem:HTMLElement,isVisible){\n const tagname = elem.getAttribute(config.tagAttributeName) || config.renderedTag;\n const attributes = Array.from(elem.attributes);\n let attributesAsString = \"\";\n attributes.forEach(attr => {\n attributesAsString += ` ${attr.nodeName}=\"${attr.nodeValue.replace(/\"/g,\""\")}\"`;\n });\n const display = isVisible ? (elem.getAttribute(config.displayAttributeName) || config.defaultDisplay) : 'none';\n elem.outerHTML = `<${tagname} style=\"display:${display}\" _feature=\"true\" ${attributesAsString}>${elem.innerHTML}</${tagname}>`;\n } \n return function (api) {\n var renderedTags :NodeListOf<HTMLElement> = window.document.querySelectorAll(config.featureTagName);\n renderedTags.forEach(tag => { renderFeatureTag(tag,false) });\n\n api.on('visibilityrule', function (event) {\n var selector = `[_feature][${config.nameAttributeName}=\"${event.name}\"]`;\n if (event.variant) selector += `[${config.variantAttributeName}=\"${event.variant}\"]`;\n var elements :NodeListOf<HTMLElement> = document.querySelectorAll(selector);\n elements.forEach(elem => { \n const dataAsString = elem.getAttribute(config.dataAttributeName);\n const data = parseDataAttribute(dataAsString);\n \n const isVisible = api.isVisible(event.name,event.variant,data);\n renderFeatureTag(elem, isVisible);\n });\n })\n\n return { name: 'htmlplugin' };\n }\n}\n\nexport {\n htmlPlugin\n}","import { EventType, FeatureToggleApi, FeatureToggleConfig, OnEvent, OnConfiguration, Plugin, Rule, FeatureFlag } from \"./types\";\n\nfunction parseToFn(fnOrBool: boolean | ((param?: any) => boolean)): (param?: any) => boolean {\n if (typeof fnOrBool === 'boolean') {\n return function () {\n return fnOrBool;\n };\n }\n\n return fnOrBool;\n}\n\nfunction getKey(name: string, variant?: string): string {\n let key = name.toLowerCase();\n if (variant && typeof variant === 'string') {\n key += `#${variant.toLowerCase()}`;\n }\n\n return key;\n}\n\nfunction initVisibilities(visibilities: FeatureToggleConfig = {}): Record<string, (param?: any) => boolean> {\n const returnVisibilities: Record<string, (param?: any) => boolean> = {};\n Object.entries(visibilities).forEach(([key, value]) => {\n if (key.startsWith('_') || key.startsWith('$')) {\n return;\n }\n\n returnVisibilities[getKey(key)] = parseToFn(value as FeatureFlag);\n });\n return returnVisibilities;\n}\n\nfunction useFeatureToggle(config: FeatureToggleConfig = {}): FeatureToggleApi {\n\n const globals: {\n datas: Record<string, any>;\n listeners: Partial<Record<EventType, Array<(param?: any) => void>>>;\n visibilities: Record<string, (param?: any) => boolean>;\n showLogs: boolean;\n usedPlugins: Plugin[];\n } = {\n datas: {},\n listeners: {},\n visibilities: initVisibilities(config),\n showLogs: false,\n usedPlugins: [],\n };\n\n function init(api: FeatureToggleApi) {\n if(config.$default){\n api.setDefaultFlag(config.$default);\n }\n\n if(config.$required){\n api.setRequiredFlag(config.$required);\n }\n\n const legacyPlugins = ((config as any)._plugins as Plugin[]) || [];\n const allPlugins = [...(config.$plugins || []), ...legacyPlugins];\n\n if (legacyPlugins.length) {\n console.log('useFeatureToggle({_plugins:[]}): Key _plugins is deprecated. Use $plugins instead. This attribute will be removed in one of the next major versions.');\n }\n\n\n if (allPlugins.length) {\n allPlugins.forEach(plugin => {\n if (typeof plugin !== 'function')\n throw new Error('featuretoggleapi()-constructor: config.plugins needs functions as entries, not ' + typeof plugin + '.');\n\n api.addPlugin(plugin);\n });\n }\n\n triggerEvent('init');\n }\n\n function triggerEvent(eventtype: EventType, param?: any): void {\n (globals.listeners[eventtype] || []).forEach((listener: (param?: any) => void) => {\n listener(param);\n });\n }\n\n const log = function (message: string): void {\n if (!globals.showLogs) {\n return;\n }\n\n // Nur Browser können Syntaxhighlighting, die anderen geben die Nachricht einfach aus und schneiden die Styletags raus\n if (globalThis.window === undefined) {\n const loggedMessage = message.replaceAll('<b>', '');\n console.log(loggedMessage);\n return;\n }\n\n const hasBoldTag = message.includes('<b>');\n const hasVisibleKeyword = message.includes('visible');\n const hasHiddenKeyword = message.includes('hidden');\n\n let formattedMessage = message.replaceAll('visible', '%cvisible');\n formattedMessage = formattedMessage.replaceAll('hidden', '%chidden');\n\n if (hasVisibleKeyword) {\n console.log(formattedMessage, 'color:green;font-weight:bold;');\n } else if (hasHiddenKeyword) {\n console.log(formattedMessage, 'color:red;font-weight:bold;');\n } else if (hasBoldTag) {\n formattedMessage = formattedMessage.replace('<b>', '%c');\n const parts = [formattedMessage, 'font-weight:bold;'];\n console.log(...parts);\n } else {\n console.log(message);\n }\n };\n\n const logAndReturn = function (returnValue: boolean, message: string): boolean {\n log(message);\n log('');\n return returnValue;\n };\n\n const getVisibility = function (\n visibilityFn: ((rule: Rule) => boolean) | undefined,\n functionName: string,\n name: string,\n variant?: string,\n data?: any\n ): boolean | undefined {\n if (visibilityFn == null) {\n return undefined;\n }\n\n const calculatedVisibility = visibilityFn({ name, variant: variant ?? undefined, data });\n\n if (typeof calculatedVisibility === 'boolean') {\n return calculatedVisibility;\n }\n\n return logAndReturn(false, `The ${functionName} returns ${calculatedVisibility}. => Please return true or false. This result (and all non-boolean results) will return false.`);\n };\n\n function parseKey(key: string): OnEvent {\n const parts = key.split('#');\n return {\n name: parts[0],\n variant: parts.length > 1 ? parts[1] : undefined,\n data: globals.datas[key],\n };\n }\n\n /*\n the following calls are possible:\n visibility(name,result);\n visibility(name,variant,result);\n visibility(name,variant,data,result);\n \n =>\n param1: name\n param2: result || variant\n param3: result || data\n param4: result\n */\n const visibilityFnParams = function (\n param1: any,\n param2?: any,\n param3?: any,\n param4?: any\n ): { name: string; variant?: string | null; data?: any; result?: boolean | ((rule: Rule) => boolean) } {\n // name must always be set\n if (param1 === undefined) {\n throw new Error('feature.visibility(): 1st parameter name must be defined');\n }\n\n if (arguments.length === 1) {\n throw new Error('feature.visibility(): 2nd parameter name must be a boolean or function, but is empty');\n }\n\n const name = param1;\n let variant: string | null | undefined = null;\n let data: any = null;\n let result: boolean | ((rule: Rule) => boolean) | undefined = undefined;\n\n if (param3 === undefined && param4 === undefined) {\n result = param2;\n } else if (param4 === undefined) {\n variant = param2;\n result = param3;\n } else {\n variant = param2;\n data = param3;\n result = param4;\n }\n\n return {\n name,\n variant,\n data,\n result,\n };\n };\n\n const getEvent = (\n name: string,\n variant?: string | null,\n data?: any,\n result?: boolean | ((rule: Rule) => boolean)\n ): OnEvent & { key: string; visibilityFunction?: (param?: any) => boolean } => {\n const event: OnEvent & { key?: string; visibilityFunction?: (param?: any) => boolean } = {\n name,\n variant: variant ?? undefined,\n data,\n };\n\n event.key = getKey(event.name, event.variant);\n\n if (result == null) {\n return event as OnEvent & { key: string };\n }\n\n event.visibilityFunction = parseToFn(result);\n event.result = event.visibilityFunction({\n name: event.name,\n variant: event.variant,\n data: event.data || {},\n _internalCall: true,\n description: 'When attaching a function, the result must be calculated internally. You can filter this out with the _internalCall:true -Flag.',\n });\n\n return event as OnEvent & { key: string; visibilityFunction: (param?: any) => boolean };\n };\n\n\n\n function isActive(name: string, variant?: string, data?: any): boolean {\n const visibilities = globals.visibilities;\n const dataInfo = data ? ` with data ${JSON.stringify(data)}` : '';\n\n log(`\\nCheck Visibility of <b>Feature \"${name}\", variant \"${variant ?? ''}\"${dataInfo}.`);\n if (name === undefined) {\n throw new Error('The attribute \"name\" is required for tag <feature></feature>. Example: <feature name=\"aname\"></feature>');\n }\n\n const requiredFn = visibilities['_required'];\n const requiredFnExists = requiredFn != null;\n const requiredFnResult = getVisibility(requiredFn, 'requiredVisibility', name, variant, data);\n\n if (!requiredFnExists) {\n log('No requiredVisibility rule specified for this feature.');\n } else if (requiredFnResult === true) {\n log('The requiredVisibility rule returns true. This feature will be shown when no other rule rejects it.');\n } else {\n return logAndReturn(false, 'The requiredVisibility rule returns false. This feature will be hidden.');\n }\n\n const visibilityFnKey = getKey(name, variant);\n const visibilityFn = visibilities[visibilityFnKey];\n const visibilityFnExists = visibilityFn != null;\n const visibilityFnResult = getVisibility(visibilityFn, 'visibility function', name, variant, data);\n\n if (visibilityFnExists) {\n return logAndReturn(visibilityFnResult ?? false, `The visibility rule returns ${visibilityFnResult}. This feature will be ${visibilityFnResult ? 'visible' : 'hidden'}.`);\n }\n\n log('No visibility rule found matching name and variant.');\n\n const variantExists = variant != null;\n const visibilityOnlyNameFnKey = getKey(name);\n const visibilityOnlyNameFn = visibilities[visibilityOnlyNameFnKey];\n const visibilityOnlyNameFnResult = getVisibility(visibilityOnlyNameFn, 'visibility function (only name)', name, variant, data);\n\n if (variantExists && typeof visibilityOnlyNameFnResult === 'boolean') {\n return logAndReturn(visibilityOnlyNameFnResult, `Found a visibility rule for name ${name} without variants. The rule returns ${visibilityOnlyNameFnResult}. => This feature will be ${visibilityOnlyNameFnResult ? 'visible' : 'hidden'}.`);\n }\n\n if (variantExists) {\n log(`No rules found for name ${name} without variants.`);\n }\n\n const defaultFn = visibilities['_default'];\n const defaultFnExists = defaultFn != null;\n const defaultFnResult = getVisibility(defaultFn, 'defaultVisibility', name, variant, data);\n\n return evaluateFallbackRules(requiredFnExists, variantExists, visibilityOnlyNameFnResult, defaultFnExists, defaultFnResult, name);\n }\n\n function evaluateFallbackRules(\n requiredFnExists: boolean,\n variantExists: boolean,\n visibilityOnlyNameFnResult: boolean | undefined,\n defaultFnExists: boolean,\n defaultFnResult: boolean | undefined,\n name: string\n ): boolean {\n if (variantExists && typeof visibilityOnlyNameFnResult === 'boolean') {\n return logAndReturn(visibilityOnlyNameFnResult, `Found a visibility rule for name ${name} without variants. The rule returns ${visibilityOnlyNameFnResult}. => This feature will be ${visibilityOnlyNameFnResult ? 'visible' : 'hidden'}.`);\n }\n\n if (variantExists) {\n log(`No rules found for name ${name} without variants.`);\n }\n\n if (defaultFnExists) {\n return logAndReturn(defaultFnResult ?? false, `Found a defaultVisibility rule. The rule returns ${defaultFnResult}. => This feature will be ${defaultFnResult ? 'visible' : 'hidden'}.`);\n }\n\n log('No default rule found.');\n\n if (requiredFnExists) {\n return logAndReturn(true, 'Only the requiredVisibility rule was found. This returned true. => This feature will be visible.');\n }\n\n return logAndReturn(false, 'No rules were found. This feature will be hidden.');\n }\n\n const api: FeatureToggleApi = {\n name: 'feature-toggle-api',\n setData: function (nameParam: string, variantOrDataParam?: string | Record<string, any>, dataParam?: any): void {\n if (nameParam === undefined) {\n throw new Error('setData(): The name of the feature must be defined, but is undefined');\n }\n\n const variant = dataParam === undefined ? undefined : (variantOrDataParam as string);\n const data = dataParam === undefined ? variantOrDataParam : dataParam;\n\n const event = getEvent(nameParam, variant, data);\n\n globals.datas[event.key] = event.data;\n triggerEvent('visibilityrule', event);\n },\n on(eventtype: EventType, fn: (event: OnEvent) => void, config?: OnConfiguration): void {\n globals.listeners[eventtype] = globals.listeners[eventtype] || [];\n globals.listeners[eventtype].push(fn);\n\n triggerEvent('registerEvent', {\n type: eventtype,\n });\n\n if (config?.ignorePreviousRules) {\n return;\n }\n\n Object.keys(globals.visibilities).forEach(key => {\n const event = parseKey(key);\n const rule = globals.visibilities[key];\n event.result = rule(event);\n fn(event);\n });\n },\n trigger: triggerEvent,\n showLogs: function (showLogs?: boolean): void {\n globals.showLogs = showLogs ?? true;\n },\n isVisible(name,variant,data){\n console.log('featureToggle.isVisible is deprecated. use featureToggle.isActive instead. This function will be removed in one of the next major versions.');\n return isActive(name,variant,data);\n },\n isActive,\n /**\n the following function calls are possible:\n visibility(name,result);\n visibility(name,variant,result);\n visibility(name,variant,data,result);\n */\n setFlag(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | ((rule: Rule) => boolean)) {\n const params = visibilityFnParams(name, resultOrVariant, resultOrData, result);\n const event = getEvent(params.name, params.variant, params.data, params.result);\n\n globals.visibilities[event.key] = event.visibilityFunction!;\n globals.datas[event.key] = event.data;\n triggerEvent('visibilityrule', event);\n },\n visibility: function (name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | ((rule: Rule) => boolean)) {\n console.log('featureToggle.visibility is deprecated. use featureToggle.setVisibility instead. This function will be removed in one of the next major versions.');\n\n api.setFlag(name, resultOrVariant, resultOrData, result);\n },\n requiredVisibility: function (fn) {\n console.log('featureToggle.requiredVisibility is deprecated. use featureToggle.setRequiredFlag instead. This function will be removed in one of the next major versions.');\n\n api.setRequiredFlag(fn);\n },\n defaultVisibility: function (fn) {\n console.log('featureToggle.requiredVisibility is deprecated. use featureToggle.setRequiredFlag instead. This function will be removed in one of the next major versions.');\n\n api.setDefaultFlag(fn);\n },\n setRequiredFlag(fn) {\n if (typeof fn != \"function\")\n throw new Error('feature.setRequiredFlag(): 1st parameter must be a function, but is ' + typeof fn);\n\n globals.visibilities['_required'] = parseToFn(fn);\n },\n setDefaultFlag(fn) {\n if (typeof fn != \"function\")\n throw new Error('feature.defaultVisibility(): 1st parameter must be a function, but is ' + typeof fn);\n\n globals.visibilities['_default'] = parseToFn(fn);\n },\n addPlugin: function (plugin: Plugin): void {\n if (globals.usedPlugins.includes(plugin)) {\n return;\n }\n\n const newPlugin = plugin(api) as Partial<FeatureToggleApi>;\n\n for(let _key of Object.keys(newPlugin)){\n api[_key] = newPlugin[_key];\n }\n\n globals.usedPlugins.push(plugin);\n },\n };\n init(api);\n\n return api;\n}\n\nexport default useFeatureToggle;"],"mappings":";AAOA,SAAS,IAAe;CACpB,OAAO;EACH,UAAU;EACV,oBAAmB,SAAS,GAAO;GAC/B,OAAO;EACX;CACJ;AACJ;AAUA,SAAS,EAAW,GAAM;CAGtB,OAFG,MAAU;AAGjB;AAEA,SAAS,EAAU,GAAI,GAAQ;CAC3B,IAAI,IAAS,CAAC;CACd,IAAI,CAAC,GACD,OAAO,CAAC;CAEZ,IAAI,IAAW,EAAI,MAAM,GAAG;CAgB5B,OAbG,EAAS,SAAS,IACV,CAAC,KAIZ,EAFuB,EAAE,CAAC,MAAM,GAEhC,CAAA,CAAM,QAAQ,SAAU,GAAM;EAC9B,IAAI,IAAO,EAAK,MAAM,GAAG;EAGzB,AAFA,EAAK,KAAK,EAAO,mBAAmB,EAAK,EAAE,GAC3C,EAAK,KAAK,EAAW,EAAO,mBAAmB,EAAK,EAAE,CAAC,GACvD,EAAO,EAAK,MAAO,EAAK,OAAO,eAC3B,EAAK;CACT,CAAC,GAEM;AACT;AAED,SAAS,EAAU,IAAwB,CAAC,GAAG;CAC5C,IAAI;CAcJ,OAZA,AAGI,IAHD,EAAO,kBACI,EAAc,IAEd,QAEd,IAAS,OAAO,OAAO,CAAC,GAAE;EACtB,KAAK,EAAQ,WAAW,KAAK,EAAQ,SAAS;EAC9C,QAAQ;CACZ,GAAE,CAAM,GAID,SAAS,GAAI;EAChB,EAAI,MAAM,EAAO;EACjB,IAAM,IAAY,EAAU,EAAO,KAAI,CAAO,GACxC,IAAS,EAAO;EAUtB,OARA,OAAO,KAAK,CAAS,CAAC,CAAC,SAAQ,MAAO;GAClC,IAAG,CAAC,EAAI,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AAyE,OAAO,CAAE;GAEtG,EAAQ,aAAa,YAAe,EAAU,CAAE;EACpD;EACA,eAAe,GAAI;GACf,IAAI,OAAO,KAAM,YACb,MAAU,MAAM,2EAA2E,OAAO,CAAE;GAExG,EAAQ,aAAa,WAAc,EAAU,CAAE;EACnD;EACA,WAAW,SAAU,GAAsB;GACvC,IAAI,EAAQ,YAAY,SAAS,CAAM,GACnC;GAGJ,IAAM,IAAY,EAAO,CAAG;GAE5B,KAAI,IAAI,KAAQ,OAAO,KAAK,CAAS,GACjC,EAAI,KAAQ,EAAU;GAG1B,EAAQ,YAAY,KAAK,CAAM;EACnC;CACJ;CAGA,OAFA,EAAK,CAAG,GAED;AACX"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/plugins/htmlplugin/plugin-html.ts
|
|
2
|
+
var e = {
|
|
3
|
+
renderedTag: "div",
|
|
4
|
+
featureTagName: "feature",
|
|
5
|
+
tagAttributeName: "tag",
|
|
6
|
+
nameAttributeName: "name",
|
|
7
|
+
variantAttributeName: "variant",
|
|
8
|
+
dataAttributeName: "data",
|
|
9
|
+
displayAttributeName: "display",
|
|
10
|
+
defaultDisplay: "block"
|
|
11
|
+
};
|
|
12
|
+
function t(e) {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(e);
|
|
15
|
+
} catch {
|
|
16
|
+
return isNaN(parseFloat(e)) ? e : parseFloat(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function n(n = {}) {
|
|
20
|
+
n = Object.assign({}, e, n);
|
|
21
|
+
function r(e, t) {
|
|
22
|
+
let r = e.getAttribute(n.tagAttributeName) || n.renderedTag, i = Array.from(e.attributes), a = "";
|
|
23
|
+
i.forEach((e) => {
|
|
24
|
+
a += ` ${e.nodeName}="${e.nodeValue.replace(/"/g, """)}"`;
|
|
25
|
+
}), e.outerHTML = `<${r} style="display:${t ? e.getAttribute(n.displayAttributeName) || n.defaultDisplay : "none"}" _feature="true" ${a}>${e.innerHTML}</${r}>`;
|
|
26
|
+
}
|
|
27
|
+
return function(e) {
|
|
28
|
+
return window.document.querySelectorAll(n.featureTagName).forEach((e) => {
|
|
29
|
+
r(e, !1);
|
|
30
|
+
}), e.on("visibilityrule", function(i) {
|
|
31
|
+
var a = `[_feature][${n.nameAttributeName}="${i.name}"]`;
|
|
32
|
+
i.variant && (a += `[${n.variantAttributeName}="${i.variant}"]`), document.querySelectorAll(a).forEach((a) => {
|
|
33
|
+
let o = t(a.getAttribute(n.dataAttributeName));
|
|
34
|
+
r(a, e.isVisible(i.name, i.variant, o));
|
|
35
|
+
});
|
|
36
|
+
}), { name: "htmlplugin" };
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { n as htmlPlugin };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=html-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-plugin.js","names":[],"sources":["../src/plugins/htmlplugin/plugin-html.ts"],"sourcesContent":["type Display = 'block' | 'inline-block' | 'inline' | 'flex' | 'inline-flex' | 'grid' | 'inline-grid';\n\ninterface HtmlPluginConfig {\n renderedTag?: string,\n featureTagName?: string,\n tagAttributeName?: string,\n nameAttributeName?:string,\n variantAttributeName?: string,\n dataAttributeName?: string,\n displayAttributeName?: string,\n defaultDisplay?: Display,\n}\n\n/*\n creates a tag that is shown / hidden, depending on the visibility rules.\n if not configured dynamically, it looks like this:\n <feature name=\"featurename\" variant=\"variantname\" data=\"data\">content </feature>\n\n Parameter: (config)\n - config.featureTagName: name of the tag. Default: \"feature\"\n - nameAttributeName: Name of the Name-Attribute: default: \"name\"\n - variantAttributeName: Name of the Variant-Attribute: default: \"variant\"\n*/\nconst defaultparams :HtmlPluginConfig = {\n renderedTag: 'div',\n featureTagName: 'feature',\n tagAttributeName: 'tag',\n nameAttributeName:'name',\n variantAttributeName: 'variant',\n dataAttributeName: 'data',\n displayAttributeName: 'display',\n defaultDisplay: 'block',\n}\nfunction parseDataAttribute(attrAsString){\n try{\n return JSON.parse(attrAsString);\n }\n catch(e)\n {\n if(!isNaN(parseFloat(attrAsString)))\n return parseFloat(attrAsString);\n \n return attrAsString;\n }\n}\n\nfunction htmlPlugin(config :HtmlPluginConfig = {}) {\n config = Object.assign({},defaultparams,config);\n\n function renderFeatureTag(elem:HTMLElement,isVisible){\n const tagname = elem.getAttribute(config.tagAttributeName) || config.renderedTag;\n const attributes = Array.from(elem.attributes);\n let attributesAsString = \"\";\n attributes.forEach(attr => {\n attributesAsString += ` ${attr.nodeName}=\"${attr.nodeValue.replace(/\"/g,\""\")}\"`;\n });\n const display = isVisible ? (elem.getAttribute(config.displayAttributeName) || config.defaultDisplay) : 'none';\n elem.outerHTML = `<${tagname} style=\"display:${display}\" _feature=\"true\" ${attributesAsString}>${elem.innerHTML}</${tagname}>`;\n } \n return function (api) {\n var renderedTags :NodeListOf<HTMLElement> = window.document.querySelectorAll(config.featureTagName);\n renderedTags.forEach(tag => { renderFeatureTag(tag,false) });\n\n api.on('visibilityrule', function (event) {\n var selector = `[_feature][${config.nameAttributeName}=\"${event.name}\"]`;\n if (event.variant) selector += `[${config.variantAttributeName}=\"${event.variant}\"]`;\n var elements :NodeListOf<HTMLElement> = document.querySelectorAll(selector);\n elements.forEach(elem => { \n const dataAsString = elem.getAttribute(config.dataAttributeName);\n const data = parseDataAttribute(dataAsString);\n \n const isVisible = api.isVisible(event.name,event.variant,data);\n renderFeatureTag(elem, isVisible);\n });\n })\n\n return { name: 'htmlplugin' };\n }\n}\n\nexport {\n htmlPlugin\n}"],"mappings":";AAuBA,IAAM,IAAkC;CACpC,aAAa;CACb,gBAAgB;CAChB,kBAAkB;CAClB,mBAAkB;CAClB,sBAAsB;CACtB,mBAAmB;CACnB,sBAAsB;CACtB,gBAAgB;AACpB;AACA,SAAS,EAAmB,GAAa;CACrC,IAAG;EACC,OAAO,KAAK,MAAM,CAAY;CAClC,QAEA;EAII,OAHI,MAAM,WAAW,CAAY,CA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default as useFeatureToggle } from './featureToggle';
|
|
4
|
+
import { FeatureFlag, FeatureFlagKey, FeatureToggleApi, FeatureToggleApiBase, FeatureToggleConfig, FirstCharOfFeatureFlagKey, OnConfiguration, EventType, OnEvent } from './types';
|
|
5
|
+
export { useFeatureToggle, urlPlugin, htmlPlugin, FeatureFlag, FeatureFlagKey, FeatureToggleApi, FeatureToggleApiBase, FeatureToggleConfig, FirstCharOfFeatureFlagKey, OnConfiguration, EventType, OnEvent };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Display = 'block' | 'inline-block' | 'inline' | 'flex' | 'inline-flex' | 'grid' | 'inline-grid';
|
|
2
|
+
interface HtmlPluginConfig {
|
|
3
|
+
renderedTag?: string;
|
|
4
|
+
featureTagName?: string;
|
|
5
|
+
tagAttributeName?: string;
|
|
6
|
+
nameAttributeName?: string;
|
|
7
|
+
variantAttributeName?: string;
|
|
8
|
+
dataAttributeName?: string;
|
|
9
|
+
displayAttributeName?: string;
|
|
10
|
+
defaultDisplay?: Display;
|
|
11
|
+
}
|
|
12
|
+
declare function htmlPlugin(config?: HtmlPluginConfig): (api: any) => {
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
export { htmlPlugin };
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export { urlPlugin };
|
|
@@ -1,117 +1,97 @@
|
|
|
1
1
|
export interface OnConfiguration {
|
|
2
|
-
ignorePreviousRules: boolean
|
|
2
|
+
ignorePreviousRules: boolean;
|
|
3
3
|
}
|
|
4
|
-
export type Plugin = (api) => Partial<FeatureToggleApi>;
|
|
5
|
-
|
|
6
|
-
export type EventType = 'visibilityrule' | 'init' | 'registerEvent' | string;
|
|
4
|
+
export type Plugin = (api: FeatureToggleApi) => Partial<FeatureToggleApi>;
|
|
5
|
+
export type EventType = 'visibilityrule' | 'init' | 'registerEvent' | (string & {});
|
|
7
6
|
export interface OnEvent {
|
|
8
|
-
name: string
|
|
9
|
-
variant
|
|
10
|
-
data: any
|
|
11
|
-
result?: boolean
|
|
7
|
+
name: string;
|
|
8
|
+
variant?: string;
|
|
9
|
+
data: any;
|
|
10
|
+
result?: boolean;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
export 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' |
|
|
15
|
-
'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
|
|
16
|
-
|
|
12
|
+
export 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' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
|
|
17
13
|
export type FeatureFlagKey = `${FirstCharOfFeatureFlagKey}${string}`;
|
|
18
|
-
export type FeatureFlag = boolean | ((rule:Rule) => boolean);
|
|
14
|
+
export type FeatureFlag = boolean | ((rule: Rule) => boolean);
|
|
19
15
|
export interface FeatureToggleConfig {
|
|
20
|
-
[key: FeatureFlagKey]: FeatureFlag
|
|
21
|
-
$plugins?: Plugin[]
|
|
16
|
+
[key: FeatureFlagKey]: FeatureFlag;
|
|
17
|
+
$plugins?: Plugin[];
|
|
22
18
|
/**
|
|
23
19
|
* @deprecated Use key`$plugins` instead.
|
|
24
20
|
*/
|
|
25
|
-
_plugins?: Plugin[]
|
|
26
|
-
|
|
21
|
+
_plugins?: Plugin[];
|
|
27
22
|
/**
|
|
28
|
-
* This rule will always run before the main rule.
|
|
23
|
+
* This rule will always run before the main rule.
|
|
29
24
|
* If it returns false, the main rules will be skipped and false is returned
|
|
30
25
|
*/
|
|
31
|
-
$required?: FeatureFlag
|
|
32
|
-
|
|
26
|
+
$required?: FeatureFlag;
|
|
33
27
|
/**
|
|
34
|
-
* This rule will always run after the main rule.
|
|
28
|
+
* This rule will always run after the main rule.
|
|
35
29
|
* If the main rule returns false, the result of the default rule will be taken.s
|
|
36
30
|
*/
|
|
37
|
-
$default?: FeatureFlag
|
|
31
|
+
$default?: FeatureFlag;
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
export interface Rule {
|
|
41
|
-
name: string
|
|
42
|
-
variant
|
|
43
|
-
data: any
|
|
44
|
-
_internalCall?: true
|
|
45
|
-
description?: string
|
|
34
|
+
name: string;
|
|
35
|
+
variant?: string;
|
|
36
|
+
data: any;
|
|
37
|
+
_internalCall?: true;
|
|
38
|
+
description?: string;
|
|
46
39
|
}
|
|
47
|
-
|
|
48
40
|
export interface FeatureToggleApiBase {
|
|
49
|
-
name: string
|
|
41
|
+
name: string;
|
|
50
42
|
setData(name: string, dataParam?: any): void;
|
|
51
|
-
setData(name: string, variant: string, dataParam?: any): void
|
|
52
|
-
setData(nameParam: string, variantOrDataParam: string | {
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
setData(name: string, variant: string, dataParam?: any): void;
|
|
44
|
+
setData(nameParam: string, variantOrDataParam: string | {
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}, dataParam?: any): void;
|
|
55
47
|
on(eventType: EventType, fn: (event: OnEvent) => void, config?: OnConfiguration): void;
|
|
56
|
-
trigger(eventtype: EventType, param?: any);
|
|
57
|
-
showLogs(showLogs?: boolean): void
|
|
58
|
-
|
|
48
|
+
trigger(eventtype: EventType, param?: any): void;
|
|
49
|
+
showLogs(showLogs?: boolean): void;
|
|
59
50
|
/**
|
|
60
51
|
* @deprecated Use `featureToggle.isActive` instead.
|
|
61
52
|
*/
|
|
62
|
-
isVisible(name: string, variant?: string, data?: any): boolean
|
|
63
|
-
|
|
64
|
-
isActive(name: string, variant?: string, data?: any): boolean
|
|
65
|
-
|
|
53
|
+
isVisible(name: string, variant?: string, data?: any): boolean;
|
|
54
|
+
isActive(name: string, variant?: string, data?: any): boolean;
|
|
66
55
|
/**
|
|
67
56
|
* @deprecated Use `featureToggle.setFlag` instead.
|
|
68
57
|
*/
|
|
69
|
-
visibility(name: string, result: boolean | ((rule: Rule) => boolean)): void
|
|
58
|
+
visibility(name: string, result: boolean | ((rule: Rule) => boolean)): void;
|
|
70
59
|
/**
|
|
71
60
|
* @deprecated Use `featureToggle.setFlag` instead.
|
|
72
61
|
*/
|
|
73
|
-
visibility(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void
|
|
62
|
+
visibility(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void;
|
|
74
63
|
/**
|
|
75
64
|
* @deprecated Use `featureToggle.setFlag` instead.
|
|
76
65
|
*/
|
|
77
|
-
visibility(name: string, variant: string | null, data: any, result: boolean | ((rule: Rule) => boolean)): void
|
|
66
|
+
visibility(name: string, variant: string | null, data: any, result: boolean | ((rule: Rule) => boolean)): void;
|
|
78
67
|
/**
|
|
79
68
|
* @deprecated Use `featureToggle.setFlag` instead.
|
|
80
69
|
*/
|
|
81
|
-
visibility(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | (() => boolean)): void
|
|
82
|
-
|
|
83
|
-
setFlag(name: string, result: boolean | ((rule: Rule) => boolean)): void
|
|
84
|
-
setFlag(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void
|
|
85
|
-
setFlag(name: string,
|
|
86
|
-
setFlag(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | (() => boolean)): void
|
|
87
|
-
|
|
70
|
+
visibility(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | ((rule: Rule) => boolean)): void;
|
|
71
|
+
setFlag(name: string, result: boolean | ((rule: Rule) => boolean)): void;
|
|
72
|
+
setFlag(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void;
|
|
73
|
+
setFlag(name: string, variant: string | null, data: any, result: boolean | ((rule: Rule) => boolean)): void;
|
|
74
|
+
setFlag(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | ((rule: Rule) => boolean)): void;
|
|
88
75
|
/**
|
|
89
76
|
* @deprecated Use `featureToggle.setRequiredFlag` instead.
|
|
90
77
|
*/
|
|
91
|
-
requiredVisibility(fn: boolean | ((result: Rule) => boolean)): void
|
|
92
|
-
|
|
78
|
+
requiredVisibility(fn: boolean | ((result: Rule) => boolean)): void;
|
|
93
79
|
/**
|
|
94
80
|
* @deprecated Use `featureToggle.setDefaultFlag` instead.
|
|
95
81
|
*/
|
|
96
|
-
defaultVisibility(fn: boolean | ((result: Rule) => boolean)): void
|
|
97
|
-
|
|
82
|
+
defaultVisibility(fn: boolean | ((result: Rule) => boolean)): void;
|
|
98
83
|
/**
|
|
99
84
|
* This rule will run first and only if it is true, the feature.setFlag() - rules apply.
|
|
100
85
|
* In other words: if the required-rule returns false, all feature.setFlag-rules return false - regardless of its normal result.
|
|
101
|
-
* @param fn
|
|
86
|
+
* @param fn
|
|
102
87
|
*/
|
|
103
|
-
setRequiredFlag(fn: boolean | ((result: Rule) => boolean)): void
|
|
104
|
-
|
|
88
|
+
setRequiredFlag(fn: boolean | ((result: Rule) => boolean)): void;
|
|
105
89
|
/**
|
|
106
90
|
* This is the default-rule and will be overwritten by feature.setFlag() - rules.
|
|
107
91
|
* In other words: If feature.setFlag == false, the result of the defaultRule applies.
|
|
108
92
|
* @param fn DefaultRule
|
|
109
93
|
*/
|
|
110
|
-
setDefaultFlag(fn: boolean | ((result: Rule) => boolean)): void
|
|
111
|
-
|
|
112
|
-
addPlugin(plugin: Plugin)
|
|
94
|
+
setDefaultFlag(fn: boolean | ((result: Rule) => boolean)): void;
|
|
95
|
+
addPlugin(plugin: Plugin): void;
|
|
113
96
|
}
|
|
114
|
-
|
|
115
97
|
export type FeatureToggleApi = FeatureToggleApiBase & Record<string, any>;
|
|
116
|
-
|
|
117
|
-
export function abc(){}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function t(e) {
|
|
11
|
+
return e === "true";
|
|
12
|
+
}
|
|
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);
|
|
21
|
+
}
|
|
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
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { r as urlPlugin };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=url-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-plugin.js","names":[],"sources":["../src/plugins/urlplugin/plugin-url.ts"],"sourcesContent":["interface URLPluginConfig{\n useMockedWindow?: boolean,\n url?: string,\n prefix?: string\n\n}\n\nfunction useWindowMock(){\n return {\n isMocked: true,\n decodeURIComponent:function(param1){\n return param1;\n }\n }\n}\n\ndeclare global {\n interface Window {\n isMocked: boolean\n }\n }\n\n declare var window: Window;\n\nfunction parseValue(value){\n if(value === 'true')\n return true;\n return false;\n}\n\nfunction getParams(url,window) {\n var params = {};\n if (!url) \n return [];\n \n var urlparts = url.split(\"?\");\n\n //no params available for url\n if(urlparts.length < 2)\n return [];\n\n const parts = urlparts[1].split('&');\n\n parts.forEach(function (part) {\n var pair = part.split('=');\n pair[0] = window.decodeURIComponent(pair[0]);\n pair[1] = parseValue(window.decodeURIComponent(pair[1]));\n params[pair[0]] = (pair[1] !== 'undefined') ?\n pair[1] : true;\n });\n\n return params;\n }\n\n function urlPlugin(config: URLPluginConfig={}) {\n let _window;\n\n if(config.useMockedWindow)\n _window = useWindowMock();\n else\n _window = window;\n \n config = Object.assign({},{\n url: _window.isMocked ? \"\" : _window.location.href,\n prefix: \"\"\n },config);\n\n \n\n return function(api){\n api.url = config.url;\n const urlparams = getParams(config.url,_window);\n const prefix = config.prefix;\n\n Object.keys(urlparams).forEach(key => {\n if(!key.startsWith(prefix))\n return;\n \n const keyWithoutPrefix = key.replace(prefix,\"\");\n api.visibility(keyWithoutPrefix,urlparams[key]);\n });\n\n return {name: 'urlplugin'};\n }\n\n}\n\nexport {\n urlPlugin\n}"],"mappings":";AAOA,SAAS,IAAe;CACpB,OAAO;EACH,UAAU;EACV,oBAAmB,SAAS,GAAO;GAC/B,OAAO;EACX;CACJ;AACJ;AAUA,SAAS,EAAW,GAAM;CAGtB,OAFG,MAAU;AAGjB;AAEA,SAAS,EAAU,GAAI,GAAQ;CAC3B,IAAI,IAAS,CAAC;CACd,IAAI,CAAC,GACD,OAAO,CAAC;CAEZ,IAAI,IAAW,EAAI,MAAM,GAAG;CAgB5B,OAbG,EAAS,SAAS,IACV,CAAC,KAIZ,EAFuB,EAAE,CAAC,MAAM,GAEhC,CAAA,CAAM,QAAQ,SAAU,GAAM;EAC9B,IAAI,IAAO,EAAK,MAAM,GAAG;EAGzB,AAFA,EAAK,KAAK,EAAO,mBAAmB,EAAK,EAAE,GAC3C,EAAK,KAAK,EAAW,EAAO,mBAAmB,EAAK,EAAE,CAAC,GACvD,EAAO,EAAK,MAAO,EAAK,OAAO,eAC3B,EAAK;CACT,CAAC,GAEM;AACT;AAED,SAAS,EAAU,IAAwB,CAAC,GAAG;CAC5C,IAAI;CAcJ,OAZA,AAGI,IAHD,EAAO,kBACI,EAAc,IAEd,QAEd,IAAS,OAAO,OAAO,CAAC,GAAE;EACtB,KAAK,EAAQ,WAAW,KAAK,EAAQ,SAAS;EAC9C,QAAQ;CACZ,GAAE,CAAM,GAID,SAAS,GAAI;EAChB,EAAI,MAAM,EAAO;EACjB,IAAM,IAAY,EAAU,EAAO,KAAI,CAAO,GACxC,IAAS,EAAO;EAUtB,OARA,OAAO,KAAK,CAAS,CAAC,CAAC,SAAQ,MAAO;GAClC,IAAG,CAAC,EAAI,WAAW,CAAM,GACrB;GAEJ,IAAM,IAAmB,EAAI,QAAQ,GAAO,EAAE;GAC9C,EAAI,WAAW,GAAiB,EAAU,EAAI;EAClD,CAAC,GAEM,EAAC,MAAM,YAAW;CAC7B;AAEJ"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feature-toggle-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Gives you advanced feature-toggle for any Framework",
|
|
5
|
-
"
|
|
6
|
-
"types": "dist/
|
|
5
|
+
"module": "./dist/feature-toggle.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/feature-toggle.js"
|
|
11
|
+
},
|
|
12
|
+
"./html-plugin": {
|
|
13
|
+
"types": "./dist/plugins/htmlplugin/plugin-html.d.ts",
|
|
14
|
+
"import": "./dist/html-plugin.js"
|
|
15
|
+
},
|
|
16
|
+
"./url-plugin": {
|
|
17
|
+
"types": "./dist/plugins/urlplugin/plugin-url.d.ts",
|
|
18
|
+
"import": "./dist/url-plugin.js"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
7
22
|
"license": "MIT",
|
|
8
23
|
"author": "Manuel Gelsen",
|
|
9
24
|
"type": "module",
|
|
@@ -12,7 +27,7 @@
|
|
|
12
27
|
"test": "tsx --test tests/**/*.test.ts",
|
|
13
28
|
"testonly": "tsx --test tests/**/*.test.ts",
|
|
14
29
|
"prebuild": "rm -rf dist",
|
|
15
|
-
"build": "
|
|
30
|
+
"build": "vite build --mode esm && vite build --mode html-esm && vite build --mode url-esm"
|
|
16
31
|
},
|
|
17
32
|
"repository": {
|
|
18
33
|
"type": "git",
|
|
@@ -21,13 +36,13 @@
|
|
|
21
36
|
"bugs": {
|
|
22
37
|
"url": "https://github.com/bassdman/feature-toggle-api.git/issues"
|
|
23
38
|
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
24
42
|
"devDependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"tslib": "^2.8.1",
|
|
30
|
-
"tsx": "^4.19.2",
|
|
31
|
-
"@rollup/plugin-terser": "^0.4.4"
|
|
43
|
+
"@types/node": "^22.20.2",
|
|
44
|
+
"tsx": "^4.23.13",
|
|
45
|
+
"vite": "^8.3.0",
|
|
46
|
+
"vite-plugin-dts": "^5.1.0"
|
|
32
47
|
}
|
|
33
48
|
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Bug report
|
|
3
|
-
about: Create a report to help us improve
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
**Describe the bug**
|
|
8
|
-
A clear and concise description of what the bug is.
|
|
9
|
-
|
|
10
|
-
**To Reproduce**
|
|
11
|
-
Steps to reproduce the behavior:
|
|
12
|
-
1. Go to '...'
|
|
13
|
-
2. Click on '....'
|
|
14
|
-
3. Scroll down to '....'
|
|
15
|
-
4. See error
|
|
16
|
-
|
|
17
|
-
**Expected behavior**
|
|
18
|
-
A clear and concise description of what you expected to happen.
|
|
19
|
-
|
|
20
|
-
**Screenshots**
|
|
21
|
-
If applicable, add screenshots to help explain your problem.
|
|
22
|
-
|
|
23
|
-
**Desktop (please complete the following information):**
|
|
24
|
-
- OS: [e.g. iOS]
|
|
25
|
-
- Browser [e.g. chrome, safari]
|
|
26
|
-
- Version [e.g. 22]
|
|
27
|
-
|
|
28
|
-
**Smartphone (please complete the following information):**
|
|
29
|
-
- Device: [e.g. iPhone6]
|
|
30
|
-
- OS: [e.g. iOS8.1]
|
|
31
|
-
- Browser [e.g. stock browser, safari]
|
|
32
|
-
- Version [e.g. 22]
|
|
33
|
-
|
|
34
|
-
**Additional context**
|
|
35
|
-
Add any other context about the problem here.
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Feature request
|
|
3
|
-
about: Suggest an idea for this project
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
**Is your feature request related to a problem? Please describe.**
|
|
8
|
-
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
9
|
-
|
|
10
|
-
**Describe the solution you'd like**
|
|
11
|
-
A clear and concise description of what you want to happen.
|
|
12
|
-
|
|
13
|
-
**Describe alternatives you've considered**
|
|
14
|
-
A clear and concise description of any alternative solutions or features you've considered.
|
|
15
|
-
|
|
16
|
-
**Additional context**
|
|
17
|
-
Add any other context or screenshots about the feature request here.
|
package/dist/feature-toggle.d.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
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) => Partial<FeatureToggleApi>;
|
|
34
|
-
type EventType = 'visibilityrule' | 'init' | 'registerEvent' | string;
|
|
35
|
-
interface OnEvent {
|
|
36
|
-
name: string;
|
|
37
|
-
variant: string;
|
|
38
|
-
data: any;
|
|
39
|
-
result?: boolean;
|
|
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' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
|
|
42
|
-
type FeatureFlagKey = `${FirstCharOfFeatureFlagKey}${string}`;
|
|
43
|
-
type FeatureFlag = boolean | ((rule: Rule) => boolean);
|
|
44
|
-
interface FeatureToggleConfig {
|
|
45
|
-
[key: FeatureFlagKey]: FeatureFlag;
|
|
46
|
-
$plugins?: Plugin[];
|
|
47
|
-
/**
|
|
48
|
-
* @deprecated Use key`$plugins` instead.
|
|
49
|
-
*/
|
|
50
|
-
_plugins?: Plugin[];
|
|
51
|
-
/**
|
|
52
|
-
* This rule will always run before the main rule.
|
|
53
|
-
* If it returns false, the main rules will be skipped and false is returned
|
|
54
|
-
*/
|
|
55
|
-
$required?: FeatureFlag;
|
|
56
|
-
/**
|
|
57
|
-
* This rule will always run after the main rule.
|
|
58
|
-
* If the main rule returns false, the result of the default rule will be taken.s
|
|
59
|
-
*/
|
|
60
|
-
$default?: FeatureFlag;
|
|
61
|
-
}
|
|
62
|
-
interface Rule {
|
|
63
|
-
name: string;
|
|
64
|
-
variant: string;
|
|
65
|
-
data: any;
|
|
66
|
-
_internalCall?: true;
|
|
67
|
-
description?: string;
|
|
68
|
-
}
|
|
69
|
-
interface FeatureToggleApiBase {
|
|
70
|
-
name: string;
|
|
71
|
-
setData(name: string, dataParam?: any): void;
|
|
72
|
-
setData(name: string, variant: string, dataParam?: any): void;
|
|
73
|
-
setData(nameParam: string, variantOrDataParam: string | {
|
|
74
|
-
[key: string]: any;
|
|
75
|
-
}, dataParam?: any): void;
|
|
76
|
-
on(eventType: EventType, fn: (event: OnEvent) => void, config?: OnConfiguration): void;
|
|
77
|
-
trigger(eventtype: EventType, param?: any): any;
|
|
78
|
-
showLogs(showLogs?: boolean): void;
|
|
79
|
-
/**
|
|
80
|
-
* @deprecated Use `featureToggle.isActive` instead.
|
|
81
|
-
*/
|
|
82
|
-
isVisible(name: string, variant?: string, data?: any): boolean;
|
|
83
|
-
isActive(name: string, variant?: string, data?: any): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* @deprecated Use `featureToggle.setFlag` instead.
|
|
86
|
-
*/
|
|
87
|
-
visibility(name: string, result: boolean | ((rule: Rule) => boolean)): void;
|
|
88
|
-
/**
|
|
89
|
-
* @deprecated Use `featureToggle.setFlag` instead.
|
|
90
|
-
*/
|
|
91
|
-
visibility(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void;
|
|
92
|
-
/**
|
|
93
|
-
* @deprecated Use `featureToggle.setFlag` instead.
|
|
94
|
-
*/
|
|
95
|
-
visibility(name: string, variant: string | null, data: any, result: boolean | ((rule: Rule) => boolean)): void;
|
|
96
|
-
/**
|
|
97
|
-
* @deprecated Use `featureToggle.setFlag` instead.
|
|
98
|
-
*/
|
|
99
|
-
visibility(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | (() => boolean)): void;
|
|
100
|
-
setFlag(name: string, result: boolean | ((rule: Rule) => boolean)): void;
|
|
101
|
-
setFlag(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void;
|
|
102
|
-
setFlag(name: string, variant: string | null, data: any, result: boolean | ((rule: Rule) => boolean)): void;
|
|
103
|
-
setFlag(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | (() => boolean)): void;
|
|
104
|
-
/**
|
|
105
|
-
* @deprecated Use `featureToggle.setRequiredFlag` instead.
|
|
106
|
-
*/
|
|
107
|
-
requiredVisibility(fn: boolean | ((result: Rule) => boolean)): void;
|
|
108
|
-
/**
|
|
109
|
-
* @deprecated Use `featureToggle.setDefaultFlag` instead.
|
|
110
|
-
*/
|
|
111
|
-
defaultVisibility(fn: boolean | ((result: Rule) => boolean)): void;
|
|
112
|
-
/**
|
|
113
|
-
* This rule will run first and only if it is true, the feature.setFlag() - rules apply.
|
|
114
|
-
* In other words: if the required-rule returns false, all feature.setFlag-rules return false - regardless of its normal result.
|
|
115
|
-
* @param fn
|
|
116
|
-
*/
|
|
117
|
-
setRequiredFlag(fn: boolean | ((result: Rule) => boolean)): void;
|
|
118
|
-
/**
|
|
119
|
-
* This is the default-rule and will be overwritten by feature.setFlag() - rules.
|
|
120
|
-
* In other words: If feature.setFlag == false, the result of the defaultRule applies.
|
|
121
|
-
* @param fn DefaultRule
|
|
122
|
-
*/
|
|
123
|
-
setDefaultFlag(fn: boolean | ((result: Rule) => boolean)): void;
|
|
124
|
-
addPlugin(plugin: Plugin): any;
|
|
125
|
-
}
|
|
126
|
-
type FeatureToggleApi = FeatureToggleApiBase & Record<string, any>;
|
|
127
|
-
|
|
128
|
-
declare function useFeatureToggle(config?: FeatureToggleConfig): FeatureToggleApi;
|
|
129
|
-
|
|
130
|
-
export { type EventType, type FeatureFlag, type FeatureFlagKey, type FeatureToggleApi, type FeatureToggleApiBase, type FeatureToggleConfig, type FirstCharOfFeatureFlagKey, type OnConfiguration, type OnEvent, htmlPlugin, urlPlugin, useFeatureToggle };
|