-
Notifications
You must be signed in to change notification settings - Fork 0
/
js-enumerate-latest.min.js
1 lines (1 loc) · 6.63 KB
/
js-enumerate-latest.min.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Enum=t():e.Enum=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}e.d(t,{default:()=>k});var r=function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;Object.keys(t).forEach((function(o){"object"!==n(t[o])||Object.isFrozen(t[o])||e(t[o],r+1)})),Object.freeze(t)},o=function(e){return null==e||""===e},i=["length","options","filters"],l=function(e){if("object"!==n(e)||e instanceof Array)throw Error("member must be a object instance, ".concat(e," is illegal."));var t=JSON.stringify(e);if(o(e.key))throw Error('member must have a "key" property, and empty string is not allowed. '.concat(t," is illegal."));if("string"!=typeof e.key)throw Error("member.key can only be a string, ".concat(t," is illegal."));if(i.indexOf(e.key)>-1)throw Error("member.key do not allow the use of built-in fields, eg: ".concat(i.join("/")));if(!e.key.match(/^[A-Za-z0-9_-]+$/))throw Error("member.key can only consist of letters, numbers, underscores and dashes, ".concat(t," is illegal."));if(e.key.startsWith("__"))throw Error("member.key cannot start with '__', which is generally used for built-in attributes, ".concat(t," is illegal."));if(void 0===e.value||null===e.value)throw Error('member must have a "value" property, undefined/null is not allowed. '.concat(t," is illegal."));if(null===e.label||""===e.label)throw Error("member.label best type is string, and empty string is not allowed. ".concat(t," is illegal."))};function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function u(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){c(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function c(e,t,n){return(t=y(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(e)}function s(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,y(r.key),r)}}function y(e){var t=function(e,t){if("object"!=f(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=f(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==f(t)?t:t+""}function b(e,t,n){h(e,t),t.set(e,n)}function h(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function p(e,t){return e.get(v(e,t))}function m(e,t,n){return e.set(v(e,t),n),n}function v(e,t,n){if("function"==typeof e?e===t:e.has(t))return arguments.length<3?t:n;throw new TypeError("Private element is not present on this object")}var d=new WeakMap,g=new WeakMap,w=new WeakSet,k=function(){function e(t){var n,o=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=i.freez,u=void 0===a||a,c=i.allDefaultValue,s=void 0===c?{key:"__ALL",value:"",label:"全部"}:c;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),h(this,n=w),n.add(this),b(this,d,[]),b(this,g,null),m(g,this,s);var y=[];if(t instanceof Array)t.forEach((function(e){l(e),y.push(e)}));else{if("object"!==f(t))throw Error("Failed to initialize enum, data=".concat(JSON.stringify(t)," is wrong format"));Object.keys(t).forEach((function(e){var n={key:e,value:t[e]};l(n),y.push(n)}))}var v=[];if(y.forEach((function(e){if(v.indexOf(e.key)>-1)throw Error("Initialization members does not allow duplicate keys, key=".concat(e.key," is duplicated."));v.push(e.key),o[e.key]=e.value})),0===v.length)throw Error("No member of the Enum is defined in the form [{key, value, label}], The Enum has at least one member");m(d,this,y),Object.defineProperty(this,"options",{enumerable:!1,configurable:!1,writable:!1,value:this.getOptions({enableAll:!1})}),Object.defineProperty(this,"filters",{enumerable:!1,configurable:!1,writable:!1,value:this.getOptions()}),u&&(r(p(d,this)),r(p(g,this)),r(this))}return t=e,n=[{key:"length",get:function(){return p(d,this).length}},{key:"map",value:function(e){return p(d,this).map(e)}},{key:"forEach",value:function(e){return p(d,this).forEach(e)}},{key:"filter",value:function(e){return p(d,this).filter(e)}},{key:"getMember",value:function(e){var t=p(d,this).filter((function(t){return t.value===e}));if(t.length>0)return t[0]}},{key:"has",value:function(e){return void 0!==this.getMember(e)}},{key:"getLabel",value:function(e){var t=this.getMember(e);return v(w,this,O).call(this,t,e)}},{key:"toJSON",value:function(){return p(d,this)}},{key:"to_filters",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.getOptions(u({enableAll:!1,keyLabel:"text"},e))}},{key:"getOptions",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.enableAll,r=void 0===n||n,o=t.keyValue,i=void 0===o?"value":o,l=t.keyLabel,a=void 0===l?"label":l,f=t.allDefaultValue,s=void 0===f?null:f,y=u(u({},p(g,this)),s),b=p(d,this).map((function(t){return u(u({},t),{},c(c({},i,t.value),a,v(w,e,O).call(e,t)))}));return r&&(b=[u(u({},y),{},c(c({},i,y.value),a,y.label))].concat(b)),b}},{key:Symbol.iterator,value:function(){var e=this,t=0;return{next:function(){return t<p(d,e).length?{done:!1,value:p(d,e)[t++]}:{done:!0}}}}}],o=[{key:"register",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Enum";"undefined"==typeof window||window[t]||(window[t]=e),"undefined"==typeof global||global[t]||(global[t]=e)}}],n&&s(t.prototype,n),o&&s(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n,o}();function O(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return e?o(e.label)?e.value:e.label:t}return t.default})()));