@byloth/core 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -3,13 +3,13 @@ var h = (s, e, t) => e in s ? a(s, e, { enumerable: !0, configurable: !0, writab
3
3
  var n = (s, e, t) => (h(s, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  class f extends Promise {
5
5
  constructor(t) {
6
- let r, i, o;
7
- t ? o = (c, u) => {
8
- r = c, i = u, t(c, u);
9
- } : o = (c, u) => {
10
- r = c, i = u;
6
+ let r, i, c;
7
+ t ? c = (u, l) => {
8
+ r = u, i = l, t(u, l);
9
+ } : c = (u, l) => {
10
+ r = u, i = l;
11
11
  };
12
- super(o);
12
+ super(c);
13
13
  n(this, "_resolve");
14
14
  n(this, "_reject");
15
15
  this._resolve = r, this._reject = i;
@@ -30,15 +30,15 @@ class f extends Promise {
30
30
  return super.finally(t), this;
31
31
  }
32
32
  }
33
- class l extends Error {
33
+ class o extends Error {
34
34
  static FromUnknown(e) {
35
- if (e instanceof l)
35
+ if (e instanceof o)
36
36
  return e;
37
37
  if (e instanceof Error) {
38
- const t = new l(e.message);
38
+ const t = new o(e.message);
39
39
  return t.stack = e.stack, t.name = e.name, t;
40
40
  }
41
- return new l(`${e}`);
41
+ return new o(`${e}`);
42
42
  }
43
43
  constructor(e, t, r = "Exception") {
44
44
  super(e), this.cause = t, this.name = r, t && (t instanceof Error ? this.stack += `
@@ -192,7 +192,7 @@ class d {
192
192
  remove(e) {
193
193
  const t = this._subscribers.indexOf(e);
194
194
  if (t < 0)
195
- throw new Error("Unable to remove the requested subscriber. It was not found.");
195
+ throw new o("Unable to remove the requested subscriber. It was not found.");
196
196
  this._subscribers.splice(t, 1);
197
197
  }
198
198
  call(...e) {
@@ -244,10 +244,10 @@ function x(s) {
244
244
  function P(s) {
245
245
  return `${s.charAt(0).toUpperCase()}${s.slice(1)}`;
246
246
  }
247
- const S = "1.0.4";
247
+ const S = "1.1.0";
248
248
  export {
249
249
  f as DeferredPromise,
250
- l as Exception,
250
+ o as Exception,
251
251
  m as JsonStorage,
252
252
  d as Subscribers,
253
253
  S as VERSION,
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/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseExecutor, PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types\";\n\nexport default class DeferredPromise<T, E = unknown> extends Promise<T>\n{\n protected _resolve: PromiseResolver<T>;\n protected _reject: PromiseRejecter<E>;\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 constructor(executor?: PromiseExecutor<T>)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n let _executor: PromiseExecutor<T>;\n\n if (executor)\n {\n _executor = (resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n\n executor(resolve, reject);\n };\n }\n else\n {\n _executor = (resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n };\n }\n\n super(_executor);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public then<F = T, R = E>(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R>)\n : DeferredPromise<F, R>\n {\n super.then(onFulfilled, onRejected);\n\n return (this as unknown) as DeferredPromise<F, R>;\n }\n public catch<R = E>(onRejected?: RejectedHandler<E, R>): DeferredPromise<T, R>\n {\n super.catch(onRejected);\n\n return (this as unknown) as DeferredPromise<T, R>;\n }\n public finally(onFinally?: (() => void) | null): DeferredPromise<T, E>\n {\n super.finally(onFinally);\n\n return this;\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","export 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 Error(\"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 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 (\"length\" in elements) { return elements.length as number; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function* range(start: number, end: number, step?: number): Iterable<number>\n{\n if (start > end) { step = step ?? -1; }\n else { step = step ?? 1; }\n\n for (let i = start; i < end; i += step) { yield i; }\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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.0.4\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models\";\nexport {\n capitalize,\n count,\n delay,\n hash,\n loadScript,\n nextAnimationFrame,\n range,\n sum,\n unique\n\n} from \"./utils\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types\";\n"],"names":["DeferredPromise","executor","_resolve","_reject","_executor","resolve","reject","__publicField","onFulfilled","onRejected","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","start","end","step","i","sum","_sum","value","unique","hash","char","capitalize","VERSION"],"mappings":";;;AAEA,MAAqBA,UAAwC,QAC7D;AAAA,EAaW,YAAYC,GACnB;AACQ,QAAAC,GACAC,GAEAC;AAEJ,IAAIH,IAEYG,IAAA,CAACC,G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C1B;AACI,SAAO,CAAC,GAAG,IAAI,IAAIA,CAAQ,CAAC;AAChC;AC7BO,SAASY,EAAKF,GACrB;AACI,MAAIE,IAAO;AACX,WAASL,IAAI,GAAGA,IAAIG,EAAM,QAAQH,KAClC;AACU,UAAAM,IAAOH,EAAM,WAAWH,CAAC;AAC/BK,IAAAA,KAASA,KAAQ,KAAKA,IAAQC,GAC9BD,KAAQ;AAAA,EACZ;AAEOA,SAAAA;AACX;ACXO,SAASE,EAAWJ,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMK,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/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseExecutor, PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T, E = unknown> extends Promise<T>\n{\n protected _resolve: PromiseResolver<T>;\n protected _reject: PromiseRejecter<E>;\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 constructor(executor?: PromiseExecutor<T>)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n let _executor: PromiseExecutor<T>;\n\n if (executor)\n {\n _executor = (resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n\n executor(resolve, reject);\n };\n }\n else\n {\n _executor = (resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n };\n }\n\n super(_executor);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public then<F = T, R = E>(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R>)\n : DeferredPromise<F, R>\n {\n super.then(onFulfilled, onRejected);\n\n return (this as unknown) as DeferredPromise<F, R>;\n }\n public catch<R = E>(onRejected?: RejectedHandler<E, R>): DeferredPromise<T, R>\n {\n super.catch(onRejected);\n\n return (this as unknown) as DeferredPromise<T, R>;\n }\n public finally(onFinally?: (() => void) | null): DeferredPromise<T, E>\n {\n super.finally(onFinally);\n\n return this;\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 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 (\"length\" in elements) { return elements.length as number; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function* range(start: number, end: number, step?: number): Iterable<number>\n{\n if (start > end) { step = step ?? -1; }\n else { step = step ?? 1; }\n\n for (let i = start; i < end; i += step) { yield i; }\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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.0\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\n capitalize,\n count,\n delay,\n hash,\n loadScript,\n nextAnimationFrame,\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","executor","_resolve","_reject","_executor","resolve","reject","__publicField","onFulfilled","onRejected","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","start","end","step","i","sum","_sum","value","unique","hash","char","capitalize","VERSION"],"mappings":";;;AAEA,MAAqBA,UAAwC,QAC7D;AAAA,EAaW,YAAYC,GACnB;AACQ,QAAAC,GACAC,GAEAC;AAEJ,IAAIH,IAEYG,IAAA,CAACC,GAASC,MACtB;AACe,MAAAJ,IAAAG,GACDF,IAAAG,GAEVL,EAASI,GAASC,CAAM;AAAA,IAAA,IAKhBF,IAAA,CAACC,GAASC,MACtB;AACe,MAAAJ,IAAAG,GACDF,IAAAG;AAAA,IAAA;AAIlB,UAAMF,CAAS;AAtCT,IAAAG,EAAA;AACA,IAAAA,EAAA;AAuCN,SAAK,WAAWL,GAChB,KAAK,UAAUC;AAAA,EACnB;AAAA,EAvCA,IAAW,UACX;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EACA,IAAW,SACX;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EAkCO,KAAmBK,GAA6CC,GAEvE;AACU,iBAAA,KAAKD,GAAaC,CAAU,GAE1B;AAAA,EACZ;AAAA,EACO,MAAaA,GACpB;AACI,iBAAM,MAAMA,CAAU,GAEd;AAAA,EACZ;AAAA,EACO,QAAQC,GACf;AACI,iBAAM,QAAQA,CAAS,GAEhB;AAAA,EACX;AACJ;ACnEA,MAAqBC,UAAkB,MACvC;AAAA,EACI,OAAc,YAAYC,GAC1B;AACI,QAAIA,aAAiBD;AAEV,aAAAC;AAEX,QAAIA,aAAiB,OACrB;AACI,YAAMC,IAAM,IAAIF,EAAUC,EAAM,OAAO;AAEvC,aAAAC,EAAI,QAAQD,EAAM,OAClBC,EAAI,OAAOD,EAAM,MAEVC;AAAA,IACX;AAEA,WAAO,IAAIF,EAAU,GAAGC,CAAK,EAAE;AAAA,EACnC;AAAA,EAEO,YAAYE,GAAiBC,GA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X;AAEiB,UAAAE,EAAMC,GAAeC,GAAaC,GACnD;AACI,EAAIF,IAAQC,IAAOC,IAAOA,KAAQ,KAC3BA,IAAOA,KAAQ;AAEtB,WAASC,IAAIH,GAAOG,IAAIF,GAAKE,KAAKD;AAAc,UAAAC;AACpD;AAEO,SAASC,EAAsBR,GACtC;AACI,MAAIS,IAAO;AACX,aAAWC,KAASV;AAAoB,IAAAS,KAAAC;AAEjC,SAAAD;AACX;AAEO,SAASE,EAAUX,GAC1B;AACI,SAAO,CAAC,GAAG,IAAI,IAAIA,CAAQ,CAAC;AAChC;AC7BO,SAASY,EAAKF,GACrB;AACI,MAAIE,IAAO;AACX,WAASL,IAAI,GAAGA,IAAIG,EAAM,QAAQH,KAClC;AACU,UAAAM,IAAOH,EAAM,WAAWH,CAAC;AAC/BK,IAAAA,KAASA,KAAQ,KAAKA,IAAQC,GAC9BD,KAAQ;AAAA,EACZ;AAEOA,SAAAA;AACX;ACXO,SAASE,EAAWJ,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMK,IAAU;"}
package/dist/core.umd.cjs CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  Caused by ${t.stack}`:this.stack+=`
4
4
 
5
- Caused by ${t}`)}}class f{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,i){const n=e.getItem(t);if(n)try{return JSON.parse(n)}catch{e.removeItem(t)}return i}_set(e,t,i){const n=JSON.stringify(i);n?e.setItem(t,n):e.removeItem(t)}get(e,t,i=this._preferPersistence){const n=i?this._persistent:this._volatile;return this._get(n,e,t)}recall(e,t){return this._get(this._volatile,e,t)}retrieve(e,t){return this.recall(e)??this.read(e,t)}read(e,t){return this._get(this._persistent,e,t)}has(e,t){return(t?this._persistent:this._volatile).getItem(e)!==null}knows(e){return this._volatile.getItem(e)!==null}find(e){return this.knows(e)??this.exists(e)}exists(e){return this._persistent.getItem(e)!==null}set(e,t,i=this._preferPersistence){const n=i?this._persistent:this._volatile;this._set(n,e,t)}remember(e,t){this._set(this._volatile,e,t)}write(e,t){this._set(this._persistent,e,t)}forget(e){this._volatile.removeItem(e)}erase(e){this._persistent.removeItem(e)}clear(e){this._volatile.removeItem(e),this._persistent.removeItem(e)}}class _{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 Error("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 m(){return new Promise((r,e)=>requestAnimationFrame(()=>r()))}async function g(r,e="text/javascript"){return new Promise((t,i)=>{const n=document.createElement("script");n.async=!0,n.defer=!0,n.src=r,n.type=e,n.onload=()=>t(),n.onerror=()=>i(),document.body.appendChild(n)})}function b(r){if("length"in r)return r.length;let e=0;for(const t of r)e+=1;return e}function*v(r,e,t){r>e?t=t??-1:t=t??1;for(let i=r;i<e;i+=t)yield i}function p(r){let e=0;for(const t of r)e+=t;return e}function w(r){return[...new Set(r)]}function y(r){let e=0;for(let t=0;t<r.length;t++){const i=r.charCodeAt(t);e=(e<<5)-e+i,e|=0}return e}function S(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}const I="1.0.4";s.DeferredPromise=o,s.Exception=c,s.JsonStorage=f,s.Subscribers=_,s.VERSION=I,s.capitalize=S,s.count=b,s.delay=d,s.hash=y,s.loadScript=g,s.nextAnimationFrame=m,s.range=v,s.sum=p,s.unique=w,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
5
+ Caused by ${t}`)}}class f{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,i){const n=e.getItem(t);if(n)try{return JSON.parse(n)}catch{e.removeItem(t)}return i}_set(e,t,i){const n=JSON.stringify(i);n?e.setItem(t,n):e.removeItem(t)}get(e,t,i=this._preferPersistence){const n=i?this._persistent:this._volatile;return this._get(n,e,t)}recall(e,t){return this._get(this._volatile,e,t)}retrieve(e,t){return this.recall(e)??this.read(e,t)}read(e,t){return this._get(this._persistent,e,t)}has(e,t){return(t?this._persistent:this._volatile).getItem(e)!==null}knows(e){return this._volatile.getItem(e)!==null}find(e){return this.knows(e)??this.exists(e)}exists(e){return this._persistent.getItem(e)!==null}set(e,t,i=this._preferPersistence){const n=i?this._persistent:this._volatile;this._set(n,e,t)}remember(e,t){this._set(this._volatile,e,t)}write(e,t){this._set(this._persistent,e,t)}forget(e){this._volatile.removeItem(e)}erase(e){this._persistent.removeItem(e)}clear(e){this._volatile.removeItem(e),this._persistent.removeItem(e)}}class _{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 m(){return new Promise((r,e)=>requestAnimationFrame(()=>r()))}async function g(r,e="text/javascript"){return new Promise((t,i)=>{const n=document.createElement("script");n.async=!0,n.defer=!0,n.src=r,n.type=e,n.onload=()=>t(),n.onerror=()=>i(),document.body.appendChild(n)})}function b(r){if("length"in r)return r.length;let e=0;for(const t of r)e+=1;return e}function*v(r,e,t){r>e?t=t??-1:t=t??1;for(let i=r;i<e;i+=t)yield i}function p(r){let e=0;for(const t of r)e+=t;return e}function w(r){return[...new Set(r)]}function y(r){let e=0;for(let t=0;t<r.length;t++){const i=r.charCodeAt(t);e=(e<<5)-e+i,e|=0}return e}function S(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}const I="1.1.0";s.DeferredPromise=o,s.Exception=c,s.JsonStorage=f,s.Subscribers=_,s.VERSION=I,s.capitalize=S,s.count=b,s.delay=d,s.hash=y,s.loadScript=g,s.nextAnimationFrame=m,s.range=v,s.sum=p,s.unique=w,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
6
6
  //# sourceMappingURL=core.umd.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.umd.cjs","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.ts","../src/models/subscribers.ts","../src/utils/async.ts","../src/utils/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseExecutor, PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types\";\n\nexport default class DeferredPromise<T, E = unknown> extends Promise<T>\n{\n protected _resolve: PromiseResolver<T>;\n protected _reject: PromiseRejecter<E>;\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 constructor(executor?: PromiseExecutor<T>)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n let _executor: PromiseExecutor<T>;\n\n if (executor)\n {\n _executor = (resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n\n executor(resolve, reject);\n };\n }\n else\n {\n _executor = (resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n };\n }\n\n super(_executor);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public then<F = T, R = E>(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R>)\n : DeferredPromise<F, R>\n {\n super.then(onFulfilled, onRejected);\n\n return (this as unknown) as DeferredPromise<F, R>;\n }\n public catch<R = E>(onRejected?: RejectedHandler<E, R>): DeferredPromise<T, R>\n {\n super.catch(onRejected);\n\n return (this as unknown) as DeferredPromise<T, R>;\n }\n public finally(onFinally?: (() => void) | null): DeferredPromise<T, E>\n {\n super.finally(onFinally);\n\n return this;\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","export 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 Error(\"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 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 (\"length\" in elements) { return elements.length as number; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function* range(start: number, end: number, step?: number): Iterable<number>\n{\n if (start > end) { step = step ?? -1; }\n else { step = step ?? 1; }\n\n for (let i = start; i < end; i += step) { yield i; }\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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.0.4\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models\";\nexport {\n capitalize,\n count,\n delay,\n hash,\n loadScript,\n nextAnimationFrame,\n range,\n sum,\n unique\n\n} from \"./utils\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types\";\n"],"names":["DeferredPromise","executor","_resolve","_reject","_executor","resolve","reject","__publicField","onFulfilled","onRejected","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","start","end","step","sum","_sum","value","unique","hash","i","char","capitalize","VERSION"],"mappings":"oYAEA,MAAqBA,UAAwC,OAC7D,CAaW,YAAYC,EACnB,CACQ,IAAAC,EACAC,EAEAC,E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,GAAI,WAAYA,EAAY,OAAOA,EAAS,OAE5C,IAAIC,EAAS,EACb,UAAWC,KAAKF,EAAsBC,GAAA,EAE/B,OAAAA,CACX,CAEiB,SAAAE,EAAMC,EAAeC,EAAaC,EACnD,CACQF,EAAQC,EAAOC,EAAOA,GAAQ,GAC3BA,EAAOA,GAAQ,EAEtB,QAAS,EAAIF,EAAO,EAAIC,EAAK,GAAKC,EAAc,MAAA,CACpD,CAEO,SAASC,EAAsBP,EACtC,CACI,IAAIQ,EAAO,EACX,UAAWC,KAAST,EAAoBQ,GAAAC,EAEjC,OAAAD,CACX,CAEO,SAASE,EAAUV,EAC1B,CACI,MAAO,CAAC,GAAG,IAAI,IAAIA,CAAQ,CAAC,CAChC,CC7BO,SAASW,EAAKF,EACrB,CACI,IAAIE,EAAO,EACX,QAASC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAClC,CACU,MAAAC,EAAOJ,EAAM,WAAWG,CAAC,EAC/BD,GAASA,GAAQ,GAAKA,EAAQE,EAC9BF,GAAQ,CACZ,CAEOA,OAAAA,CACX,CCXO,SAASG,EAAWL,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMM,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/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseExecutor, PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T, E = unknown> extends Promise<T>\n{\n protected _resolve: PromiseResolver<T>;\n protected _reject: PromiseRejecter<E>;\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 constructor(executor?: PromiseExecutor<T>)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n let _executor: PromiseExecutor<T>;\n\n if (executor)\n {\n _executor = (resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n\n executor(resolve, reject);\n };\n }\n else\n {\n _executor = (resolve, reject) =>\n {\n _resolve = resolve;\n _reject = reject;\n };\n }\n\n super(_executor);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public then<F = T, R = E>(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R>)\n : DeferredPromise<F, R>\n {\n super.then(onFulfilled, onRejected);\n\n return (this as unknown) as DeferredPromise<F, R>;\n }\n public catch<R = E>(onRejected?: RejectedHandler<E, R>): DeferredPromise<T, R>\n {\n super.catch(onRejected);\n\n return (this as unknown) as DeferredPromise<T, R>;\n }\n public finally(onFinally?: (() => void) | null): DeferredPromise<T, E>\n {\n super.finally(onFinally);\n\n return this;\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 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 (\"length\" in elements) { return elements.length as number; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function* range(start: number, end: number, step?: number): Iterable<number>\n{\n if (start > end) { step = step ?? -1; }\n else { step = step ?? 1; }\n\n for (let i = start; i < end; i += step) { yield i; }\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","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.0\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\n capitalize,\n count,\n delay,\n hash,\n loadScript,\n nextAnimationFrame,\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","executor","_resolve","_reject","_executor","resolve","reject","__publicField","onFulfilled","onRejected","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","start","end","step","sum","_sum","value","unique","hash","i","char","capitalize","VERSION"],"mappings":"oYAEA,MAAqBA,UAAwC,OAC7D,CAaW,YAAYC,EACnB,CACQ,IAAAC,EACAC,EAEAC,EAEAH,EAEYG,EAAA,CAACC,EAASC,IACtB,CACeJ,EAAAG,EACDF,EAAAG,EAEVL,EAASI,EAASC,CAAM,CAAA,EAKhBF,EAAA,CAACC,EAASC,IACtB,CACeJ,EAAAG,EACDF,EAAAG,CAAA,EAIlB,MAAMF,CAAS,EAtCTG,EAAA,iBACAA,EAAA,gBAuCN,KAAK,SAAWL,EAChB,KAAK,QAAUC,CACnB,CAvCA,IAAW,SACX,CACI,OAAO,KAAK,QAChB,CACA,IAAW,QACX,CACI,OAAO,KAAK,OAChB,CAkCO,KAAmBK,EAA6CC,EAEvE,CACU,aAAA,KAAKD,EAAaC,CAAU,EAE1B,IACZ,CACO,MAAaA,EACpB,CACI,aAAM,MAAMA,CAAU,EAEd,IACZ,CACO,QAAQC,EACf,CACI,aAAM,QAAQA,CAAS,EAEhB,IACX,CACJ,CCnEA,MAAqBC,UAAkB,KACvC,CACI,OAAc,YAAYC,EAC1B,CACI,GAA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C,EAC/BD,GAASA,GAAQ,GAAKA,EAAQE,EAC9BF,GAAQ,CACZ,CAEOA,OAAAA,CACX,CCXO,SAASG,EAAWL,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMM,EAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byloth/core",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "An unopinionated collection of useful functions and classes that I use widely in all my projects. 🔧",
5
5
  "keywords": [
6
6
  "Core",
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- export const VERSION = "1.0.4";
1
+ export const VERSION = "1.1.0";
2
2
 
3
- export { DeferredPromise, Exception, JsonStorage, Subscribers } from "./models";
3
+ export { DeferredPromise, Exception, JsonStorage, Subscribers } from "./models/index.js";
4
4
  export {
5
5
  capitalize,
6
6
  count,
@@ -12,7 +12,7 @@ export {
12
12
  sum,
13
13
  unique
14
14
 
15
- } from "./utils";
15
+ } from "./utils/index.js";
16
16
 
17
17
  export type {
18
18
  Constructor,
@@ -23,4 +23,4 @@ export type {
23
23
  PromiseResolver,
24
24
  RejectedHandler
25
25
 
26
- } from "./types";
26
+ } from "./types.js";
@@ -1,4 +1,4 @@
1
- import type { PromiseExecutor, PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from "../types";
1
+ import type { PromiseExecutor, PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from "../types.js";
2
2
 
3
3
  export default class DeferredPromise<T, E = unknown> extends Promise<T>
4
4
  {
@@ -1,6 +1,6 @@
1
- import DeferredPromise from "./deferred-promise";
2
- import Exception from "./exception";
3
- import JsonStorage from "./json-storage";
4
- import Subscribers from "./subscribers";
1
+ import DeferredPromise from "./deferred-promise.js";
2
+ import Exception from "./exception.js";
3
+ import JsonStorage from "./json-storage.js";
4
+ import Subscribers from "./subscribers.js";
5
5
 
6
6
  export { DeferredPromise, Exception, JsonStorage, Subscribers };
@@ -1,3 +1,5 @@
1
+ import Exception from "./exception.js";
2
+
1
3
  export default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>
2
4
  {
3
5
  protected _subscribers: T[];
@@ -16,7 +18,7 @@ export default class Subscribers<P extends unknown[] = [], R = void, T extends (
16
18
  const index = this._subscribers.indexOf(subscriber);
17
19
  if (index < 0)
18
20
  {
19
- throw new Error("Unable to remove the requested subscriber. It was not found.");
21
+ throw new Exception("Unable to remove the requested subscriber. It was not found.");
20
22
  }
21
23
 
22
24
  this._subscribers.splice(index, 1);
@@ -1,5 +1,5 @@
1
- export { delay, nextAnimationFrame } from "./async";
2
- export { loadScript } from "./dom";
3
- export { count, range, sum, unique } from "./iterator";
4
- export { hash } from "./math";
5
- export { capitalize } from "./string";
1
+ export { delay, nextAnimationFrame } from "./async.js";
2
+ export { loadScript } from "./dom.js";
3
+ export { count, range, sum, unique } from "./iterator.js";
4
+ export { hash } from "./math.js";
5
+ export { capitalize } from "./string.js";