@byloth/core 1.1.3 → 1.1.4

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,22 +1,22 @@
1
1
  var h = Object.defineProperty;
2
- var a = (s, e, t) => e in s ? h(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var n = (s, e, t) => (a(s, typeof e != "symbol" ? e + "" : e, t), t);
2
+ var a = (r, e, t) => e in r ? h(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var n = (r, e, t) => (a(r, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  class d {
5
5
  constructor(e, t) {
6
6
  n(this, "_resolve");
7
7
  n(this, "_reject");
8
8
  n(this, "_promise");
9
- let i, r;
9
+ let i, s;
10
10
  const c = new Promise((u, l) => {
11
- i = u, r = l;
11
+ i = u, s = l;
12
12
  });
13
- this._promise = c.then(e, t), this._resolve = i, this._reject = r;
13
+ this._promise = c.then(e, t), this._resolve = i, this._reject = s;
14
14
  }
15
- resolve(e) {
16
- this._resolve(e);
15
+ get resolve() {
16
+ return this._resolve;
17
17
  }
18
- reject(e) {
19
- this._reject(e);
18
+ get reject() {
19
+ return this._reject;
20
20
  }
21
21
  then(e, t) {
22
22
  return this._promise.then(e, t);
@@ -54,22 +54,22 @@ class m {
54
54
  this._preferPersistence = e, this._volatile = window.sessionStorage, this._persistent = window.localStorage;
55
55
  }
56
56
  _get(e, t, i) {
57
- const r = e.getItem(t);
58
- if (r)
57
+ const s = e.getItem(t);
58
+ if (s)
59
59
  try {
60
- return JSON.parse(r);
60
+ return JSON.parse(s);
61
61
  } catch {
62
62
  e.removeItem(t);
63
63
  }
64
64
  return i;
65
65
  }
66
66
  _set(e, t, i) {
67
- const r = JSON.stringify(i);
68
- r ? e.setItem(t, r) : e.removeItem(t);
67
+ const s = JSON.stringify(i);
68
+ s ? e.setItem(t, s) : e.removeItem(t);
69
69
  }
70
70
  get(e, t, i = this._preferPersistence) {
71
- const r = i ? this._persistent : this._volatile;
72
- return this._get(r, e, t);
71
+ const s = i ? this._persistent : this._volatile;
72
+ return this._get(s, e, t);
73
73
  }
74
74
  recall(e, t) {
75
75
  return this._get(this._volatile, e, t);
@@ -131,8 +131,8 @@ class m {
131
131
  * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.
132
132
  */
133
133
  set(e, t, i = this._preferPersistence) {
134
- const r = i ? this._persistent : this._volatile;
135
- this._set(r, e, t);
134
+ const s = i ? this._persistent : this._volatile;
135
+ this._set(s, e, t);
136
136
  }
137
137
  /**
138
138
  * Sets the value with the specified name in the volatile `sessionStorage`.
@@ -179,7 +179,7 @@ class m {
179
179
  this._volatile.removeItem(e), this._persistent.removeItem(e);
180
180
  }
181
181
  }
182
- class v {
182
+ class g {
183
183
  constructor() {
184
184
  n(this, "_subscribers");
185
185
  this._subscribers = [];
@@ -197,94 +197,94 @@ class v {
197
197
  return this._subscribers.slice().map((t) => t(...e));
198
198
  }
199
199
  }
200
- async function g(s) {
201
- return new Promise((e, t) => setTimeout(e, s));
200
+ async function v(r) {
201
+ return new Promise((e, t) => setTimeout(e, r));
202
202
  }
203
203
  async function p() {
204
- return new Promise((s, e) => requestAnimationFrame(() => s()));
204
+ return new Promise((r, e) => requestAnimationFrame(() => r()));
205
205
  }
206
- var f = /* @__PURE__ */ ((s) => (s[s.Second = 1e3] = "Second", s[s.Minute = 6e4] = "Minute", s[s.Hour = 36e5] = "Hour", s[s.Day = 864e5] = "Day", s[s.Week = 6048e5] = "Week", s[s.Month = 2592e6] = "Month", s[s.Year = 31536e6] = "Year", s))(f || {});
207
- function b(s, e, t = 864e5) {
208
- return Math.floor((e.getTime() - s.getTime()) / t);
206
+ 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 || {});
207
+ function b(r, e, t = 864e5) {
208
+ return Math.floor((e.getTime() - r.getTime()) / t);
209
209
  }
210
- function* w(s, e, t = 864e5) {
210
+ function* w(r, e, t = 864e5) {
211
211
  const i = e.getTime();
212
- let r = s.getTime();
213
- for (; r < i; )
214
- yield new Date(r), r += t;
212
+ let s = r.getTime();
213
+ for (; s < i; )
214
+ yield new Date(s), s += t;
215
215
  }
216
- function y(s, e = 864e5) {
217
- return new Date(Math.floor(s.getTime() / e) * e);
216
+ function y(r, e = 864e5) {
217
+ return new Date(Math.floor(r.getTime() / e) * e);
218
218
  }
219
- async function I(s, e = "text/javascript") {
219
+ async function I(r, e = "text/javascript") {
220
220
  return new Promise((t, i) => {
221
- const r = document.createElement("script");
222
- r.async = !0, r.defer = !0, r.src = s, r.type = e, r.onload = () => t(), r.onerror = () => i(), document.body.appendChild(r);
221
+ const s = document.createElement("script");
222
+ s.async = !0, s.defer = !0, s.src = r, s.type = e, s.onload = () => t(), s.onerror = () => i(), document.body.appendChild(s);
223
223
  });
224
224
  }
225
- function M(s) {
226
- if (Array.isArray(s))
227
- return s.length;
225
+ function M(r) {
226
+ if (Array.isArray(r))
227
+ return r.length;
228
228
  let e = 0;
229
- for (const t of s)
229
+ for (const t of r)
230
230
  e += 1;
231
231
  return e;
232
232
  }
233
- function* S(s, e, t = 1) {
234
- e === void 0 && (e = s, s = 0), s > e && (t = t ?? -1);
235
- for (let i = s; i < e; i += t)
233
+ function* S(r, e, t = 1) {
234
+ e === void 0 && (e = r, r = 0), r > e && (t = t ?? -1);
235
+ for (let i = r; i < e; i += t)
236
236
  yield i;
237
237
  }
238
- function k(s) {
238
+ function k(r) {
239
239
  let e = 0;
240
- for (const t of s)
240
+ for (const t of r)
241
241
  e += t;
242
242
  return e;
243
243
  }
244
- function P(s) {
245
- return [...new Set(s)];
244
+ function P(r) {
245
+ return [...new Set(r)];
246
246
  }
247
- function j(s) {
247
+ function j(r) {
248
248
  let e = 0;
249
- for (let t = 0; t < s.length; t++) {
250
- const i = s.charCodeAt(t);
249
+ for (let t = 0; t < r.length; t++) {
250
+ const i = r.charCodeAt(t);
251
251
  e = (e << 5) - e + i, e |= 0;
252
252
  }
253
253
  return e;
254
254
  }
255
- function T(s = 1, e, t) {
256
- if (e === void 0 && (e = s, s = 0), s === e)
257
- return s;
255
+ function T(r = 1, e, t) {
256
+ if (e === void 0 && (e = r, r = 0), r === e)
257
+ return r;
258
258
  let i;
259
259
  if (t === !0)
260
- i = (r) => r;
260
+ i = (s) => s;
261
261
  else if (t === void 0)
262
- Math.abs(e - s) <= 1 ? i = (r) => r : i = Math.floor;
262
+ Math.abs(e - r) <= 1 ? i = (s) => s : i = Math.floor;
263
263
  else if (t === !1)
264
264
  i = Math.floor;
265
265
  else {
266
- const r = 10 ** t;
267
- i = (c) => Math.floor(c * r) / r;
266
+ const s = 10 ** t;
267
+ i = (c) => Math.floor(c * s) / s;
268
268
  }
269
- return i(Math.random() * (e - s) + s);
269
+ return i(Math.random() * (e - r) + r);
270
270
  }
271
- function x(s) {
272
- return `${s.charAt(0).toUpperCase()}${s.slice(1)}`;
271
+ function x(r) {
272
+ return `${r.charAt(0).toUpperCase()}${r.slice(1)}`;
273
273
  }
274
- const A = "1.1.3";
274
+ const A = "1.1.4";
275
275
  export {
276
276
  f as DateUnit,
277
277
  d as DeferredPromise,
278
278
  o as Exception,
279
279
  m as JsonStorage,
280
- v as Subscribers,
280
+ g as Subscribers,
281
281
  A as VERSION,
282
282
  x as capitalize,
283
283
  M as count,
284
284
  b as dateDifference,
285
285
  w as dateRange,
286
286
  y as dateRound,
287
- g as delay,
287
+ v as delay,
288
288
  j as hash,
289
289
  I as loadScript,
290
290
  p as nextAnimationFrame,
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/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, MaybePromise } 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>, onRejected?: RejectedHandler<E, R>)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n const _promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n });\n\n this._promise = _promise.then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public resolve(value: MaybePromise<T>)\n {\n this._resolve(value);\n }\n public reject(reason: E)\n {\n this._reject(reason);\n }\n\n public then<N = F | R, H = R>(onFulfilled?: FulfilledHandler<F | R, N>, onRejected?: RejectedHandler<R, H>)\n : Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H>): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: () => void): Promise<F | R>\n {\n return this._promise.finally(onFinally);\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 if (import.meta.env.DEV)\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\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 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","export 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)\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function* dateRange(start: Date, end: Date, offset = DateUnit.Day)\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\nexport function dateRound(date: Date, unit = DateUnit.Day)\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","export 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): Generator<number, void>;\nexport function range(start: number, end: number): Generator<number, void>;\nexport function range(start: number, end: number, step: number): Generator<number, void>;\nexport function* range(start: number, end?: number, step = 1): Generator<number, void>\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\nexport function sum<T extends number>(elements: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of elements) { _sum += value; }\n\n return _sum;\n}\n\nexport function unique<T>(elements: Iterable<T>): T[]\n{\n return [...new Set(elements)];\n}\n","export function hash(value: string): number\n{\n let hash = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash |= 0;\n }\n\n return hash;\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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.3\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\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 sum,\n unique\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","_promise","resolve","reject","value","reason","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","sum","_sum","unique","hash","i","char","random","min","max","decimals","rounder","digits","capitalize","VERSION"],"mappings":";;;AAEA,MAAqBA,EACrB;AAAA,EAMW,YAAYC,GAAsCC,GACzD;AANU,IAAAC,EAAA;AACA,IAAAA,EAAA;AAEA,IAAAA,EAAA;AAIF,QAAAC,GACAC;AAEJ,UAAMC,IAAW,IAAI,QAAW,CAACC,GAASC,MAC1C;AACe,MAAAJ,IAAAG,GACDF,IAAAG;AAAA,IAAA,CACb;AAED,SAAK,WAAWF,EAAS,KAAKL,GAAaC,CAAU,GAErD,KAAK,WAAWE,GAChB,KAAK,UAAUC;AAAA,EACnB;AAAA,EAEO,QAAQI,GACf;AACI,SAAK,SAASA,CAAK;AAAA,EACvB;AAAA,EACO,OAAOC,GACd;AACI,SAAK,QAAQA,CAAM;AAAA,EACvB;AAAA,EAEO,KAAuBT,GAA0CC,GAExE;AACI,WAAO,KAAK,SAAS,KAAKD,GAAaC,CAAU;AAAA,EACrD;AAAA,EACO,M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AAC;AAC5D;ACHO,MAAM2D,IAAU;"}
1
+ {"version":3,"file":"core.js","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.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>, onRejected?: RejectedHandler<E, R>)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n const _promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n });\n\n this._promise = _promise.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>(onFulfilled?: FulfilledHandler<F | R, N>, onRejected?: RejectedHandler<R, H>)\n : Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H>): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: () => void): Promise<F | R>\n {\n return this._promise.finally(onFinally);\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 if (import.meta.env.DEV)\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\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 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","export 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)\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function* dateRange(start: Date, end: Date, offset = DateUnit.Day)\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\nexport function dateRound(date: Date, unit = DateUnit.Day)\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","export 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): Generator<number, void>;\nexport function range(start: number, end: number): Generator<number, void>;\nexport function range(start: number, end: number, step: number): Generator<number, void>;\nexport function* range(start: number, end?: number, step = 1): Generator<number, void>\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\nexport function sum<T extends number>(elements: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of elements) { _sum += value; }\n\n return _sum;\n}\n\nexport function unique<T>(elements: Iterable<T>): T[]\n{\n return [...new Set(elements)];\n}\n","export function hash(value: string): number\n{\n let hash = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash |= 0;\n }\n\n return hash;\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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.4\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\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 sum,\n unique\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","_promise","resolve","reject","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","sum","_sum","value","unique","hash","i","char","random","min","max","decimals","rounder","digits","capitalize","VERSION"],"mappings":";;;AAEA,MAAqBA,EACrB;AAAA,EAMW,YAAYC,GAAsCC,GACzD;AANU,IAAAC,EAAA;AACA,IAAAA,EAAA;AAEA,IAAAA,EAAA;AAIF,QAAAC,GACAC;AAEJ,UAAMC,IAAW,IAAI,QAAW,CAACC,GAASC,MAC1C;AACe,MAAAJ,IAAAG,GACDF,IAAAG;AAAA,IAAA,CACb;AAED,SAAK,WAAWF,EAAS,KAAKL,GAAaC,CAAU,GAErD,KAAK,WAAWE,GAChB,KAAK,UAAUC;AAAA,EACnB;AAAA,EAEA,IAAW,UACX;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EACA,IAAW,SACX;AACI,WAAO,KAA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SAASK,EAAWX,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMY,IAAU;"}
package/dist/core.umd.cjs CHANGED
@@ -1,6 +1,6 @@
1
- (function(i,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(i=typeof globalThis<"u"?globalThis:i||self,o(i.Core={}))})(this,function(i){"use strict";var A=Object.defineProperty;var C=(i,o,c)=>o in i?A(i,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):i[o]=c;var u=(i,o,c)=>(C(i,typeof o!="symbol"?o+"":o,c),c);class o{constructor(e,t){u(this,"_resolve");u(this,"_reject");u(this,"_promise");let n,r;const l=new Promise((j,k)=>{n=j,r=k});this._promise=l.then(e,t),this._resolve=n,this._reject=r}resolve(e){this._resolve(e)}reject(e){this._reject(e)}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}}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,n="Exception"){super(e),this.cause=t,this.name=n,t&&(t instanceof Error?this.stack+=`
1
+ (function(i,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(i=typeof globalThis<"u"?globalThis:i||self,o(i.Core={}))})(this,function(i){"use strict";var A=Object.defineProperty;var C=(i,o,c)=>o in i?A(i,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):i[o]=c;var u=(i,o,c)=>(C(i,typeof o!="symbol"?o+"":o,c),c);class o{constructor(e,t){u(this,"_resolve");u(this,"_reject");u(this,"_promise");let n,s;const l=new Promise((j,k)=>{n=j,s=k});this._promise=l.then(e,t),this._resolve=n,this._reject=s}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)}}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,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 h{constructor(e=!0){u(this,"_preferPersistence");u(this,"_volatile");u(this,"_persistent");this._preferPersistence=e,this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(e,t,n){const r=e.getItem(t);if(r)try{return JSON.parse(r)}catch{e.removeItem(t)}return n}_set(e,t,n){const r=JSON.stringify(n);r?e.setItem(t,r):e.removeItem(t)}get(e,t,n=this._preferPersistence){const r=n?this._persistent:this._volatile;return this._get(r,e,t)}recall(e,t){return this._get(this._volatile,e,t)}retrieve(e,t){return this.recall(e)??this.read(e,t)}read(e,t){return this._get(this._persistent,e,t)}has(e,t){return(t?this._persistent:this._volatile).getItem(e)!==null}knows(e){return this._volatile.getItem(e)!==null}find(e){return this.knows(e)??this.exists(e)}exists(e){return this._persistent.getItem(e)!==null}set(e,t,n=this._preferPersistence){const r=n?this._persistent:this._volatile;this._set(r,e,t)}remember(e,t){this._set(this._volatile,e,t)}write(e,t){this._set(this._persistent,e,t)}forget(e){this._volatile.removeItem(e)}erase(e){this._persistent.removeItem(e)}clear(e){this._volatile.removeItem(e),this._persistent.removeItem(e)}}class f{constructor(){u(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 d(s){return new Promise((e,t)=>setTimeout(e,s))}async function _(){return new Promise((s,e)=>requestAnimationFrame(()=>s()))}var a=(s=>(s[s.Second=1e3]="Second",s[s.Minute=6e4]="Minute",s[s.Hour=36e5]="Hour",s[s.Day=864e5]="Day",s[s.Week=6048e5]="Week",s[s.Month=2592e6]="Month",s[s.Year=31536e6]="Year",s))(a||{});function m(s,e,t=864e5){return Math.floor((e.getTime()-s.getTime())/t)}function*g(s,e,t=864e5){const n=e.getTime();let r=s.getTime();for(;r<n;)yield new Date(r),r+=t}function v(s,e=864e5){return new Date(Math.floor(s.getTime()/e)*e)}async function b(s,e="text/javascript"){return new Promise((t,n)=>{const r=document.createElement("script");r.async=!0,r.defer=!0,r.src=s,r.type=e,r.onload=()=>t(),r.onerror=()=>n(),document.body.appendChild(r)})}function w(s){if(Array.isArray(s))return s.length;let e=0;for(const t of s)e+=1;return e}function*y(s,e,t=1){e===void 0&&(e=s,s=0),s>e&&(t=t??-1);for(let n=s;n<e;n+=t)yield n}function S(s){let e=0;for(const t of s)e+=t;return e}function p(s){return[...new Set(s)]}function I(s){let e=0;for(let t=0;t<s.length;t++){const n=s.charCodeAt(t);e=(e<<5)-e+n,e|=0}return e}function M(s=1,e,t){if(e===void 0&&(e=s,s=0),s===e)return s;let n;if(t===!0)n=r=>r;else if(t===void 0)Math.abs(e-s)<=1?n=r=>r:n=Math.floor;else if(t===!1)n=Math.floor;else{const r=10**t;n=l=>Math.floor(l*r)/r}return n(Math.random()*(e-s)+s)}function P(s){return`${s.charAt(0).toUpperCase()}${s.slice(1)}`}const T="1.1.3";i.DateUnit=a,i.DeferredPromise=o,i.Exception=c,i.JsonStorage=h,i.Subscribers=f,i.VERSION=T,i.capitalize=P,i.count=w,i.dateDifference=m,i.dateRange=g,i.dateRound=v,i.delay=d,i.hash=I,i.loadScript=b,i.nextAnimationFrame=_,i.random=M,i.range=y,i.sum=S,i.unique=p,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
5
+ Caused by ${t}`)}}class h{constructor(e=!0){u(this,"_preferPersistence");u(this,"_volatile");u(this,"_persistent");this._preferPersistence=e,this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(e,t,n){const s=e.getItem(t);if(s)try{return JSON.parse(s)}catch{e.removeItem(t)}return n}_set(e,t,n){const s=JSON.stringify(n);s?e.setItem(t,s):e.removeItem(t)}get(e,t,n=this._preferPersistence){const s=n?this._persistent:this._volatile;return this._get(s,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 s=n?this._persistent:this._volatile;this._set(s,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 f{constructor(){u(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 d(r){return new Promise((e,t)=>setTimeout(e,r))}async function _(){return new Promise((r,e)=>requestAnimationFrame(()=>r()))}var a=(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))(a||{});function m(r,e,t=864e5){return Math.floor((e.getTime()-r.getTime())/t)}function*g(r,e,t=864e5){const n=e.getTime();let s=r.getTime();for(;s<n;)yield new Date(s),s+=t}function v(r,e=864e5){return new Date(Math.floor(r.getTime()/e)*e)}async function b(r,e="text/javascript"){return new Promise((t,n)=>{const s=document.createElement("script");s.async=!0,s.defer=!0,s.src=r,s.type=e,s.onload=()=>t(),s.onerror=()=>n(),document.body.appendChild(s)})}function w(r){if(Array.isArray(r))return r.length;let e=0;for(const t of r)e+=1;return e}function*y(r,e,t=1){e===void 0&&(e=r,r=0),r>e&&(t=t??-1);for(let n=r;n<e;n+=t)yield n}function S(r){let e=0;for(const t of r)e+=t;return e}function p(r){return[...new Set(r)]}function I(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 M(r=1,e,t){if(e===void 0&&(e=r,r=0),r===e)return r;let n;if(t===!0)n=s=>s;else if(t===void 0)Math.abs(e-r)<=1?n=s=>s:n=Math.floor;else if(t===!1)n=Math.floor;else{const s=10**t;n=l=>Math.floor(l*s)/s}return n(Math.random()*(e-r)+r)}function P(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}const T="1.1.4";i.DateUnit=a,i.DeferredPromise=o,i.Exception=c,i.JsonStorage=h,i.Subscribers=f,i.VERSION=T,i.capitalize=P,i.count=w,i.dateDifference=m,i.dateRange=g,i.dateRound=v,i.delay=d,i.hash=I,i.loadScript=b,i.nextAnimationFrame=_,i.random=M,i.range=y,i.sum=S,i.unique=p,Object.defineProperty(i,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/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, MaybePromise } 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>, onRejected?: RejectedHandler<E, R>)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n const _promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n });\n\n this._promise = _promise.then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public resolve(value: MaybePromise<T>)\n {\n this._resolve(value);\n }\n public reject(reason: E)\n {\n this._reject(reason);\n }\n\n public then<N = F | R, H = R>(onFulfilled?: FulfilledHandler<F | R, N>, onRejected?: RejectedHandler<R, H>)\n : Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H>): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: () => void): Promise<F | R>\n {\n return this._promise.finally(onFinally);\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 if (import.meta.env.DEV)\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\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 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","export 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)\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function* dateRange(start: Date, end: Date, offset = DateUnit.Day)\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\nexport function dateRound(date: Date, unit = DateUnit.Day)\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","export 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): Generator<number, void>;\nexport function range(start: number, end: number): Generator<number, void>;\nexport function range(start: number, end: number, step: number): Generator<number, void>;\nexport function* range(start: number, end?: number, step = 1): Generator<number, void>\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\nexport function sum<T extends number>(elements: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of elements) { _sum += value; }\n\n return _sum;\n}\n\nexport function unique<T>(elements: Iterable<T>): T[]\n{\n return [...new Set(elements)];\n}\n","export function hash(value: string): number\n{\n let hash = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash |= 0;\n }\n\n return hash;\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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.3\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\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 sum,\n unique\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","_promise","resolve","reject","value","reason","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","sum","_sum","unique","hash","i","char","random","min","max","decimals","rounder","digits","capitalize","VERSION"],"mappings":"oYAEA,MAAqBA,CACrB,CAMW,YAAYC,EAAsCC,EACzD,CANUC,EAAA,iBACAA,EAAA,gBAEAA,EAAA,iBAIF,IAAAC,EACAC,EAEJ,MAAMC,EAAW,IAAI,QAAW,CAACC,EAASC,IAC1C,CACeJ,EAAAG,EACDF,EAAAG,CAAA,CACb,EAED,KAAK,SAAWF,EAAS,KAAKL,EAAaC,CAAU,EAErD,KAAK,SAAWE,EAChB,KAAK,QAAUC,CACnB,CAEO,QAAQI,EACf,CACI,KAAK,SAASA,CAAK,CACvB,CACO,OAAOC,EACd,CACI,KAAK,QAAQA,CAAM,CACvB,CAEO,KAAuBT,EAA0CC,EAExE,CACI,OAAO,KAAK,SAAS,KAAKD,EAAaC,CAAU,CACrD,CACO,MAAaA,EACpB,CACW,OAAA,KAAK,SAAS,MAAMA,CAAU,CACzC,CACO,QAAQS,EACf,CACW,OAAA,KAAK,SAAS,QAAQA,CAAS,CAC1C,CACJ,CChDA,MAAqBC,UAAkB,KACvC,CACI,OAAc,YAAYC,EAC1B,CACI,GAAIA,aAAiBD,EAEV,OAAAC,EAEX,GAAIA,aAAiB,MACrB,CACI,MAAMC,EAAM,IAAIF,EAAUC,EAAM,OAAO,EAEvC,OAAAC,EAAI,MAAQD,EAAM,MAClBC,EAAI,KAAOD,EAAM,KAEVC,CACX,CAEA,OAAO,IAAIF,EAAU,GAAGC,CAAK,EAAE,CACnC,CAEO,YAAYE,EAAiBC,EAAiBC,EAAO,YAC5D,CACI,MAAMF,CAAO,EAE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models/exception.ts","../src/models/json-storage.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>, onRejected?: RejectedHandler<E, R>)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n const _promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n });\n\n this._promise = _promise.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>(onFulfilled?: FulfilledHandler<F | R, N>, onRejected?: RejectedHandler<R, H>)\n : Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H>): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: () => void): Promise<F | R>\n {\n return this._promise.finally(onFinally);\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 if (import.meta.env.DEV)\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\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 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","export 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)\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function* dateRange(start: Date, end: Date, offset = DateUnit.Day)\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\nexport function dateRound(date: Date, unit = DateUnit.Day)\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","export 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): Generator<number, void>;\nexport function range(start: number, end: number): Generator<number, void>;\nexport function range(start: number, end: number, step: number): Generator<number, void>;\nexport function* range(start: number, end?: number, step = 1): Generator<number, void>\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\nexport function sum<T extends number>(elements: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of elements) { _sum += value; }\n\n return _sum;\n}\n\nexport function unique<T>(elements: Iterable<T>): T[]\n{\n return [...new Set(elements)];\n}\n","export function hash(value: string): number\n{\n let hash = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash |= 0;\n }\n\n return hash;\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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.4\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\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 sum,\n unique\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","_promise","resolve","reject","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","sum","_sum","value","unique","hash","i","char","random","min","max","decimals","rounder","digits","capitalize","VERSION"],"mappings":"oYAEA,MAAqBA,CACrB,CAMW,YAAYC,EAAsCC,EACzD,CANUC,EAAA,iBACAA,EAAA,gBAEAA,EAAA,iBAIF,IAAAC,EACAC,EAEJ,MAAMC,EAAW,IAAI,QAAW,CAACC,EAASC,IAC1C,CACeJ,EAAAG,EACDF,EAAAG,CAAA,CACb,EAED,KAAK,SAAWF,EAAS,KAAKL,EAAaC,CAAU,EAErD,KAAK,SAAWE,EAChB,KAAK,QAAUC,CACnB,CAEA,IAAW,SACX,CACI,OAAO,KAAK,QAChB,CACA,IAAW,QACX,CACI,OAAO,KAAK,OAChB,CAEO,KAAuBJ,EAA0CC,EAExE,CACI,OAAO,KAAK,SAAS,KAAKD,EAAaC,CAAU,CACrD,CACO,MAAaA,EACpB,CACW,OAAA,KAAK,SAAS,MAAMA,CAAU,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EAAU,KAAK,cAGdD,IAAa,GAElBC,EAAU,KAAK,UAGnB,CACI,MAAMC,EAAS,IAAMF,EAErBC,EAAWT,GAAU,KAAK,MAAMA,EAAQU,CAAM,EAAIA,CACtD,CAEA,OAAOD,EAAQ,KAAK,OAAA,GAAYF,EAAMD,GAAOA,CAAG,CACpD,CC5DO,SAASK,EAAWX,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMY,EAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byloth/core",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
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",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "1.1.3";
1
+ export const VERSION = "1.1.4";
2
2
 
3
3
  export { DeferredPromise, Exception, JsonStorage, Subscribers } from "./models/index.js";
4
4
  export {
@@ -1,4 +1,4 @@
1
- import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler, MaybePromise } from "../types.js";
1
+ import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from "../types.js";
2
2
 
3
3
  export default class DeferredPromise<T = void, E = unknown, F = T, R = never>
4
4
  {
@@ -24,13 +24,13 @@ export default class DeferredPromise<T = void, E = unknown, F = T, R = never>
24
24
  this._reject = _reject!;
25
25
  }
26
26
 
27
- public resolve(value: MaybePromise<T>)
27
+ public get resolve(): PromiseResolver<T>
28
28
  {
29
- this._resolve(value);
29
+ return this._resolve;
30
30
  }
31
- public reject(reason: E)
31
+ public get reject(): PromiseRejecter<E>
32
32
  {
33
- this._reject(reason);
33
+ return this._reject;
34
34
  }
35
35
 
36
36
  public then<N = F | R, H = R>(onFulfilled?: FulfilledHandler<F | R, N>, onRejected?: RejectedHandler<R, H>)