@byloth/core 1.2.0-rc.2 → 1.2.0

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
@@ -1,15 +1,15 @@
1
1
  var a = Object.defineProperty;
2
2
  var h = (r, e, t) => e in r ? a(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
3
  var o = (r, e, t) => (h(r, typeof e != "symbol" ? e + "" : e, t), t);
4
- class m {
4
+ class v {
5
5
  constructor(e, t) {
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,50 +33,50 @@ 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
 
51
51
  Caused by ${t}`);
52
52
  }
53
53
  }
54
- class v {
54
+ class m {
55
55
  constructor(e = !0) {
56
56
  o(this, "_preferPersistence");
57
57
  o(this, "_volatile");
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,68 @@ 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;
199
- return new u({
200
- *[Symbol.iterator]() {
201
- for (; ; ) {
202
- const s = n.next();
203
- if (s.done)
204
- return s.value;
205
- e(s.value, t) && (yield s.value), t += 1;
206
- }
220
+ const s = this._iterator;
221
+ return new u(function* () {
222
+ for (; ; ) {
223
+ const n = s.next();
224
+ if (n.done)
225
+ return n.value;
226
+ e(n.value, t) && (yield n.value), t += 1;
207
227
  }
208
228
  });
209
229
  }
210
230
  map(e) {
211
231
  let t = 0;
212
- const n = this._iterator;
213
- return new u({
214
- *[Symbol.iterator]() {
215
- for (; ; ) {
216
- const s = n.next();
217
- if (s.done)
218
- return s.value;
219
- yield e(s.value, t), t += 1;
220
- }
232
+ const s = this._iterator;
233
+ return new u(function* () {
234
+ for (; ; ) {
235
+ const n = s.next();
236
+ if (n.done)
237
+ return n.value;
238
+ yield e(n.value, t), t += 1;
221
239
  }
222
240
  });
223
241
  }
224
242
  reduce(e, t) {
225
- let n = 0, s = t;
243
+ let s = 0, n = t;
226
244
  for (; ; ) {
227
245
  const i = this._iterator.next();
228
246
  if (i.done)
229
- return s;
230
- s = e(s, i.value, n), n += 1;
247
+ return n;
248
+ n = e(n, i.value, s), s += 1;
231
249
  }
232
250
  }
233
251
  forEach(e) {
234
252
  let t = 0;
235
253
  for (; ; ) {
236
- const n = this._iterator.next();
237
- if (n.done)
254
+ const s = this._iterator.next();
255
+ if (s.done)
238
256
  return;
239
- e(n.value, t), t += 1;
257
+ e(s.value, t), t += 1;
240
258
  }
241
259
  }
242
260
  next(...e) {
@@ -260,7 +278,7 @@ class w {
260
278
  remove(e) {
261
279
  const t = this._subscribers.indexOf(e);
262
280
  if (t < 0)
263
- throw new c("Unable to remove the requested subscriber. It was not found.");
281
+ throw new l("Unable to remove the requested subscriber. It was not found.");
264
282
  this._subscribers.splice(t, 1);
265
283
  }
266
284
  call(...e) {
@@ -270,28 +288,28 @@ class w {
270
288
  async function g(r) {
271
289
  return new Promise((e, t) => setTimeout(e, r));
272
290
  }
273
- async function y() {
291
+ async function b() {
274
292
  return new Promise((r, e) => requestAnimationFrame(() => r()));
275
293
  }
276
294
  var f = /* @__PURE__ */ ((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 || {});
277
- function b(r, e, t = 864e5) {
295
+ function y(r, e, t = 864e5) {
278
296
  return Math.floor((e.getTime() - r.getTime()) / t);
279
297
  }
280
298
  function p(r, e, t = 864e5) {
281
299
  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;
300
+ const s = e.getTime();
301
+ let n = r.getTime();
302
+ for (; n < s; )
303
+ yield new Date(n), n += t;
286
304
  });
287
305
  }
288
306
  function x(r, e = 864e5) {
289
307
  return new Date(Math.floor(r.getTime() / e) * e);
290
308
  }
291
309
  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);
310
+ return new Promise((t, s) => {
311
+ const n = document.createElement("script");
312
+ n.async = !0, n.defer = !0, n.src = r, n.type = e, n.onload = () => t(), n.onerror = () => s(), document.body.appendChild(n);
295
313
  });
296
314
  }
297
315
  function I(r) {
@@ -305,15 +323,15 @@ function I(r) {
305
323
  function M(r, e, t = 1) {
306
324
  return new u(function* () {
307
325
  e === void 0 && (e = r, r = 0), r > e && (t = t ?? -1);
308
- for (let n = r; n < e; n += t)
309
- yield n;
326
+ for (let s = r; s < e; s += t)
327
+ yield s;
310
328
  });
311
329
  }
312
330
  function k(r) {
313
331
  const e = [...r];
314
332
  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]];
333
+ const s = Math.floor(Math.random() * (t + 1));
334
+ [e[t], e[s]] = [e[s], e[t]];
317
335
  }
318
336
  return e;
319
337
  }
@@ -324,52 +342,52 @@ function j(r) {
324
342
  e.has(t) || (e.add(t), yield t);
325
343
  });
326
344
  }
327
- function _(r, e) {
345
+ function d(r, e) {
328
346
  return new u(function* () {
329
- const t = r[Symbol.iterator](), n = e[Symbol.iterator]();
347
+ const t = r[Symbol.iterator](), s = e[Symbol.iterator]();
330
348
  for (; ; ) {
331
- const s = t.next(), i = n.next();
332
- if (s.done || i.done)
349
+ const n = t.next(), i = s.next();
350
+ if (n.done || i.done)
333
351
  break;
334
- yield [s.value, i.value];
352
+ yield [n.value, i.value];
335
353
  }
336
354
  });
337
355
  }
338
356
  function P(r, e) {
339
357
  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;
358
+ let n = 0, i = 0;
359
+ for (const c of r)
360
+ n += c, i += 1;
361
+ return n / i;
362
+ }
363
+ let t = 0, s = 0;
364
+ for (const [n, i] of d(r, e))
365
+ t += n * i, s += i;
366
+ return t / s;
349
367
  }
350
368
  function T(r) {
351
369
  let e = 0;
352
370
  for (let t = 0; t < r.length; t++) {
353
- const n = r.charCodeAt(t);
354
- e = (e << 5) - e + n, e |= 0;
371
+ const s = r.charCodeAt(t);
372
+ e = (e << 5) - e + s, e |= 0;
355
373
  }
356
374
  return e;
357
375
  }
358
376
  function A(r = 1, e, t) {
359
377
  if (e === void 0 && (e = r, r = 0), r === e)
360
378
  return r;
361
- let n;
379
+ let s;
362
380
  if (t === !0)
363
- n = (s) => s;
381
+ s = (n) => n;
364
382
  else if (t === void 0)
365
- Math.abs(e - r) <= 1 ? n = (s) => s : n = Math.floor;
383
+ Math.abs(e - r) <= 1 ? s = (n) => n : s = Math.floor;
366
384
  else if (t === !1)
367
- n = Math.floor;
385
+ s = Math.floor;
368
386
  else {
369
- const s = 10 ** t;
370
- n = (i) => Math.floor(i * s) / s;
387
+ const n = 10 ** t;
388
+ s = (i) => Math.floor(i * n) / n;
371
389
  }
372
- return n(Math.random() * (e - r) + r);
390
+ return s(Math.random() * (e - r) + r);
373
391
  }
374
392
  function $(r) {
375
393
  let e = 0;
@@ -380,30 +398,30 @@ function $(r) {
380
398
  function C(r) {
381
399
  return `${r.charAt(0).toUpperCase()}${r.slice(1)}`;
382
400
  }
383
- const E = "1.2.0-rc.2";
401
+ const E = "1.2.0";
384
402
  export {
385
403
  f as DateUnit,
386
- m as DeferredPromise,
387
- c as Exception,
388
- v as JsonStorage,
404
+ v as DeferredPromise,
405
+ l as Exception,
406
+ m as JsonStorage,
389
407
  u as SmartIterator,
390
408
  w as Subscribers,
391
409
  E as VERSION,
392
410
  P as average,
393
411
  C as capitalize,
394
412
  I as count,
395
- b as dateDifference,
413
+ y as dateDifference,
396
414
  p as dateRange,
397
415
  x as dateRound,
398
416
  g as delay,
399
417
  T as hash,
400
418
  S as loadScript,
401
- y as nextAnimationFrame,
419
+ b as nextAnimationFrame,
402
420
  A as random,
403
421
  M as range,
404
422
  k as shuffle,
405
423
  $ as sum,
406
424
  j as unique,
407
- _ as zip
425
+ d as zip
408
426
  };
409
427
  //# 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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qD,IAAc;AAClB,WAASC,IAAI,GAAGA,IAAItD,EAAM,QAAQsD,KAClC;AACU,UAAAC,IAAOvD,EAAM,WAAWsD,CAAC;AACf,IAAAD,KAAAA,KAAe,KAAKA,IAAeE,GACpCF,KAAA;AAAA,EACnB;AAEO,SAAAA;AACX;AAOO,SAASG,EAAOC,IAAc,GAAGC,GAAcC,GACtD;AAOI,MANID,MAAQ,WAEFA,IAAAD,GACAA,IAAA,IAGNA,MAAQC;AAED,WAAAD;AAGP,MAAAG;AAEJ,MAAID,MAAa;AAEb,IAAAC,IAAU,CAAC5D,MAAUA;AAAA,WAEhB2D,MAAa;AAElB,IAAI,KAAK,IAAID,IAAMD,CAAG,KAAK,IAEvBG,IAAU,CAAC5D,MAAUA,IAIrB4D,IAAU,KAAK;AAAA,WAGdD,MAAa;AAElB,IAAAC,IAAU,KAAK;AAAA,OAGnB;AACI,UAAMC,IAAS,MAAMF;AAErB,IAAAC,IAAU,CAAC5D,MAAU,KAAK,MAAMA,IAAQ6D,CAAM,IAAIA;AAAA,EACtD;AAEA,SAAOD,EAAQ,KAAK,OAAA,KAAYF,IAAMD,KAAOA,CAAG;AACpD;AAEO,SAASK,EAAsBvD,GACtC;AACI,MAAI2C,IAAO;AACX,aAAWlD,KAASO;AAAkB,IAAA2C,KAAAlD;AAE/B,SAAAkD;AACX;ACpGO,SAASa,EAAW/D,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,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(argument: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)\n {\n if (argument instanceof Function)\n {\n this._iterator = argument();\n }\n else if (Symbol.iterator in argument)\n {\n this._iterator = argument[Symbol.iterator]() as Iterator<T, R, N>;\n }\n else\n {\n this._iterator = argument;\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(predicate: 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 (!(predicate(result.value, index))) { return false; }\n\n index += 1;\n }\n }\n public some(predicate: 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 (predicate(result.value, index)) { return true; }\n\n index += 1;\n }\n }\n\n public filter(predicate: 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>(function* ()\n {\n while (true)\n {\n const result = iterator.next();\n\n if (result.done) { return result.value; }\n if (predicate(result.value, index)) { yield result.value; }\n\n index += 1;\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>(function* ()\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 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\";\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","argument","value","predicate","index","result","iterator","iteratee","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","iterable","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,EA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pD;AAEO,SAASK,EAAsBxD,GACtC;AACI,MAAI4C,IAAO;AACX,aAAWrD,KAASS;AAAkB,IAAA4C,KAAArD;AAE/B,SAAAqD;AACX;ACpGO,SAASa,EAAWlE,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMmE,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(function*(){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(function*(){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 w(){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 g(r,e,t=864e5){return Math.floor((e.getTime()-r.getTime())/t)}function b(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 y(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";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=g,s.dateRange=b,s.dateRound=y,s.delay=v,s.hash=P,s.loadScript=S,s.nextAnimationFrame=w,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,CACI,OAAO,KAAK,QAChB,CACA,IAAW,QACX,CACI,OAAO,KAAK,OAChB,CAEO,KACHJ,EACAC,EACJ,CACI,OAAO,KAAK,SAAS,KAAKD,EAAaC,CAAU,CACrD,CACO,MAAaA,EACpB,CACW,OAAA,KAAK,SAAS,MAAMA,CAAU,CACzC,CACO,QAAQM,EACf,CACW,OAAA,KAAK,SAAS,QAAQA,CAAS,CAC1C,CAEO,MAAMC,EACb,CACI,OAAAA,EAAQ,KAAK,KAAK,QAAS,KAAK,MAAM,EAE/B,IACX,CAEA,IAAY,OAAO,WAAW,GAC9B,CACW,MAAA,iBACX,CACJ,CC5DA,MAAqBC,UAAkB,KACvC,CACI,OAAc,YAAYC,EAC1B,CACI,GAAIA,aAAiBD,EAEV,OAAAC,EAEX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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(argument: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)\n {\n if (argument instanceof Function)\n {\n this._iterator = argument();\n }\n else if (Symbol.iterator in argument)\n {\n this._iterator = argument[Symbol.iterator]() as Iterator<T, R, N>;\n }\n else\n {\n this._iterator = argument;\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(predicate: 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 (!(predicate(result.value, index))) { return false; }\n\n index += 1;\n }\n }\n public some(predicate: 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 (predicate(result.value, index)) { return true; }\n\n index += 1;\n }\n }\n\n public filter(predicate: 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>(function* ()\n {\n while (true)\n {\n const result = iterator.next();\n\n if (result.done) { return result.value; }\n if (predicate(result.value, index)) { yield result.value; }\n\n index += 1;\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>(function* ()\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 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\";\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","argument","value","predicate","index","result","iterator","iteratee","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","iterable","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,CACI,OAAO,KAAK,QAChB,CACA,IAAW,QACX,CACI,OAAO,KAAK,OAChB,CAEO,KACHJ,EACAC,EACJ,CACI,OAAO,KAAK,SAAS,KAAKD,EAAaC,CAAU,CACrD,CACO,MAAaA,EACpB,CACW,OAAA,KAAK,SAAS,MAAMA,CAAU,CACzC,CACO,QAAQM,EACf,CACW,OAAA,KAAK,SAAS,QAAQA,CAAS,CAC1C,CAEO,MAAMC,EACb,CACI,OAAAA,EAAQ,KAAK,KAAK,QAAS,KAAK,MAAM,EAE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B,CAEO,SAASsB,EAAKvD,EACrB,CACI,IAAIwD,EAAc,EAClB,QAASC,EAAI,EAAGA,EAAIzD,EAAM,OAAQyD,IAClC,CACU,MAAAC,EAAO1D,EAAM,WAAWyD,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,EAAW/D,GAAUA,UAEhB8D,IAAa,OAEd,KAAK,IAAID,EAAMD,CAAG,GAAK,EAEvBG,EAAW/D,GAAUA,EAIrB+D,EAAU,KAAK,cAGdD,IAAa,GAElBC,EAAU,KAAK,UAGnB,CACI,MAAMC,EAAS,IAAMF,EAErBC,EAAW/D,GAAU,KAAK,MAAMA,EAAQgE,CAAM,EAAIA,CACtD,CAEA,OAAOD,EAAQ,KAAK,OAAA,GAAYF,EAAMD,GAAOA,CAAG,CACpD,CAEO,SAASK,EAAsBxD,EACtC,CACI,IAAI4C,EAAO,EACX,UAAWrD,KAASS,EAAkB4C,GAAArD,EAE/B,OAAAqD,CACX,CCpGO,SAASa,EAAWlE,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMmE,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",
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.17.0",
61
+ "@typescript-eslint/parser": "^6.17.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";
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
  {
@@ -10,69 +10,93 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
10
10
  public constructor(iterable: Iterable<T>);
11
11
  public constructor(iterator: Iterator<T, R, N>);
12
12
  public constructor(generatorFn: GeneratorFunction<T, R, N>);
13
- public constructor(iterable: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)
13
+ public constructor(argument: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)
14
14
  {
15
- if (iterable instanceof Function)
15
+ if (argument instanceof Function)
16
16
  {
17
- this._iterator = iterable();
17
+ this._iterator = argument();
18
18
  }
19
- else if (Symbol.iterator in iterable)
19
+ else if (Symbol.iterator in argument)
20
20
  {
21
- this._iterator = iterable[Symbol.iterator]() as Iterator<T, R, N>;
21
+ this._iterator = argument[Symbol.iterator]() as Iterator<T, R, N>;
22
22
  }
23
23
  else
24
24
  {
25
- this._iterator = iterable;
25
+ this._iterator = argument;
26
26
  }
27
27
 
28
28
  if (this._iterator.return) { this.return = (value?: R) => this._iterator.return!(value); }
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(predicate: 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 (!(predicate(result.value, index))) { return false; }
43
+
44
+ index += 1;
45
+ }
46
+ }
47
+ public some(predicate: 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 (predicate(result.value, index)) { return true; }
58
+
59
+ index += 1;
60
+ }
61
+ }
62
+
63
+ public filter(predicate: Iteratee<T, boolean>): SmartIterator<T, R, N>
33
64
  {
34
65
  let index = 0;
35
66
  const iterator = this._iterator;
36
67
 
37
- return new SmartIterator<T, R, N>({
38
- *[Symbol.iterator]()
68
+ return new SmartIterator<T, R, N>(function* ()
69
+ {
70
+ while (true)
39
71
  {
40
- while (true)
41
- {
42
- const result = iterator.next();
43
- if (result.done) { return result.value; }
44
-
45
- if (callback(result.value, index))
46
- {
47
- yield result.value;
48
- }
49
-
50
- index += 1;
51
- }
72
+ const result = iterator.next();
73
+
74
+ if (result.done) { return result.value; }
75
+ if (predicate(result.value, index)) { yield result.value; }
76
+
77
+ index += 1;
52
78
  }
53
79
  });
54
80
  }
55
- public map<V>(callback: (value: T, index: number) => V): SmartIterator<V, R>
81
+ public map<V>(iteratee: Iteratee<T, V>): SmartIterator<V, R>
56
82
  {
57
83
  let index = 0;
58
84
  const iterator = this._iterator;
59
85
 
60
- return new SmartIterator<V, R>({
61
- *[Symbol.iterator]()
86
+ return new SmartIterator<V, R>(function* ()
87
+ {
88
+ while (true)
62
89
  {
63
- while (true)
64
- {
65
- const result = iterator.next();
66
- if (result.done) { return result.value; }
90
+ const result = iterator.next();
91
+ if (result.done) { return result.value; }
67
92
 
68
- yield callback(result.value, index);
93
+ yield iteratee(result.value, index);
69
94
 
70
- index += 1;
71
- }
95
+ index += 1;
72
96
  }
73
97
  });
74
98
  }
75
- public reduce<U>(callback: (accumulator: U, value: T, index: number) => U, initialValue: U): U
99
+ public reduce<A>(reducer: Reducer<T, A>, initialValue: A): A
76
100
  {
77
101
  let index = 0;
78
102
  let accumulator = initialValue;
@@ -83,13 +107,13 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
83
107
  const result = this._iterator.next();
84
108
  if (result.done) { return accumulator; }
85
109
 
86
- accumulator = callback(accumulator, result.value, index);
110
+ accumulator = reducer(accumulator, result.value, index);
87
111
 
88
112
  index += 1;
89
113
  }
90
114
  }
91
115
 
92
- public forEach(callback: (value: T, index: number) => void): void
116
+ public forEach(iteratee: Iteratee<T>): void
93
117
  {
94
118
  let index = 0;
95
119
 
@@ -99,7 +123,7 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
99
123
  const result = this._iterator.next();
100
124
  if (result.done) { return; }
101
125
 
102
- callback(result.value, index);
126
+ iteratee(result.value, index);
103
127
 
104
128
  index += 1;
105
129
  }
package/src/types.ts CHANGED
@@ -1,5 +1,9 @@
1
- export type Constructor<T extends object, P extends unknown[] = []> = new (...args: P) => T;
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export type Constructor<T extends object, P extends unknown[] = any[]> = new (...args: P) => T;
3
+
2
4
  export type GeneratorFunction<T, R = void, N = undefined> = () => Generator<T, R, N>;
5
+ export type Iteratee<T, R = void> = (value: T, index: number) => R;
6
+ export type Reducer<T, A> = (accumulator: A, value: T, index: number) => A;
3
7
 
4
8
  export type MaybePromise<T> = T | PromiseLike<T>;
5
9