imba
Version:
2 lines (1 loc) • 6.07 kB
JavaScript
var d=Symbol.for("#__init__"),R=Symbol.for("#__initor__");var F=Symbol.for("#meta"),x=Symbol.for("imba");var a={IsExtension:1,IsTag:2,HasDescriptors:4,HasSuperCalls:8,HasConstructor:16,HasFields:32,HasMixins:64,HasInitor:128,HasDecorators:256,IsObjectExtension:512,IsMixin:1024},m=new Map,T=globalThis[x]||(globalThis[x]={counter:0,classes:m});function g(r,t={}){return m.has(r)||m.set(r,{symbol:Symbol(r.name),parent:Object.getPrototypeOf(r.prototype)?.constructor,for:r,uses:null,inits:null,id:T.counter++,...t}),m.get(r)}function _(r,t){return typeof t=="string"?typeof r===t:t?.[Symbol.hasInstance]?.(r)}function j(r){return r?.toIterable?.()||r}function E(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 v(r,t,e,n={}){let o=r.constructor;!e&&t&&(e=Object.getOwnPropertyDescriptors(t),delete e.constructor,e[d]&&(console.warn(`Cannot define plain fields when extending class ${o.name}`),delete e[d]));let i=g(o);if(i&&i.augments){let u=new Map;for(let s of Object.keys(e)){let l=Object.getOwnPropertyDescriptor(r,s);for(let f of i.augments){let h=u.get(f);h||u.set(f,h={});let y=Object.getOwnPropertyDescriptor(f.prototype,s);y&&!E(l,y)?console.warn("wont extend",s,y,l):h[s]=e[s]}}for(let[s,l]of u)Object.keys(l).length&&v(s.prototype,null,l)}return Object.defineProperties(r,e),r}function b(r,t){let e=g(r),n=g(t),o=n.parent;for(;o&&g(o)?.flags&a.IsMixin;){b(r,o),o=null;break}if(o&&!(r.prototype instanceof o))throw new Error(`Mixin ${t.name} has superclass not present in target class`);if(!n.augments){n.augments=new Set;let u=n.ref=Symbol(t.name),s=Object[Symbol.hasInstance];t.prototype[u]=!0,Object.defineProperty(t,Symbol.hasInstance,{value:function(l){return this===t?l&&!!l[u]:s.call(this,l)}})}if(r.prototype[n.ref])return r;if(n.uses)for(let u of n.uses)b(r,u);n.augments.add(r),e.uses||(e.uses=[]),e.uses.push(t);let i=Object.getOwnPropertyDescriptors(t.prototype);return delete i.constructor,i[d]&&(e.inits||(e.inits=[]),e.inits.push(t.prototype[d]),delete i[d]),Object.defineProperties(r.prototype,i),t?.mixed instanceof Function&&t.mixed(r),r}var p={cache:{},self:null,target:null,proxy:new Proxy({},{apply:(r,t,e)=>Reflect.apply(p.target,t,e),get:(r,t)=>{let e=Reflect.get(p.target,t,p.self);return e instanceof Function?e.bind(p.self):e},set:(r,t,e,n)=>Reflect.set(p.target,t,e,p.self)})};function c(r,t,e,n,o=null){let i=Object.getPrototypeOf(r.prototype),u=(n&(a.HasMixins|a.IsExtension))==a.HasMixins,s;if(u&&(m.set(r,m.get(i.constructor)),i=Object.getPrototypeOf(i)),o){let f=n&a.IsObjectExtension?o:o.prototype,h=g(r);if(h.uses){o===f&&console.warn("Cannot extend object with mixins");for(let y of h.uses)b(o,y)}return n&a.HasSuperCalls&&(p.cache[t]=Object.create(Object.getPrototypeOf(f),Object.getOwnPropertyDescriptors(f))),v(f,r.prototype),o}let l=i?.constructor;if(s=g(r,{symbol:t}),Object.defineProperty(r,F,{value:s,enumerable:!1,configurable:!0}),e&&r.name!==e&&Object.defineProperty(r,"name",{value:e,configurable:!0}),s.flags=n,n&a.HasConstructor&&(r.prototype[R]=t),s.uses)for(let f of s.uses)f.mixes?.(r);return l?.inherited instanceof Function&&l.inherited(r),r}var L=Symbol(),$=class ${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=j(this),o=n.length;e<o;e++){let i=n[e];t.indexOf(i)==-1&&t.push(i)}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(o){let i=t(o,e);if(!n.has(i))return n.add(i),!0})}sorted(t,e=!1){let n=this.slice(),o=t;return typeof t=="string"?o=function(i){return i[t]}:_(t,Map)?o=function(i){return t.get(i)}:_(t,Function)||(o=function(i){return i}),e?n.sort(function(i,u){let s=o(i),l=o(u);return s<l?1:s>l?-1:0}):n.sort(function(i,u){let s=o(i),l=o(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)}};c($,L,"Array",1,Array);var C=$;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 q=Symbol(),O=class O{to(t){var e=this;return Array.from({length:t-this+1},function(n,o){return e+o})}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,o=1){let i=(this-t)/(e-t);return n+i*(o-n)}};c(O,q,"Number",1,Number);var H=O;var Z=Symbol(),S=class S{filter(t){return new Set(Array.from(this).filter(t))}};c(S,Z,"Set",1,Set);var I=S;var K=Symbol(),M=class M{setnx(t,e){return this.get(t)??(this.set(t,e)&&e)}};c(M,K,"WeakMap",1,WeakMap);var z=M,N=Symbol(),w=class w{setnx(t,e){return this.get(t)??(this.set(t,e)&&e)}};c(w,N,"Map",1,Map);var A=w;var U=Symbol(),P=class P{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}};c(P,U,"String",1,String);var D=P;