@byloth/core 1.5.3 → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +521 -364
- package/dist/core.js.map +1 -1
- package/dist/core.umd.cjs +2 -2
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +8 -8
- package/src/helpers.ts +3 -0
- package/src/index.ts +16 -4
- package/src/models/aggregators/reduced-iterator.ts +2 -2
- package/src/models/exceptions/core.ts +3 -4
- package/src/models/exceptions/index.ts +41 -1
- package/src/models/game-loop.ts +83 -0
- package/src/models/index.ts +10 -4
- package/src/models/iterators/smart-async-iterator.ts +3 -1
- package/src/models/iterators/smart-iterator.ts +3 -1
- package/src/models/json/index.ts +3 -0
- package/src/models/{json-storage.ts → json/json-storage.ts} +39 -26
- package/src/models/json/types.ts +3 -0
- package/src/models/publisher.ts +39 -0
- package/src/models/timers/clock.ts +47 -0
- package/src/models/timers/countdown.ts +81 -0
- package/src/models/timers/index.ts +4 -0
- package/src/models/types.ts +9 -0
- package/src/utils/date.ts +4 -4
- package/src/utils/index.ts +1 -1
- package/src/models/subscribers.ts +0 -35
package/dist/core.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(o,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(o=typeof globalThis<"u"?globalThis:o||self,f(o.Core={}))})(this,function(o){"use strict";var me=Object.defineProperty;var we=(o,f,_)=>f in o?me(o,f,{enumerable:!0,configurable:!0,writable:!0,value:_}):o[f]=_;var a=(o,f,_)=>we(o,typeof f!="symbol"?f+"":f,_);var N,C;const f=typeof window<"u"&&typeof window.document<"u",_=typeof process<"u"&&((N=process.versions)==null?void 0:N.node),O=typeof self=="object"&&((C=self.constructor)==null?void 0:C.name)==="DedicatedWorkerGlobalScope";class d extends Error{static FromUnknown(e){if(e instanceof d)return e;if(e instanceof Error){const t=new d(e.message);return t.stack=e.stack,t.name=e.name,t}return new d(`${e}`)}constructor(e,t,n="Exception"){super(e),this.cause=t,this.name=n,t&&(t instanceof Error?this.stack+=`
|
|
2
2
|
|
|
3
3
|
Caused by ${t.stack}`:this.stack+=`
|
|
4
4
|
|
|
5
|
-
Caused by ${t}`)}get[Symbol.toStringTag](){return"Exception"}}class I extends l{constructor(e,t,n="FatalErrorException"){e===void 0&&(e="The routine has encountered an unrecoverable error and cannot continue as expected. Please, refresh the page and try again. If the problem persists, contact the support team."),super(e,t,n)}get[Symbol.toStringTag](){return"FatalErrorException"}}class P extends l{constructor(e,t,n="NotImplementedException"){e===void 0&&(e="This feature is not implemented yet. Please, try again later."),super(e,t,n)}get[Symbol.toStringTag](){return"NotImplementedException"}}class R extends l{constructor(e,t,n="FileNotFoundException"){super(e,t,n)}get[Symbol.toStringTag](){return"FileNotFoundException"}}class F extends l{constructor(e,t,n="KeyException"){super(e,t,n)}get[Symbol.toStringTag](){return"KeyException"}}class j extends l{constructor(e,t,n="NetworkException"){super(e,t,n)}get[Symbol.toStringTag](){return"NetworkException"}}class A extends l{constructor(e,t,n="PermissionException"){super(e,t,n)}get[Symbol.toStringTag](){return"PermissionException"}}class S extends l{constructor(e,t,n="ReferenceException"){super(e,t,n)}get[Symbol.toStringTag](){return"ReferenceException"}}class q extends l{constructor(e,t,n="RuntimeException"){super(e,t,n)}get[Symbol.toStringTag](){return"RuntimeException"}}class b extends l{constructor(e,t,n="TimeoutException"){super(e,t,n)}get[Symbol.toStringTag](){return"TimeoutException"}}class k extends l{constructor(e,t,n="TypeException"){super(e,t,n)}get[Symbol.toStringTag](){return"TypeException"}}class d extends l{constructor(e,t,n="ValueException"){super(e,t,n)}get[Symbol.toStringTag](){return"ValueException"}}class f{constructor(e){a(this,"_elements");this._elements=new c(e)}filter(e){const t=this._elements;return new f(function*(){for(const[n,[r,s]]of t.enumerate())e(r,s,n)&&(yield[r,s])})}map(e){const t=this._elements;return new f(function*(){for(const[n,[r,s]]of t.enumerate())yield[r,e(r,s,n)]})}reduce(e,t){let n=0,r;if(t!==void 0)r=t;else{const s=this._elements.next();if(s.done)throw new k("Reduce of empty iterator with no initial value");n+=1,r=s.value[1]}for(const[s,u]of this._elements)r=e(s,r,u,n),n+=1;return r}keys(){const e=this._elements;return new c(function*(){for(const[t]of e)yield t})}items(){return this._elements}values(){const e=this._elements;return new c(function*(){for(const[t,n]of e)yield n})}toArray(){return Array.from(this.values())}toMap(){return new Map(this.items())}toObject(){return Object.fromEntries(this.items())}get[Symbol.toStringTag](){return"ReducedIterator"}}class y{constructor(e){a(this,"_elements");this._elements=new c(e)}every(e){const t=new Map;for(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!0];u&&t.set(n,[s+1,e(n,r,s)])}return new f(function*(){for(const[n,[r,s]]of t)yield[n,s]})}some(e){const t=new Map;for(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!1];u||t.set(n,[s+1,e(n,r,s)])}return new f(function*(){for(const[n,[r,s]]of t)yield[n,s]})}filter(e){const t=this._elements;return new y(function*(){const n=new Map;for(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),e(r,s,u)&&(yield[r,s])}})}map(e){const t=this._elements;return new y(function*(){const n=new Map;for(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),yield[r,e(r,s,u)]}})}reduce(e,t){const n=new Map;for(const[r,s]of this._elements){let u,h;if(n.has(r))[u,h]=n.get(r),u+=1;else if(t!==void 0)u=0,h=t(r);else{n.set(r,[0,s]);continue}h=e(r,h,s,u),n.set(r,[u,h])}return new f(function*(){for(const[r,[s,u]]of n)yield[r,u]})}unique(){const e=this._elements;return new y(function*(){const t=new Map;for(const[n,r]of e){const s=t.get(n)??new Set;s.has(r)||(s.add(r),t.set(n,s),yield[n,r])}})}count(){const e=new Map;for(const[t]of this._elements){const n=e.get(t)??0;e.set(t,n+1)}return new f(function*(){for(const[t,n]of e)yield[t,n]})}first(){const e=new Map;for(const[t,n]of this._elements)e.has(t)||e.set(t,n);return new f(function*(){for(const[t,n]of e)yield[t,n]})}last(){const e=new Map;for(const[t,n]of this._elements)e.set(t,n);return new f(function*(){for(const[t,n]of e)yield[t,n]})}keys(){const e=this._elements;return new c(function*(){const t=new Set;for(const[n]of e)t.has(n)||(t.add(n),yield n)})}items(){return this._elements}values(){const e=this._elements;return new c(function*(){for(const[t,n]of e)yield n})}toArray(){return Array.from(this.toMap().values())}toMap(){const e=new Map;for(const[t,n]of this._elements){const r=e.get(t)??[];r.push(n),e.set(t,r)}return e}toObject(){const e={};for(const[t,n]of this._elements){const r=e[t]??[];r.push(n),e[t]=r}return e}get[Symbol.toStringTag](){return"AggregatedIterator"}}class _{constructor(e){a(this,"_elements");this._elements=new c(e)}filter(e){return new _(this._elements.filter(e))}map(e){return new _(this._elements.map(e))}unique(){return new _(this._elements.unique())}groupBy(e){return new y(this._elements.map((t,n)=>[e(t,n),t]))}get[Symbol.toStringTag](){return"Aggregator"}}class w{constructor(e){a(this,"_elements");this._elements=new m(e)}async every(e){const t=new Map;for await(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!0];u&&t.set(n,[s+1,await e(n,r,s)])}return new f(function*(){for(const[n,[r,s]]of t)yield[n,s]})}async some(e){const t=new Map;for await(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!1];u||t.set(n,[s+1,await e(n,r,s)])}return new f(function*(){for(const[n,[r,s]]of t)yield[n,s]})}filter(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),await e(r,s,u)&&(yield[r,s])}})}map(e){const t=this._elements;return new w(async function*(){const n=new Map;for await(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),yield[r,await e(r,s,u)]}})}async reduce(e,t){const n=new Map;for await(const[r,s]of this._elements){let u,h;if(n.has(r))[u,h]=n.get(r),u+=1;else if(t!==void 0)u=0,h=await t(r);else{n.set(r,[0,s]);continue}h=await e(r,h,s,u),n.set(r,[u,h])}return new f(function*(){for(const[r,[s,u]]of n)yield[r,u]})}unique(){const e=this._elements;return new w(async function*(){const t=new Map;for await(const[n,r]of e){const s=t.get(n)??new Set;s.has(r)||(s.add(r),t.set(n,s),yield[n,r])}})}async count(){const e=new Map;for await(const[t]of this._elements){const n=e.get(t)??0;e.set(t,n+1)}return new f(function*(){for(const[t,n]of e)yield[t,n]})}async first(){const e=new Map;for await(const[t,n]of this._elements)e.has(t)||e.set(t,n);return new f(function*(){for(const[t,n]of e)yield[t,n]})}async last(){const e=new Map;for await(const[t,n]of this._elements)e.set(t,n);return new f(function*(){for(const[t,n]of e)yield[t,n]})}keys(){const e=this._elements;return new m(async function*(){const t=new Set;for await(const[n]of e)t.has(n)||(t.add(n),yield n)})}items(){return this._elements}values(){const e=this._elements;return new m(async function*(){for await(const[t,n]of e)yield n})}async toArray(){const e=await this.toMap();return Array.from(e.values())}async toMap(){const e=new Map;for await(const[t,n]of this._elements){const r=e.get(t)??[];r.push(n),e.set(t,r)}return e}async toObject(){const e={};for await(const[t,n]of this._elements){const r=e[t]??[];r.push(n),e[t]=r}return e}get[Symbol.toStringTag](){return"AggregatedAsyncIterator"}}class g{constructor(e){a(this,"_elements");this._elements=new m(e)}filter(e){return new g(this._elements.filter(e))}map(e){return new g(this._elements.map(e))}unique(){return new g(this._elements.unique())}groupBy(e){return new w(this._elements.map(async(t,n)=>[await e(t,n),t]))}get[Symbol.toStringTag](){return"AsyncAggregator"}}class N{constructor(e=!0){a(this,"_preferPersistence");a(this,"_volatile");a(this,"_persistent");this._preferPersistence=e,this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(e,t,n){const r=e.getItem(t);if(r)try{return JSON.parse(r)}catch{console.warn(`The "${r}" value for "${t}" property cannot be parsed. Clearing the storage...`),e.removeItem(t)}return n}_set(e,t,n){const r=JSON.stringify(n);r?e.setItem(t,r):e.removeItem(t)}get(e,t,n=this._preferPersistence){const r=n?this._persistent:this._volatile;return this._get(r,e,t)}recall(e,t){return this._get(this._volatile,e,t)}retrieve(e,t){return this.recall(e)??this.read(e,t)}read(e,t){return this._get(this._persistent,e,t)}has(e,t){return(t?this._persistent:this._volatile).getItem(e)!==null}knows(e){return this._volatile.getItem(e)!==null}find(e){return this.knows(e)??this.exists(e)}exists(e){return this._persistent.getItem(e)!==null}set(e,t,n=this._preferPersistence){const r=n?this._persistent:this._volatile;this._set(r,e,t)}remember(e,t){this._set(this._volatile,e,t)}write(e,t){this._set(this._persistent,e,t)}forget(e){this._volatile.removeItem(e)}erase(e){this._persistent.removeItem(e)}clear(e){this._volatile.removeItem(e),this._persistent.removeItem(e)}get[Symbol.toStringTag](){return"JsonStorage"}}class O{constructor(){a(this,"_subscribers");this._subscribers=[]}add(e){this._subscribers.push(e)}remove(e){const t=this._subscribers.indexOf(e);if(t<0)throw new S("Unable to remove the requested subscriber. It was not found.");this._subscribers.splice(t,1)}call(...e){return this._subscribers.slice().map(t=>t(...e))}get[Symbol.toStringTag](){return"Subscribers"}}class p{constructor(e){a(this,"_isPending");a(this,"_isFulfilled");a(this,"_isRejected");a(this,"_promise");this._isPending=!0,this._isFulfilled=!1,this._isRejected=!1;const t=r=>(this._isPending=!1,this._isFulfilled=!0,r),n=r=>{throw this._isPending=!1,this._isRejected=!0,r};this._promise=new Promise(e).then(t,n)}get isPending(){return this._isPending}get isFulfilled(){return this._isFulfilled}get isRejected(){return this._isRejected}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}get[Symbol.toStringTag](){return"SmartPromise"}}class C extends p{constructor(t,n){let r,s;super((u,h)=>{r=u,s=h});a(this,"_resolve");a(this,"_reject");this._promise.then(t,n),this._resolve=r,this._reject=s}get resolve(){return this._resolve}get reject(){return this._reject}watch(t){return t.then(this.resolve,this.reject),this}get[Symbol.toStringTag](){return"DeferredPromise"}}class $ extends p{constructor(e,t){super((n,r)=>{const s=x=>{clearTimeout(M),n(x)},u=x=>{clearTimeout(M),r(x)},M=setTimeout(()=>u(new b("The operation has timed out.")),t);e(s,u)})}get[Symbol.toStringTag](){return"TimedPromise"}}class v{static Boolean(e=.5){return Math.random()<e}static Integer(e,t){return Math.floor(t===void 0?Math.random()*e:Math.random()*(t-e)+e)}static Decimal(e,t){return e===void 0?Math.random():t===void 0?Math.random()*e:Math.random()*(t-e)+e}static Index(e){if(e.length===0)throw new d("You must provide at least one element.");return this.Integer(e.length)}static Choice(e){return e[v.Index(e)]}constructor(){}}async function z(o){return new Promise((e,t)=>setTimeout(e,o))}async function V(){return new Promise((o,e)=>requestAnimationFrame(()=>o()))}var E=(o=>(o[o.Millisecond=1]="Millisecond",o[o.Second=1e3]="Second",o[o.Minute=6e4]="Minute",o[o.Hour=36e5]="Hour",o[o.Day=864e5]="Day",o[o.Week=6048e5]="Week",o[o.Month=2592e6]="Month",o[o.Year=31536e6]="Year",o))(E||{});function J(o,e,t=864e5){return o=new Date(o),e=new Date(e),Math.floor((e.getTime()-o.getTime())/t)}function Y(o,e,t=864e5){return o=new Date(o),e=new Date(e),new c(function*(){const n=e.getTime();let r=o.getTime();for(;r<n;)yield new Date(r),r+=t})}function K(o,e=864e5){return o=new Date(o),new Date(Math.floor(o.getTime()/e)*e)}function B(o,e="text/javascript"){return new Promise((t,n)=>{const r=document.createElement("script");r.async=!0,r.defer=!0,r.src=o,r.type=e,r.onload=()=>t(),r.onerror=()=>n(),document.body.appendChild(r)})}function H(...o){return new c(function*(){for(const e of o)for(const t of e)yield t})}function W(o){if(Array.isArray(o))return o.length;let e=0;for(const t of o)e+=1;return e}function D(o){return new c(function*(){let e=0;for(const t of o)yield[e,t],e+=1})}function G(o,e,t=1){return new c(function*(){e===void 0&&(e=o,o=0),o>e&&(t=t??-1);for(let n=o;n<e;n+=t)yield n})}function L(o){const e=Array.from(o);for(let t=e.length-1;t>0;t-=1){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}function Q(o){return new c(function*(){const e=new Set;for(const t of o)e.has(t)||(e.add(t),yield t)})}function T(o,e){return new c(function*(){const t=o[Symbol.iterator](),n=e[Symbol.iterator]();for(;;){const r=t.next(),s=n.next();if(r.done||s.done)break;yield[r.value,s.value]}})}function X(o,e){if(e===void 0){let s=0,u=0;for(const h of o)s+=h,u+=1;if(u===0)throw new d("You must provide at least one value.");return s/u}let t=0,n=0,r=0;for(const[s,u]of T(o,e)){if(u<=0)throw new d(`The weight for the value #${r} must be greater than zero.`);t+=s*u,n+=u,r+=1}if(r===0)throw new d("You must provide at least one value and weight.");if(n>0)throw new d("The sum of weights must be greater than zero.");return t/n}function Z(o){let e=0;for(let t=0;t<o.length;t+=1){const n=o.charCodeAt(t);e=(e<<5)-e+n,e|=0}return e}function U(o){let e=0;for(const t of o)e+=t;return e}function ee(o){return`${o.charAt(0).toUpperCase()}${o.slice(1)}`}const te="1.5.3";i.AggregatedAsyncIterator=w,i.AggregatedIterator=y,i.Aggregator=_,i.AsyncAggregator=g,i.DateUnit=E,i.DeferredPromise=C,i.Exception=l,i.FatalErrorException=I,i.FileNotFoundException=R,i.JsonStorage=N,i.KeyException=F,i.NetworkException=j,i.NotImplementedException=P,i.PermissionException=A,i.Random=v,i.ReducedIterator=f,i.ReferenceException=S,i.RuntimeException=q,i.SmartAsyncIterator=m,i.SmartIterator=c,i.SmartPromise=p,i.Subscribers=O,i.TimedPromise=$,i.TimeoutException=b,i.TypeException=k,i.VERSION=te,i.ValueException=d,i.average=X,i.capitalize=ee,i.chain=H,i.count=W,i.dateDifference=J,i.dateRange=Y,i.dateRound=K,i.delay=z,i.enumerate=D,i.hash=Z,i.loadScript=B,i.nextAnimationFrame=V,i.range=G,i.shuffle=L,i.sum=U,i.unique=Q,i.zip=T,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
|
5
|
+
Caused by ${t}`)}get[Symbol.toStringTag](){return"Exception"}}class v extends d{constructor(e,t,n="FatalErrorException"){e===void 0&&(e="The program has encountered an unrecoverable error and cannot continue as expected. Please, try again later. If the problem persists, contact the support team."),super(e,t,n)}get[Symbol.toStringTag](){return"FatalErrorException"}}class $ extends v{constructor(e,t,n="NotImplementedException"){e===void 0&&(e="This feature is not implemented yet. Please, try again later."),super(e,t,n)}get[Symbol.toStringTag](){return"NotImplementedException"}}class E extends d{constructor(e,t,n="FileException"){super(e,t,n)}get[Symbol.toStringTag](){return"FileException"}}class W extends E{constructor(e,t,n="FileExistsException"){super(e,t,n)}get[Symbol.toStringTag](){return"FileExistsException"}}class z extends E{constructor(e,t,n="FileNotFoundException"){super(e,t,n)}get[Symbol.toStringTag](){return"FileNotFoundException"}}class J extends d{constructor(e,t,n="KeyException"){super(e,t,n)}get[Symbol.toStringTag](){return"KeyException"}}class V extends d{constructor(e,t,n="NetworkException"){super(e,t,n)}get[Symbol.toStringTag](){return"NetworkException"}}class Y extends d{constructor(e,t,n="PermissionException"){super(e,t,n)}get[Symbol.toStringTag](){return"PermissionException"}}class I extends d{constructor(e,t,n="ReferenceException"){super(e,t,n)}get[Symbol.toStringTag](){return"ReferenceException"}}class y extends d{constructor(e,t,n="RuntimeException"){super(e,t,n)}get[Symbol.toStringTag](){return"RuntimeException"}}class B extends y{constructor(e,t,n="EnvironmentException"){super(e,t,n)}get[Symbol.toStringTag](){return"EnvironmentException"}}class j extends d{constructor(e,t,n="TimeoutException"){super(e,t,n)}get[Symbol.toStringTag](){return"TimeoutException"}}class K extends d{constructor(e,t,n="TypeException"){super(e,t,n)}get[Symbol.toStringTag](){return"TypeException"}}class m extends d{constructor(e,t,n="ValueException"){super(e,t,n)}get[Symbol.toStringTag](){return"ValueException"}}class k extends m{constructor(e,t,n="RangeException"){super(e,t,n)}get[Symbol.toStringTag](){return"RangeException"}}class c{constructor(e){a(this,"_iterator");a(this,"return");a(this,"throw");e instanceof Function?this._iterator=e():Symbol.iterator in e?this._iterator=e[Symbol.iterator]():this._iterator=e,this._iterator.return&&(this.return=t=>this._iterator.return(t)),this._iterator.throw&&(this.throw=t=>this._iterator.throw(t))}every(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return!0;if(!e(n.value,t))return!1;t+=1}}some(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return!1;if(e(n.value,t))return!0;t+=1}}filter(e){const t=this._iterator;return new c(function*(){let n=0;for(;;){const r=t.next();if(r.done)return r.value;e(r.value,n)&&(yield r.value),n+=1}})}map(e){const t=this._iterator;return new c(function*(){let n=0;for(;;){const r=t.next();if(r.done)return r.value;yield e(r.value,n),n+=1}})}reduce(e,t){let n=0,r=t;if(r===void 0){const s=this._iterator.next();if(s.done)throw new m("Cannot reduce an empty iterator without an initial value.");r=s.value,n+=1}for(;;){const s=this._iterator.next();if(s.done)return r;r=e(r,s.value,n),n+=1}}enumerate(){return this.map((e,t)=>[t,e])}unique(){const e=this._iterator;return new c(function*(){const t=new Set;for(;;){const n=e.next();if(n.done)return n.value;t.has(n.value)||(t.add(n.value),yield n.value)}})}count(){let e=0;for(;;){if(this._iterator.next().done)return e;e+=1}}forEach(e){let t=0;for(;;){const n=this._iterator.next();if(n.done)return;e(n.value,t),t+=1}}next(...e){return this._iterator.next(...e)}toArray(){return Array.from(this)}get[Symbol.toStringTag](){return"SmartIterator"}[Symbol.iterator](){return this}}class w{constructor(e){a(this,"_iterator");a(this,"return");a(this,"throw");if(e instanceof Function){const t=e();Symbol.asyncIterator in t?this._iterator=t:this._iterator=async function*(){let n=[];for(;;){const r=t.next(...n);if(r.done)return r.value;n=[yield r.value]}}()}else if(Symbol.asyncIterator in e)this._iterator=e[Symbol.asyncIterator]();else if(Symbol.iterator in e){const t=e[Symbol.iterator]();this._iterator=async function*(){for(;;){const n=t.next();if(n.done)return n.value;yield n.value}}()}else this._iterator=async function*(){let t=[];for(;;){const n=await e.next(...t);if(n.done)return n.value;t=[yield n.value]}}();this._iterator.return&&(this.return=t=>this._iterator.return(t)),this._iterator.throw&&(this.throw=t=>this._iterator.throw(t))}async every(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return!0;if(!e(n.value,t))return!1;t+=1}}async some(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return!1;if(e(n.value,t))return!0;t+=1}}filter(e){const t=this._iterator;return new w(async function*(){let n=0;for(;;){const r=await t.next();if(r.done)return r.value;e(r.value,n)&&(yield r.value),n+=1}})}map(e){const t=this._iterator;return new w(async function*(){let n=0;for(;;){const r=await t.next();if(r.done)return r.value;yield e(r.value,n),n+=1}})}async reduce(e,t){let n=0,r=t;if(r===void 0){const s=await this._iterator.next();if(s.done)throw new m("Cannot reduce an empty iterator without an initial value.");r=s.value,n+=1}for(;;){const s=await this._iterator.next();if(s.done)return r;r=await e(r,s.value,n),n+=1}}enumerate(){return this.map((e,t)=>[t,e])}unique(){const e=this._iterator;return new w(async function*(){const t=new Set;for(;;){const n=await e.next();if(n.done)return n.value;t.has(n.value)||(t.add(n.value),yield n.value)}})}async count(){let e=0;for(;;){if((await this._iterator.next()).done)return e;e+=1}}async forEach(e){let t=0;for(;;){const n=await this._iterator.next();if(n.done)return;await e(n.value,t),t+=1}}next(...e){return this._iterator.next(...e)}async toArray(){const e=[];for(;;){const t=await this._iterator.next();if(t.done)return e;e.push(t.value)}}get[Symbol.toStringTag](){return"SmartAsyncIterator"}[Symbol.asyncIterator](){return this}}class l{constructor(e){a(this,"_elements");this._elements=new c(e)}filter(e){const t=this._elements;return new l(function*(){for(const[n,[r,s]]of t.enumerate())e(r,s,n)&&(yield[r,s])})}map(e){const t=this._elements;return new l(function*(){for(const[n,[r,s]]of t.enumerate())yield[r,e(r,s,n)]})}reduce(e,t){let n=0,r;if(t!==void 0)r=t;else{const s=this._elements.next();if(s.done)throw new m("Cannot reduce an empty iterator without an initial value.");n+=1,r=s.value[1]}for(const[s,u]of this._elements)r=e(s,r,u,n),n+=1;return r}keys(){const e=this._elements;return new c(function*(){for(const[t]of e)yield t})}items(){return this._elements}values(){const e=this._elements;return new c(function*(){for(const[t,n]of e)yield n})}toArray(){return Array.from(this.values())}toMap(){return new Map(this.items())}toObject(){return Object.fromEntries(this.items())}get[Symbol.toStringTag](){return"ReducedIterator"}}class g{constructor(e){a(this,"_elements");this._elements=new c(e)}every(e){const t=new Map;for(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!0];u&&t.set(n,[s+1,e(n,r,s)])}return new l(function*(){for(const[n,[r,s]]of t)yield[n,s]})}some(e){const t=new Map;for(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!1];u||t.set(n,[s+1,e(n,r,s)])}return new l(function*(){for(const[n,[r,s]]of t)yield[n,s]})}filter(e){const t=this._elements;return new g(function*(){const n=new Map;for(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),e(r,s,u)&&(yield[r,s])}})}map(e){const t=this._elements;return new g(function*(){const n=new Map;for(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),yield[r,e(r,s,u)]}})}reduce(e,t){const n=new Map;for(const[r,s]of this._elements){let u,h;if(n.has(r))[u,h]=n.get(r),u+=1;else if(t!==void 0)u=0,h=t(r);else{n.set(r,[0,s]);continue}h=e(r,h,s,u),n.set(r,[u,h])}return new l(function*(){for(const[r,[s,u]]of n)yield[r,u]})}unique(){const e=this._elements;return new g(function*(){const t=new Map;for(const[n,r]of e){const s=t.get(n)??new Set;s.has(r)||(s.add(r),t.set(n,s),yield[n,r])}})}count(){const e=new Map;for(const[t]of this._elements){const n=e.get(t)??0;e.set(t,n+1)}return new l(function*(){for(const[t,n]of e)yield[t,n]})}first(){const e=new Map;for(const[t,n]of this._elements)e.has(t)||e.set(t,n);return new l(function*(){for(const[t,n]of e)yield[t,n]})}last(){const e=new Map;for(const[t,n]of this._elements)e.set(t,n);return new l(function*(){for(const[t,n]of e)yield[t,n]})}keys(){const e=this._elements;return new c(function*(){const t=new Set;for(const[n]of e)t.has(n)||(t.add(n),yield n)})}items(){return this._elements}values(){const e=this._elements;return new c(function*(){for(const[t,n]of e)yield n})}toArray(){return Array.from(this.toMap().values())}toMap(){const e=new Map;for(const[t,n]of this._elements){const r=e.get(t)??[];r.push(n),e.set(t,r)}return e}toObject(){const e={};for(const[t,n]of this._elements){const r=e[t]??[];r.push(n),e[t]=r}return e}get[Symbol.toStringTag](){return"AggregatedIterator"}}class x{constructor(e){a(this,"_elements");this._elements=new c(e)}filter(e){return new x(this._elements.filter(e))}map(e){return new x(this._elements.map(e))}unique(){return new x(this._elements.unique())}groupBy(e){return new g(this._elements.map((t,n)=>[e(t,n),t]))}get[Symbol.toStringTag](){return"Aggregator"}}class p{constructor(e){a(this,"_elements");this._elements=new w(e)}async every(e){const t=new Map;for await(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!0];u&&t.set(n,[s+1,await e(n,r,s)])}return new l(function*(){for(const[n,[r,s]]of t)yield[n,s]})}async some(e){const t=new Map;for await(const[n,r]of this._elements){const[s,u]=t.get(n)??[0,!1];u||t.set(n,[s+1,await e(n,r,s)])}return new l(function*(){for(const[n,[r,s]]of t)yield[n,s]})}filter(e){const t=this._elements;return new p(async function*(){const n=new Map;for await(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),await e(r,s,u)&&(yield[r,s])}})}map(e){const t=this._elements;return new p(async function*(){const n=new Map;for await(const[r,s]of t){const u=n.get(r)??0;n.set(r,u+1),yield[r,await e(r,s,u)]}})}async reduce(e,t){const n=new Map;for await(const[r,s]of this._elements){let u,h;if(n.has(r))[u,h]=n.get(r),u+=1;else if(t!==void 0)u=0,h=await t(r);else{n.set(r,[0,s]);continue}h=await e(r,h,s,u),n.set(r,[u,h])}return new l(function*(){for(const[r,[s,u]]of n)yield[r,u]})}unique(){const e=this._elements;return new p(async function*(){const t=new Map;for await(const[n,r]of e){const s=t.get(n)??new Set;s.has(r)||(s.add(r),t.set(n,s),yield[n,r])}})}async count(){const e=new Map;for await(const[t]of this._elements){const n=e.get(t)??0;e.set(t,n+1)}return new l(function*(){for(const[t,n]of e)yield[t,n]})}async first(){const e=new Map;for await(const[t,n]of this._elements)e.has(t)||e.set(t,n);return new l(function*(){for(const[t,n]of e)yield[t,n]})}async last(){const e=new Map;for await(const[t,n]of this._elements)e.set(t,n);return new l(function*(){for(const[t,n]of e)yield[t,n]})}keys(){const e=this._elements;return new w(async function*(){const t=new Set;for await(const[n]of e)t.has(n)||(t.add(n),yield n)})}items(){return this._elements}values(){const e=this._elements;return new w(async function*(){for await(const[t,n]of e)yield n})}async toArray(){const e=await this.toMap();return Array.from(e.values())}async toMap(){const e=new Map;for await(const[t,n]of this._elements){const r=e.get(t)??[];r.push(n),e.set(t,r)}return e}async toObject(){const e={};for await(const[t,n]of this._elements){const r=e[t]??[];r.push(n),e[t]=r}return e}get[Symbol.toStringTag](){return"AggregatedAsyncIterator"}}class b{constructor(e){a(this,"_elements");this._elements=new w(e)}filter(e){return new b(this._elements.filter(e))}map(e){return new b(this._elements.map(e))}unique(){return new b(this._elements.unique())}groupBy(e){return new p(this._elements.map(async(t,n)=>[await e(t,n),t]))}get[Symbol.toStringTag](){return"AsyncAggregator"}}var S=(i=>(i[i.Millisecond=1]="Millisecond",i[i.Second=1e3]="Second",i[i.Minute=6e4]="Minute",i[i.Hour=36e5]="Hour",i[i.Day=864e5]="Day",i[i.Week=6048e5]="Week",i[i.Month=2592e6]="Month",i[i.Year=31536e6]="Year",i))(S||{});function G(i,e,t=864e5){return i=new Date(i),e=new Date(e),Math.floor((e.getTime()-i.getTime())/t)}function H(i,e,t=864e5){return i=new Date(i),e=new Date(e),new c(function*(){const n=e.getTime();let r=i.getTime();for(;r<n;)yield new Date(r),r+=t})}function L(i,e=864e5){return i=new Date(i),new Date(Math.floor(i.getTime()/e)*e)}class T{constructor(e,t=30){a(this,"_handle");a(this,"_startTime");a(this,"_isRunning");a(this,"_start");a(this,"_stop");this._startTime=0,this._isRunning=!1,f?(this._start=()=>{e(this.elapsedTime),this._handle=window.requestAnimationFrame(this._start)},this._stop=()=>window.cancelAnimationFrame(this._handle)):(console.warn(`Not a browser environment detected. Using setInterval@${t}fps instead of requestAnimationFrame...`),this._start=()=>{const n=S.Second/t;this._handle=setInterval(()=>e(this.elapsedTime),n)},this._stop=()=>clearInterval(this._handle))}get startTime(){return this._startTime}get isRunning(){return this._isRunning}get elapsedTime(){return performance.now()-this._startTime}start(e=0){if(this._isRunning)throw new y("The game loop has already been started.");this._startTime=performance.now()-e,this._start(),this._isRunning=!0}stop(){if(!this._isRunning)throw new y("The game loop hadn't yet started.");if(!this._handle)throw new v;this._stop(),this._handle=void 0,this._isRunning=!1}}class Q{constructor(e=!0){a(this,"_preferPersistence");a(this,"_volatile");a(this,"_persistent");if(this._preferPersistence=e,!f)throw new B("The `JSONStorage` class can only be instantiated within a browser environment.");this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(e,t,n){const r=e.getItem(t);if(r)try{return JSON.parse(r)}catch{console.warn(`The "${r}" value for "${t}" property cannot be parsed. Clearing the storage...`),e.removeItem(t)}return n}_set(e,t,n){const r=JSON.stringify(n);r?e.setItem(t,r):e.removeItem(t)}get(e,t,n=this._preferPersistence){const r=n?this._persistent:this._volatile;return this._get(r,e,t)}recall(e,t){return this._get(this._volatile,e,t)}retrieve(e,t){return this.recall(e)??this.read(e,t)}read(e,t){return this._get(this._persistent,e,t)}has(e,t){return(t?this._persistent:this._volatile).getItem(e)!==null}knows(e){return this._volatile.getItem(e)!==null}find(e){return this.knows(e)??this.exists(e)}exists(e){return this._persistent.getItem(e)!==null}set(e,t,n=this._preferPersistence){const r=n?this._persistent:this._volatile;this._set(r,e,t)}remember(e,t){this._set(this._volatile,e,t)}write(e,t){this._set(this._persistent,e,t)}forget(e){this._volatile.removeItem(e)}erase(e){this._persistent.removeItem(e)}clear(e){this._volatile.removeItem(e),this._persistent.removeItem(e)}get[Symbol.toStringTag](){return"JSONStorage"}}class M{constructor(e){a(this,"_isPending");a(this,"_isFulfilled");a(this,"_isRejected");a(this,"_promise");this._isPending=!0,this._isFulfilled=!1,this._isRejected=!1;const t=r=>(this._isPending=!1,this._isFulfilled=!0,r),n=r=>{throw this._isPending=!1,this._isRejected=!0,r};this._promise=new Promise(e).then(t,n)}get isPending(){return this._isPending}get isFulfilled(){return this._isFulfilled}get isRejected(){return this._isRejected}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}get[Symbol.toStringTag](){return"SmartPromise"}}class A extends M{constructor(t,n){let r,s;super((u,h)=>{r=u,s=h});a(this,"_resolve");a(this,"_reject");this._promise.then(t,n),this._resolve=r,this._reject=s}get resolve(){return this._resolve}get reject(){return this._reject}watch(t){return t.then(this.resolve,this.reject),this}get[Symbol.toStringTag](){return"DeferredPromise"}}class X extends M{constructor(e,t){super((n,r)=>{const s=P=>{clearTimeout(q),n(P)},u=P=>{clearTimeout(q),r(P)},q=setTimeout(()=>u(new j("The operation has timed out.")),t);e(s,u)})}get[Symbol.toStringTag](){return"TimedPromise"}}class R{constructor(){a(this,"_subscribers");this._subscribers=[]}subscribe(e){return this._subscribers.push(e),()=>{const t=this._subscribers.indexOf(e);if(t<0)throw new I("Unable to unsubscribe the required subscriber. The subscription was already unsubscribed.");this._subscribers.splice(t,1)}}publish(...e){return this._subscribers.slice().map(t=>t(...e))}get[Symbol.toStringTag](){return"Publisher"}}class Z extends T{constructor(t=S.Second){super(n=>this._publisher.publish(n),t);a(this,"_publisher");this._publisher=new R}start(t=0){if(this._isRunning)throw new y("The clock has already been started.");super.start(t)}stop(){if(!this._isRunning)throw new y("The clock hadn't yet started.");super.stop()}onTick(t,n=0){if(n<0)throw new k("The tick step must be a non-negative number.");if(n===0)return this._publisher.subscribe(t);let r=0;return this._publisher.subscribe(s=>{s-r<n||(t(s),r=s)})}}class U extends T{constructor(t,n=S.Second){super(s=>{this._duration-=s;const u=this.remainingTime;this._publisher.publish(u),u<=0&&this.stop()},n);a(this,"_deferrer");a(this,"_publisher");a(this,"_duration");this._publisher=new R,this._duration=t}get duration(){return this._duration}get remainingTime(){return this._duration-this.elapsedTime}start(t=this.duration){if(this._isRunning)throw new y("The countdown has already been started.");if(this._deferrer)throw new v;return this._deferrer=new A(()=>this.stop()),super.start(this.duration-t),this._deferrer}stop(t){if(!this._isRunning)throw new y("The countdown hadn't yet started.");if(!this._deferrer)throw new v;super.stop(),t!==void 0?this._deferrer.reject(t):this._deferrer.resolve(),this._deferrer=void 0}onTick(t,n=0){if(n<0)throw new k("The tick step must be a non-negative number.");if(n===0)return this._publisher.subscribe(t);let r=0;return this._publisher.subscribe(s=>{r-s<n||(t(s),r=s)})}}class F{static Boolean(e=.5){return Math.random()<e}static Integer(e,t){return Math.floor(t===void 0?Math.random()*e:Math.random()*(t-e)+e)}static Decimal(e,t){return e===void 0?Math.random():t===void 0?Math.random()*e:Math.random()*(t-e)+e}static Index(e){if(e.length===0)throw new m("You must provide at least one element.");return this.Integer(e.length)}static Choice(e){return e[F.Index(e)]}constructor(){}}async function ee(i){return new Promise((e,t)=>setTimeout(e,i))}async function te(){return new Promise((i,e)=>requestAnimationFrame(()=>i()))}function ne(i,e="text/javascript"){return new Promise((t,n)=>{const r=document.createElement("script");r.async=!0,r.defer=!0,r.src=i,r.type=e,r.onload=()=>t(),r.onerror=()=>n(),document.body.appendChild(r)})}function re(...i){return new c(function*(){for(const e of i)for(const t of e)yield t})}function se(i){if(Array.isArray(i))return i.length;let e=0;for(const t of i)e+=1;return e}function ie(i){return new c(function*(){let e=0;for(const t of i)yield[e,t],e+=1})}function oe(i,e,t=1){return new c(function*(){e===void 0&&(e=i,i=0),i>e&&(t=t??-1);for(let n=i;n<e;n+=t)yield n})}function ue(i){const e=Array.from(i);for(let t=e.length-1;t>0;t-=1){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}function ae(i){return new c(function*(){const e=new Set;for(const t of i)e.has(t)||(e.add(t),yield t)})}function D(i,e){return new c(function*(){const t=i[Symbol.iterator](),n=e[Symbol.iterator]();for(;;){const r=t.next(),s=n.next();if(r.done||s.done)break;yield[r.value,s.value]}})}function ce(i,e){if(e===void 0){let s=0,u=0;for(const h of i)s+=h,u+=1;if(u===0)throw new m("You must provide at least one value.");return s/u}let t=0,n=0,r=0;for(const[s,u]of D(i,e)){if(u<=0)throw new m(`The weight for the value #${r} must be greater than zero.`);t+=s*u,n+=u,r+=1}if(r===0)throw new m("You must provide at least one value and weight.");if(n>0)throw new m("The sum of weights must be greater than zero.");return t/n}function le(i){let e=0;for(let t=0;t<i.length;t+=1){const n=i.charCodeAt(t);e=(e<<5)-e+n,e|=0}return e}function he(i){let e=0;for(const t of i)e+=t;return e}function fe(i){return`${i.charAt(0).toUpperCase()}${i.slice(1)}`}const de="2.0.0-rc.1";o.AggregatedAsyncIterator=p,o.AggregatedIterator=g,o.Aggregator=x,o.AsyncAggregator=b,o.Clock=Z,o.Countdown=U,o.DeferredPromise=A,o.Exception=d,o.FatalErrorException=v,o.FileException=E,o.FileExistsException=W,o.FileNotFoundException=z,o.GameLoop=T,o.JSONStorage=Q,o.KeyException=J,o.NetworkException=V,o.NotImplementedException=$,o.PermissionException=Y,o.Publisher=R,o.Random=F,o.RangeException=k,o.ReducedIterator=l,o.ReferenceException=I,o.RuntimeException=y,o.SmartAsyncIterator=w,o.SmartIterator=c,o.SmartPromise=M,o.TimeUnit=S,o.TimedPromise=X,o.TimeoutException=j,o.TypeException=K,o.VERSION=de,o.ValueException=m,o.average=ce,o.capitalize=fe,o.chain=re,o.count=se,o.dateDifference=G,o.dateRange=H,o.dateRound=L,o.delay=ee,o.enumerate=ie,o.hash=le,o.isBrowser=f,o.isNode=_,o.isWebWorker=O,o.loadScript=ne,o.nextAnimationFrame=te,o.range=oe,o.shuffle=ue,o.sum=he,o.unique=ae,o.zip=D,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
|
6
6
|
//# sourceMappingURL=core.umd.cjs.map
|