@byloth/core 1.1.5 → 1.1.6

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,16 +1,15 @@
1
1
  var h = Object.defineProperty;
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
- class d {
2
+ var l = (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) => (l(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ class _ {
5
5
  constructor(e, t) {
6
6
  n(this, "_resolve");
7
7
  n(this, "_reject");
8
8
  n(this, "_promise");
9
9
  let i, s;
10
- const c = new Promise((u, l) => {
11
- i = u, s = l;
12
- });
13
- this._promise = c.then(e, t), this._resolve = i, this._reject = s;
10
+ this._promise = new Promise((c, u) => {
11
+ i = c, s = u;
12
+ }).then(e, t), this._resolve = i, this._reject = s;
14
13
  }
15
14
  get resolve() {
16
15
  return this._resolve;
@@ -27,6 +26,12 @@ class d {
27
26
  finally(e) {
28
27
  return this._promise.finally(e);
29
28
  }
29
+ watch(e) {
30
+ return e.then(this.resolve, this.reject), this;
31
+ }
32
+ get [Symbol.toStringTag]() {
33
+ return "DeferredPromise";
34
+ }
30
35
  }
31
36
  class o extends Error {
32
37
  static FromUnknown(e) {
@@ -46,7 +51,7 @@ Caused by ${t.stack}` : this.stack += `
46
51
  Caused by ${t}`);
47
52
  }
48
53
  }
49
- class m {
54
+ class d {
50
55
  constructor(e = !0) {
51
56
  n(this, "_preferPersistence");
52
57
  n(this, "_volatile");
@@ -179,7 +184,7 @@ class m {
179
184
  this._volatile.removeItem(e), this._persistent.removeItem(e);
180
185
  }
181
186
  }
182
- class g {
187
+ class m {
183
188
  constructor() {
184
189
  n(this, "_subscribers");
185
190
  this._subscribers = [];
@@ -197,32 +202,32 @@ class g {
197
202
  return this._subscribers.slice().map((t) => t(...e));
198
203
  }
199
204
  }
200
- async function v(r) {
205
+ async function g(r) {
201
206
  return new Promise((e, t) => setTimeout(e, r));
202
207
  }
203
- async function p() {
208
+ async function v() {
204
209
  return new Promise((r, e) => requestAnimationFrame(() => r()));
205
210
  }
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) {
211
+ var a = /* @__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))(a || {});
212
+ function p(r, e, t = 864e5) {
208
213
  return Math.floor((e.getTime() - r.getTime()) / t);
209
214
  }
210
- function* w(r, e, t = 864e5) {
215
+ function* b(r, e, t = 864e5) {
211
216
  const i = e.getTime();
212
217
  let s = r.getTime();
213
218
  for (; s < i; )
214
219
  yield new Date(s), s += t;
215
220
  }
216
- function y(r, e = 864e5) {
221
+ function w(r, e = 864e5) {
217
222
  return new Date(Math.floor(r.getTime() / e) * e);
218
223
  }
219
- async function I(r, e = "text/javascript") {
224
+ async function y(r, e = "text/javascript") {
220
225
  return new Promise((t, i) => {
221
226
  const s = document.createElement("script");
222
227
  s.async = !0, s.defer = !0, s.src = r, s.type = e, s.onload = () => t(), s.onerror = () => i(), document.body.appendChild(s);
223
228
  });
224
229
  }
225
- function M(r) {
230
+ function I(r) {
226
231
  if (Array.isArray(r))
227
232
  return r.length;
228
233
  let e = 0;
@@ -235,16 +240,16 @@ function* S(r, e, t = 1) {
235
240
  for (let i = r; i < e; i += t)
236
241
  yield i;
237
242
  }
238
- function k(r) {
243
+ function M(r) {
239
244
  let e = 0;
240
245
  for (const t of r)
241
246
  e += t;
242
247
  return e;
243
248
  }
244
- function P(r) {
249
+ function k(r) {
245
250
  return [...new Set(r)];
246
251
  }
247
- function j(r) {
252
+ function P(r) {
248
253
  let e = 0;
249
254
  for (let t = 0; t < r.length; t++) {
250
255
  const i = r.charCodeAt(t);
@@ -252,7 +257,7 @@ function j(r) {
252
257
  }
253
258
  return e;
254
259
  }
255
- function T(r = 1, e, t) {
260
+ function j(r = 1, e, t) {
256
261
  if (e === void 0 && (e = r, r = 0), r === e)
257
262
  return r;
258
263
  let i;
@@ -268,29 +273,29 @@ function T(r = 1, e, t) {
268
273
  }
269
274
  return i(Math.random() * (e - r) + r);
270
275
  }
271
- function x(r) {
276
+ function T(r) {
272
277
  return `${r.charAt(0).toUpperCase()}${r.slice(1)}`;
273
278
  }
274
- const A = "1.1.5";
279
+ const x = "1.1.6";
275
280
  export {
276
- f as DateUnit,
277
- d as DeferredPromise,
281
+ a as DateUnit,
282
+ _ as DeferredPromise,
278
283
  o as Exception,
279
- m as JsonStorage,
280
- g as Subscribers,
281
- A as VERSION,
282
- x as capitalize,
283
- M as count,
284
- b as dateDifference,
285
- w as dateRange,
286
- y as dateRound,
287
- v as delay,
288
- j as hash,
289
- I as loadScript,
290
- p as nextAnimationFrame,
291
- T as random,
284
+ d as JsonStorage,
285
+ m as Subscribers,
286
+ x as VERSION,
287
+ T as capitalize,
288
+ I as count,
289
+ p as dateDifference,
290
+ b as dateRange,
291
+ w as dateRound,
292
+ g as delay,
293
+ P as hash,
294
+ y as loadScript,
295
+ v as nextAnimationFrame,
296
+ j as random,
292
297
  S as range,
293
- k as sum,
294
- P as unique
298
+ M as sum,
299
+ k as unique
295
300
  };
296
301
  //# 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/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 as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\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.5\";\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,KAAK;AAAA,EAChB;AAAA,EAEO,KAAuBJ,GAA0CC,GAExE;AACI,WAAO,KAAK,SAAS,KAA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AAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMY,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> | 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 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 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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.6\";\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","resolve","reject","onFinally","promise","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","hashedValue","i","char","random","min","max","decimals","rounder","digits","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,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AAID,IAAMD,CAAG,KAAK,IAEvBG,IAAU,CAACV,MAAUA,IAIrBU,IAAU,KAAK;AAAA,WAGdD,MAAa;AAElB,IAAAC,IAAU,KAAK;AAAA,OAGnB;AACI,UAAMC,IAAS,MAAMF;AAErB,IAAAC,IAAU,CAACV,MAAU,KAAK,MAAMA,IAAQW,CAAM,IAAIA;AAAA,EACtD;AAEA,SAAOD,EAAQ,KAAK,OAAA,KAAYF,IAAMD,KAAOA,CAAG;AACpD;AC5DO,SAASK,EAAWZ,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMa,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,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+=`
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 k=Object.defineProperty;var A=(i,o,c)=>o in i?k(i,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):i[o]=c;var u=(i,o,c)=>(A(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;this._promise=new Promise((l,j)=>{n=l,s=j}).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)}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,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 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.5";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.6";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 } 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 as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\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.5\";\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,CACzC,CACO,QAAQO,EACf,CACW,OAAA,KAAK,SAAS,QAAQA,CA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,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"}
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 } 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 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 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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.6\";\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","resolve","reject","onFinally","promise","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","hashedValue","i","char","random","min","max","decimals","rounder","digits","capitalize","VERSION"],"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IM,EAAO,EACX,UAAWC,KAASP,EAAoBM,GAAAC,EAEjC,OAAAD,CACX,CAEO,SAASE,EAAUR,EAC1B,CACI,MAAO,CAAC,GAAG,IAAI,IAAIA,CAAQ,CAAC,CAChC,CCrCO,SAASS,EAAKF,EACrB,CACI,IAAIG,EAAc,EAClB,QAASC,EAAI,EAAGA,EAAIJ,EAAM,OAAQI,IAClC,CACU,MAAAC,EAAOL,EAAM,WAAWI,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,EAAWV,GAAUA,UAEhBS,IAAa,OAEd,KAAK,IAAID,EAAMD,CAAG,GAAK,EAEvBG,EAAWV,GAAUA,EAIrBU,EAAU,KAAK,cAGdD,IAAa,GAElBC,EAAU,KAAK,UAGnB,CACI,MAAMC,EAAS,IAAMF,EAErBC,EAAWV,GAAU,KAAK,MAAMA,EAAQW,CAAM,EAAIA,CACtD,CAEA,OAAOD,EAAQ,KAAK,OAAA,GAAYF,EAAMD,GAAOA,CAAG,CACpD,CC5DO,SAASK,EAAWZ,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMa,EAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byloth/core",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
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",
@@ -56,11 +56,11 @@
56
56
  "ci": "yarn install --frozen-lockfile"
57
57
  },
58
58
  "devDependencies": {
59
- "@byloth/eslint-config-typescript": "^2.6.5",
60
- "@typescript-eslint/eslint-plugin": "^6.7.4",
61
- "@typescript-eslint/parser": "^6.7.4",
62
- "eslint": "^8.50.0",
59
+ "@byloth/eslint-config-typescript": "^2.6.7",
60
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
61
+ "@typescript-eslint/parser": "^6.10.0",
62
+ "eslint": "^8.53.0",
63
63
  "typescript": "^5.2.2",
64
- "vite": "^4.4.10"
64
+ "vite": "^4.5.0"
65
65
  }
66
66
  }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "1.1.5";
1
+ export const VERSION = "1.1.6";
2
2
 
3
3
  export { DeferredPromise, Exception, JsonStorage, Subscribers } from "./models/index.js";
4
4
  export {
@@ -7,18 +7,17 @@ export default class DeferredPromise<T = void, E = unknown, F = T, R = never>
7
7
 
8
8
  protected _promise: Promise<F | R>;
9
9
 
10
- public constructor(onFulfilled?: FulfilledHandler<T, F>, onRejected?: RejectedHandler<E, R>)
10
+ public constructor(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R> | null)
11
11
  {
12
12
  let _resolve: PromiseResolver<T>;
13
13
  let _reject: PromiseRejecter<E>;
14
14
 
15
- const _promise = new Promise<T>((resolve, reject) =>
15
+ this._promise = new Promise<T>((resolve, reject) =>
16
16
  {
17
17
  _resolve = resolve as PromiseResolver<T>;
18
18
  _reject = reject as PromiseRejecter<E>;
19
- });
20
19
 
21
- this._promise = _promise.then(onFulfilled, onRejected);
20
+ }).then(onFulfilled, onRejected);
22
21
 
23
22
  this._resolve = _resolve!;
24
23
  this._reject = _reject!;
@@ -33,17 +32,30 @@ export default class DeferredPromise<T = void, E = unknown, F = T, R = never>
33
32
  return this._reject;
34
33
  }
35
34
 
36
- public then<N = F | R, H = R>(onFulfilled?: FulfilledHandler<F | R, N>, onRejected?: RejectedHandler<R, H>)
37
- : Promise<N | H>
35
+ public then<N = F | R, H = R>(
36
+ onFulfilled?: FulfilledHandler<F | R, N> | null,
37
+ onRejected?: RejectedHandler<R, H> | null): Promise<N | H>
38
38
  {
39
39
  return this._promise.then(onFulfilled, onRejected);
40
40
  }
41
- public catch<H = R>(onRejected?: RejectedHandler<R, H>): Promise<F | R | H>
41
+ public catch<H = R>(onRejected?: RejectedHandler<R, H> | null): Promise<F | R | H>
42
42
  {
43
43
  return this._promise.catch(onRejected);
44
44
  }
45
- public finally(onFinally?: () => void): Promise<F | R>
45
+ public finally(onFinally?: (() => void) | null): Promise<F | R>
46
46
  {
47
47
  return this._promise.finally(onFinally);
48
48
  }
49
+
50
+ public watch(promise: Promise<T>): this
51
+ {
52
+ promise.then(this.resolve, this.reject);
53
+
54
+ return this;
55
+ }
56
+
57
+ public get [Symbol.toStringTag]()
58
+ {
59
+ return "DeferredPromise";
60
+ }
49
61
  }
package/src/utils/math.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  export function hash(value: string): number
2
2
  {
3
- let hash = 0;
3
+ let hashedValue = 0;
4
4
  for (let i = 0; i < value.length; i++)
5
5
  {
6
6
  const char = value.charCodeAt(i);
7
- hash = ((hash << 5) - hash) + char;
8
- hash |= 0;
7
+ hashedValue = ((hashedValue << 5) - hashedValue) + char;
8
+ hashedValue |= 0;
9
9
  }
10
10
 
11
- return hash;
11
+ return hashedValue;
12
12
  }
13
13
 
14
14
  export function random(): number;