This repository was archived by the owner on Jul 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathflags.js
More file actions
1 lines (1 loc) · 3.33 KB
/
flags.js
File metadata and controls
1 lines (1 loc) · 3.33 KB
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["flags.js"]=t():e["flags.js"]=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(t.s=0)}([function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i="feature_",l=function(){function e(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];n(this,e),this.ctx={},this.config=t,this.rules=r,this.ctx=o}return u(e,null,[{key:"parseConfig",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?e.parse:arguments[1];return Object.keys(t).reduce(function(e,r){var o=n(r,t[r]);return o&&(e[o.key]=o.val),e},{})}},{key:"parse",value:function(e,t){var n=e.toLowerCase();if(-1!==n.indexOf(i))return{key:n.slice(i.length),val:t}}}]),u(e,[{key:"addRule",value:function(e,t){this.rules[e]=t}},{key:"testRule",value:function(e,t,n){return this.rules[t]?this.rules[t].call(n,e[t]):this.tryBooleanOps(e,t,n)}},{key:"tryBooleanOps",value:function(e,t,n){var r=this;if("or"===t)return e[t].some(function(e){return Object.keys(e).some(function(t){return r.testRule(e,t,n)})});if("and"===t)return e[t].every(function(e){return Object.keys(e).some(function(t){return r.testRule(e,t,n)})});if("not"===t){var u=function(){var o=e[t];return{v:!Object.keys(o).some(function(e){return r.testRule(o,e,n)})}}();if("object"===("undefined"==typeof u?"undefined":o(u)))return u.v}return!1}},{key:"enabled",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?this.ctx:arguments[1],r=this.config[e];if(!r)return!1;if(r===!0||r===!1)return r;var o=Object.keys(r),u=o.some(function(e){return t.testRule(r,e,n)});return u}},{key:"allEnabled",value:function(){var e=this,t=arguments.length<=0||void 0===arguments[0]?this.ctx:arguments[0],n=arguments.length<=1||void 0===arguments[1]?!0:arguments[1];return Object.keys(this.config).filter(function(r){return e.enabled(r,t)===n})}},{key:"allDisabled",value:function(){var e=arguments.length<=0||void 0===arguments[0]?this.ctx:arguments[0];return this.allEnabled(e,!1)}},{key:"withContext",value:function(t){return new e(this.config,this.rules,t)}},{key:"clone",value:function(){var t=arguments.length<=0||void 0===arguments[0]?this.config:arguments[0],n=arguments.length<=1||void 0===arguments[1]?this.rules:arguments[1],o=arguments.length<=2||void 0===arguments[2]?this.ctx:arguments[2];return new e(r({},t),r({},n),r({},o))}}]),e}();t["default"]=l}])});