UNPKG

2.52 kBJavaScriptView Raw
1function a(r){let t;return r?(t=r.toIterable)?t.call(r):r:[]}function d(r,t){let e=Object.getOwnPropertyDescriptors(t);return delete e.constructor,Object.defineProperties(r,e),r}var i=class{get emptyΦ(){return this.length===0}get size(){return this.length}set size(t){this.length=t}get random(){return this[Math.floor(Math.random()*this.length)]}clear(){return this.length=0}async resolve(){return await Promise.all(this)}get unique(){let t=[];for(let e=0,o=a(this),s=o.length;e<s;e++){let n=o[e];t.indexOf(n)==-1&&t.push(n)}return t}add(t){return this.has(t)||this.push(t),t}has(t){return this.includes(t)}get reversed(){return this.slice().reverse()}sorted(t,e=!1){let o=this.slice(),s=t;return typeof t=="string"?s=function(n){return n[t]}:t instanceof Map?s=function(n){return t.get(n)}:t instanceof Function||(s=function(n){return n}),o.sort(function(n,f){let c=s(n),p=s(f);return c>p?1:c<p?-1:0}),e?o.reversed:o}delete(t){let e=this.indexOf(t);if(!(e<0))return this.splice(e,1)}};d(Array.prototype,i.prototype);globalThis.sleep=function(r=0,t){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};function g(r,t){let e=Object.getOwnPropertyDescriptors(t);return delete e.constructor,Object.defineProperties(r,e),r}var u=class{to(t){var e=this;return Array.from({length:t-this+1},function(o,s){return e+s})}floor(){return Math.floor(this)}ceil(){return Math.ceil(this)}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,o=0,s=1){let n=(this-t)/(e-t);return o+n*(s-o)}};g(Number.prototype,u.prototype);function M(r,t){let e=Object.getOwnPropertyDescriptors(t);return delete e.constructor,Object.defineProperties(r,e),r}var l=class{filter(t){return new Set(Array.from(this).filter(t))}};M(Set.prototype,l.prototype);function m(r,t){let e=Object.getOwnPropertyDescriptors(t);return delete e.constructor,Object.defineProperties(r,e),r}var h=class{get upperΦ(){return/^[A-Z][A-Z_\d]*$/.test(this)}get numΦ(){return this.intΦ||this.floatΦ}get intΦ(){return/^-?\d+$/.test(this)}get floatΦ(){return/^-?\d+\.\d+$/.test(this)}get pascalΦ(){return/^[A-Z]+[a-z]+[A-Za-z]*/.test(this)}};m(String.prototype,h.prototype);