@operato/utils
Advanced tools
Comparing version 2.0.0-alpha.0 to 2.0.0-alpha.8
@@ -6,2 +6,11 @@ # Change Log | ||
## [2.0.0-alpha.8](https://github.com/hatiolab/operato/compare/v2.0.0-alpha.7...v2.0.0-alpha.8) (2024-01-20) | ||
### :bug: Bug Fix | ||
* comment for libraries ([bdf20d0](https://github.com/hatiolab/operato/commit/bdf20d057819187106b4a9e37d25c2c1f7febb39)) | ||
## [2.0.0-alpha.0](https://github.com/hatiolab/operato/compare/v1.13.1...v2.0.0-alpha.0) (2024-01-05) | ||
@@ -8,0 +17,0 @@ |
@@ -0,2 +1,8 @@ | ||
/** | ||
* Type definition for available filter operators that can be used in query filters. | ||
*/ | ||
declare type FilterOperator = 'search' | 'eq' | 'between' | 'gte' | 'lte' | 'is_not_true' | 'in' | 'like' | 'i_like' | 'noteq' | 'is_empty_num_id' | 'is_blank' | 'is_present' | 'is_not_false' | 'is_true' | 'is_false' | 'is_not_null' | 'is_null' | 'notin_with_null' | 'notin' | 'gt' | 'lt' | 'i_nlike' | 'nlike'; | ||
/** | ||
* Type definition for a query filter that can be applied to filter data. | ||
*/ | ||
declare type QueryFilter = { | ||
@@ -7,3 +13,11 @@ name: string; | ||
}; | ||
/** | ||
* A utility function to adjust query filters based on changes provided in `filtersChange`. | ||
* | ||
* @param {QueryFilter[]} filters - The current query filters. | ||
* @param {QueryFilter[]} filtersChange - The changes to be applied to the filters. | ||
* @param {boolean} replaceIf - A flag indicating whether to replace existing filters if a filter with the same name exists. | ||
* @returns {QueryFilter[]} The adjusted query filters. | ||
*/ | ||
export declare function adjustFilters(filters: QueryFilter[], filtersChange: QueryFilter[], replaceIf?: boolean): QueryFilter[]; | ||
export {}; |
@@ -0,1 +1,9 @@ | ||
/** | ||
* A utility function to adjust query filters based on changes provided in `filtersChange`. | ||
* | ||
* @param {QueryFilter[]} filters - The current query filters. | ||
* @param {QueryFilter[]} filtersChange - The changes to be applied to the filters. | ||
* @param {boolean} replaceIf - A flag indicating whether to replace existing filters if a filter with the same name exists. | ||
* @returns {QueryFilter[]} The adjusted query filters. | ||
*/ | ||
export function adjustFilters(filters, filtersChange, replaceIf = true) { | ||
@@ -2,0 +10,0 @@ var filtersNew = [...filters]; |
@@ -0,6 +1,19 @@ | ||
/** | ||
* A simple asynchronous lock utility class that allows controlling access to a critical section. | ||
* It provides a mechanism to create a lock and wait for its release using promises. | ||
*/ | ||
export declare class AsyncLock { | ||
unlock?: any; | ||
promise?: Promise<unknown> | undefined; | ||
/** | ||
* Creates an instance of the AsyncLock class. | ||
* | ||
* @param {boolean} [lock=false] - Optional parameter to lock the instance immediately upon creation. | ||
*/ | ||
constructor(lock?: boolean); | ||
/** | ||
* Locks the instance, making it awaitable until unlocked. | ||
* A new promise is created for the lock, and the existing unlock function is replaced with a new one. | ||
*/ | ||
lock(): void; | ||
} |
@@ -0,2 +1,11 @@ | ||
/** | ||
* A simple asynchronous lock utility class that allows controlling access to a critical section. | ||
* It provides a mechanism to create a lock and wait for its release using promises. | ||
*/ | ||
export class AsyncLock { | ||
/** | ||
* Creates an instance of the AsyncLock class. | ||
* | ||
* @param {boolean} [lock=false] - Optional parameter to lock the instance immediately upon creation. | ||
*/ | ||
constructor(lock = false) { | ||
@@ -8,2 +17,6 @@ this.promise = new Promise(resolve => (this.unlock = resolve)); | ||
} | ||
/** | ||
* Locks the instance, making it awaitable until unlocked. | ||
* A new promise is created for the lock, and the existing unlock function is replaced with a new one. | ||
*/ | ||
lock() { | ||
@@ -10,0 +23,0 @@ this.promise = new Promise(resolve => (this.unlock = resolve)); |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Copies the specified text to the clipboard. | ||
* | ||
* @param {string} textToCopy - The text to be copied to the clipboard. | ||
* @param {string} [type] - Optional MIME type for the clipboard data (e.g., 'text/plain', 'text/html'). | ||
* @returns {Promise<void>} - A promise that resolves when the text is successfully copied to the clipboard. | ||
*/ | ||
export declare function copyToClipboard(textToCopy: string, type?: string): Promise<void>; |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Copies the specified text to the clipboard. | ||
* | ||
* @param {string} textToCopy - The text to be copied to the clipboard. | ||
* @param {string} [type] - Optional MIME type for the clipboard data (e.g., 'text/plain', 'text/html'). | ||
* @returns {Promise<void>} - A promise that resolves when the text is successfully copied to the clipboard. | ||
*/ | ||
export async function copyToClipboard(textToCopy, type) { | ||
@@ -2,0 +9,0 @@ if (navigator.clipboard && window.isSecureContext) { |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Finds the closest ancestor element of the given base element that matches the provided CSS selector. | ||
* | ||
* @param {string} selector - The CSS selector to search for. | ||
* @param {Element} base - The base element to start the search from. | ||
* @returns {Element | null} - The closest ancestor element matching the selector, or null if none is found. | ||
*/ | ||
export declare function closestElement(selector: string, base: Element): Element | null; |
/* | ||
* inspired by https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd | ||
*/ | ||
/** | ||
* Finds the closest ancestor element of the given base element that matches the provided CSS selector. | ||
* | ||
* @param {string} selector - The CSS selector to search for. | ||
* @param {Element} base - The base element to start the search from. | ||
* @returns {Element | null} - The closest ancestor element matching the selector, or null if none is found. | ||
*/ | ||
export function closestElement(selector, base) { | ||
@@ -5,0 +12,0 @@ function __closestFrom(el) { |
@@ -0,1 +1,11 @@ | ||
/** | ||
* Parses the given pathname and extracts information about the contextPath, prefix, domain, and path. | ||
* | ||
* @param {string} pathname - The pathname to parse. | ||
* @returns {object} - An object containing the parsed information: | ||
* - contextPath: The context path portion of the pathname. | ||
* - prefix: The prefix portion of the pathname. | ||
* - domain: The domain portion of the pathname. | ||
* - path: The remaining path after contextPath, prefix, and domain. | ||
*/ | ||
export declare function getPathInfo(pathname: string): { | ||
@@ -7,2 +17,7 @@ contextPath: string; | ||
}; | ||
/** | ||
* Sets the context path prefix used for parsing pathnames. | ||
* | ||
* @param {string} contextPathPrefix - The new context path prefix to set. | ||
*/ | ||
export declare function setContextPathPrefix(contextPathPrefix?: string): void; |
@@ -0,2 +1,17 @@ | ||
/** | ||
* A regular expression pattern used to parse the pathname into different parts. | ||
* It captures the contextPath, prefix, domain, and path. | ||
* Example: /contextPathPrefix/domain/path/to/resource | ||
*/ | ||
var CONTEXT_PATH_PREFIX = 'domain|business'; | ||
/** | ||
* Parses the given pathname and extracts information about the contextPath, prefix, domain, and path. | ||
* | ||
* @param {string} pathname - The pathname to parse. | ||
* @returns {object} - An object containing the parsed information: | ||
* - contextPath: The context path portion of the pathname. | ||
* - prefix: The prefix portion of the pathname. | ||
* - domain: The domain portion of the pathname. | ||
* - path: The remaining path after contextPath, prefix, and domain. | ||
*/ | ||
export function getPathInfo(pathname) { | ||
@@ -16,2 +31,7 @@ var regexp = new RegExp(`(/(${CONTEXT_PATH_PREFIX})/([^/]+))?(/?.*)`); | ||
} | ||
/** | ||
* Sets the context path prefix used for parsing pathnames. | ||
* | ||
* @param {string} contextPathPrefix - The new context path prefix to set. | ||
*/ | ||
export function setContextPathPrefix(contextPathPrefix) { | ||
@@ -18,0 +38,0 @@ console.log('context-path-prefix was just set to ', `'${contextPathPrefix || 'domain|business'}'`); |
@@ -0,3 +1,21 @@ | ||
/** | ||
* Sets a cookie with the given name, value, and expiration days. | ||
* | ||
* @param {string} cname - The name of the cookie. | ||
* @param {string} cvalue - The value to be stored in the cookie. | ||
* @param {number} exdays - The number of days until the cookie expires. | ||
*/ | ||
export declare function setCookie(cname: string, cvalue: string, exdays: number): void; | ||
/** | ||
* Retrieves the value of a cookie with the given name. | ||
* | ||
* @param {string} cname - The name of the cookie to retrieve. | ||
* @returns {string} - The value of the cookie, or an empty string if the cookie is not found. | ||
*/ | ||
export declare function getCookie(cname: string): string; | ||
/** | ||
* Deletes a cookie with the given name. | ||
* | ||
* @param {string} name - The name of the cookie to delete. | ||
*/ | ||
export declare function deleteCookie(name: string): void; |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Sets a cookie with the given name, value, and expiration days. | ||
* | ||
* @param {string} cname - The name of the cookie. | ||
* @param {string} cvalue - The value to be stored in the cookie. | ||
* @param {number} exdays - The number of days until the cookie expires. | ||
*/ | ||
export function setCookie(cname, cvalue, exdays) { | ||
@@ -7,2 +14,8 @@ var d = new Date(); | ||
} | ||
/** | ||
* Retrieves the value of a cookie with the given name. | ||
* | ||
* @param {string} cname - The name of the cookie to retrieve. | ||
* @returns {string} - The value of the cookie, or an empty string if the cookie is not found. | ||
*/ | ||
export function getCookie(cname) { | ||
@@ -23,2 +36,7 @@ var name = cname + '='; | ||
} | ||
/** | ||
* Deletes a cookie with the given name. | ||
* | ||
* @param {string} name - The name of the cookie to delete. | ||
*/ | ||
export function deleteCookie(name) { | ||
@@ -25,0 +43,0 @@ document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Detects if the content of an HTMLElement overflows its boundaries. | ||
* | ||
* @param {HTMLElement} el - The HTMLElement to check for overflow. | ||
* @returns {boolean} - `true` if overflow is detected, `false` otherwise. | ||
*/ | ||
export declare function detectOverflow(el: HTMLElement): boolean; |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Detects if the content of an HTMLElement overflows its boundaries. | ||
* | ||
* @param {HTMLElement} el - The HTMLElement to check for overflow. | ||
* @returns {boolean} - `true` if overflow is detected, `false` otherwise. | ||
*/ | ||
export function detectOverflow(el) { | ||
@@ -2,0 +8,0 @@ var styleOverflow = el.style.overflow; |
@@ -0,1 +1,13 @@ | ||
/** | ||
* Formats a number according to the given mask. | ||
* | ||
* ```example | ||
* var formattedValue = format('+$#,##0.00', 12345.67); | ||
* console.log(formattedValue); // Output: +$12,345.67 | ||
* ``` | ||
* | ||
* @param {any} mask - The formatting mask to apply. | ||
* @param {any} value - The value to format. | ||
* @returns {string} - The formatted string. | ||
*/ | ||
export declare function format(mask: any, value: any): string; |
@@ -5,2 +5,14 @@ /* | ||
*/ | ||
/** | ||
* Formats a number according to the given mask. | ||
* | ||
* ```example | ||
* var formattedValue = format('+$#,##0.00', 12345.67); | ||
* console.log(formattedValue); // Output: +$12,345.67 | ||
* ``` | ||
* | ||
* @param {any} mask - The formatting mask to apply. | ||
* @param {any} value - The value to format. | ||
* @returns {string} - The formatted string. | ||
*/ | ||
export function format(mask, value) { | ||
@@ -7,0 +19,0 @@ if (!mask || isNaN(+value)) { |
@@ -0,3 +1,18 @@ | ||
/** | ||
* Logs an error message with optional stack trace. | ||
* | ||
* @param {...any} args - The error message and optional additional data. | ||
*/ | ||
export declare var error: (...args: any[]) => void; | ||
/** | ||
* Logs a warning message with optional stack trace. | ||
* | ||
* @param {...any} args - The warning message and optional additional data. | ||
*/ | ||
export declare var warn: (...args: any[]) => void; | ||
/** | ||
* Logs a debug message. | ||
* | ||
* @param {...any} args - The debug message and optional additional data. | ||
*/ | ||
export declare var debug: (...args: any[]) => void; |
@@ -1,7 +0,9 @@ | ||
/* | ||
* Copyright © HatioLab Inc. All rights reserved. | ||
*/ | ||
const ERROR = '[ERROR]'; | ||
const WARN = '[WARN]'; | ||
const DEBUG = '[DEBUG]'; | ||
/** | ||
* Logs an error message with optional stack trace. | ||
* | ||
* @param {...any} args - The error message and optional additional data. | ||
*/ | ||
export var error = (...args) => { | ||
@@ -12,2 +14,7 @@ var trace = []; | ||
}; | ||
/** | ||
* Logs a warning message with optional stack trace. | ||
* | ||
* @param {...any} args - The warning message and optional additional data. | ||
*/ | ||
export var warn = (...args) => { | ||
@@ -18,3 +25,8 @@ var trace = []; | ||
}; | ||
/** | ||
* Logs a debug message. | ||
* | ||
* @param {...any} args - The debug message and optional additional data. | ||
*/ | ||
export var debug = (...args) => console.log(DEBUG, ...args); | ||
//# sourceMappingURL=logger.js.map |
type Constructor = new (...args: any[]) => {}; | ||
/** | ||
* A higher-order function that enhances a base class with infinite scrolling functionality. | ||
* | ||
* @template TBase - The base class constructor type. | ||
* @param {TBase} Base - The base class to enhance with infinite scrolling. | ||
* @returns {TBase & InfiniteScrollable} - The extended class with infinite scrolling capabilities. | ||
*/ | ||
export default function InfiniteScrollable<TBase extends Constructor>(Base: TBase): { | ||
new (...args: any[]): { | ||
/** | ||
* Default options for infinite scrolling. | ||
* | ||
* @type {object} | ||
* @property {number} threshold - The threshold value to trigger loading more items. | ||
* @property {number} limit - The limit of items to load per page. | ||
* @property {string} totalProp - The property name for the total number of items. | ||
* @property {string} pageProp - The property name for the current page number. | ||
*/ | ||
_infiniteScrollOptions: { | ||
@@ -10,3 +26,11 @@ threshold: number; | ||
}; | ||
/** | ||
* Event handler for the scroll event with debouncing. | ||
* | ||
* @param {Event} e - The scroll event object. | ||
*/ | ||
onScroll: import("lodash").DebouncedFunc<(e: any) => void>; | ||
/** | ||
* An async function to handle scroll action when the threshold is reached. | ||
*/ | ||
scrollAction(): Promise<void>; | ||
@@ -13,0 +37,0 @@ }; |
import debounce from 'lodash-es/debounce'; | ||
/** | ||
* A higher-order function that enhances a base class with infinite scrolling functionality. | ||
* | ||
* @template TBase - The base class constructor type. | ||
* @param {TBase} Base - The base class to enhance with infinite scrolling. | ||
* @returns {TBase & InfiniteScrollable} - The extended class with infinite scrolling capabilities. | ||
*/ | ||
export default function InfiniteScrollable(Base) { | ||
@@ -6,2 +13,11 @@ return class Scrolling extends Base { | ||
super(...arguments); | ||
/** | ||
* Default options for infinite scrolling. | ||
* | ||
* @type {object} | ||
* @property {number} threshold - The threshold value to trigger loading more items. | ||
* @property {number} limit - The limit of items to load per page. | ||
* @property {string} totalProp - The property name for the total number of items. | ||
* @property {string} pageProp - The property name for the current page number. | ||
*/ | ||
this._infiniteScrollOptions = { | ||
@@ -13,2 +29,7 @@ threshold: 20, | ||
}; | ||
/** | ||
* Event handler for the scroll event with debouncing. | ||
* | ||
* @param {Event} e - The scroll event object. | ||
*/ | ||
this.onScroll = debounce(e => { | ||
@@ -33,2 +54,5 @@ //@ts-ignore inheritted class should have scrollTargetEl property | ||
// } | ||
/** | ||
* An async function to handle scroll action when the threshold is reached. | ||
*/ | ||
async scrollAction() { | ||
@@ -35,0 +59,0 @@ console.warn('scroll action not implemented.'); |
@@ -26,2 +26,6 @@ /** | ||
export declare function isMacOS(): boolean; | ||
/** | ||
* method to tell if platform of running browser is Safari | ||
* @returns {boolean} | ||
*/ | ||
export declare function isSafari(): false | RegExpMatchArray | null; |
@@ -37,2 +37,6 @@ /** | ||
} | ||
/** | ||
* method to tell if platform of running browser is Safari | ||
* @returns {boolean} | ||
*/ | ||
export function isSafari() { | ||
@@ -39,0 +43,0 @@ return !navigator.userAgent.match(/chrome|chromium|crios/i) && navigator.userAgent.match(/safari/i); |
@@ -0,1 +1,16 @@ | ||
/** | ||
* Generates a regular expression pattern for validating passwords based on specified criteria. | ||
* | ||
* @param {object} options - An object containing options for generating the pattern. | ||
* @param {boolean} options.lowerCase - Indicates whether the password should contain at least one lowercase character. | ||
* @param {boolean} options.upperCase - Indicates whether the password should contain at least one uppercase character. | ||
* @param {boolean} options.digit - Indicates whether the password should contain at least one digit. | ||
* @param {boolean} options.specialCharacter - Indicates whether the password should contain at least one special character. | ||
* @param {boolean} options.allowRepeat - Indicates whether repeated characters are allowed in the password. | ||
* @param {boolean} options.useTightPattern - Indicates whether to use a tight pattern for password length. | ||
* @param {boolean} options.useLoosePattern - Indicates whether to use a loose pattern for password length. | ||
* @param {number} options.tightCharacterLength - The minimum length of the password for the tight pattern. | ||
* @param {number} options.looseCharacterLength - The minimum length of the password for the loose pattern. | ||
* @returns {RegExp} - A regular expression pattern for validating passwords based on the specified criteria. | ||
*/ | ||
export declare function generatePasswordPatternRegExp({ lowerCase, upperCase, digit, specialCharacter, allowRepeat, useTightPattern, useLoosePattern, tightCharacterLength, looseCharacterLength }?: { | ||
@@ -2,0 +17,0 @@ lowerCase?: boolean; |
@@ -0,1 +1,16 @@ | ||
/** | ||
* Generates a regular expression pattern for validating passwords based on specified criteria. | ||
* | ||
* @param {object} options - An object containing options for generating the pattern. | ||
* @param {boolean} options.lowerCase - Indicates whether the password should contain at least one lowercase character. | ||
* @param {boolean} options.upperCase - Indicates whether the password should contain at least one uppercase character. | ||
* @param {boolean} options.digit - Indicates whether the password should contain at least one digit. | ||
* @param {boolean} options.specialCharacter - Indicates whether the password should contain at least one special character. | ||
* @param {boolean} options.allowRepeat - Indicates whether repeated characters are allowed in the password. | ||
* @param {boolean} options.useTightPattern - Indicates whether to use a tight pattern for password length. | ||
* @param {boolean} options.useLoosePattern - Indicates whether to use a loose pattern for password length. | ||
* @param {number} options.tightCharacterLength - The minimum length of the password for the tight pattern. | ||
* @param {number} options.looseCharacterLength - The minimum length of the password for the loose pattern. | ||
* @returns {RegExp} - A regular expression pattern for validating passwords based on the specified criteria. | ||
*/ | ||
export function generatePasswordPatternRegExp({ lowerCase = true, upperCase = true, digit = true, specialCharacter = true, allowRepeat = false, useTightPattern = true, useLoosePattern = false, tightCharacterLength = 8, looseCharacterLength = 15 } = {}) { | ||
@@ -2,0 +17,0 @@ var tightChecklist = useTightPattern |
@@ -0,1 +1,12 @@ | ||
/** | ||
* Converts a large number into a human-readable string representation with SI unit prefixes (K, M, B, T, P, E). | ||
* | ||
* This function takes a large number as input and converts it into a human-readable string representation using SI unit prefixes | ||
* (K for thousand, M for million, B for billion, T for trillion, P for quadrillion, E for quintillion, etc.). | ||
* It checks the magnitude of the input number and selects the appropriate SI unit, | ||
* then formats the number with two decimal places and appends the corresponding SI unit symbol to create the readable string. | ||
* | ||
* @param {number} n - The number to be converted. | ||
* @returns {string} - A human-readable string representation of the number with SI unit prefixes. | ||
*/ | ||
export declare function stringifyBigNumber(n: number): string | number; |
@@ -0,1 +1,12 @@ | ||
/** | ||
* Converts a large number into a human-readable string representation with SI unit prefixes (K, M, B, T, P, E). | ||
* | ||
* This function takes a large number as input and converts it into a human-readable string representation using SI unit prefixes | ||
* (K for thousand, M for million, B for billion, T for trillion, P for quadrillion, E for quintillion, etc.). | ||
* It checks the magnitude of the input number and selects the appropriate SI unit, | ||
* then formats the number with two decimal places and appends the corresponding SI unit symbol to create the readable string. | ||
* | ||
* @param {number} n - The number to be converted. | ||
* @returns {string} - A human-readable string representation of the number with SI unit prefixes. | ||
*/ | ||
export function stringifyBigNumber(n) { | ||
@@ -2,0 +13,0 @@ if (n < 1000) { |
import { TimeCapsule } from './timecapsule'; | ||
/** | ||
* Type definition for holding state information. | ||
* @typedef {Object} StateHolder | ||
* @property {*} state - The state to be held. | ||
*/ | ||
export type StateHolder = { | ||
state: any; | ||
}; | ||
/** | ||
* Class responsible for taking and managing snapshots of state. | ||
*/ | ||
export declare class SnapshotTaker { | ||
@@ -10,8 +18,31 @@ private _brake; | ||
timecapsule?: TimeCapsule; | ||
/** | ||
* Creates an instance of SnapshotTaker. | ||
* @param {*} state_holder - The object that holds the state to be snapshot. | ||
* @param {TimeCapsule} timecapsule - The TimeCapsule instance associated with this SnapshotTaker. | ||
*/ | ||
constructor(state_holder: any, timecapsule: TimeCapsule); | ||
/** | ||
* Disposes of the SnapshotTaker and clears associated references. | ||
*/ | ||
dispose(): void; | ||
/** | ||
* Marks the SnapshotTaker as dirty and initiates snapshot creation. | ||
*/ | ||
touch(): void; | ||
/** | ||
* Takes a snapshot of the current state. | ||
* @param {boolean} [force=false] - If true, the snapshot is taken even if not dirty. | ||
*/ | ||
take(force?: boolean): void; | ||
/** | ||
* Gets the brake state of the SnapshotTaker. | ||
* @returns {boolean} - true if the brake is active, false otherwise. | ||
*/ | ||
get brake(): boolean; | ||
/** | ||
* Sets the brake state of the SnapshotTaker and initiates snapshot creation. | ||
* @param {boolean} brake - The new brake state. | ||
*/ | ||
set brake(brake: boolean); | ||
} |
@@ -1,5 +0,7 @@ | ||
/* | ||
* Copyright © HatioLab Inc. All rights reserved. | ||
import debounce from 'lodash-es/debounce'; | ||
/** | ||
* A function that takes a SnapshotTaker as an argument and initiates snapshot creation | ||
* using a debouncer to delay the process. | ||
* @param {SnapshotTaker} taker - The SnapshotTaker instance to trigger snapshots for. | ||
*/ | ||
import debounce from 'lodash-es/debounce'; | ||
var debouncer = debounce(taker => { | ||
@@ -10,2 +12,7 @@ if (!taker.brake) { | ||
}, 1000, { leading: true, trailing: false }); | ||
/** | ||
* Function to trigger snapshot creation for a SnapshotTaker instance. | ||
* Checks if the taker is in a brake state or not dirty before triggering the snapshot. | ||
* @param {SnapshotTaker} taker - The SnapshotTaker instance to create a snapshot for. | ||
*/ | ||
function take_snapshot(taker) { | ||
@@ -16,3 +23,11 @@ if (taker.brake || !taker.dirty) | ||
} | ||
/** | ||
* Class responsible for taking and managing snapshots of state. | ||
*/ | ||
export class SnapshotTaker { | ||
/** | ||
* Creates an instance of SnapshotTaker. | ||
* @param {*} state_holder - The object that holds the state to be snapshot. | ||
* @param {TimeCapsule} timecapsule - The TimeCapsule instance associated with this SnapshotTaker. | ||
*/ | ||
constructor(state_holder, timecapsule) { | ||
@@ -25,2 +40,5 @@ this._brake = false; | ||
} | ||
/** | ||
* Disposes of the SnapshotTaker and clears associated references. | ||
*/ | ||
dispose() { | ||
@@ -30,2 +48,5 @@ delete this.state_holder; | ||
} | ||
/** | ||
* Marks the SnapshotTaker as dirty and initiates snapshot creation. | ||
*/ | ||
touch() { | ||
@@ -36,2 +57,6 @@ this.dirty = true; | ||
/* 모든 조건에 관계없이 현재 상태를 snapshot으로 취한다. */ | ||
/** | ||
* Takes a snapshot of the current state. | ||
* @param {boolean} [force=false] - If true, the snapshot is taken even if not dirty. | ||
*/ | ||
take(force = false) { | ||
@@ -44,2 +69,6 @@ var _a, _b; | ||
} | ||
/** | ||
* Gets the brake state of the SnapshotTaker. | ||
* @returns {boolean} - true if the brake is active, false otherwise. | ||
*/ | ||
get brake() { | ||
@@ -49,2 +78,6 @@ return this._brake; | ||
/* 마우스를 드래깅하는 동안, 보통 brake 를 ON 시킨다. */ | ||
/** | ||
* Sets the brake state of the SnapshotTaker and initiates snapshot creation. | ||
* @param {boolean} brake - The new brake state. | ||
*/ | ||
set brake(brake) { | ||
@@ -51,0 +84,0 @@ this._brake = !!brake; |
import { SnapshotTaker } from './snapshot-taker'; | ||
/** | ||
* A utility class for managing and navigating through a history of snapshots. | ||
*/ | ||
export declare class TimeCapsule { | ||
@@ -7,14 +10,61 @@ private q; | ||
private _snapshot_taker; | ||
/** | ||
* Creates an instance of TimeCapsule. | ||
* @param {number} maxsize - The maximum number of snapshots to store. | ||
* @param {any} [start_state] - The initial state to be stored as the first snapshot (optional). | ||
*/ | ||
constructor(maxsize: number, start_state?: any); | ||
/** | ||
* Disposes of the TimeCapsule and clears all stored snapshots. | ||
*/ | ||
dispose(): void; | ||
/** | ||
* Captures a snapshot of the current state and stores it. | ||
* @param {any} state - The state to be captured as a snapshot. | ||
*/ | ||
snapshot(state: any): void; | ||
/** | ||
* Moves forward to the next snapshot in the history. | ||
* @returns {any} The next state snapshot if available, or logs a warning if not. | ||
*/ | ||
forward(): any; | ||
/** | ||
* Moves backward to the previous snapshot in the history. | ||
* @returns {any} The previous state snapshot if available, or logs a warning if not. | ||
*/ | ||
backward(): any; | ||
/** | ||
* Gets the current state snapshot. | ||
* @returns {any} The current state snapshot if available, or logs a warning if not. | ||
*/ | ||
get current(): any; | ||
/** | ||
* Gets the number of snapshots stored in the TimeCapsule. | ||
* @returns {number} The count of stored snapshots. | ||
*/ | ||
get length(): number; | ||
/** | ||
* Checks if there is a snapshot available to move forward. | ||
* @returns {boolean} True if moving forward is possible, otherwise false. | ||
*/ | ||
get forwardable(): boolean; | ||
/** | ||
* Checks if there is a snapshot available to move backward. | ||
* @returns {boolean} True if moving backward is possible, otherwise false. | ||
*/ | ||
get backwardable(): boolean; | ||
/** | ||
* Gets the SnapshotTaker associated with this TimeCapsule. | ||
* @returns {SnapshotTaker | null} The associated SnapshotTaker, or null if not set. | ||
*/ | ||
get snapshot_taker(): SnapshotTaker | null; | ||
/** | ||
* Sets the SnapshotTaker for this TimeCapsule. | ||
* @param {SnapshotTaker | null} snapshot_taker - The SnapshotTaker instance to associate with this TimeCapsule. | ||
*/ | ||
set snapshot_taker(snapshot_taker: SnapshotTaker | null); | ||
/** | ||
* Resets the TimeCapsule, clearing all stored snapshots and resetting the position. | ||
*/ | ||
reset(): void; | ||
} |
@@ -1,6 +0,11 @@ | ||
/* | ||
* Copyright © HatioLab Inc. All rights reserved. | ||
import { error, warn } from '../logger'; | ||
/** | ||
* A utility class for managing and navigating through a history of snapshots. | ||
*/ | ||
import { error, warn } from '../logger'; | ||
export class TimeCapsule { | ||
/** | ||
* Creates an instance of TimeCapsule. | ||
* @param {number} maxsize - The maximum number of snapshots to store. | ||
* @param {any} [start_state] - The initial state to be stored as the first snapshot (optional). | ||
*/ | ||
constructor(maxsize, start_state) { | ||
@@ -23,5 +28,12 @@ this.q = []; | ||
} | ||
/** | ||
* Disposes of the TimeCapsule and clears all stored snapshots. | ||
*/ | ||
dispose() { | ||
this.reset(); | ||
} | ||
/** | ||
* Captures a snapshot of the current state and stores it. | ||
* @param {any} state - The state to be captured as a snapshot. | ||
*/ | ||
snapshot(state) { | ||
@@ -34,2 +46,6 @@ this.q.splice(this.pos + 1, this.q.length - (this.pos + 1), state); | ||
} | ||
/** | ||
* Moves forward to the next snapshot in the history. | ||
* @returns {any} The next state snapshot if available, or logs a warning if not. | ||
*/ | ||
forward() { | ||
@@ -43,2 +59,6 @@ if (this.snapshot_taker) | ||
} | ||
/** | ||
* Moves backward to the previous snapshot in the history. | ||
* @returns {any} The previous state snapshot if available, or logs a warning if not. | ||
*/ | ||
backward() { | ||
@@ -52,2 +72,6 @@ if (this.snapshot_taker) | ||
} | ||
/** | ||
* Gets the current state snapshot. | ||
* @returns {any} The current state snapshot if available, or logs a warning if not. | ||
*/ | ||
get current() { | ||
@@ -58,17 +82,40 @@ if (this.pos !== -1) | ||
} | ||
/** | ||
* Gets the number of snapshots stored in the TimeCapsule. | ||
* @returns {number} The count of stored snapshots. | ||
*/ | ||
get length() { | ||
return this.q.length; | ||
} | ||
/** | ||
* Checks if there is a snapshot available to move forward. | ||
* @returns {boolean} True if moving forward is possible, otherwise false. | ||
*/ | ||
get forwardable() { | ||
return this.pos < this.q.length - 1; | ||
} | ||
/** | ||
* Checks if there is a snapshot available to move backward. | ||
* @returns {boolean} True if moving backward is possible, otherwise false. | ||
*/ | ||
get backwardable() { | ||
return this.pos > 0; | ||
} | ||
/** | ||
* Gets the SnapshotTaker associated with this TimeCapsule. | ||
* @returns {SnapshotTaker | null} The associated SnapshotTaker, or null if not set. | ||
*/ | ||
get snapshot_taker() { | ||
return this._snapshot_taker; | ||
} | ||
/** | ||
* Sets the SnapshotTaker for this TimeCapsule. | ||
* @param {SnapshotTaker | null} snapshot_taker - The SnapshotTaker instance to associate with this TimeCapsule. | ||
*/ | ||
set snapshot_taker(snapshot_taker) { | ||
this._snapshot_taker = snapshot_taker; | ||
} | ||
/** | ||
* Resets the TimeCapsule, clearing all stored snapshots and resetting the position. | ||
*/ | ||
reset() { | ||
@@ -75,0 +122,0 @@ this.q = []; |
@@ -5,3 +5,3 @@ { | ||
"author": "heartyoh", | ||
"version": "2.0.0-alpha.0", | ||
"version": "2.0.0-alpha.8", | ||
"main": "dist/src/index.js", | ||
@@ -121,3 +121,3 @@ "module": "dist/src/index.js", | ||
}, | ||
"gitHead": "f995e977847947a1ac4043ff7c627a5cf2ada67b" | ||
"gitHead": "9b76564615d73b9da50d13d30d43cdaa0d4a6fa6" | ||
} |
@@ -0,1 +1,4 @@ | ||
/** | ||
* Type definition for available filter operators that can be used in query filters. | ||
*/ | ||
declare type FilterOperator = | ||
@@ -27,2 +30,5 @@ | 'search' | ||
/** | ||
* Type definition for a query filter that can be applied to filter data. | ||
*/ | ||
declare type QueryFilter = { | ||
@@ -34,2 +40,5 @@ name: string | ||
/** | ||
* Type definition for sorting parameters that can be applied to sort data in a query. | ||
*/ | ||
declare type QuerySorter = { | ||
@@ -40,2 +49,5 @@ name: string | ||
/** | ||
* Type definition for pagination parameters that can be applied to paginate query results. | ||
*/ | ||
declare type QueryPaginator = { | ||
@@ -46,2 +58,10 @@ page?: number | ||
/** | ||
* A utility function to adjust query filters based on changes provided in `filtersChange`. | ||
* | ||
* @param {QueryFilter[]} filters - The current query filters. | ||
* @param {QueryFilter[]} filtersChange - The changes to be applied to the filters. | ||
* @param {boolean} replaceIf - A flag indicating whether to replace existing filters if a filter with the same name exists. | ||
* @returns {QueryFilter[]} The adjusted query filters. | ||
*/ | ||
export function adjustFilters( | ||
@@ -48,0 +68,0 @@ filters: QueryFilter[], |
@@ -0,1 +1,5 @@ | ||
/** | ||
* A simple asynchronous lock utility class that allows controlling access to a critical section. | ||
* It provides a mechanism to create a lock and wait for its release using promises. | ||
*/ | ||
export class AsyncLock { | ||
@@ -5,2 +9,7 @@ unlock?: any | ||
/** | ||
* Creates an instance of the AsyncLock class. | ||
* | ||
* @param {boolean} [lock=false] - Optional parameter to lock the instance immediately upon creation. | ||
*/ | ||
constructor(lock: boolean = false) { | ||
@@ -12,2 +21,6 @@ if (lock) { | ||
/** | ||
* Locks the instance, making it awaitable until unlocked. | ||
* A new promise is created for the lock, and the existing unlock function is replaced with a new one. | ||
*/ | ||
lock() { | ||
@@ -14,0 +27,0 @@ this.promise = new Promise(resolve => (this.unlock = resolve)) |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Copies the specified text to the clipboard. | ||
* | ||
* @param {string} textToCopy - The text to be copied to the clipboard. | ||
* @param {string} [type] - Optional MIME type for the clipboard data (e.g., 'text/plain', 'text/html'). | ||
* @returns {Promise<void>} - A promise that resolves when the text is successfully copied to the clipboard. | ||
*/ | ||
export async function copyToClipboard(textToCopy: string, type?: string): Promise<void> { | ||
@@ -2,0 +9,0 @@ if (navigator.clipboard && window.isSecureContext) { |
/* | ||
* inspired by https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd | ||
*/ | ||
/** | ||
* Finds the closest ancestor element of the given base element that matches the provided CSS selector. | ||
* | ||
* @param {string} selector - The CSS selector to search for. | ||
* @param {Element} base - The base element to start the search from. | ||
* @returns {Element | null} - The closest ancestor element matching the selector, or null if none is found. | ||
*/ | ||
export function closestElement(selector: string, base: Element) { | ||
@@ -5,0 +13,0 @@ function __closestFrom(el: Element | Window | Document | null): Element | null { |
@@ -0,3 +1,18 @@ | ||
/** | ||
* A regular expression pattern used to parse the pathname into different parts. | ||
* It captures the contextPath, prefix, domain, and path. | ||
* Example: /contextPathPrefix/domain/path/to/resource | ||
*/ | ||
var CONTEXT_PATH_PREFIX = 'domain|business' | ||
/** | ||
* Parses the given pathname and extracts information about the contextPath, prefix, domain, and path. | ||
* | ||
* @param {string} pathname - The pathname to parse. | ||
* @returns {object} - An object containing the parsed information: | ||
* - contextPath: The context path portion of the pathname. | ||
* - prefix: The prefix portion of the pathname. | ||
* - domain: The domain portion of the pathname. | ||
* - path: The remaining path after contextPath, prefix, and domain. | ||
*/ | ||
export function getPathInfo(pathname: string) { | ||
@@ -19,2 +34,7 @@ var regexp = new RegExp(`(/(${CONTEXT_PATH_PREFIX})/([^/]+))?(/?.*)`) | ||
/** | ||
* Sets the context path prefix used for parsing pathnames. | ||
* | ||
* @param {string} contextPathPrefix - The new context path prefix to set. | ||
*/ | ||
export function setContextPathPrefix(contextPathPrefix?: string) { | ||
@@ -21,0 +41,0 @@ console.log('context-path-prefix was just set to ', `'${contextPathPrefix || 'domain|business'}'`) |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Sets a cookie with the given name, value, and expiration days. | ||
* | ||
* @param {string} cname - The name of the cookie. | ||
* @param {string} cvalue - The value to be stored in the cookie. | ||
* @param {number} exdays - The number of days until the cookie expires. | ||
*/ | ||
export function setCookie(cname: string, cvalue: string, exdays: number) { | ||
@@ -8,2 +15,8 @@ var d = new Date() | ||
/** | ||
* Retrieves the value of a cookie with the given name. | ||
* | ||
* @param {string} cname - The name of the cookie to retrieve. | ||
* @returns {string} - The value of the cookie, or an empty string if the cookie is not found. | ||
*/ | ||
export function getCookie(cname: string) { | ||
@@ -25,4 +38,9 @@ var name = cname + '=' | ||
/** | ||
* Deletes a cookie with the given name. | ||
* | ||
* @param {string} name - The name of the cookie to delete. | ||
*/ | ||
export function deleteCookie(name: string) { | ||
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;' | ||
} |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Detects if the content of an HTMLElement overflows its boundaries. | ||
* | ||
* @param {HTMLElement} el - The HTMLElement to check for overflow. | ||
* @returns {boolean} - `true` if overflow is detected, `false` otherwise. | ||
*/ | ||
export function detectOverflow(el: HTMLElement) { | ||
@@ -2,0 +8,0 @@ var styleOverflow = el.style.overflow |
@@ -6,2 +6,14 @@ /* | ||
/** | ||
* Formats a number according to the given mask. | ||
* | ||
* ```example | ||
* var formattedValue = format('+$#,##0.00', 12345.67); | ||
* console.log(formattedValue); // Output: +$12,345.67 | ||
* ``` | ||
* | ||
* @param {any} mask - The formatting mask to apply. | ||
* @param {any} value - The value to format. | ||
* @returns {string} - The formatted string. | ||
*/ | ||
export function format(mask: any, value: any): string { | ||
@@ -8,0 +20,0 @@ if (!mask || isNaN(+value)) { |
@@ -1,5 +0,1 @@ | ||
/* | ||
* Copyright © HatioLab Inc. All rights reserved. | ||
*/ | ||
const ERROR = '[ERROR]' | ||
@@ -9,2 +5,7 @@ const WARN = '[WARN]' | ||
/** | ||
* Logs an error message with optional stack trace. | ||
* | ||
* @param {...any} args - The error message and optional additional data. | ||
*/ | ||
export var error = (...args: any[]) => { | ||
@@ -16,2 +17,7 @@ var trace = [] as string[] | ||
/** | ||
* Logs a warning message with optional stack trace. | ||
* | ||
* @param {...any} args - The warning message and optional additional data. | ||
*/ | ||
export var warn = (...args: any[]) => { | ||
@@ -23,2 +29,7 @@ var trace = [] as string[] | ||
/** | ||
* Logs a debug message. | ||
* | ||
* @param {...any} args - The debug message and optional additional data. | ||
*/ | ||
export var debug = (...args: any[]) => console.log(DEBUG, ...args) |
@@ -5,4 +5,20 @@ import debounce from 'lodash-es/debounce' | ||
/** | ||
* A higher-order function that enhances a base class with infinite scrolling functionality. | ||
* | ||
* @template TBase - The base class constructor type. | ||
* @param {TBase} Base - The base class to enhance with infinite scrolling. | ||
* @returns {TBase & InfiniteScrollable} - The extended class with infinite scrolling capabilities. | ||
*/ | ||
export default function InfiniteScrollable<TBase extends Constructor>(Base: TBase) { | ||
return class Scrolling extends Base { | ||
/** | ||
* Default options for infinite scrolling. | ||
* | ||
* @type {object} | ||
* @property {number} threshold - The threshold value to trigger loading more items. | ||
* @property {number} limit - The limit of items to load per page. | ||
* @property {string} totalProp - The property name for the total number of items. | ||
* @property {string} pageProp - The property name for the current page number. | ||
*/ | ||
_infiniteScrollOptions = { | ||
@@ -15,2 +31,7 @@ threshold: 20, | ||
/** | ||
* Event handler for the scroll event with debouncing. | ||
* | ||
* @param {Event} e - The scroll event object. | ||
*/ | ||
onScroll = debounce(e => { | ||
@@ -41,2 +62,5 @@ //@ts-ignore inheritted class should have scrollTargetEl property | ||
/** | ||
* An async function to handle scroll action when the threshold is reached. | ||
*/ | ||
async scrollAction() { | ||
@@ -43,0 +67,0 @@ console.warn('scroll action not implemented.') |
@@ -42,4 +42,8 @@ /** | ||
/** | ||
* method to tell if platform of running browser is Safari | ||
* @returns {boolean} | ||
*/ | ||
export function isSafari() { | ||
return !navigator.userAgent.match(/chrome|chromium|crios/i) && navigator.userAgent.match(/safari/i) | ||
} |
@@ -0,1 +1,16 @@ | ||
/** | ||
* Generates a regular expression pattern for validating passwords based on specified criteria. | ||
* | ||
* @param {object} options - An object containing options for generating the pattern. | ||
* @param {boolean} options.lowerCase - Indicates whether the password should contain at least one lowercase character. | ||
* @param {boolean} options.upperCase - Indicates whether the password should contain at least one uppercase character. | ||
* @param {boolean} options.digit - Indicates whether the password should contain at least one digit. | ||
* @param {boolean} options.specialCharacter - Indicates whether the password should contain at least one special character. | ||
* @param {boolean} options.allowRepeat - Indicates whether repeated characters are allowed in the password. | ||
* @param {boolean} options.useTightPattern - Indicates whether to use a tight pattern for password length. | ||
* @param {boolean} options.useLoosePattern - Indicates whether to use a loose pattern for password length. | ||
* @param {number} options.tightCharacterLength - The minimum length of the password for the tight pattern. | ||
* @param {number} options.looseCharacterLength - The minimum length of the password for the loose pattern. | ||
* @returns {RegExp} - A regular expression pattern for validating passwords based on the specified criteria. | ||
*/ | ||
export function generatePasswordPatternRegExp({ | ||
@@ -2,0 +17,0 @@ lowerCase = true, |
@@ -0,1 +1,13 @@ | ||
/** | ||
* Converts a large number into a human-readable string representation with SI unit prefixes (K, M, B, T, P, E). | ||
* | ||
* This function takes a large number as input and converts it into a human-readable string representation using SI unit prefixes | ||
* (K for thousand, M for million, B for billion, T for trillion, P for quadrillion, E for quintillion, etc.). | ||
* It checks the magnitude of the input number and selects the appropriate SI unit, | ||
* then formats the number with two decimal places and appends the corresponding SI unit symbol to create the readable string. | ||
* | ||
* @param {number} n - The number to be converted. | ||
* @returns {string} - A human-readable string representation of the number with SI unit prefixes. | ||
*/ | ||
export function stringifyBigNumber(n: number) { | ||
@@ -2,0 +14,0 @@ if (n < 1000) { |
@@ -1,8 +0,9 @@ | ||
/* | ||
* Copyright © HatioLab Inc. All rights reserved. | ||
*/ | ||
import { TimeCapsule } from './timecapsule' | ||
import debounce from 'lodash-es/debounce' | ||
/** | ||
* A function that takes a SnapshotTaker as an argument and initiates snapshot creation | ||
* using a debouncer to delay the process. | ||
* @param {SnapshotTaker} taker - The SnapshotTaker instance to trigger snapshots for. | ||
*/ | ||
var debouncer = debounce( | ||
@@ -18,2 +19,7 @@ taker => { | ||
/** | ||
* Function to trigger snapshot creation for a SnapshotTaker instance. | ||
* Checks if the taker is in a brake state or not dirty before triggering the snapshot. | ||
* @param {SnapshotTaker} taker - The SnapshotTaker instance to create a snapshot for. | ||
*/ | ||
function take_snapshot(taker: SnapshotTaker) { | ||
@@ -24,2 +30,7 @@ if (taker.brake || !taker.dirty) return | ||
/** | ||
* Type definition for holding state information. | ||
* @typedef {Object} StateHolder | ||
* @property {*} state - The state to be held. | ||
*/ | ||
export type StateHolder = { | ||
@@ -29,2 +40,5 @@ state: any | ||
/** | ||
* Class responsible for taking and managing snapshots of state. | ||
*/ | ||
export class SnapshotTaker { | ||
@@ -38,2 +52,7 @@ private _brake: boolean = false | ||
/** | ||
* Creates an instance of SnapshotTaker. | ||
* @param {*} state_holder - The object that holds the state to be snapshot. | ||
* @param {TimeCapsule} timecapsule - The TimeCapsule instance associated with this SnapshotTaker. | ||
*/ | ||
constructor(state_holder: any, timecapsule: TimeCapsule) { | ||
@@ -45,2 +64,5 @@ this.state_holder = state_holder | ||
/** | ||
* Disposes of the SnapshotTaker and clears associated references. | ||
*/ | ||
dispose() { | ||
@@ -51,2 +73,5 @@ delete this.state_holder | ||
/** | ||
* Marks the SnapshotTaker as dirty and initiates snapshot creation. | ||
*/ | ||
touch() { | ||
@@ -58,2 +83,6 @@ this.dirty = true | ||
/* 모든 조건에 관계없이 현재 상태를 snapshot으로 취한다. */ | ||
/** | ||
* Takes a snapshot of the current state. | ||
* @param {boolean} [force=false] - If true, the snapshot is taken even if not dirty. | ||
*/ | ||
take(force: boolean = false) { | ||
@@ -66,2 +95,6 @@ if (this.dirty || force) { | ||
/** | ||
* Gets the brake state of the SnapshotTaker. | ||
* @returns {boolean} - true if the brake is active, false otherwise. | ||
*/ | ||
get brake() { | ||
@@ -72,2 +105,6 @@ return this._brake | ||
/* 마우스를 드래깅하는 동안, 보통 brake 를 ON 시킨다. */ | ||
/** | ||
* Sets the brake state of the SnapshotTaker and initiates snapshot creation. | ||
* @param {boolean} brake - The new brake state. | ||
*/ | ||
set brake(brake) { | ||
@@ -74,0 +111,0 @@ this._brake = !!brake |
@@ -1,5 +0,1 @@ | ||
/* | ||
* Copyright © HatioLab Inc. All rights reserved. | ||
*/ | ||
import { debug, error, warn } from '../logger' | ||
@@ -9,2 +5,5 @@ | ||
/** | ||
* A utility class for managing and navigating through a history of snapshots. | ||
*/ | ||
export class TimeCapsule { | ||
@@ -17,2 +16,7 @@ private q: Array<any> = [] | ||
/** | ||
* Creates an instance of TimeCapsule. | ||
* @param {number} maxsize - The maximum number of snapshots to store. | ||
* @param {any} [start_state] - The initial state to be stored as the first snapshot (optional). | ||
*/ | ||
constructor(maxsize: number, start_state?: any) { | ||
@@ -33,2 +37,5 @@ maxsize = Number(maxsize) | ||
/** | ||
* Disposes of the TimeCapsule and clears all stored snapshots. | ||
*/ | ||
dispose() { | ||
@@ -38,2 +45,6 @@ this.reset() | ||
/** | ||
* Captures a snapshot of the current state and stores it. | ||
* @param {any} state - The state to be captured as a snapshot. | ||
*/ | ||
snapshot(state: any) { | ||
@@ -49,2 +60,6 @@ this.q.splice(this.pos + 1, this.q.length - (this.pos + 1), state) | ||
/** | ||
* Moves forward to the next snapshot in the history. | ||
* @returns {any} The next state snapshot if available, or logs a warning if not. | ||
*/ | ||
forward() { | ||
@@ -59,2 +74,6 @@ if (this.snapshot_taker) this.snapshot_taker.take() | ||
/** | ||
* Moves backward to the previous snapshot in the history. | ||
* @returns {any} The previous state snapshot if available, or logs a warning if not. | ||
*/ | ||
backward() { | ||
@@ -69,2 +88,6 @@ if (this.snapshot_taker) this.snapshot_taker.take() | ||
/** | ||
* Gets the current state snapshot. | ||
* @returns {any} The current state snapshot if available, or logs a warning if not. | ||
*/ | ||
get current() { | ||
@@ -76,2 +99,6 @@ if (this.pos !== -1) return this.q[this.pos] | ||
/** | ||
* Gets the number of snapshots stored in the TimeCapsule. | ||
* @returns {number} The count of stored snapshots. | ||
*/ | ||
get length() { | ||
@@ -81,2 +108,6 @@ return this.q.length | ||
/** | ||
* Checks if there is a snapshot available to move forward. | ||
* @returns {boolean} True if moving forward is possible, otherwise false. | ||
*/ | ||
get forwardable() { | ||
@@ -86,2 +117,6 @@ return this.pos < this.q.length - 1 | ||
/** | ||
* Checks if there is a snapshot available to move backward. | ||
* @returns {boolean} True if moving backward is possible, otherwise false. | ||
*/ | ||
get backwardable() { | ||
@@ -91,2 +126,6 @@ return this.pos > 0 | ||
/** | ||
* Gets the SnapshotTaker associated with this TimeCapsule. | ||
* @returns {SnapshotTaker | null} The associated SnapshotTaker, or null if not set. | ||
*/ | ||
get snapshot_taker(): SnapshotTaker | null { | ||
@@ -96,2 +135,6 @@ return this._snapshot_taker | ||
/** | ||
* Sets the SnapshotTaker for this TimeCapsule. | ||
* @param {SnapshotTaker | null} snapshot_taker - The SnapshotTaker instance to associate with this TimeCapsule. | ||
*/ | ||
set snapshot_taker(snapshot_taker: SnapshotTaker | null) { | ||
@@ -101,2 +144,5 @@ this._snapshot_taker = snapshot_taker | ||
/** | ||
* Resets the TimeCapsule, clearing all stored snapshots and resetting the position. | ||
*/ | ||
reset() { | ||
@@ -103,0 +149,0 @@ this.q = [] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
264887
2992