functools-kit
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "functools-kit", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A library with helpers for react-declarative app backend development", | ||
@@ -5,0 +5,0 @@ "author": { |
# func-kit | ||
> A library with helpers for react-declarative app backend development | ||
> A library with helpers for [react-declarative](https://github.com/react-declarative/react-declarative) app backend development | ||
## What inside | ||
The complete description is available [by this link](https://github.com/react-declarative/react-declarative/blob/master/docs/code/UTILS.md). This npm module exports the following TypeScript definitions: | ||
1. **Utility Functions** : | ||
- `randomString`: Generates a random string using UUID. | ||
- `compareFulltext<T>`: Compares a search term against a data object. | ||
- `compareArray`: Checks if two arrays are equal. | ||
- `isObject`: Verifies if a value is an object. | ||
- `formatText`: Formats a string based on a template with customizable options. | ||
- `singleshot` and `singlerun`: Functions that run once and allow clearing/resetting. | ||
- `debounce`: Creates a debounced version of a function. | ||
- `retry`: Retries a function multiple times until it succeeds. | ||
- `deepFlat`: Deep flattens an array. | ||
- `memoize`: Caches function results based on argument changes. | ||
- `trycatch`: Wraps a function with a try-catch block. | ||
- `sleep`: Delays execution by a specified time. | ||
- `cancelable`, `queued`, `execpool`: Wrappers for promise-based functions with enhanced functionality like cancellation and concurrency control. | ||
- `createAwaiter`: Creates an awaitable promise and returns resolve and reject out of the closure. | ||
2. **Interfaces and Types** : | ||
- `IParams`, `IClearable`, `ITaskStatus`, `ICounted`, `IError`, and various `IWrappedFn` types for defining functionalities related to tasks, observers, and clearing mechanisms. | ||
- `TObserver`, `TSubject`, `TObservable`, `TBehaviorSubject`: Types representing observer and subject patterns for handling observable data streams. | ||
3. **Classes** : | ||
- `Task`: Represents a task with status tracking. | ||
- `Observer`, `Subject`, `BehaviorSubject`: Classes implementing observer/observable patterns. | ||
- `EventEmitter`: Provides event management capabilities. | ||
- `Operator`, `Source`: Utility classes for creating and manipulating observers. | ||
4. **Constants** : | ||
- `CANCELED_SYMBOL`: A unique symbol representing cancellation status. |
export { randomString } from './utils/randomString'; | ||
export { compareFulltext } from './utils/compareFulltext'; | ||
export { promiseState, promiseValue } from './utils/promiseState'; | ||
@@ -15,2 +14,4 @@ export { compareArray } from './utils/compareArray'; | ||
export { queued } from './utils/hof/queued'; | ||
export { execpool } from './utils/hof/execpool'; | ||
export { retry } from './utils/hof/retry'; | ||
export { cached } from './utils/hof/cached'; | ||
@@ -23,2 +24,4 @@ export { memoize } from './utils/hof/memoize'; | ||
export { createAwaiter } from './utils/createAwaiter'; | ||
export { BehaviorSubject } from './utils/rx/BehaviorSubject'; | ||
@@ -25,0 +28,0 @@ export { EventEmitter } from './utils/rx/EventEmitter'; |
103
types.d.ts
@@ -20,12 +20,2 @@ /** | ||
/** | ||
* Determines the state of a given promise. | ||
* | ||
* @param promise - The promise to check the state of. | ||
* | ||
* @returns - The state of the promise, which can be either 'sync' or 'async'. | ||
*/ | ||
declare const promiseState: <T = any>(promise: Promise<T> | T) => "sync" | "async"; | ||
declare const promiseValue: <T = any>(promise: Promise<T> | T) => T | null; | ||
/** | ||
* Compares two arrays and determines if they are equal. | ||
@@ -135,3 +125,3 @@ * | ||
*/ | ||
interface IWrappedFn$1<T extends any = any, P extends any[] = any> { | ||
interface IWrappedFn$3<T extends any = any, P extends any[] = any> { | ||
(...args: P): Promise<T | typeof CANCELED_SYMBOL>; | ||
@@ -155,3 +145,3 @@ cancel(): void; | ||
*/ | ||
declare const cancelable: <T extends unknown = any, P extends any[] = any[]>(promise: (...args: P) => Promise<T>) => IWrappedFn$1<T, P>; | ||
declare const cancelable: <T extends unknown = any, P extends any[] = any[]>(promise: (...args: P) => Promise<T>) => IWrappedFn$3<T, P>; | ||
@@ -181,3 +171,3 @@ /** | ||
*/ | ||
interface IWrappedFn<T extends any = any, P extends any[] = any> { | ||
interface IWrappedFn$2<T extends any = any, P extends any[] = any> { | ||
(...args: P): Promise<T | typeof CANCELED_SYMBOL>; | ||
@@ -195,5 +185,64 @@ clear(): void; | ||
*/ | ||
declare const queued: <T extends unknown = any, P extends any[] = any[]>(promise: (...args: P) => Promise<T>) => IWrappedFn<T, P>; | ||
declare const queued: <T extends unknown = any, P extends any[] = any[]>(promise: (...args: P) => Promise<T>) => IWrappedFn$2<T, P>; | ||
/** | ||
* Represents the configuration options for the execution pool. | ||
* | ||
* @interface | ||
* @property maxExec - The maximum number of executions allowed concurrently. | ||
* @property delay - The delay in milliseconds between executions. | ||
*/ | ||
interface IConfig$1 { | ||
maxExec: number; | ||
delay: number; | ||
} | ||
/** | ||
* Represents a wrapped function that returns a promise. | ||
* | ||
* @template T - The type of the result of the wrapped function. | ||
* @template P - The types of the parameters of the wrapped function. | ||
* | ||
* @interface | ||
* @function | ||
* @param args - The arguments to pass to the wrapped function. | ||
* @returns A promise that resolves with the result of the wrapped function. | ||
* @function clear - Clears all pending executions in the execution pool. | ||
*/ | ||
interface IWrappedFn$1<T extends any = any, P extends any[] = any> { | ||
(...args: P): Promise<T>; | ||
clear(): void; | ||
} | ||
/** | ||
* Creates an execution pool for asynchronous functions with a limited concurrency. | ||
* | ||
* @template T - The type of the result of the wrapped function. | ||
* @template P - The types of the parameters of the wrapped function. | ||
* | ||
* @function | ||
* @param run - The function to be executed in the pool. | ||
* @param options - Optional configuration options for the execution pool. | ||
* @returns A wrapped function that executes asynchronously within the execution pool. | ||
*/ | ||
declare const execpool: <T extends unknown = any, P extends any[] = any[]>(run: (...args: P) => Promise<T>, { maxExec, delay, }?: Partial<IConfig$1>) => IWrappedFn$1<T, P>; | ||
/** | ||
* Represents a wrapped function that returns a promise. | ||
* @template T - The type of the promise's resolved value. | ||
* @template P - The type of the function's arguments. | ||
*/ | ||
interface IWrappedFn<T extends any = any, P extends any[] = any> { | ||
(...args: P): Promise<T | typeof CANCELED_SYMBOL>; | ||
cancel(): void; | ||
clear(): void; | ||
} | ||
/** | ||
* Retries a function multiple times until it succeeds or reaches the maximum number of retries. | ||
* | ||
* @param run - The function to run. | ||
* @param count - The maximum number of retries (default is 5). | ||
* @returns - The wrapped function that can be canceled. | ||
*/ | ||
declare const retry: <T extends unknown = any, P extends any[] = any[]>(run: (...args: P) => Promise<T>, count?: number) => IWrappedFn<T, P>; | ||
/** | ||
* Interface for objects that can be cleared. | ||
@@ -303,2 +352,26 @@ * | ||
/** | ||
* Represents an object used for awaiting a value or a promise. | ||
* | ||
* @template T - The type of the value to be resolved. | ||
* | ||
* @interface | ||
* @function | ||
* @param value - The value or promise to resolve. | ||
* @param reason - The reason for rejecting the promise. | ||
*/ | ||
interface IAwaiter<T extends unknown> { | ||
resolve(value: T | PromiseLike<T>): void; | ||
reject(reason?: any): void; | ||
} | ||
/** | ||
* Creates an awaiter object along with a promise. | ||
* | ||
* @template T - The type of the value to be resolved. | ||
* | ||
* @function | ||
* @returns An array containing the promise and the awaiter object. | ||
*/ | ||
declare const createAwaiter: <T extends unknown>() => [Promise<T>, IAwaiter<T>]; | ||
type Function$2 = (...args: any[]) => any; | ||
@@ -1133,2 +1206,2 @@ /** | ||
export { BehaviorSubject, CANCELED_SYMBOL as CANCELED_PROMISE_SYMBOL, EventEmitter, Observer, Operator, Source, Subject, type TBehaviorSubject, type TObservable, type TObserver, type TSubject, Task, cached, cancelable, compareArray, compareFulltext, compose, debounce, deepFlat, formatText, isObject, memoize, promiseState, promiseValue, queued, randomString, singlerun, singleshot, sleep, trycatch }; | ||
export { BehaviorSubject, CANCELED_SYMBOL as CANCELED_PROMISE_SYMBOL, EventEmitter, Observer, Operator, Source, Subject, type TBehaviorSubject, type TObservable, type TObserver, type TSubject, Task, cached, cancelable, compareArray, compareFulltext, compose, createAwaiter, debounce, deepFlat, execpool, formatText, isObject, memoize, queued, randomString, retry, singlerun, singleshot, sleep, trycatch }; |
170301
57
4294
58