UNPKG

e-enum

Version:

ts enum object, 带typescript签名的多字段枚举关联对象映射

2 lines (1 loc) 1.88 kB
"use strict";var m=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var k=(t,e)=>{for(var s in e)m(t,s,{get:e[s],enumerable:!0})},b=(t,e,s,y)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of C(e))!$.call(t,r)&&r!==s&&m(t,r,{get:()=>e[r],enumerable:!(y=E(e,r))||y.enumerable});return t};var h=t=>b(m({},"__esModule",{value:!0}),t);var R={};k(R,{default:()=>K,eEnum:()=>f});module.exports=h(R);var O=function(){let e={};for(let s=0;s<arguments.length;s++){let y=arguments[s];if(y!=null)for(let r in y)Object.prototype.hasOwnProperty.call(y,r)&&(e[r]=y[r])}return e};function D(t){return Object.prototype.toString.call(t)==="[object Array]"}function p(t,e){for(let s=0;s<t.length;s++)if(t[s]===e)return!0;return!1}var I=["$list","$map","$options"],a=["$is","$eq","$in"];function f(t){var r,c,d;let e={},s={};for(let u in t)if(Object.prototype.hasOwnProperty.call(t,u)){let o=t[u];if(p(I,u))throw new Error(`The built-in property "${u}" cannot be used!`);if(!o||!("code"in o))throw new Error("Code must be specified!");for(let n=0;n<a.length;n++)if(a[n]in o)throw new Error(`The built-in property "${a[n]}" cannot be used!`);if(s[o.code])throw new Error(`The code "${(d=(c=(r=o.code)==null?void 0:r.toString)==null?void 0:c.call(r))!=null?d:""}" has been used!`);let i=O(o,{$eq:n=>n===o.code,$is:n=>n===u,$in:n=>p(n,u)});e[u]=i,s[o.code]=i}return O(e,s,{$list(u=[]){let o=[],l=D(u)?u:[u];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i];!n.$exclude&&!n.$in(l)&&o.push(n)}return o.sort((i,n)=>(i.$sort||0)-(n.$sort||0))},$map(u,o=[]){if(typeof u!="function")throw new Error("is not a function!");let l=[],i=this.$list(o);for(let n=0;n<i.length;n++)l.push(u(i[n]));return l},$options(u=[]){return this.$map(o=>({label:o.label||String(o.code),value:o.code}),u)}})}var K=f;