@byloth/core 1.2.0-rc.2 → 1.2.0-rc.3

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 CHANGED
@@ -6,10 +6,10 @@ class m {
6
6
  o(this, "_resolve");
7
7
  o(this, "_reject");
8
8
  o(this, "_promise");
9
- let n, s;
10
- this._promise = new Promise((i, l) => {
11
- n = i, s = l;
12
- }).then(e, t), this._resolve = n, this._reject = s;
9
+ let s, n;
10
+ this._promise = new Promise((i, c) => {
11
+ s = i, n = c;
12
+ }).then(e, t), this._resolve = s, this._reject = n;
13
13
  }
14
14
  get resolve() {
15
15
  return this._resolve;
@@ -33,18 +33,18 @@ class m {
33
33
  return "DeferredPromise";
34
34
  }
35
35
  }
36
- class c extends Error {
36
+ class l extends Error {
37
37
  static FromUnknown(e) {
38
- if (e instanceof c)
38
+ if (e instanceof l)
39
39
  return e;
40
40
  if (e instanceof Error) {
41
- const t = new c(e.message);
41
+ const t = new l(e.message);
42
42
  return t.stack = e.stack, t.name = e.name, t;
43
43
  }
44
- return new c(`${e}`);
44
+ return new l(`${e}`);
45
45
  }
46
- constructor(e, t, n = "Exception") {
47
- super(e), this.cause = t, this.name = n, t && (t instanceof Error ? this.stack += `
46
+ constructor(e, t, s = "Exception") {
47
+ super(e), this.cause = t, this.name = s, t && (t instanceof Error ? this.stack += `
48
48
 
49
49
  Caused by ${t.stack}` : this.stack += `
50
50
 
@@ -58,25 +58,25 @@ class v {
58
58
  o(this, "_persistent");
59
59
  this._preferPersistence = e, this._volatile = window.sessionStorage, this._persistent = window.localStorage;
60
60
  }
61
- _get(e, t, n) {
62
- const s = e.getItem(t);
63
- if (s)
61
+ _get(e, t, s) {
62
+ const n = e.getItem(t);
63
+ if (n)
64
64
  try {
65
- return JSON.parse(s);
65
+ return JSON.parse(n);
66
66
  } catch {
67
67
  console.warn(
68
- `The "${s}" value for "${t}" property cannot be parsed. Clearing the storage...`
68
+ `The "${n}" value for "${t}" property cannot be parsed. Clearing the storage...`
69
69
  ), e.removeItem(t);
70
70
  }
71
- return n;
71
+ return s;
72
72
  }
73
- _set(e, t, n) {
74
- const s = JSON.stringify(n);
75
- s ? e.setItem(t, s) : e.removeItem(t);
73
+ _set(e, t, s) {
74
+ const n = JSON.stringify(s);
75
+ n ? e.setItem(t, n) : e.removeItem(t);
76
76
  }
77
- get(e, t, n = this._preferPersistence) {
78
- const s = n ? this._persistent : this._volatile;
79
- return this._get(s, e, t);
77
+ get(e, t, s = this._preferPersistence) {
78
+ const n = s ? this._persistent : this._volatile;
79
+ return this._get(n, e, t);
80
80
  }
81
81
  recall(e, t) {
82
82
  return this._get(this._volatile, e, t);
@@ -137,9 +137,9 @@ class v {
137
137
  * @param newValue The new value to set.
138
138
  * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.
139
139
  */
140
- set(e, t, n = this._preferPersistence) {
141
- const s = n ? this._persistent : this._volatile;
142
- this._set(s, e, t);
140
+ set(e, t, s = this._preferPersistence) {
141
+ const n = s ? this._persistent : this._volatile;
142
+ this._set(n, e, t);
143
143
  }
144
144
  /**
145
145
  * Sets the value with the specified name in the volatile `sessionStorage`.
@@ -193,50 +193,72 @@ class u {
193
193
  o(this, "throw");
194
194
  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));
195
195
  }
196
+ every(e) {
197
+ let t = 0;
198
+ for (; ; ) {
199
+ const s = this._iterator.next();
200
+ if (s.done)
201
+ return !0;
202
+ if (!e(s.value, t))
203
+ return !1;
204
+ t += 1;
205
+ }
206
+ }
207
+ some(e) {
208
+ let t = 0;
209
+ for (; ; ) {
210
+ const s = this._iterator.next();
211
+ if (s.done)
212
+ return !1;
213
+ if (e(s.value, t))
214
+ return !0;
215
+ t += 1;
216
+ }
217
+ }
196
218
  filter(e) {
197
219
  let t = 0;
198
- const n = this._iterator;
220
+ const s = this._iterator;
199
221
  return new u({
200
222
  *[Symbol.iterator]() {
201
223
  for (; ; ) {
202
- const s = n.next();
203
- if (s.done)
204
- return s.value;
205
- e(s.value, t) && (yield s.value), t += 1;
224
+ const n = s.next();
225
+ if (n.done)
226
+ return n.value;
227
+ e(n.value, t) && (yield n.value), t += 1;
206
228
  }
207
229
  }
208
230
  });
209
231
  }
210
232
  map(e) {
211
233
  let t = 0;
212
- const n = this._iterator;
234
+ const s = this._iterator;
213
235
  return new u({
214
236
  *[Symbol.iterator]() {
215
237
  for (; ; ) {
216
- const s = n.next();
217
- if (s.done)
218
- return s.value;
219
- yield e(s.value, t), t += 1;
238
+ const n = s.next();
239
+ if (n.done)
240
+ return n.value;
241
+ yield e(n.value, t), t += 1;
220
242
  }
221
243
  }
222
244
  });
223
245
  }
224
246
  reduce(e, t) {
225
- let n = 0, s = t;
247
+ let s = 0, n = t;
226
248
  for (; ; ) {
227
249
  const i = this._iterator.next();
228
250
  if (i.done)
229
- return s;
230
- s = e(s, i.value, n), n += 1;
251
+ return n;
252
+ n = e(n, i.value, s), s += 1;
231
253
  }
232
254
  }
233
255
  forEach(e) {
234
256
  let t = 0;
235
257
  for (; ; ) {
236
- const n = this._iterator.next();
237
- if (n.done)
258
+ const s = this._iterator.next();
259
+ if (s.done)
238
260
  return;
239
- e(n.value, t), t += 1;
261
+ e(s.value, t), t += 1;
240
262
  }
241
263
  }
242
264
  next(...e) {
@@ -260,7 +282,7 @@ class w {
260
282
  remove(e) {
261
283
  const t = this._subscribers.indexOf(e);
262
284
  if (t < 0)
263
- throw new c("Unable to remove the requested subscriber. It was not found.");
285
+ throw new l("Unable to remove the requested subscriber. It was not found.");
264
286
  this._subscribers.splice(t, 1);
265
287
  }
266
288
  call(...e) {
@@ -279,19 +301,19 @@ function b(r, e, t = 864e5) {
279
301
  }
280
302
  function p(r, e, t = 864e5) {
281
303
  return new u(function* () {
282
- const n = e.getTime();
283
- let s = r.getTime();
284
- for (; s < n; )
285
- yield new Date(s), s += t;
304
+ const s = e.getTime();
305
+ let n = r.getTime();
306
+ for (; n < s; )
307
+ yield new Date(n), n += t;
286
308
  });
287
309
  }
288
310
  function x(r, e = 864e5) {
289
311
  return new Date(Math.floor(r.getTime() / e) * e);
290
312
  }
291
313
  async function S(r, e = "text/javascript") {
292
- return new Promise((t, n) => {
293
- const s = document.createElement("script");
294
- s.async = !0, s.defer = !0, s.src = r, s.type = e, s.onload = () => t(), s.onerror = () => n(), document.body.appendChild(s);
314
+ return new Promise((t, s) => {
315
+ const n = document.createElement("script");
316
+ n.async = !0, n.defer = !0, n.src = r, n.type = e, n.onload = () => t(), n.onerror = () => s(), document.body.appendChild(n);
295
317
  });
296
318
  }
297
319
  function I(r) {
@@ -305,15 +327,15 @@ function I(r) {
305
327
  function M(r, e, t = 1) {
306
328
  return new u(function* () {
307
329
  e === void 0 && (e = r, r = 0), r > e && (t = t ?? -1);
308
- for (let n = r; n < e; n += t)
309
- yield n;
330
+ for (let s = r; s < e; s += t)
331
+ yield s;
310
332
  });
311
333
  }
312
334
  function k(r) {
313
335
  const e = [...r];
314
336
  for (let t = e.length - 1; t > 0; t -= 1) {
315
- const n = Math.floor(Math.random() * (t + 1));
316
- [e[t], e[n]] = [e[n], e[t]];
337
+ const s = Math.floor(Math.random() * (t + 1));
338
+ [e[t], e[s]] = [e[s], e[t]];
317
339
  }
318
340
  return e;
319
341
  }
@@ -324,52 +346,52 @@ function j(r) {
324
346
  e.has(t) || (e.add(t), yield t);
325
347
  });
326
348
  }
327
- function _(r, e) {
349
+ function d(r, e) {
328
350
  return new u(function* () {
329
- const t = r[Symbol.iterator](), n = e[Symbol.iterator]();
351
+ const t = r[Symbol.iterator](), s = e[Symbol.iterator]();
330
352
  for (; ; ) {
331
- const s = t.next(), i = n.next();
332
- if (s.done || i.done)
353
+ const n = t.next(), i = s.next();
354
+ if (n.done || i.done)
333
355
  break;
334
- yield [s.value, i.value];
356
+ yield [n.value, i.value];
335
357
  }
336
358
  });
337
359
  }
338
360
  function P(r, e) {
339
361
  if (e === void 0) {
340
- let s = 0, i = 0;
341
- for (const l of r)
342
- s += l, i += 1;
343
- return s / i;
344
- }
345
- let t = 0, n = 0;
346
- for (const [s, i] of _(r, e))
347
- t += s * i, n += i;
348
- return t / n;
362
+ let n = 0, i = 0;
363
+ for (const c of r)
364
+ n += c, i += 1;
365
+ return n / i;
366
+ }
367
+ let t = 0, s = 0;
368
+ for (const [n, i] of d(r, e))
369
+ t += n * i, s += i;
370
+ return t / s;
349
371
  }
350
372
  function T(r) {
351
373
  let e = 0;
352
374
  for (let t = 0; t < r.length; t++) {
353
- const n = r.charCodeAt(t);
354
- e = (e << 5) - e + n, e |= 0;
375
+ const s = r.charCodeAt(t);
376
+ e = (e << 5) - e + s, e |= 0;
355
377
  }
356
378
  return e;
357
379
  }
358
380
  function A(r = 1, e, t) {
359
381
  if (e === void 0 && (e = r, r = 0), r === e)
360
382
  return r;
361
- let n;
383
+ let s;
362
384
  if (t === !0)
363
- n = (s) => s;
385
+ s = (n) => n;
364
386
  else if (t === void 0)
365
- Math.abs(e - r) <= 1 ? n = (s) => s : n = Math.floor;
387
+ Math.abs(e - r) <= 1 ? s = (n) => n : s = Math.floor;
366
388
  else if (t === !1)
367
- n = Math.floor;
389
+ s = Math.floor;
368
390
  else {
369
- const s = 10 ** t;
370
- n = (i) => Math.floor(i * s) / s;
391
+ const n = 10 ** t;
392
+ s = (i) => Math.floor(i * n) / n;
371
393
  }
372
- return n(Math.random() * (e - r) + r);
394
+ return s(Math.random() * (e - r) + r);
373
395
  }
374
396
  function $(r) {
375
397
  let e = 0;
@@ -380,11 +402,11 @@ function $(r) {
380
402
  function C(r) {
381
403
  return `${r.charAt(0).toUpperCase()}${r.slice(1)}`;
382
404
  }
383
- const E = "1.2.0-rc.2";
405
+ const E = "1.2.0-rc.3";
384
406
  export {
385
407
  f as DateUnit,
386
408
  m as DeferredPromise,
387
- c as Exception,
409
+ l as Exception,
388
410
  v as JsonStorage,
389
411
  u as SmartIterator,
390
412
  w as Subscribers,
@@ -404,6 +426,6 @@ export {
404
426
  k as shuffle,
405
427
  $ as sum,
406
428
  j as unique,
407
- _ as zip
429
+ d as zip
408
430
  };
409
431
  //# sourceMappingURL=core.js.map
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.ts","../src/models/smart-iterator.ts","../src/models/subscribers.ts","../src/utils/async.ts","../src/utils/date.ts","../src/utils/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T = void, E = unknown, F = T, R = never>\n{\n protected _resolve!: PromiseResolver<T>;\n protected _reject!: PromiseRejecter<E>;\n\n protected _promise: Promise<F | R>;\n\n public constructor(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R> | null)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n this._promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\n\n }).then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(\n onFulfilled?: FulfilledHandler<F | R, N> | null,\n onRejected?: RejectedHandler<R, H> | null): Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H> | null): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: (() => void) | null): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n\n public watch(promise: Promise<T>): this\n {\n promise.then(this.resolve, this.reject);\n\n return this;\n }\n\n public get [Symbol.toStringTag]()\n {\n return \"DeferredPromise\";\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import type { GeneratorFunction } from \"../types.js\";\n\nexport default class SmartIterator<T, R = void, N = undefined> implements Iterator<T, R, N>\n{\n protected _iterator: Iterator<T, R, N>;\n\n public return?: (value?: R) => IteratorResult<T, R>;\n public throw?: (error?: unknown) => IteratorResult<T, R>;\n\n public constructor(iterable: Iterable<T>);\n public constructor(iterator: Iterator<T, R, N>);\n public constructor(generatorFn: GeneratorFunction<T, R, N>);\n public constructor(iterable: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)\n {\n if (iterable instanceof Function)\n {\n this._iterator = iterable();\n }\n else if (Symbol.iterator in iterable)\n {\n this._iterator = iterable[Symbol.iterator]() as Iterator<T, R, N>;\n }\n else\n {\n this._iterator = iterable;\n }\n\n if (this._iterator.return) { this.return = (value?: R) => this._iterator.return!(value); }\n if (this._iterator.throw) { this.throw = (error?: unknown) => this._iterator.throw!(error); }\n }\n\n public filter(callback: (value: T, index: number) => boolean): SmartIterator<T, R, N>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<T, R, N>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n if (callback(result.value, index))\n {\n yield result.value;\n }\n\n index += 1;\n }\n }\n });\n }\n public map<V>(callback: (value: T, index: number) => V): SmartIterator<V, R>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<V, R>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n yield callback(result.value, index);\n\n index += 1;\n }\n }\n });\n }\n public reduce<U>(callback: (accumulator: U, value: T, index: number) => U, initialValue: U): U\n {\n let index = 0;\n let accumulator = initialValue;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return accumulator; }\n\n accumulator = callback(accumulator, result.value, index);\n\n index += 1;\n }\n }\n\n public forEach(callback: (value: T, index: number) => void): void\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return; }\n\n callback(result.value, index);\n\n index += 1;\n }\n }\n\n public next(...values: N extends undefined ? [] : [N]): IteratorResult<T, R>\n {\n return this._iterator.next(...values);\n }\n\n public toArray(): T[]\n {\n return [...this];\n }\n\n public [Symbol.iterator](): SmartIterator<T, R, N> { return this; }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day): number\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function dateRange(start: Date, end: Date, offset = DateUnit.Day): SmartIterator<Date>\n{\n return new SmartIterator<Date>(function* ()\n {\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n });\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day): Date\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): SmartIterator<number>;\nexport function range(start: number, end: number): SmartIterator<number>;\nexport function range(start: number, end: number, step: number): SmartIterator<number>;\nexport function range(start: number, end?: number, step = 1): SmartIterator<number>\n{\n return new SmartIterator<number>(function* ()\n {\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n });\n}\n\nexport function shuffle<T>(iterable: Iterable<T>): T[]\n{\n const array = [...iterable];\n\n for (let index = array.length - 1; index > 0; index -= 1)\n {\n const jndex = Math.floor(Math.random() * (index + 1));\n\n [array[index], array[jndex]] = [array[jndex], array[index]];\n }\n\n return array;\n}\n\nexport function unique<T>(elements: Iterable<T>): SmartIterator<T>\n{\n return new SmartIterator<T>(function* ()\n {\n const seen = new Set<T>();\n\n for (const element of elements)\n {\n if (seen.has(element)) { continue; }\n\n seen.add(element);\n\n yield element;\n }\n });\n}\n\nexport function zip<T, U>(first: Iterable<T>, second: Iterable<U>): SmartIterator<[T, U]>\n{\n return new SmartIterator<[T, U]>(function* ()\n {\n const firstIterator = first[Symbol.iterator]();\n const secondIterator = second[Symbol.iterator]();\n\n while (true)\n {\n const firstResult = firstIterator.next();\n const secondResult = secondIterator.next();\n\n if ((firstResult.done) || (secondResult.done)) { break; }\n\n yield [firstResult.value, secondResult.value];\n }\n });\n}\n","import { zip } from \"./iterator.js\";\n\nexport function average<T extends number>(values: Iterable<T>): number;\nexport function average<T extends number>(values: Iterable<T>, weights: Iterable<number>): number;\nexport function average<T extends number>(values: Iterable<T>, weights?: Iterable<number>): number\n{\n if (weights === undefined)\n {\n let _sum = 0;\n let _count = 0;\n\n for (const value of values)\n {\n _sum += value;\n _count += 1;\n }\n\n return _sum / _count;\n }\n\n let _sum = 0;\n let _count = 0;\n\n for (const [value, weight] of zip(values, weights))\n {\n _sum += value * weight;\n _count += weight;\n }\n\n return _sum / _count;\n}\n\nexport function hash(value: string): number\n{\n let hashedValue = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hashedValue = ((hashedValue << 5) - hashedValue) + char;\n hashedValue |= 0;\n }\n\n return hashedValue;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n\nexport function sum<T extends number>(values: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of values) { _sum += value; }\n\n return _sum;\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.2.0-rc.2\";\n\nexport { DeferredPromise, Exception, JsonStorage, SmartIterator, Subscribers } from \"./models/index.js\";\nexport {\n average,\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n shuffle,\n sum,\n unique,\n zip\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","resolve","reject","onFinally","promise","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","SmartIterator","iterable","value","callback","index","iterator","result","initialValue","accumulator","values","Subscribers","subscriber","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","shuffle","array","jndex","unique","seen","element","zip","first","second","firstIterator","secondIterator","firstResult","secondResult","average","weights","_sum","weight","hash","hashedValue","i","char","random","min","max","decimals","rounder","digits","sum","capitalize","VERSION"],"mappings":";;;AAEA,MAAqBA,EACrB;AAAA,EAMW,YAAYC,GAA6CC,GAChE;AANU,IAAAC,EAAA;AACA,IAAAA,EAAA;AAEA,IAAAA,EAAA;AAIF,QAAAC,GACAC;AAEJ,SAAK,WAAW,IAAI,QAAW,CAACC,GAASC,MACzC;AACe,MAAAH,IAAAE,GACDD,IAAAE;AAAA,IAEb,CAAA,EAAE,KAAKN,GAAaC,CAAU,GAE/B,KAAK,WAAWE,GAChB,KAAK,UAAUC;AAAA,EACnB;AAAA,EAEA,IAAW,UACX;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EACA,IAAW,SACX;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,KACHJ,GACAC,GACJ;AACI,WAAO,KAAK,SAAS,KAAKD,GAAaC,CAAU;AAAA,EACrD;AAAA,EACO,MAAaA,GACpB;AACW,WAAA,KAAK,SAAS,MAAMA,CAAU;AAAA,EACzC;AAAA,EACO,QAAQM,GACf;AACW,WAAA,KAAK,SAAS,QAAQA,CAAS;AAAA,EAC1C;AAAA,EAEO,MAAMC,GACb;AACI,WAAAA,EAAQ,KAAK,KAAK,SAAS,KAAK,MAAM,GAE/B;AAAA,EACX;AAAA,EAEA,KAAY,OAAO,WAAW,IAC9B;AACW,WAAA;AAAA,EACX;AACJ;AC5DA,MAAqBC,UAAkB,MACvC;AAAA,EACI,OAAc,YAAYC,GAC1B;AACI,QAAIA,aAAiBD;AAEV,aAAAC;AAEX,QAAIA,aAAiB,OACrB;AACI,YAAMC,IAAM,IAAIF,EAAUC,EAAM,OAAO;AAEvC,aAAAC,EAAI,QAAQD,EAAM,OAClBC,EAAI,OAAOD,EAAM,MAEVC;AAAA,IACX;AAEA,WAAO,IAAIF,EAAU,GAAGC,CAAK,EAAE;AAAA,EACnC;AAAA,EAEO,YAAYE,GAAiBC,GAAiBC,IAAO,aAC5D;AACI,UAAMF,CAAO,GAEb,KAAK,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AM,CAAC,CAAC;AAC5D;ACHO,MAAMgE,IAAU;"}
1
+ {"version":3,"file":"core.js","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.ts","../src/models/smart-iterator.ts","../src/models/subscribers.ts","../src/utils/async.ts","../src/utils/date.ts","../src/utils/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T = void, E = unknown, F = T, R = never>\n{\n protected _resolve!: PromiseResolver<T>;\n protected _reject!: PromiseRejecter<E>;\n\n protected _promise: Promise<F | R>;\n\n public constructor(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R> | null)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n this._promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\n\n }).then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(\n onFulfilled?: FulfilledHandler<F | R, N> | null,\n onRejected?: RejectedHandler<R, H> | null): Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H> | null): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: (() => void) | null): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n\n public watch(promise: Promise<T>): this\n {\n promise.then(this.resolve, this.reject);\n\n return this;\n }\n\n public get [Symbol.toStringTag]()\n {\n return \"DeferredPromise\";\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import type { GeneratorFunction, Iteratee, Reducer } from \"../types.js\";\n\nexport default class SmartIterator<T, R = void, N = undefined> implements Iterator<T, R, N>\n{\n protected _iterator: Iterator<T, R, N>;\n\n public return?: (value?: R) => IteratorResult<T, R>;\n public throw?: (error?: unknown) => IteratorResult<T, R>;\n\n public constructor(iterable: Iterable<T>);\n public constructor(iterator: Iterator<T, R, N>);\n public constructor(generatorFn: GeneratorFunction<T, R, N>);\n public constructor(iterable: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)\n {\n if (iterable instanceof Function)\n {\n this._iterator = iterable();\n }\n else if (Symbol.iterator in iterable)\n {\n this._iterator = iterable[Symbol.iterator]() as Iterator<T, R, N>;\n }\n else\n {\n this._iterator = iterable;\n }\n\n if (this._iterator.return) { this.return = (value?: R) => this._iterator.return!(value); }\n if (this._iterator.throw) { this.throw = (error?: unknown) => this._iterator.throw!(error); }\n }\n\n public every(iteratee: Iteratee<T, boolean>): boolean\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n\n if (result.done) { return true; }\n if (!(iteratee(result.value, index))) { return false; }\n\n index += 1;\n }\n }\n public some(iteratee: Iteratee<T, boolean>): boolean\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n\n if (result.done) { return false; }\n if (iteratee(result.value, index)) { return true; }\n\n index += 1;\n }\n }\n\n public filter(iteratee: Iteratee<T, boolean>): SmartIterator<T, R, N>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<T, R, N>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n\n if (result.done) { return result.value; }\n if (iteratee(result.value, index)) { yield result.value; }\n\n index += 1;\n }\n }\n });\n }\n public map<V>(iteratee: Iteratee<T, V>): SmartIterator<V, R>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<V, R>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n yield iteratee(result.value, index);\n\n index += 1;\n }\n }\n });\n }\n public reduce<A>(reducer: Reducer<T, A>, initialValue: A): A\n {\n let index = 0;\n let accumulator = initialValue;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return accumulator; }\n\n accumulator = reducer(accumulator, result.value, index);\n\n index += 1;\n }\n }\n\n public forEach(iteratee: Iteratee<T>): void\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return; }\n\n iteratee(result.value, index);\n\n index += 1;\n }\n }\n\n public next(...values: N extends undefined ? [] : [N]): IteratorResult<T, R>\n {\n return this._iterator.next(...values);\n }\n\n public toArray(): T[]\n {\n return [...this];\n }\n\n public [Symbol.iterator](): SmartIterator<T, R, N> { return this; }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day): number\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function dateRange(start: Date, end: Date, offset = DateUnit.Day): SmartIterator<Date>\n{\n return new SmartIterator<Date>(function* ()\n {\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n });\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day): Date\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): SmartIterator<number>;\nexport function range(start: number, end: number): SmartIterator<number>;\nexport function range(start: number, end: number, step: number): SmartIterator<number>;\nexport function range(start: number, end?: number, step = 1): SmartIterator<number>\n{\n return new SmartIterator<number>(function* ()\n {\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n });\n}\n\nexport function shuffle<T>(iterable: Iterable<T>): T[]\n{\n const array = [...iterable];\n\n for (let index = array.length - 1; index > 0; index -= 1)\n {\n const jndex = Math.floor(Math.random() * (index + 1));\n\n [array[index], array[jndex]] = [array[jndex], array[index]];\n }\n\n return array;\n}\n\nexport function unique<T>(elements: Iterable<T>): SmartIterator<T>\n{\n return new SmartIterator<T>(function* ()\n {\n const seen = new Set<T>();\n\n for (const element of elements)\n {\n if (seen.has(element)) { continue; }\n\n seen.add(element);\n\n yield element;\n }\n });\n}\n\nexport function zip<T, U>(first: Iterable<T>, second: Iterable<U>): SmartIterator<[T, U]>\n{\n return new SmartIterator<[T, U]>(function* ()\n {\n const firstIterator = first[Symbol.iterator]();\n const secondIterator = second[Symbol.iterator]();\n\n while (true)\n {\n const firstResult = firstIterator.next();\n const secondResult = secondIterator.next();\n\n if ((firstResult.done) || (secondResult.done)) { break; }\n\n yield [firstResult.value, secondResult.value];\n }\n });\n}\n","import { zip } from \"./iterator.js\";\n\nexport function average<T extends number>(values: Iterable<T>): number;\nexport function average<T extends number>(values: Iterable<T>, weights: Iterable<number>): number;\nexport function average<T extends number>(values: Iterable<T>, weights?: Iterable<number>): number\n{\n if (weights === undefined)\n {\n let _sum = 0;\n let _count = 0;\n\n for (const value of values)\n {\n _sum += value;\n _count += 1;\n }\n\n return _sum / _count;\n }\n\n let _sum = 0;\n let _count = 0;\n\n for (const [value, weight] of zip(values, weights))\n {\n _sum += value * weight;\n _count += weight;\n }\n\n return _sum / _count;\n}\n\nexport function hash(value: string): number\n{\n let hashedValue = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hashedValue = ((hashedValue << 5) - hashedValue) + char;\n hashedValue |= 0;\n }\n\n return hashedValue;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n\nexport function sum<T extends number>(values: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of values) { _sum += value; }\n\n return _sum;\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.2.0-rc.3\";\n\nexport { DeferredPromise, Exception, JsonStorage, SmartIterator, Subscribers } from \"./models/index.js\";\nexport {\n average,\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n shuffle,\n sum,\n unique,\n zip\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n GeneratorFunction,\n Iteratee,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n Reducer,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","resolve","reject","onFinally","promise","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","SmartIterator","iterable","value","iteratee","index","result","iterator","reducer","initialValue","accumulator","values","Subscribers","subscriber","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","shuffle","array","jndex","unique","seen","element","zip","first","second","firstIterator","secondIterator","firstResult","secondResult","average","weights","_sum","weight","hash","hashedValue","i","char","random","min","max","decimals","rounder","digits","sum","capitalize","VERSION"],"mappings":";;;AAEA,MAAqBA,EACrB;AAAA,EAMW,YAAYC,GAA6CC,GAChE;AANU,IAAAC,EAAA;AACA,IAAAA,EAAA;AAEA,IAAAA,EAAA;AAIF,QAAAC,GACAC;AAEJ,SAAK,WAAW,IAAI,QAAW,CAACC,GAASC,MACzC;AACe,MAAAH,IAAAE,GACDD,IAAAE;AAAA,IAEb,CAAA,EAAE,KAAKN,GAAaC,CAAU,GAE/B,KAAK,WAAWE,GAChB,KAAK,UAAUC;AAAA,EACnB;AAAA,EAEA,IAAW,UACX;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EACA,IAAW,SACX;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,KACHJ,GACAC,GACJ;AACI,WAAO,KAAK,SAAS,KAAKD,GAAaC,CAAU;AAAA,EACrD;AAAA,EACO,MAAaA,GACpB;AACW,WAAA,KAAK,SAAS,MAAMA,CAAU;AAAA,EACzC;AAAA,EACO,QAAQM,GACf;AACW,WAAA,KAAK,SAAS,QAAQA,CAAS;AAAA,EAC1C;AAAA,EAEO,MAAMC,GACb;AACI,WAAAA,EAAQ,KAAK,KAAK,SAAS,KAAK,MAAM,GAE/B;AAAA,EACX;AAAA,EAEA,KAAY,OAAO,WAAW,IAC9B;AACW,WAAA;AAAA,EACX;AACJ;AC5DA,MAAqBC,UAAkB,MACvC;AAAA,EACI,OAAc,YAAYC,GAC1B;AACI,QAAIA,aAAiBD;AAEV,aAAAC;AAEX,QAAIA,aAAiB,OACrB;AACI,YAAMC,IAAM,IAAIF,EAAUC,EAAM,OAAO;AAE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GACAA,IAAA,IAGNA,MAAQC;AAED,WAAAD;AAGP,MAAAG;AAEJ,MAAID,MAAa;AAEb,IAAAC,IAAU,CAAC7D,MAAUA;AAAA,WAEhB4D,MAAa;AAElB,IAAI,KAAK,IAAID,IAAMD,CAAG,KAAK,IAEvBG,IAAU,CAAC7D,MAAUA,IAIrB6D,IAAU,KAAK;AAAA,WAGdD,MAAa;AAElB,IAAAC,IAAU,KAAK;AAAA,OAGnB;AACI,UAAMC,IAAS,MAAMF;AAErB,IAAAC,IAAU,CAAC7D,MAAU,KAAK,MAAMA,IAAQ8D,CAAM,IAAIA;AAAA,EACtD;AAEA,SAAOD,EAAQ,KAAK,OAAA,KAAYF,IAAMD,KAAOA,CAAG;AACpD;AAEO,SAASK,EAAsBvD,GACtC;AACI,MAAI2C,IAAO;AACX,aAAWnD,KAASQ;AAAkB,IAAA2C,KAAAnD;AAE/B,SAAAmD;AACX;ACpGO,SAASa,EAAWhE,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMiE,IAAU;"}
package/dist/core.umd.cjs CHANGED
@@ -1,6 +1,6 @@
1
- (function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.Core={}))})(this,function(s){"use strict";var E=Object.defineProperty;var $=(s,u,c)=>u in s?E(s,u,{enumerable:!0,configurable:!0,writable:!0,value:c}):s[u]=c;var a=(s,u,c)=>($(s,typeof u!="symbol"?u+"":u,c),c);class u{constructor(e,t){a(this,"_resolve");a(this,"_reject");a(this,"_promise");let i,n;this._promise=new Promise((o,h)=>{i=o,n=h}).then(e,t),this._resolve=i,this._reject=n}get resolve(){return this._resolve}get reject(){return this._reject}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}watch(e){return e.then(this.resolve,this.reject),this}get[Symbol.toStringTag](){return"DeferredPromise"}}class c extends Error{static FromUnknown(e){if(e instanceof c)return e;if(e instanceof Error){const t=new c(e.message);return t.stack=e.stack,t.name=e.name,t}return new c(`${e}`)}constructor(e,t,i="Exception"){super(e),this.cause=t,this.name=i,t&&(t instanceof Error?this.stack+=`
1
+ (function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.Core={}))})(this,function(s){"use strict";var E=Object.defineProperty;var $=(s,u,l)=>u in s?E(s,u,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[u]=l;var c=(s,u,l)=>($(s,typeof u!="symbol"?u+"":u,l),l);class u{constructor(e,t){c(this,"_resolve");c(this,"_reject");c(this,"_promise");let n,i;this._promise=new Promise((o,h)=>{n=o,i=h}).then(e,t),this._resolve=n,this._reject=i}get resolve(){return this._resolve}get reject(){return this._reject}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}watch(e){return e.then(this.resolve,this.reject),this}get[Symbol.toStringTag](){return"DeferredPromise"}}class l extends Error{static FromUnknown(e){if(e instanceof l)return e;if(e instanceof Error){const t=new l(e.message);return t.stack=e.stack,t.name=e.name,t}return new l(`${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}`)}}class _{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,i){const n=e.getItem(t);if(n)try{return JSON.parse(n)}catch{console.warn(`The "${n}" value for "${t}" property cannot be parsed. Clearing the storage...`),e.removeItem(t)}return i}_set(e,t,i){const n=JSON.stringify(i);n?e.setItem(t,n):e.removeItem(t)}get(e,t,i=this._preferPersistence){const n=i?this._persistent:this._volatile;return this._get(n,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,i=this._preferPersistence){const n=i?this._persistent:this._volatile;this._set(n,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)}}class l{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))}filter(e){let t=0;const i=this._iterator;return new l({*[Symbol.iterator](){for(;;){const n=i.next();if(n.done)return n.value;e(n.value,t)&&(yield n.value),t+=1}}})}map(e){let t=0;const i=this._iterator;return new l({*[Symbol.iterator](){for(;;){const n=i.next();if(n.done)return n.value;yield e(n.value,t),t+=1}}})}reduce(e,t){let i=0,n=t;for(;;){const o=this._iterator.next();if(o.done)return n;n=e(n,o.value,i),i+=1}}forEach(e){let t=0;for(;;){const i=this._iterator.next();if(i.done)return;e(i.value,t),t+=1}}next(...e){return this._iterator.next(...e)}toArray(){return[...this]}[Symbol.iterator](){return this}}class m{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 c("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))}}async function v(r){return new Promise((e,t)=>setTimeout(e,r))}async function g(){return new Promise((r,e)=>requestAnimationFrame(()=>r()))}var f=(r=>(r[r.Second=1e3]="Second",r[r.Minute=6e4]="Minute",r[r.Hour=36e5]="Hour",r[r.Day=864e5]="Day",r[r.Week=6048e5]="Week",r[r.Month=2592e6]="Month",r[r.Year=31536e6]="Year",r))(f||{});function w(r,e,t=864e5){return Math.floor((e.getTime()-r.getTime())/t)}function y(r,e,t=864e5){return new l(function*(){const i=e.getTime();let n=r.getTime();for(;n<i;)yield new Date(n),n+=t})}function b(r,e=864e5){return new Date(Math.floor(r.getTime()/e)*e)}async function S(r,e="text/javascript"){return new Promise((t,i)=>{const n=document.createElement("script");n.async=!0,n.defer=!0,n.src=r,n.type=e,n.onload=()=>t(),n.onerror=()=>i(),document.body.appendChild(n)})}function I(r){if(Array.isArray(r))return r.length;let e=0;for(const t of r)e+=1;return e}function p(r,e,t=1){return new l(function*(){e===void 0&&(e=r,r=0),r>e&&(t=t??-1);for(let i=r;i<e;i+=t)yield i})}function M(r){const e=[...r];for(let t=e.length-1;t>0;t-=1){const i=Math.floor(Math.random()*(t+1));[e[t],e[i]]=[e[i],e[t]]}return e}function T(r){return new l(function*(){const e=new Set;for(const t of r)e.has(t)||(e.add(t),yield t)})}function d(r,e){return new l(function*(){const t=r[Symbol.iterator](),i=e[Symbol.iterator]();for(;;){const n=t.next(),o=i.next();if(n.done||o.done)break;yield[n.value,o.value]}})}function j(r,e){if(e===void 0){let n=0,o=0;for(const h of r)n+=h,o+=1;return n/o}let t=0,i=0;for(const[n,o]of d(r,e))t+=n*o,i+=o;return t/i}function P(r){let e=0;for(let t=0;t<r.length;t++){const i=r.charCodeAt(t);e=(e<<5)-e+i,e|=0}return e}function k(r=1,e,t){if(e===void 0&&(e=r,r=0),r===e)return r;let i;if(t===!0)i=n=>n;else if(t===void 0)Math.abs(e-r)<=1?i=n=>n:i=Math.floor;else if(t===!1)i=Math.floor;else{const n=10**t;i=o=>Math.floor(o*n)/n}return i(Math.random()*(e-r)+r)}function A(r){let e=0;for(const t of r)e+=t;return e}function R(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}const C="1.2.0-rc.2";s.DateUnit=f,s.DeferredPromise=u,s.Exception=c,s.JsonStorage=_,s.SmartIterator=l,s.Subscribers=m,s.VERSION=C,s.average=j,s.capitalize=R,s.count=I,s.dateDifference=w,s.dateRange=y,s.dateRound=b,s.delay=v,s.hash=P,s.loadScript=S,s.nextAnimationFrame=g,s.random=k,s.range=p,s.shuffle=M,s.sum=A,s.unique=T,s.zip=d,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
5
+ Caused by ${t}`)}}class _{constructor(e=!0){c(this,"_preferPersistence");c(this,"_volatile");c(this,"_persistent");this._preferPersistence=e,this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(e,t,n){const i=e.getItem(t);if(i)try{return JSON.parse(i)}catch{console.warn(`The "${i}" value for "${t}" property cannot be parsed. Clearing the storage...`),e.removeItem(t)}return n}_set(e,t,n){const i=JSON.stringify(n);i?e.setItem(t,i):e.removeItem(t)}get(e,t,n=this._preferPersistence){const i=n?this._persistent:this._volatile;return this._get(i,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 i=n?this._persistent:this._volatile;this._set(i,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)}}class a{constructor(e){c(this,"_iterator");c(this,"return");c(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){let t=0;const n=this._iterator;return new a({*[Symbol.iterator](){for(;;){const i=n.next();if(i.done)return i.value;e(i.value,t)&&(yield i.value),t+=1}}})}map(e){let t=0;const n=this._iterator;return new a({*[Symbol.iterator](){for(;;){const i=n.next();if(i.done)return i.value;yield e(i.value,t),t+=1}}})}reduce(e,t){let n=0,i=t;for(;;){const o=this._iterator.next();if(o.done)return i;i=e(i,o.value,n),n+=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[...this]}[Symbol.iterator](){return this}}class m{constructor(){c(this,"_subscribers");this._subscribers=[]}add(e){this._subscribers.push(e)}remove(e){const t=this._subscribers.indexOf(e);if(t<0)throw new l("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))}}async function v(r){return new Promise((e,t)=>setTimeout(e,r))}async function g(){return new Promise((r,e)=>requestAnimationFrame(()=>r()))}var f=(r=>(r[r.Second=1e3]="Second",r[r.Minute=6e4]="Minute",r[r.Hour=36e5]="Hour",r[r.Day=864e5]="Day",r[r.Week=6048e5]="Week",r[r.Month=2592e6]="Month",r[r.Year=31536e6]="Year",r))(f||{});function w(r,e,t=864e5){return Math.floor((e.getTime()-r.getTime())/t)}function y(r,e,t=864e5){return new a(function*(){const n=e.getTime();let i=r.getTime();for(;i<n;)yield new Date(i),i+=t})}function b(r,e=864e5){return new Date(Math.floor(r.getTime()/e)*e)}async function S(r,e="text/javascript"){return new Promise((t,n)=>{const i=document.createElement("script");i.async=!0,i.defer=!0,i.src=r,i.type=e,i.onload=()=>t(),i.onerror=()=>n(),document.body.appendChild(i)})}function I(r){if(Array.isArray(r))return r.length;let e=0;for(const t of r)e+=1;return e}function p(r,e,t=1){return new a(function*(){e===void 0&&(e=r,r=0),r>e&&(t=t??-1);for(let n=r;n<e;n+=t)yield n})}function M(r){const e=[...r];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 T(r){return new a(function*(){const e=new Set;for(const t of r)e.has(t)||(e.add(t),yield t)})}function d(r,e){return new a(function*(){const t=r[Symbol.iterator](),n=e[Symbol.iterator]();for(;;){const i=t.next(),o=n.next();if(i.done||o.done)break;yield[i.value,o.value]}})}function j(r,e){if(e===void 0){let i=0,o=0;for(const h of r)i+=h,o+=1;return i/o}let t=0,n=0;for(const[i,o]of d(r,e))t+=i*o,n+=o;return t/n}function P(r){let e=0;for(let t=0;t<r.length;t++){const n=r.charCodeAt(t);e=(e<<5)-e+n,e|=0}return e}function k(r=1,e,t){if(e===void 0&&(e=r,r=0),r===e)return r;let n;if(t===!0)n=i=>i;else if(t===void 0)Math.abs(e-r)<=1?n=i=>i:n=Math.floor;else if(t===!1)n=Math.floor;else{const i=10**t;n=o=>Math.floor(o*i)/i}return n(Math.random()*(e-r)+r)}function A(r){let e=0;for(const t of r)e+=t;return e}function R(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}const C="1.2.0-rc.3";s.DateUnit=f,s.DeferredPromise=u,s.Exception=l,s.JsonStorage=_,s.SmartIterator=a,s.Subscribers=m,s.VERSION=C,s.average=j,s.capitalize=R,s.count=I,s.dateDifference=w,s.dateRange=y,s.dateRound=b,s.delay=v,s.hash=P,s.loadScript=S,s.nextAnimationFrame=g,s.random=k,s.range=p,s.shuffle=M,s.sum=A,s.unique=T,s.zip=d,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
6
6
  //# sourceMappingURL=core.umd.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.umd.cjs","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.ts","../src/models/smart-iterator.ts","../src/models/subscribers.ts","../src/utils/async.ts","../src/utils/date.ts","../src/utils/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T = void, E = unknown, F = T, R = never>\n{\n protected _resolve!: PromiseResolver<T>;\n protected _reject!: PromiseRejecter<E>;\n\n protected _promise: Promise<F | R>;\n\n public constructor(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R> | null)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n this._promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\n\n }).then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(\n onFulfilled?: FulfilledHandler<F | R, N> | null,\n onRejected?: RejectedHandler<R, H> | null): Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H> | null): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: (() => void) | null): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n\n public watch(promise: Promise<T>): this\n {\n promise.then(this.resolve, this.reject);\n\n return this;\n }\n\n public get [Symbol.toStringTag]()\n {\n return \"DeferredPromise\";\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import type { GeneratorFunction } from \"../types.js\";\n\nexport default class SmartIterator<T, R = void, N = undefined> implements Iterator<T, R, N>\n{\n protected _iterator: Iterator<T, R, N>;\n\n public return?: (value?: R) => IteratorResult<T, R>;\n public throw?: (error?: unknown) => IteratorResult<T, R>;\n\n public constructor(iterable: Iterable<T>);\n public constructor(iterator: Iterator<T, R, N>);\n public constructor(generatorFn: GeneratorFunction<T, R, N>);\n public constructor(iterable: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)\n {\n if (iterable instanceof Function)\n {\n this._iterator = iterable();\n }\n else if (Symbol.iterator in iterable)\n {\n this._iterator = iterable[Symbol.iterator]() as Iterator<T, R, N>;\n }\n else\n {\n this._iterator = iterable;\n }\n\n if (this._iterator.return) { this.return = (value?: R) => this._iterator.return!(value); }\n if (this._iterator.throw) { this.throw = (error?: unknown) => this._iterator.throw!(error); }\n }\n\n public filter(callback: (value: T, index: number) => boolean): SmartIterator<T, R, N>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<T, R, N>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n if (callback(result.value, index))\n {\n yield result.value;\n }\n\n index += 1;\n }\n }\n });\n }\n public map<V>(callback: (value: T, index: number) => V): SmartIterator<V, R>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<V, R>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n yield callback(result.value, index);\n\n index += 1;\n }\n }\n });\n }\n public reduce<U>(callback: (accumulator: U, value: T, index: number) => U, initialValue: U): U\n {\n let index = 0;\n let accumulator = initialValue;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return accumulator; }\n\n accumulator = callback(accumulator, result.value, index);\n\n index += 1;\n }\n }\n\n public forEach(callback: (value: T, index: number) => void): void\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return; }\n\n callback(result.value, index);\n\n index += 1;\n }\n }\n\n public next(...values: N extends undefined ? [] : [N]): IteratorResult<T, R>\n {\n return this._iterator.next(...values);\n }\n\n public toArray(): T[]\n {\n return [...this];\n }\n\n public [Symbol.iterator](): SmartIterator<T, R, N> { return this; }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day): number\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function dateRange(start: Date, end: Date, offset = DateUnit.Day): SmartIterator<Date>\n{\n return new SmartIterator<Date>(function* ()\n {\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n });\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day): Date\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): SmartIterator<number>;\nexport function range(start: number, end: number): SmartIterator<number>;\nexport function range(start: number, end: number, step: number): SmartIterator<number>;\nexport function range(start: number, end?: number, step = 1): SmartIterator<number>\n{\n return new SmartIterator<number>(function* ()\n {\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n });\n}\n\nexport function shuffle<T>(iterable: Iterable<T>): T[]\n{\n const array = [...iterable];\n\n for (let index = array.length - 1; index > 0; index -= 1)\n {\n const jndex = Math.floor(Math.random() * (index + 1));\n\n [array[index], array[jndex]] = [array[jndex], array[index]];\n }\n\n return array;\n}\n\nexport function unique<T>(elements: Iterable<T>): SmartIterator<T>\n{\n return new SmartIterator<T>(function* ()\n {\n const seen = new Set<T>();\n\n for (const element of elements)\n {\n if (seen.has(element)) { continue; }\n\n seen.add(element);\n\n yield element;\n }\n });\n}\n\nexport function zip<T, U>(first: Iterable<T>, second: Iterable<U>): SmartIterator<[T, U]>\n{\n return new SmartIterator<[T, U]>(function* ()\n {\n const firstIterator = first[Symbol.iterator]();\n const secondIterator = second[Symbol.iterator]();\n\n while (true)\n {\n const firstResult = firstIterator.next();\n const secondResult = secondIterator.next();\n\n if ((firstResult.done) || (secondResult.done)) { break; }\n\n yield [firstResult.value, secondResult.value];\n }\n });\n}\n","import { zip } from \"./iterator.js\";\n\nexport function average<T extends number>(values: Iterable<T>): number;\nexport function average<T extends number>(values: Iterable<T>, weights: Iterable<number>): number;\nexport function average<T extends number>(values: Iterable<T>, weights?: Iterable<number>): number\n{\n if (weights === undefined)\n {\n let _sum = 0;\n let _count = 0;\n\n for (const value of values)\n {\n _sum += value;\n _count += 1;\n }\n\n return _sum / _count;\n }\n\n let _sum = 0;\n let _count = 0;\n\n for (const [value, weight] of zip(values, weights))\n {\n _sum += value * weight;\n _count += weight;\n }\n\n return _sum / _count;\n}\n\nexport function hash(value: string): number\n{\n let hashedValue = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hashedValue = ((hashedValue << 5) - hashedValue) + char;\n hashedValue |= 0;\n }\n\n return hashedValue;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n\nexport function sum<T extends number>(values: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of values) { _sum += value; }\n\n return _sum;\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.2.0-rc.2\";\n\nexport { DeferredPromise, Exception, JsonStorage, SmartIterator, Subscribers } from \"./models/index.js\";\nexport {\n average,\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n shuffle,\n sum,\n unique,\n zip\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","resolve","reject","onFinally","promise","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","SmartIterator","iterable","value","callback","index","iterator","result","initialValue","accumulator","values","Subscribers","subscriber","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","shuffle","array","jndex","unique","seen","element","zip","first","second","firstIterator","secondIterator","firstResult","secondResult","average","weights","_sum","weight","hash","hashedValue","i","char","random","min","max","decimals","rounder","digits","sum","capitalize","VERSION"],"mappings":"oYAEA,MAAqBA,CACrB,CAMW,YAAYC,EAA6CC,EAChE,CANUC,EAAA,iBACAA,EAAA,gBAEAA,EAAA,iBAIF,IAAAC,EACAC,EAEJ,KAAK,SAAW,IAAI,QAAW,CAACC,EAASC,IACzC,CACeH,EAAAE,EACDD,EAAAE,CAEb,CAAA,EAAE,KAAKN,EAAaC,CAAU,EAE/B,KAAK,SAAWE,EAChB,KAAK,QAAUC,CACnB,CAEA,IAAW,SACX,CAC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EO,SAASqB,EAAKpD,EACrB,CACI,IAAIqD,EAAc,EAClB,QAASC,EAAI,EAAGA,EAAItD,EAAM,OAAQsD,IAClC,CACU,MAAAC,EAAOvD,EAAM,WAAWsD,CAAC,EACfD,GAAAA,GAAe,GAAKA,EAAeE,EACpCF,GAAA,CACnB,CAEO,OAAAA,CACX,CAOO,SAASG,EAAOC,EAAc,EAAGC,EAAcC,EACtD,CAOI,GANID,IAAQ,SAEFA,EAAAD,EACAA,EAAA,GAGNA,IAAQC,EAED,OAAAD,EAGP,IAAAG,EAEJ,GAAID,IAAa,GAEbC,EAAW5D,GAAUA,UAEhB2D,IAAa,OAEd,KAAK,IAAID,EAAMD,CAAG,GAAK,EAEvBG,EAAW5D,GAAUA,EAIrB4D,EAAU,KAAK,cAGdD,IAAa,GAElBC,EAAU,KAAK,UAGnB,CACI,MAAMC,EAAS,IAAMF,EAErBC,EAAW5D,GAAU,KAAK,MAAMA,EAAQ6D,CAAM,EAAIA,CACtD,CAEA,OAAOD,EAAQ,KAAK,OAAA,GAAYF,EAAMD,GAAOA,CAAG,CACpD,CAEO,SAASK,EAAsBvD,EACtC,CACI,IAAI2C,EAAO,EACX,UAAWlD,KAASO,EAAkB2C,GAAAlD,EAE/B,OAAAkD,CACX,CCpGO,SAASa,EAAW/D,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMgE,EAAU"}
1
+ {"version":3,"file":"core.umd.cjs","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.ts","../src/models/smart-iterator.ts","../src/models/subscribers.ts","../src/utils/async.ts","../src/utils/date.ts","../src/utils/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T = void, E = unknown, F = T, R = never>\n{\n protected _resolve!: PromiseResolver<T>;\n protected _reject!: PromiseRejecter<E>;\n\n protected _promise: Promise<F | R>;\n\n public constructor(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R> | null)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n this._promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\n\n }).then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(\n onFulfilled?: FulfilledHandler<F | R, N> | null,\n onRejected?: RejectedHandler<R, H> | null): Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H> | null): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: (() => void) | null): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n\n public watch(promise: Promise<T>): this\n {\n promise.then(this.resolve, this.reject);\n\n return this;\n }\n\n public get [Symbol.toStringTag]()\n {\n return \"DeferredPromise\";\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import type { GeneratorFunction, Iteratee, Reducer } from \"../types.js\";\n\nexport default class SmartIterator<T, R = void, N = undefined> implements Iterator<T, R, N>\n{\n protected _iterator: Iterator<T, R, N>;\n\n public return?: (value?: R) => IteratorResult<T, R>;\n public throw?: (error?: unknown) => IteratorResult<T, R>;\n\n public constructor(iterable: Iterable<T>);\n public constructor(iterator: Iterator<T, R, N>);\n public constructor(generatorFn: GeneratorFunction<T, R, N>);\n public constructor(iterable: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)\n {\n if (iterable instanceof Function)\n {\n this._iterator = iterable();\n }\n else if (Symbol.iterator in iterable)\n {\n this._iterator = iterable[Symbol.iterator]() as Iterator<T, R, N>;\n }\n else\n {\n this._iterator = iterable;\n }\n\n if (this._iterator.return) { this.return = (value?: R) => this._iterator.return!(value); }\n if (this._iterator.throw) { this.throw = (error?: unknown) => this._iterator.throw!(error); }\n }\n\n public every(iteratee: Iteratee<T, boolean>): boolean\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n\n if (result.done) { return true; }\n if (!(iteratee(result.value, index))) { return false; }\n\n index += 1;\n }\n }\n public some(iteratee: Iteratee<T, boolean>): boolean\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n\n if (result.done) { return false; }\n if (iteratee(result.value, index)) { return true; }\n\n index += 1;\n }\n }\n\n public filter(iteratee: Iteratee<T, boolean>): SmartIterator<T, R, N>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<T, R, N>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n\n if (result.done) { return result.value; }\n if (iteratee(result.value, index)) { yield result.value; }\n\n index += 1;\n }\n }\n });\n }\n public map<V>(iteratee: Iteratee<T, V>): SmartIterator<V, R>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<V, R>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n yield iteratee(result.value, index);\n\n index += 1;\n }\n }\n });\n }\n public reduce<A>(reducer: Reducer<T, A>, initialValue: A): A\n {\n let index = 0;\n let accumulator = initialValue;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return accumulator; }\n\n accumulator = reducer(accumulator, result.value, index);\n\n index += 1;\n }\n }\n\n public forEach(iteratee: Iteratee<T>): void\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return; }\n\n iteratee(result.value, index);\n\n index += 1;\n }\n }\n\n public next(...values: N extends undefined ? [] : [N]): IteratorResult<T, R>\n {\n return this._iterator.next(...values);\n }\n\n public toArray(): T[]\n {\n return [...this];\n }\n\n public [Symbol.iterator](): SmartIterator<T, R, N> { return this; }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day): number\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function dateRange(start: Date, end: Date, offset = DateUnit.Day): SmartIterator<Date>\n{\n return new SmartIterator<Date>(function* ()\n {\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n });\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day): Date\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): SmartIterator<number>;\nexport function range(start: number, end: number): SmartIterator<number>;\nexport function range(start: number, end: number, step: number): SmartIterator<number>;\nexport function range(start: number, end?: number, step = 1): SmartIterator<number>\n{\n return new SmartIterator<number>(function* ()\n {\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n });\n}\n\nexport function shuffle<T>(iterable: Iterable<T>): T[]\n{\n const array = [...iterable];\n\n for (let index = array.length - 1; index > 0; index -= 1)\n {\n const jndex = Math.floor(Math.random() * (index + 1));\n\n [array[index], array[jndex]] = [array[jndex], array[index]];\n }\n\n return array;\n}\n\nexport function unique<T>(elements: Iterable<T>): SmartIterator<T>\n{\n return new SmartIterator<T>(function* ()\n {\n const seen = new Set<T>();\n\n for (const element of elements)\n {\n if (seen.has(element)) { continue; }\n\n seen.add(element);\n\n yield element;\n }\n });\n}\n\nexport function zip<T, U>(first: Iterable<T>, second: Iterable<U>): SmartIterator<[T, U]>\n{\n return new SmartIterator<[T, U]>(function* ()\n {\n const firstIterator = first[Symbol.iterator]();\n const secondIterator = second[Symbol.iterator]();\n\n while (true)\n {\n const firstResult = firstIterator.next();\n const secondResult = secondIterator.next();\n\n if ((firstResult.done) || (secondResult.done)) { break; }\n\n yield [firstResult.value, secondResult.value];\n }\n });\n}\n","import { zip } from \"./iterator.js\";\n\nexport function average<T extends number>(values: Iterable<T>): number;\nexport function average<T extends number>(values: Iterable<T>, weights: Iterable<number>): number;\nexport function average<T extends number>(values: Iterable<T>, weights?: Iterable<number>): number\n{\n if (weights === undefined)\n {\n let _sum = 0;\n let _count = 0;\n\n for (const value of values)\n {\n _sum += value;\n _count += 1;\n }\n\n return _sum / _count;\n }\n\n let _sum = 0;\n let _count = 0;\n\n for (const [value, weight] of zip(values, weights))\n {\n _sum += value * weight;\n _count += weight;\n }\n\n return _sum / _count;\n}\n\nexport function hash(value: string): number\n{\n let hashedValue = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hashedValue = ((hashedValue << 5) - hashedValue) + char;\n hashedValue |= 0;\n }\n\n return hashedValue;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n\nexport function sum<T extends number>(values: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of values) { _sum += value; }\n\n return _sum;\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.2.0-rc.3\";\n\nexport { DeferredPromise, Exception, JsonStorage, SmartIterator, Subscribers } from \"./models/index.js\";\nexport {\n average,\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n shuffle,\n sum,\n unique,\n zip\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n GeneratorFunction,\n Iteratee,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n Reducer,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","resolve","reject","onFinally","promise","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","SmartIterator","iterable","value","iteratee","index","result","iterator","reducer","initialValue","accumulator","values","Subscribers","subscriber","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","shuffle","array","jndex","unique","seen","element","zip","first","second","firstIterator","secondIterator","firstResult","secondResult","average","weights","_sum","weight","hash","hashedValue","i","char","random","min","max","decimals","rounder","digits","sum","capitalize","VERSION"],"mappings":"oYAEA,MAAqBA,CACrB,CAMW,YAAYC,EAA6CC,EAChE,CANUC,EAAA,iBACAA,EAAA,gBAEAA,EAAA,i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OAAA,GAAYF,EAAMD,GAAOA,CAAG,CACpD,CAEO,SAASK,EAAsBvD,EACtC,CACI,IAAI2C,EAAO,EACX,UAAWnD,KAASQ,EAAkB2C,GAAAnD,EAE/B,OAAAmD,CACX,CCpGO,SAASa,EAAWhE,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMiE,EAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byloth/core",
3
- "version": "1.2.0-rc.2",
3
+ "version": "1.2.0-rc.3",
4
4
  "description": "An unopinionated collection of useful functions and classes that I use widely in all my projects. 🔧",
5
5
  "keywords": [
6
6
  "Core",
@@ -57,8 +57,8 @@
57
57
  },
58
58
  "devDependencies": {
59
59
  "@byloth/eslint-config-typescript": "^2.6.8",
60
- "@typescript-eslint/eslint-plugin": "^6.15.0",
61
- "@typescript-eslint/parser": "^6.15.0",
60
+ "@typescript-eslint/eslint-plugin": "^6.16.0",
61
+ "@typescript-eslint/parser": "^6.16.0",
62
62
  "eslint": "^8.56.0",
63
63
  "typescript": "^5.3.3",
64
64
  "vite": "^5.0.10"
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "1.2.0-rc.2";
1
+ export const VERSION = "1.2.0-rc.3";
2
2
 
3
3
  export { DeferredPromise, Exception, JsonStorage, SmartIterator, Subscribers } from "./models/index.js";
4
4
  export {
@@ -25,10 +25,13 @@ export {
25
25
  export type {
26
26
  Constructor,
27
27
  FulfilledHandler,
28
+ GeneratorFunction,
29
+ Iteratee,
28
30
  MaybePromise,
29
31
  PromiseExecutor,
30
32
  PromiseRejecter,
31
33
  PromiseResolver,
34
+ Reducer,
32
35
  RejectedHandler
33
36
 
34
37
  } from "./types.js";
@@ -1,4 +1,4 @@
1
- import type { GeneratorFunction } from "../types.js";
1
+ import type { GeneratorFunction, Iteratee, Reducer } from "../types.js";
2
2
 
3
3
  export default class SmartIterator<T, R = void, N = undefined> implements Iterator<T, R, N>
4
4
  {
@@ -29,7 +29,38 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
29
29
  if (this._iterator.throw) { this.throw = (error?: unknown) => this._iterator.throw!(error); }
30
30
  }
31
31
 
32
- public filter(callback: (value: T, index: number) => boolean): SmartIterator<T, R, N>
32
+ public every(iteratee: Iteratee<T, boolean>): boolean
33
+ {
34
+ let index = 0;
35
+
36
+ // eslint-disable-next-line no-constant-condition
37
+ while (true)
38
+ {
39
+ const result = this._iterator.next();
40
+
41
+ if (result.done) { return true; }
42
+ if (!(iteratee(result.value, index))) { return false; }
43
+
44
+ index += 1;
45
+ }
46
+ }
47
+ public some(iteratee: Iteratee<T, boolean>): boolean
48
+ {
49
+ let index = 0;
50
+
51
+ // eslint-disable-next-line no-constant-condition
52
+ while (true)
53
+ {
54
+ const result = this._iterator.next();
55
+
56
+ if (result.done) { return false; }
57
+ if (iteratee(result.value, index)) { return true; }
58
+
59
+ index += 1;
60
+ }
61
+ }
62
+
63
+ public filter(iteratee: Iteratee<T, boolean>): SmartIterator<T, R, N>
33
64
  {
34
65
  let index = 0;
35
66
  const iterator = this._iterator;
@@ -40,19 +71,16 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
40
71
  while (true)
41
72
  {
42
73
  const result = iterator.next();
43
- if (result.done) { return result.value; }
44
74
 
45
- if (callback(result.value, index))
46
- {
47
- yield result.value;
48
- }
75
+ if (result.done) { return result.value; }
76
+ if (iteratee(result.value, index)) { yield result.value; }
49
77
 
50
78
  index += 1;
51
79
  }
52
80
  }
53
81
  });
54
82
  }
55
- public map<V>(callback: (value: T, index: number) => V): SmartIterator<V, R>
83
+ public map<V>(iteratee: Iteratee<T, V>): SmartIterator<V, R>
56
84
  {
57
85
  let index = 0;
58
86
  const iterator = this._iterator;
@@ -65,14 +93,14 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
65
93
  const result = iterator.next();
66
94
  if (result.done) { return result.value; }
67
95
 
68
- yield callback(result.value, index);
96
+ yield iteratee(result.value, index);
69
97
 
70
98
  index += 1;
71
99
  }
72
100
  }
73
101
  });
74
102
  }
75
- public reduce<U>(callback: (accumulator: U, value: T, index: number) => U, initialValue: U): U
103
+ public reduce<A>(reducer: Reducer<T, A>, initialValue: A): A
76
104
  {
77
105
  let index = 0;
78
106
  let accumulator = initialValue;
@@ -83,13 +111,13 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
83
111
  const result = this._iterator.next();
84
112
  if (result.done) { return accumulator; }
85
113
 
86
- accumulator = callback(accumulator, result.value, index);
114
+ accumulator = reducer(accumulator, result.value, index);
87
115
 
88
116
  index += 1;
89
117
  }
90
118
  }
91
119
 
92
- public forEach(callback: (value: T, index: number) => void): void
120
+ public forEach(iteratee: Iteratee<T>): void
93
121
  {
94
122
  let index = 0;
95
123
 
@@ -99,7 +127,7 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
99
127
  const result = this._iterator.next();
100
128
  if (result.done) { return; }
101
129
 
102
- callback(result.value, index);
130
+ iteratee(result.value, index);
103
131
 
104
132
  index += 1;
105
133
  }
package/src/types.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  export type Constructor<T extends object, P extends unknown[] = []> = new (...args: P) => T;
2
+
2
3
  export type GeneratorFunction<T, R = void, N = undefined> = () => Generator<T, R, N>;
4
+ export type Iteratee<T, R = void> = (value: T, index: number) => R;
5
+ export type Reducer<T, A> = (accumulator: A, value: T, index: number) => A;
3
6
 
4
7
  export type MaybePromise<T> = T | PromiseLike<T>;
5
8