imba
Version:
2 lines (1 loc) • 6.3 kB
JavaScript
var d=Symbol.for("#__init__"),T=Symbol.for("#__initor__");var E=Symbol.for("#meta"),x=Symbol.for("imba");var p={IsExtension:1,IsTag:2,HasDescriptors:4,HasSuperCalls:8,HasConstructor:16,HasFields:32,HasMixins:64,HasInitor:128,HasDecorators:256,IsObjectExtension:512,IsMixin:1024},g=new Map,b=globalThis[x]||(globalThis[x]={counter:0,classes:g});function y(r,t={}){var e;return g.has(r)||g.set(r,{symbol:Symbol(r.name),parent:(e=Object.getPrototypeOf(r.prototype))==null?void 0:e.constructor,for:r,uses:null,inits:null,id:b.counter++,...t}),g.get(r)}function $(r,t){var e;return typeof t=="string"?typeof r===t:(e=t==null?void 0:t[Symbol.hasInstance])==null?void 0:e.call(t,r)}function v(r){var t;return((t=r==null?void 0:r.toIterable)==null?void 0:t.call(r))||r}function L(r,t){if(!r||!t)return!1;if(r.get)return t.get===r.get;if(r.set)return t.set===r.set;if(r.value)return r.value===t.value}function C(r,t,e,n={}){let i=r.constructor;!e&&t&&(e=Object.getOwnPropertyDescriptors(t),delete e.constructor,e[d]&&(console.warn(`Cannot define plain fields when extending class ${i.name}`),delete e[d]));let o=y(i);if(o&&o.augments){let u=new Map;for(let s of Object.keys(e)){let l=Object.getOwnPropertyDescriptor(r,s);for(let a of o.augments){let c=u.get(a);c||u.set(a,c={});let m=Object.getOwnPropertyDescriptor(a.prototype,s);m&&!L(l,m)?console.warn("wont extend",s,m,l):c[s]=e[s]}}for(let[s,l]of u)Object.keys(l).length&&C(s.prototype,null,l)}return Object.defineProperties(r,e),r}function _(r,t){var u;let e=y(r),n=y(t),i=n.parent;for(;i&&((u=y(i))==null?void 0:u.flags)&p.IsMixin;){_(r,i),i=null;break}if(i&&!(r.prototype instanceof i))throw new Error(`Mixin ${t.name} has superclass not present in target class`);if(!n.augments){n.augments=new Set;let s=n.ref=Symbol(t.name),l=Object[Symbol.hasInstance];t.prototype[s]=!0,Object.defineProperty(t,Symbol.hasInstance,{value:function(a){return this===t?a&&!!a[s]:l.call(this,a)}})}if(r.prototype[n.ref])return r;if(n.uses)for(let s of n.uses)_(r,s);n.augments.add(r),e.uses||(e.uses=[]),e.uses.push(t);let o=Object.getOwnPropertyDescriptors(t.prototype);return delete o.constructor,o[d]&&(e.inits||(e.inits=[]),e.inits.push(t.prototype[d]),delete o[d]),Object.defineProperties(r.prototype,o),(t==null?void 0:t.mixed)instanceof Function&&t.mixed(r),r}var h={cache:{},self:null,target:null,proxy:new Proxy({},{apply:(r,t,e)=>Reflect.apply(h.target,t,e),get:(r,t)=>{let e=Reflect.get(h.target,t,h.self);return e instanceof Function?e.bind(h.self):e},set:(r,t,e,n)=>Reflect.set(h.target,t,e,h.self)})};function f(r,t,e,n,i=null){var a;let o=Object.getPrototypeOf(r.prototype),u=(n&(p.HasMixins|p.IsExtension))==p.HasMixins,s;if(u&&(g.set(r,g.get(o.constructor)),o=Object.getPrototypeOf(o)),i){let c=n&p.IsObjectExtension?i:i.prototype,m=y(r);if(m.uses){i===c&&console.warn("Cannot extend object with mixins");for(let F of m.uses)_(i,F)}return n&p.HasSuperCalls&&(h.cache[t]=Object.create(Object.getPrototypeOf(c),Object.getOwnPropertyDescriptors(c))),C(c,r.prototype),i}let l=o==null?void 0:o.constructor;if(s=y(r,{symbol:t}),Object.defineProperty(r,E,{value:s,enumerable:!1,configurable:!0}),e&&r.name!==e&&Object.defineProperty(r,"name",{value:e,configurable:!0}),s.flags=n,n&p.HasConstructor&&(r.prototype[T]=t),s.uses)for(let c of s.uses)(a=c.mixes)==null||a.call(c,r);return(l==null?void 0:l.inherited)instanceof Function&&l.inherited(r),r}var q=Symbol(),O=class O{get size(){return this.length}set size(t){this.length=t}get emptyΦ(){return this.size===0}get anyΦ(){return this.size>0}get manyΦ(){return this.size>1}get oneΦ(){return this.size===1}get random(){return this[Math.floor(Math.random()*this.length)]}clear(){return this.length=0,this}async resolve(){return await Promise.all(this)}get unique(){let t=[];for(let e=0,n=v(this),i=n.length;e<i;e++){let o=n[e];t.indexOf(o)==-1&&t.push(o)}return t}set unique(t){Object.defineProperty(this,"unique",{value:t})}add(t){return this.has(t)||this.push(t),t}has(t){return this.includes(t)}uniq(t=null){var e=this;if(!t)return Array.from(new Set(this));let n=new Set;return this.filter(function(i){let o=t(i,e);if(!n.has(o))return n.add(o),!0})}sorted(t,e=!1){let n=this.slice(),i=t;return typeof t=="string"?i=function(o){return o[t]}:$(t,Map)?i=function(o){return t.get(o)}:$(t,Function)||(i=function(o){return o}),e?n.sort(function(o,u){let s=i(o),l=i(u);return s<l?1:s>l?-1:0}):n.sort(function(o,u){let s=i(o),l=i(u);return s>l?1:s<l?-1:0})}delete(t){let e=this.indexOf(t);return e<0?!1:(this.splice(e,1),!0)}};f(O,q,"Array",1,Array);var H=O;globalThis.sleep=function(r=0,t=null){return new Promise(function(e){return setTimeout(function(){return t&&t(),e()},r)})};Math.randΞint=function(r,t){return r=Math.ceil(r),t=Math.floor(t),Math.floor(Math.random()*(t-r+1)+r)};Math.randΞfloat=function(r,t){return Math.random()*(t-r)+r};Math.randΞbool=function(){return Math.random()<.5};var Z=Symbol(),S=class S{to(t){var e=this;return Array.from({length:t-this+1},function(n,i){return e+i})}floor(){return Math.floor(this)}ceil(){return Math.ceil(this)}times(t){let e=0,n=this;for(;e<n;)t(e++)}round(t=1){if(t!=1){let e=1/t;return Math.round(this*e)/e}return Math.round(this)}clamp(t,e){return typeof e!="number"?Math.max(this,t):Math.min(typeof t!="number"?this:Math.max(this,t),e)}lerp(t,e,n=0,i=1){let o=(this-t)/(e-t);return n+o*(i-n)}};f(S,Z,"Number",1,Number);var I=S;var K=Symbol(),M=class M{filter(t){return new Set(Array.from(this).filter(t))}};f(M,K,"Set",1,Set);var z=M;var N=Symbol(),w=class w{setnx(t,e){var n;return(n=this.get(t))!=null?n:this.set(t,e)&&e}};f(w,N,"WeakMap",1,WeakMap);var A=w,U=Symbol(),P=class P{setnx(t,e){var n;return(n=this.get(t))!=null?n:this.set(t,e)&&e}};f(P,U,"Map",1,Map);var D=P;var V=Symbol(),j=class j{get upperΦ(){return/^[A-Z][A-Z_\d]*$/.test(this)}get numΦ(){return this.intΦ||this.floatΦ}get intΦ(){return/^-?(0|[1-9]\d*)$/.test(this)}get floatΦ(){return/^-?\d+\.\d+$/.test(this)}get pascalΦ(){return/^[A-Z]+[a-z]+[A-Za-z]*/.test(this)}get slug(){let t=this.normalize("NFKD");return t=t.replace(/[\u0300-\u036f]/g,""),t=t.trim(),t=t.toLowerCase(),t=t.replace(/[^a-z0-9 -]/g,""),t=t.replace(/\s+/g,"-"),t=t.replace(/-+/g,"-"),t}pluck(t){let e=this.match(t),n=e&&e.length;return n>2?e.slice(1):e?e[n-1]:null}};f(j,V,"String",1,String);var R=j;