@byloth/core 1.1.4 → 1.1.5
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 +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.umd.cjs +1 -1
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/models/deferred-promise.ts +2 -2
- package/src/types.ts +2 -2
package/dist/core.js
CHANGED
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;\n _reject = reject;\n });\n\n this._promise = _promise.then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(onFulfilled?: FulfilledHandler<F | R, N>, onRejected?: RejectedHandler<R, H>)\n : Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H>): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: () => void): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n if (import.meta.env.DEV)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n }\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","export enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day)\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function* dateRange(start: Date, end: Date, offset = DateUnit.Day)\n{\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day)\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","export function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): Generator<number, void>;\nexport function range(start: number, end: number): Generator<number, void>;\nexport function range(start: number, end: number, step: number): Generator<number, void>;\nexport function* range(start: number, end?: number, step = 1): Generator<number, void>\n{\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n}\n\nexport function sum<T extends number>(elements: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of elements) { _sum += value; }\n\n return _sum;\n}\n\nexport function unique<T>(elements: Iterable<T>): T[]\n{\n return [...new Set(elements)];\n}\n","export function hash(value: string): number\n{\n let hash = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash |= 0;\n }\n\n return hash;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.4\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n sum,\n unique\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","_promise","resolve","reject","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","sum","_sum","value","unique","hash","i","char","random","min","max","decimals","rounder","digits","capitalize","VERSION"],"mappings":";;;AAEA,MAAqBA,EACrB;AAAA,EAMW,YAAYC,GAAsCC,GACzD;AANU,IAAAC,EAAA;AACA,IAAAA,EAAA;AAEA,IAAAA,EAAA;A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ID,IAAMD,CAAG,KAAK,IAEvBG,IAAU,CAACT,MAAUA,IAIrBS,IAAU,KAAK;AAAA,WAGdD,MAAa;AAElB,IAAAC,IAAU,KAAK;AAAA,OAGnB;AACI,UAAMC,IAAS,MAAMF;AAErB,IAAAC,IAAU,CAACT,MAAU,KAAK,MAAMA,IAAQU,CAAM,IAAIA;AAAA,EACtD;AAEA,SAAOD,EAAQ,KAAK,OAAA,KAAYF,IAAMD,KAAOA,CAAG;AACpD;AC5DO,SAASK,EAAWX,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,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>, 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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,MAAQC;AAED,WAAAD;AAGP,MAAAG;AAEJ,MAAID,MAAa;AAEb,IAAAC,IAAU,CAACT,MAAUA;AAAA,WAEhBQ,MAAa;AAElB,IAAI,KAAK,IAAID,IAAMD,CAAG,KAAK,IAEvBG,IAAU,CAACT,MAAUA,IAIrBS,IAAU,KAAK;AAAA,WAGdD,MAAa;AAElB,IAAAC,IAAU,KAAK;AAAA,OAGnB;AACI,UAAMC,IAAS,MAAMF;AAErB,IAAAC,IAAU,CAACT,MAAU,KAAK,MAAMA,IAAQU,CAAM,IAAIA;AAAA,EACtD;AAEA,SAAOD,EAAQ,KAAK,OAAA,KAAYF,IAAMD,KAAOA,CAAG;AACpD;AC5DO,SAASK,EAAWX,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMY,IAAU;"}
|
package/dist/core.umd.cjs
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
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
|
+
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"})});
|
|
6
6
|
//# sourceMappingURL=core.umd.cjs.map
|
package/dist/core.umd.cjs.map
CHANGED
|
@@ -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;\n _reject = reject;\n });\n\n this._promise = _promise.then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(onFulfilled?: FulfilledHandler<F | R, N>, onRejected?: RejectedHandler<R, H>)\n : Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H>): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: () => void): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n if (import.meta.env.DEV)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n }\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","export enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day)\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function* dateRange(start: Date, end: Date, offset = DateUnit.Day)\n{\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day)\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","export function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): Generator<number, void>;\nexport function range(start: number, end: number): Generator<number, void>;\nexport function range(start: number, end: number, step: number): Generator<number, void>;\nexport function* range(start: number, end?: number, step = 1): Generator<number, void>\n{\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n}\n\nexport function sum<T extends number>(elements: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of elements) { _sum += value; }\n\n return _sum;\n}\n\nexport function unique<T>(elements: Iterable<T>): T[]\n{\n return [...new Set(elements)];\n}\n","export function hash(value: string): number\n{\n let hash = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash |= 0;\n }\n\n return hash;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.4\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n sum,\n unique\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","_promise","resolve","reject","onFinally","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","sum","_sum","value","unique","hash","i","char","random","min","max","decimals","rounder","digits","capitalize","VERSION"],"mappings":"oYAEA,MAAqBA,CACrB,CAMW,YAAYC,EAAsCC,EACzD,CANUC,EAAA,iBACAA,EAAA,gBAEAA,EAAA,iBAIF,IAAAC,EACAC,EAEJ,MAAMC,EAAW,IAAI,QAAW,CAACC,EAASC,IAC1C,CACeJ,EAAAG,EACDF,EAAAG,CAAA,CACb,EAED,KAAK,SAAWF,EAAS,KAAKL,EAAaC,CAAU,EAErD,KAAK,SAAWE,EAChB,KAAK,QAAUC,CACnB,CAEA,IAAW,SACX,CACI,OAAO,KAAK,QAChB,CACA,IAAW,QACX,CACI,OAAO,KAAK,OAChB,CAEO,KAAuBJ,EAA0CC,EAExE,CACI,OAAO,KAAK,SAAS,KAAKD,EAAaC,CAAU,CACrD,CACO,MAAaA,EACpB,CACW,OAAA,KAAK,SAAS,MAAMA,CAAU,CACzC,CACO,QAAQO,EACf,CACW,OAAA,KAAK,SAAS,QAAQA,CAAS,CAC1C,CACJ,CChDA,MAAqBC,UAAkB,KACvC,CACI,OAAc,YAAYC,EAC1B,CACI,GAAIA,aAAiBD,EAEV,OAAAC,EAEX,GAAIA,aAA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,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>, 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,EAEr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OO,SAASG,EAAOC,EAAc,EAAGC,EAAcC,EACtD,CAOI,GANID,IAAQ,SAEFA,EAAAD,EACAA,EAAA,GAGNA,IAAQC,EAED,OAAAD,EAGP,IAAAG,EAEJ,GAAID,IAAa,GAEbC,EAAWT,GAAUA,UAEhBQ,IAAa,OAEd,KAAK,IAAID,EAAMD,CAAG,GAAK,EAEvBG,EAAWT,GAAUA,EAIrBS,EAAU,KAAK,cAGdD,IAAa,GAElBC,EAAU,KAAK,UAGnB,CACI,MAAMC,EAAS,IAAMF,EAErBC,EAAWT,GAAU,KAAK,MAAMA,EAAQU,CAAM,EAAIA,CACtD,CAEA,OAAOD,EAAQ,KAAK,OAAA,GAAYF,EAAMD,GAAOA,CAAG,CACpD,CC5DO,SAASK,EAAWX,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMY,EAAU"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,8 +14,8 @@ export default class DeferredPromise<T = void, E = unknown, F = T, R = never>
|
|
|
14
14
|
|
|
15
15
|
const _promise = new Promise<T>((resolve, reject) =>
|
|
16
16
|
{
|
|
17
|
-
_resolve = resolve
|
|
18
|
-
_reject = reject
|
|
17
|
+
_resolve = resolve as PromiseResolver<T>;
|
|
18
|
+
_reject = reject as PromiseRejecter<E>;
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
this._promise = _promise.then(onFulfilled, onRejected);
|
package/src/types.ts
CHANGED
|
@@ -4,6 +4,6 @@ export type MaybePromise<T> = T | PromiseLike<T>;
|
|
|
4
4
|
export type FulfilledHandler<T = void, R = T> = (value: T) => MaybePromise<R>;
|
|
5
5
|
export type RejectedHandler<E = unknown, R = never> = (reason: E) => MaybePromise<R>;
|
|
6
6
|
|
|
7
|
-
export type PromiseResolver<T = void> = (result
|
|
8
|
-
export type PromiseRejecter<E = unknown> = (reason
|
|
7
|
+
export type PromiseResolver<T = void> = (result?: MaybePromise<T>) => void;
|
|
8
|
+
export type PromiseRejecter<E = unknown> = (reason?: MaybePromise<E>) => void;
|
|
9
9
|
export type PromiseExecutor<T = void, E = unknown> = (resolve: PromiseResolver<T>, reject: PromiseRejecter<E>) => void;
|