Comparing version 0.1.1 to 0.1.2
@@ -0,1 +1,100 @@ | ||
type StorageParams = { | ||
key: string; | ||
handleGetStorage?: (key: string) => Record<string, unknown>; | ||
handleSetStorage?: (key: string, value: Record<string, unknown>) => void; | ||
}; | ||
declare class Storage { | ||
#private; | ||
get storage(): Record<string, unknown>; | ||
get length(): number; | ||
constructor(params: StorageParams | StorageParams['key']); | ||
protected _getStorage(key: string): Record<string, unknown>; | ||
protected _setStorage(key: string, value: Record<string, unknown>): void; | ||
getItem<V>(path: string, defaultValue?: V): V extends undefined ? unknown : V; | ||
setItem(path: string, value: unknown, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
removeItem(path: string, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
clear(): void; | ||
key(index: number): string; | ||
} | ||
declare class LocalStorage extends Storage { | ||
protected _getStorage(key: string): Record<string, unknown>; | ||
protected _setStorage(key: string, value: Record<string, unknown>): void; | ||
} | ||
declare class Cache<K = any, V = any> { | ||
readonly _cacheMap: Map<any, any>; | ||
getItem(key: K): any; | ||
setItem(key: K, value: V, options?: { | ||
expires?: number; | ||
}): void; | ||
removeItem(key: K): void; | ||
clear(): void; | ||
key(index: number): any; | ||
get length(): number; | ||
static readonly _cacheMap: Map<any, any>; | ||
static getItem(key: any): any; | ||
static setItem(key: any, value: any, options?: { | ||
expires?: number; | ||
}): void; | ||
static removeItem(key: any): void; | ||
static clear(): void; | ||
static key(index: number): any; | ||
static get length(): number; | ||
} | ||
type HandleResult = { | ||
token: string; | ||
expires: number; | ||
}; | ||
type Handle = () => HandleResult | Promise<HandleResult>; | ||
declare class CacheToken { | ||
key: string; | ||
handle?: Handle; | ||
constructor(key: string, handle?: Handle); | ||
getToken(): Promise<string | null>; | ||
setToken(token: string, options?: { | ||
expires?: number; | ||
}): Promise<void>; | ||
static cache: Cache<string, string>; | ||
static getToken(options?: { | ||
key?: string; | ||
}): string | null; | ||
static setToken(token: string, options?: { | ||
expires?: number; | ||
key?: string; | ||
}): void; | ||
} | ||
declare class LocalStorageToken extends CacheToken { | ||
static storage: LocalStorage; | ||
static getToken(options?: { | ||
key?: string; | ||
}): string | null; | ||
static setToken(token: string, options?: { | ||
expires?: number; | ||
key?: string; | ||
}): any; | ||
} | ||
declare class SessionStorage extends Storage { | ||
protected _getStorage(key: string): Record<string, unknown>; | ||
protected _setStorage(key: string, value: Record<string, unknown>): void; | ||
} | ||
declare class SessionStorageToken extends CacheToken { | ||
static storage: SessionStorage; | ||
static getToken(options?: { | ||
key?: string; | ||
}): string | null; | ||
static setToken(token: string, options?: { | ||
expires?: number; | ||
key?: string; | ||
}): any; | ||
} | ||
type Key = string; | ||
@@ -48,2 +147,2 @@ type Value = string; | ||
export { cookie }; | ||
export { LocalStorage, LocalStorageToken, SessionStorage, SessionStorageToken, cookie }; |
@@ -9,20 +9,193 @@ export { default as clone } from 'lodash-es/clone'; | ||
declare function setCache(key: string, value: any, options?: { | ||
expires?: number; | ||
}): void; | ||
declare function getCache(key: string): any; | ||
declare const cache: { | ||
setCache: typeof setCache; | ||
getCache: typeof getCache; | ||
declare class Cache<K = any, V = any> { | ||
readonly _cacheMap: Map<any, any>; | ||
getItem(key: K): any; | ||
setItem(key: K, value: V, options?: { | ||
expires?: number; | ||
}): void; | ||
removeItem(key: K): void; | ||
clear(): void; | ||
key(index: number): any; | ||
get length(): number; | ||
static readonly _cacheMap: Map<any, any>; | ||
static getItem(key: any): any; | ||
static setItem(key: any, value: any, options?: { | ||
expires?: number; | ||
}): void; | ||
static removeItem(key: any): void; | ||
static clear(): void; | ||
static key(index: number): any; | ||
static get length(): number; | ||
} | ||
type HandleResult = { | ||
token: string; | ||
expires: number; | ||
}; | ||
type Handle = () => HandleResult | Promise<HandleResult>; | ||
declare class CacheToken { | ||
key: string; | ||
handle?: Handle; | ||
constructor(key: string, handle?: Handle); | ||
getToken(): Promise<string | null>; | ||
setToken(token: string, options?: { | ||
expires?: number; | ||
}): Promise<void>; | ||
static cache: Cache<string, string>; | ||
static getToken(options?: { | ||
key?: string; | ||
}): string | null; | ||
static setToken(token: string, options?: { | ||
expires?: number; | ||
key?: string; | ||
}): void; | ||
} | ||
declare const color: { | ||
isHexColor: (color: string) => boolean; | ||
rgbToHex: (r: number, g: number, b: number) => string; | ||
hexToRGB: (hex: string, opacity?: number) => string; | ||
colorIsDark: (color: string) => boolean | undefined; | ||
darken: (color: string, amount: number) => string; | ||
lighten: (color: string, amount: number) => string; | ||
calculateBestTextColor: (hexColor: string) => "#000000" | "#FFFFFF"; | ||
/** | ||
* 基于种子的随机数生成器 | ||
*/ | ||
declare class SeededRandom { | ||
seed: number; | ||
constructor(seed?: string | number); | ||
/** | ||
* 获取随机数 0-1 | ||
* @returns 随机数 | ||
*/ | ||
random(): number; | ||
/** | ||
* 根据最大值和最小值获取随机数 | ||
* @param min 最小值 | ||
* @param max 最大值 默认为最小值 | ||
* @param precision 小数精度 默认为0 | ||
* @returns 整数随机数 | ||
*/ | ||
randomNumber(min: number, max?: number, precision?: number): number; | ||
/** | ||
* 根据长度获取随机字符串 | ||
* @param length 长度 默认16 | ||
* @param chars 字符串 默认为0-9a-zA-Z | ||
* @returns 随机字符串 | ||
*/ | ||
randomString(length?: number, chars?: string): string; | ||
/** | ||
* 获取随机布尔值 | ||
* @returns 随机布尔值 | ||
*/ | ||
randomBoolean(): boolean; | ||
/** | ||
* 根据数组获取随机元素 | ||
* @param array 数组 | ||
* @param from 开始位置 默认为0 | ||
* @param to 结束位置 默认为数组长度 | ||
* @returns 随机元素 | ||
*/ | ||
randomElement<T>(array: T[], from?: number, to?: number): T; | ||
/** | ||
* 获取随机uuid | ||
* @returns 随机uuid | ||
*/ | ||
uuid(): string; | ||
/** | ||
* 获取随机Hex颜色 | ||
* @returns 随机Hex颜色 | ||
*/ | ||
randomColor(): string; | ||
/** | ||
* 获取随机rgb颜色 | ||
* @returns 随机rgb颜色 | ||
*/ | ||
randomRGBColor(): string; | ||
/** | ||
* 获取随机rgba颜色 | ||
* @returns 随机rgba颜色 | ||
*/ | ||
randomRGBAColor(): string; | ||
/** 默认种子 */ | ||
static seed: number; | ||
/** | ||
* 获取随机数 0-1 | ||
* @param seed 种子 | ||
* @returns 随机数 | ||
*/ | ||
static random(seed?: string | number): number; | ||
/** | ||
* 根据最大值和最小值获取随机数 | ||
* @param min 最小值 | ||
* @param max 最大值 默认为最小值 | ||
* @param precision 精度 默认为0 | ||
* @param seed 种子 | ||
* @returns 整数随机数 | ||
*/ | ||
static randomNumber(min: number, max?: number, precision?: number, seed?: string | number): number; | ||
/** | ||
* 根据长度获取随机字符串 | ||
* @param length 长度 默认16 | ||
* @param chars 字符串 默认为0-9a-zA-Z | ||
* @param seed 种子 | ||
* @returns 随机字符串 | ||
*/ | ||
static randomString(length?: number, chars?: string, seed?: string | number): string; | ||
/** | ||
* 获取随机布尔值 | ||
* @param seed 种子 | ||
* @returns 随机布尔值 | ||
*/ | ||
static randomBoolean(seed?: string | number): boolean; | ||
/** | ||
* 根据数组获取随机元素 | ||
* @param array 数组 | ||
* @param from 开始位置 默认为0 | ||
* @param to 结束位置 默认为数组长度 | ||
* @param seed 种子 | ||
* @returns 随机元素 | ||
*/ | ||
static randomElement<T>(array: T[], from?: number, to?: number, seed?: string | number): T; | ||
/** | ||
* 获取随机uuid | ||
* @param seed 种子 | ||
* @returns 随机uuid | ||
*/ | ||
static uuid(seed?: string | number): string; | ||
/** | ||
* 获取随机Hex颜色 | ||
* @param seed 种子 | ||
* @returns 随机Hex颜色 | ||
*/ | ||
static randomColor(seed?: string | number): string; | ||
/** | ||
* 获取随机rgb颜色 | ||
* @param seed 种子 | ||
* @returns 随机rgb颜色 | ||
*/ | ||
static randomRGBColor(seed?: string | number): string; | ||
/** | ||
* 获取随机rgba颜色 | ||
* @param seed 种子 | ||
* @returns 随机rgba颜色 | ||
*/ | ||
static randomRGBAColor(seed?: string | number): string; | ||
} | ||
type StorageParams = { | ||
key: string; | ||
handleGetStorage?: (key: string) => Record<string, unknown>; | ||
handleSetStorage?: (key: string, value: Record<string, unknown>) => void; | ||
}; | ||
declare class Storage { | ||
#private; | ||
get storage(): Record<string, unknown>; | ||
get length(): number; | ||
constructor(params: StorageParams | StorageParams['key']); | ||
protected _getStorage(key: string): Record<string, unknown>; | ||
protected _setStorage(key: string, value: Record<string, unknown>): void; | ||
getItem<V>(path: string, defaultValue?: V): V extends undefined ? unknown : V; | ||
setItem(path: string, value: unknown, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
removeItem(path: string, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
clear(): void; | ||
key(index: number): string; | ||
} | ||
@@ -37,13 +210,2 @@ type Any = any | ||
interface DebounceAsyncWorker<T extends AnyFunction> { | ||
(this: Any, ...args: Parameters<T>): void; | ||
} | ||
/** | ||
* 创建一个支持异步防抖动函数,该函数会从上一次被调用后,延迟 `wait` 毫秒后执行。 | ||
* @param func 需要防抖动的函数 | ||
* @param wait 执行延迟的毫秒数,可选,默认为 0 | ||
* @returns 新的防抖动函数 | ||
*/ | ||
declare function debounceAsync<T extends AnyFunction>(func: T, wait?: number): DebounceAsyncWorker<T>; | ||
/** 事件监听器 */ | ||
@@ -99,18 +261,20 @@ declare class EventListener { | ||
/** | ||
* `get` 函数从给定的对象中获取指定路径的值。如果路径不存在,将返回默认值。 | ||
* | ||
* @param object - 要从中获取值的对象。 | ||
* @param path - 要获取的值的路径,以点分隔。 | ||
* @param defaultValue - 如果路径不存在,将返回的默认值。 | ||
* @returns 路径上的值,如果路径不存在,则返回默认值。 | ||
*/ | ||
declare function get<T extends Record<string, unknown>, P extends string, D extends T[P]>(object: T, path: P, defaultValue?: D): P extends keyof T ? T[P] : D; | ||
declare function groupBy<T extends AnyObject>(collection: T[], iteratee: (item: T, index: number) => string): Record<string, T[]>; | ||
declare function memoize<T, R, P extends Array<Any>>(func: (this: T, ...args: P) => R, resolver?: (this: T, ...args: P) => string): { | ||
(this: T, ...args: P): R; | ||
cache: Map<any, any>; | ||
type TaskWorkerNext<Args extends unknown[]> = (...args: Args) => void; | ||
type TaskWorker<Data, NextArgs extends unknown[]> = (data: Data, next: TaskWorkerNext<NextArgs>) => void; | ||
type TaskId = number; | ||
type TaskStatus = 'pending' | 'running' | 'done'; | ||
type TaskCallback<Args extends unknown[]> = TaskWorkerNext<Args>; | ||
type Task<Data, TaskCallbackArgs extends unknown[]> = { | ||
id: TaskId; | ||
status: TaskStatus; | ||
data: Data; | ||
callback?: TaskCallback<TaskCallbackArgs>; | ||
}; | ||
declare class Queue<Data, TaskCallbackArgs extends unknown[]> extends EventListener { | ||
#private; | ||
constructor(worker: TaskWorker<Data, TaskCallbackArgs>, maxConcurrency?: number); | ||
push(data: Data, callback?: TaskCallback<TaskCallbackArgs>): number; | ||
remove(id: TaskId): void; | ||
remove(task: Task<Data, TaskCallbackArgs>): void; | ||
} | ||
@@ -193,155 +357,2 @@ type Service<RecordItem extends Any> = (page: number, size: number) => Promise<{ | ||
type TaskWorkerNext<Args extends unknown[]> = (...args: Args) => void; | ||
type TaskWorker<Data, NextArgs extends unknown[]> = (data: Data, next: TaskWorkerNext<NextArgs>) => void; | ||
type TaskId = number; | ||
type TaskStatus = 'pending' | 'running' | 'done'; | ||
type TaskCallback<Args extends unknown[]> = TaskWorkerNext<Args>; | ||
type Task<Data, TaskCallbackArgs extends unknown[]> = { | ||
id: TaskId; | ||
status: TaskStatus; | ||
data: Data; | ||
callback?: TaskCallback<TaskCallbackArgs>; | ||
}; | ||
declare class Queue<Data, TaskCallbackArgs extends unknown[]> extends EventListener { | ||
#private; | ||
constructor(worker: TaskWorker<Data, TaskCallbackArgs>, maxConcurrency?: number); | ||
push(data: Data, callback?: TaskCallback<TaskCallbackArgs>): number; | ||
remove(id: TaskId): void; | ||
remove(task: Task<Data, TaskCallbackArgs>): void; | ||
} | ||
/** | ||
* 基于种子的随机数生成器 | ||
*/ | ||
declare class SeededRandom { | ||
seed: number; | ||
constructor(seed?: string | number); | ||
/** | ||
* 获取随机数 0-1 | ||
* @returns 随机数 | ||
*/ | ||
random(): number; | ||
/** | ||
* 根据最大值和最小值获取随机数 | ||
* @param min 最小值 | ||
* @param max 最大值 默认为最小值 | ||
* @param precision 小数精度 默认为0 | ||
* @returns 整数随机数 | ||
*/ | ||
randomNumber(min: number, max?: number, precision?: number): number; | ||
/** | ||
* 根据长度获取随机字符串 | ||
* @param length 长度 默认16 | ||
* @param chars 字符串 默认为0-9a-zA-Z | ||
* @returns 随机字符串 | ||
*/ | ||
randomString(length?: number, chars?: string): string; | ||
/** | ||
* 获取随机布尔值 | ||
* @returns 随机布尔值 | ||
*/ | ||
randomBoolean(): boolean; | ||
/** | ||
* 根据数组获取随机元素 | ||
* @param array 数组 | ||
* @param from 开始位置 默认为0 | ||
* @param to 结束位置 默认为数组长度 | ||
* @returns 随机元素 | ||
*/ | ||
randomElement<T>(array: T[], from?: number, to?: number): T; | ||
/** | ||
* 获取随机uuid | ||
* @returns 随机uuid | ||
*/ | ||
uuid(): string; | ||
/** | ||
* 获取随机Hex颜色 | ||
* @returns 随机Hex颜色 | ||
*/ | ||
randomColor(): string; | ||
/** | ||
* 获取随机rgb颜色 | ||
* @returns 随机rgb颜色 | ||
*/ | ||
randomRGBColor(): string; | ||
/** | ||
* 获取随机rgba颜色 | ||
* @returns 随机rgba颜色 | ||
*/ | ||
randomRGBAColor(): string; | ||
/** 默认种子 */ | ||
static seed: number; | ||
/** | ||
* 获取随机数 0-1 | ||
* @param seed 种子 | ||
* @returns 随机数 | ||
*/ | ||
static random(seed?: string | number): number; | ||
/** | ||
* 根据最大值和最小值获取随机数 | ||
* @param min 最小值 | ||
* @param max 最大值 默认为最小值 | ||
* @param precision 精度 默认为0 | ||
* @param seed 种子 | ||
* @returns 整数随机数 | ||
*/ | ||
static randomNumber(min: number, max?: number, precision?: number, seed?: string | number): number; | ||
/** | ||
* 根据长度获取随机字符串 | ||
* @param length 长度 默认16 | ||
* @param chars 字符串 默认为0-9a-zA-Z | ||
* @param seed 种子 | ||
* @returns 随机字符串 | ||
*/ | ||
static randomString(length?: number, chars?: string, seed?: string | number): string; | ||
/** | ||
* 获取随机布尔值 | ||
* @param seed 种子 | ||
* @returns 随机布尔值 | ||
*/ | ||
static randomBoolean(seed?: string | number): boolean; | ||
/** | ||
* 根据数组获取随机元素 | ||
* @param array 数组 | ||
* @param from 开始位置 默认为0 | ||
* @param to 结束位置 默认为数组长度 | ||
* @param seed 种子 | ||
* @returns 随机元素 | ||
*/ | ||
static randomElement<T>(array: T[], from?: number, to?: number, seed?: string | number): T; | ||
/** | ||
* 获取随机uuid | ||
* @param seed 种子 | ||
* @returns 随机uuid | ||
*/ | ||
static uuid(seed?: string | number): string; | ||
/** | ||
* 获取随机Hex颜色 | ||
* @param seed 种子 | ||
* @returns 随机Hex颜色 | ||
*/ | ||
static randomColor(seed?: string | number): string; | ||
/** | ||
* 获取随机rgb颜色 | ||
* @param seed 种子 | ||
* @returns 随机rgb颜色 | ||
*/ | ||
static randomRGBColor(seed?: string | number): string; | ||
/** | ||
* 获取随机rgba颜色 | ||
* @param seed 种子 | ||
* @returns 随机rgba颜色 | ||
*/ | ||
static randomRGBAColor(seed?: string | number): string; | ||
} | ||
/** | ||
* 设置对象中指定路径的值 | ||
* @param object - 目标对象 | ||
* @param path - 路径字符串,用于指定要设置值的位置 | ||
* @param value - 要设置的值 | ||
* @returns 设置的值 | ||
*/ | ||
declare function set<T extends Record<string, unknown>, P extends string, V>(object: T, path: P, value: V): V; | ||
type SendHandlePromise = (data: string, resolve: (value: unknown) => void, reject: (value?: unknown) => void) => void; | ||
@@ -370,3 +381,3 @@ type EventListenerHandleCallback = (data: string, callback: UnknownFunction) => void; | ||
* socket 连接到服务器。 | ||
* @param url socket 地址(默认: window.location) | ||
* @param url socket 地址 | ||
* @param options socket 配置 | ||
@@ -416,20 +427,49 @@ */ | ||
type StorageParams = { | ||
key: string; | ||
handleGetStorage?: (key: string) => Record<string, unknown>; | ||
handleSetStorage?: (key: string, value: Record<string, unknown>) => void; | ||
declare const color: { | ||
isHexColor: (color: string) => boolean; | ||
rgbToHex: (r: number, g: number, b: number) => string; | ||
hexToRGB: (hex: string, opacity?: number) => string; | ||
colorIsDark: (color: string) => boolean | undefined; | ||
darken: (color: string, amount: number) => string; | ||
lighten: (color: string, amount: number) => string; | ||
calculateBestTextColor: (hexColor: string) => "#000000" | "#FFFFFF"; | ||
}; | ||
declare class Storage { | ||
#private; | ||
get storage(): Record<string, unknown>; | ||
constructor(params: StorageParams | StorageParams['key']); | ||
getItem<V>(path: string, defaultValue?: V): V extends undefined ? unknown : V; | ||
setItem(path: string, value: unknown, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
removeItem(path: string, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
interface DebounceAsyncWorker<T extends AnyFunction> { | ||
(this: Any, ...args: Parameters<T>): void; | ||
} | ||
/** | ||
* 创建一个支持异步防抖动函数,该函数会从上一次被调用后,延迟 `wait` 毫秒后执行。 | ||
* @param func 需要防抖动的函数 | ||
* @param wait 执行延迟的毫秒数,可选,默认为 0 | ||
* @returns 新的防抖动函数 | ||
*/ | ||
declare function debounceAsync<T extends AnyFunction>(func: T, wait?: number): DebounceAsyncWorker<T>; | ||
/** | ||
* `get` 函数从给定的对象中获取指定路径的值。如果路径不存在,将返回默认值。 | ||
* | ||
* @param object - 要从中获取值的对象。 | ||
* @param path - 要获取的值的路径,以点分隔。 | ||
* @param defaultValue - 如果路径不存在,将返回的默认值。 | ||
* @returns 路径上的值,如果路径不存在,则返回默认值。 | ||
*/ | ||
declare function get<T extends Record<string, unknown>, P extends string, D extends T[P]>(object: T, path: P, defaultValue?: D): P extends keyof T ? T[P] : D; | ||
declare function groupBy<T extends AnyObject>(collection: T[], iteratee: (item: T, index: number) => string): Record<string, T[]>; | ||
declare function memoize<T, R, P extends Array<Any>>(func: (this: T, ...args: P) => R, resolver?: (this: T, ...args: P) => string): { | ||
(this: T, ...args: P): R; | ||
cache: Map<any, any>; | ||
}; | ||
/** | ||
* 设置对象中指定路径的值 | ||
* @param object - 目标对象 | ||
* @param path - 路径字符串,用于指定要设置值的位置 | ||
* @param value - 要设置的值 | ||
* @returns 设置的值 | ||
*/ | ||
declare function set<T extends Record<string, unknown>, P extends string, V>(object: T, path: P, value: V): V; | ||
declare function templateCompiled(template: string, options?: { | ||
@@ -441,24 +481,2 @@ escape?: RegExp; | ||
type HandleResult = { | ||
token: string; | ||
expires: number; | ||
}; | ||
type Handle = () => HandleResult | Promise<HandleResult>; | ||
declare class TokenHandle { | ||
key: string; | ||
handle: Handle; | ||
constructor(key: string, handle: Handle); | ||
getToken(): Promise<string>; | ||
setToken(token: string, options?: { | ||
expires?: number; | ||
}): Promise<void>; | ||
static getToken(options?: { | ||
key?: string; | ||
}): string | null; | ||
static setToken(token: string, options?: { | ||
expires?: number; | ||
key?: string; | ||
}): void; | ||
} | ||
type Node$2<T extends Record<string, unknown>, K extends string> = (Pick<T, Exclude<keyof T, K>> & { | ||
@@ -481,4 +499,2 @@ [Key in K]?: Array<Node$2<T, K>>; | ||
declare function uniqWith<T>(array: T[], iteratee: (item: T, compare: T) => boolean): T[]; | ||
declare function uniq(array: unknown[]): unknown[]; | ||
@@ -490,2 +506,4 @@ | ||
declare function uniqWith<T>(array: T[], iteratee: (item: T, compare: T) => boolean): T[]; | ||
declare function urlParams(scene: string): Record<string, string>; | ||
@@ -495,2 +513,2 @@ | ||
export { EventListener, Paging, PagingLazy, PromiseTimeout, Queue, SeededRandom, SocketManager, Storage, TokenHandle, cache, color, debounceAsync, get, groupBy, memoize, set, templateCompiled, tree, treeBy, treeFlat, uniq, uniqBy, uniqWith, urlParams, wrap }; | ||
export { Cache, CacheToken, EventListener, Paging, PagingLazy, PromiseTimeout, Queue, SeededRandom, SocketManager, Storage, color, debounceAsync, get, groupBy, memoize, set, templateCompiled, tree, treeBy, treeFlat, uniq, uniqBy, uniqWith, urlParams, wrap }; |
@@ -57,32 +57,194 @@ export { default as clone } from 'lodash-es/clone'; | ||
declare function setCache(key: string, value: any, options?: { | ||
expires?: number; | ||
}): void; | ||
declare function getCache(key: string): any; | ||
declare const cache: { | ||
setCache: typeof setCache; | ||
getCache: typeof getCache; | ||
}; | ||
declare class Cache<K = any, V = any> { | ||
readonly _cacheMap: Map<any, any>; | ||
getItem(key: K): any; | ||
setItem(key: K, value: V, options?: { | ||
expires?: number; | ||
}): void; | ||
removeItem(key: K): void; | ||
clear(): void; | ||
key(index: number): any; | ||
get length(): number; | ||
static readonly _cacheMap: Map<any, any>; | ||
static getItem(key: any): any; | ||
static setItem(key: any, value: any, options?: { | ||
expires?: number; | ||
}): void; | ||
static removeItem(key: any): void; | ||
static clear(): void; | ||
static key(index: number): any; | ||
static get length(): number; | ||
} | ||
declare const color: { | ||
isHexColor: (color: string) => boolean; | ||
rgbToHex: (r: number, g: number, b: number) => string; | ||
hexToRGB: (hex: string, opacity?: number) => string; | ||
colorIsDark: (color: string) => boolean | undefined; | ||
darken: (color: string, amount: number) => string; | ||
lighten: (color: string, amount: number) => string; | ||
calculateBestTextColor: (hexColor: string) => "#000000" | "#FFFFFF"; | ||
type HandleResult = { | ||
token: string; | ||
expires: number; | ||
}; | ||
type Handle = () => HandleResult | Promise<HandleResult>; | ||
declare class CacheToken { | ||
key: string; | ||
handle?: Handle; | ||
constructor(key: string, handle?: Handle); | ||
getToken(): Promise<string | null>; | ||
setToken(token: string, options?: { | ||
expires?: number; | ||
}): Promise<void>; | ||
static cache: Cache<string, string>; | ||
static getToken(options?: { | ||
key?: string; | ||
}): string | null; | ||
static setToken(token: string, options?: { | ||
expires?: number; | ||
key?: string; | ||
}): void; | ||
} | ||
interface DebounceAsyncWorker<T extends AnyFunction> { | ||
(this: Any, ...args: Parameters<T>): void; | ||
} | ||
/** | ||
* 创建一个支持异步防抖动函数,该函数会从上一次被调用后,延迟 `wait` 毫秒后执行。 | ||
* @param func 需要防抖动的函数 | ||
* @param wait 执行延迟的毫秒数,可选,默认为 0 | ||
* @returns 新的防抖动函数 | ||
* 基于种子的随机数生成器 | ||
*/ | ||
declare function debounceAsync<T extends AnyFunction>(func: T, wait?: number): DebounceAsyncWorker<T>; | ||
declare class SeededRandom { | ||
seed: number; | ||
constructor(seed?: string | number); | ||
/** | ||
* 获取随机数 0-1 | ||
* @returns 随机数 | ||
*/ | ||
random(): number; | ||
/** | ||
* 根据最大值和最小值获取随机数 | ||
* @param min 最小值 | ||
* @param max 最大值 默认为最小值 | ||
* @param precision 小数精度 默认为0 | ||
* @returns 整数随机数 | ||
*/ | ||
randomNumber(min: number, max?: number, precision?: number): number; | ||
/** | ||
* 根据长度获取随机字符串 | ||
* @param length 长度 默认16 | ||
* @param chars 字符串 默认为0-9a-zA-Z | ||
* @returns 随机字符串 | ||
*/ | ||
randomString(length?: number, chars?: string): string; | ||
/** | ||
* 获取随机布尔值 | ||
* @returns 随机布尔值 | ||
*/ | ||
randomBoolean(): boolean; | ||
/** | ||
* 根据数组获取随机元素 | ||
* @param array 数组 | ||
* @param from 开始位置 默认为0 | ||
* @param to 结束位置 默认为数组长度 | ||
* @returns 随机元素 | ||
*/ | ||
randomElement<T>(array: T[], from?: number, to?: number): T; | ||
/** | ||
* 获取随机uuid | ||
* @returns 随机uuid | ||
*/ | ||
uuid(): string; | ||
/** | ||
* 获取随机Hex颜色 | ||
* @returns 随机Hex颜色 | ||
*/ | ||
randomColor(): string; | ||
/** | ||
* 获取随机rgb颜色 | ||
* @returns 随机rgb颜色 | ||
*/ | ||
randomRGBColor(): string; | ||
/** | ||
* 获取随机rgba颜色 | ||
* @returns 随机rgba颜色 | ||
*/ | ||
randomRGBAColor(): string; | ||
/** 默认种子 */ | ||
static seed: number; | ||
/** | ||
* 获取随机数 0-1 | ||
* @param seed 种子 | ||
* @returns 随机数 | ||
*/ | ||
static random(seed?: string | number): number; | ||
/** | ||
* 根据最大值和最小值获取随机数 | ||
* @param min 最小值 | ||
* @param max 最大值 默认为最小值 | ||
* @param precision 精度 默认为0 | ||
* @param seed 种子 | ||
* @returns 整数随机数 | ||
*/ | ||
static randomNumber(min: number, max?: number, precision?: number, seed?: string | number): number; | ||
/** | ||
* 根据长度获取随机字符串 | ||
* @param length 长度 默认16 | ||
* @param chars 字符串 默认为0-9a-zA-Z | ||
* @param seed 种子 | ||
* @returns 随机字符串 | ||
*/ | ||
static randomString(length?: number, chars?: string, seed?: string | number): string; | ||
/** | ||
* 获取随机布尔值 | ||
* @param seed 种子 | ||
* @returns 随机布尔值 | ||
*/ | ||
static randomBoolean(seed?: string | number): boolean; | ||
/** | ||
* 根据数组获取随机元素 | ||
* @param array 数组 | ||
* @param from 开始位置 默认为0 | ||
* @param to 结束位置 默认为数组长度 | ||
* @param seed 种子 | ||
* @returns 随机元素 | ||
*/ | ||
static randomElement<T>(array: T[], from?: number, to?: number, seed?: string | number): T; | ||
/** | ||
* 获取随机uuid | ||
* @param seed 种子 | ||
* @returns 随机uuid | ||
*/ | ||
static uuid(seed?: string | number): string; | ||
/** | ||
* 获取随机Hex颜色 | ||
* @param seed 种子 | ||
* @returns 随机Hex颜色 | ||
*/ | ||
static randomColor(seed?: string | number): string; | ||
/** | ||
* 获取随机rgb颜色 | ||
* @param seed 种子 | ||
* @returns 随机rgb颜色 | ||
*/ | ||
static randomRGBColor(seed?: string | number): string; | ||
/** | ||
* 获取随机rgba颜色 | ||
* @param seed 种子 | ||
* @returns 随机rgba颜色 | ||
*/ | ||
static randomRGBAColor(seed?: string | number): string; | ||
} | ||
type StorageParams = { | ||
key: string; | ||
handleGetStorage?: (key: string) => Record<string, unknown>; | ||
handleSetStorage?: (key: string, value: Record<string, unknown>) => void; | ||
}; | ||
declare class Storage { | ||
#private; | ||
get storage(): Record<string, unknown>; | ||
get length(): number; | ||
constructor(params: StorageParams | StorageParams['key']); | ||
protected _getStorage(key: string): Record<string, unknown>; | ||
protected _setStorage(key: string, value: Record<string, unknown>): void; | ||
getItem<V>(path: string, defaultValue?: V): V extends undefined ? unknown : V; | ||
setItem(path: string, value: unknown, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
removeItem(path: string, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
clear(): void; | ||
key(index: number): string; | ||
} | ||
/** 事件监听器 */ | ||
@@ -138,18 +300,20 @@ declare class EventListener { | ||
/** | ||
* `get` 函数从给定的对象中获取指定路径的值。如果路径不存在,将返回默认值。 | ||
* | ||
* @param object - 要从中获取值的对象。 | ||
* @param path - 要获取的值的路径,以点分隔。 | ||
* @param defaultValue - 如果路径不存在,将返回的默认值。 | ||
* @returns 路径上的值,如果路径不存在,则返回默认值。 | ||
*/ | ||
declare function get<T extends Record<string, unknown>, P extends string, D extends T[P]>(object: T, path: P, defaultValue?: D): P extends keyof T ? T[P] : D; | ||
declare function groupBy<T extends AnyObject>(collection: T[], iteratee: (item: T, index: number) => string): Record<string, T[]>; | ||
declare function memoize<T, R, P extends Array<Any>>(func: (this: T, ...args: P) => R, resolver?: (this: T, ...args: P) => string): { | ||
(this: T, ...args: P): R; | ||
cache: Map<any, any>; | ||
type TaskWorkerNext<Args extends unknown[]> = (...args: Args) => void; | ||
type TaskWorker<Data, NextArgs extends unknown[]> = (data: Data, next: TaskWorkerNext<NextArgs>) => void; | ||
type TaskId = number; | ||
type TaskStatus = 'pending' | 'running' | 'done'; | ||
type TaskCallback<Args extends unknown[]> = TaskWorkerNext<Args>; | ||
type Task<Data, TaskCallbackArgs extends unknown[]> = { | ||
id: TaskId; | ||
status: TaskStatus; | ||
data: Data; | ||
callback?: TaskCallback<TaskCallbackArgs>; | ||
}; | ||
declare class Queue<Data, TaskCallbackArgs extends unknown[]> extends EventListener { | ||
#private; | ||
constructor(worker: TaskWorker<Data, TaskCallbackArgs>, maxConcurrency?: number); | ||
push(data: Data, callback?: TaskCallback<TaskCallbackArgs>): number; | ||
remove(id: TaskId): void; | ||
remove(task: Task<Data, TaskCallbackArgs>): void; | ||
} | ||
@@ -232,155 +396,2 @@ type Service<RecordItem extends Any> = (page: number, size: number) => Promise<{ | ||
type TaskWorkerNext<Args extends unknown[]> = (...args: Args) => void; | ||
type TaskWorker<Data, NextArgs extends unknown[]> = (data: Data, next: TaskWorkerNext<NextArgs>) => void; | ||
type TaskId = number; | ||
type TaskStatus = 'pending' | 'running' | 'done'; | ||
type TaskCallback<Args extends unknown[]> = TaskWorkerNext<Args>; | ||
type Task<Data, TaskCallbackArgs extends unknown[]> = { | ||
id: TaskId; | ||
status: TaskStatus; | ||
data: Data; | ||
callback?: TaskCallback<TaskCallbackArgs>; | ||
}; | ||
declare class Queue<Data, TaskCallbackArgs extends unknown[]> extends EventListener { | ||
#private; | ||
constructor(worker: TaskWorker<Data, TaskCallbackArgs>, maxConcurrency?: number); | ||
push(data: Data, callback?: TaskCallback<TaskCallbackArgs>): number; | ||
remove(id: TaskId): void; | ||
remove(task: Task<Data, TaskCallbackArgs>): void; | ||
} | ||
/** | ||
* 基于种子的随机数生成器 | ||
*/ | ||
declare class SeededRandom { | ||
seed: number; | ||
constructor(seed?: string | number); | ||
/** | ||
* 获取随机数 0-1 | ||
* @returns 随机数 | ||
*/ | ||
random(): number; | ||
/** | ||
* 根据最大值和最小值获取随机数 | ||
* @param min 最小值 | ||
* @param max 最大值 默认为最小值 | ||
* @param precision 小数精度 默认为0 | ||
* @returns 整数随机数 | ||
*/ | ||
randomNumber(min: number, max?: number, precision?: number): number; | ||
/** | ||
* 根据长度获取随机字符串 | ||
* @param length 长度 默认16 | ||
* @param chars 字符串 默认为0-9a-zA-Z | ||
* @returns 随机字符串 | ||
*/ | ||
randomString(length?: number, chars?: string): string; | ||
/** | ||
* 获取随机布尔值 | ||
* @returns 随机布尔值 | ||
*/ | ||
randomBoolean(): boolean; | ||
/** | ||
* 根据数组获取随机元素 | ||
* @param array 数组 | ||
* @param from 开始位置 默认为0 | ||
* @param to 结束位置 默认为数组长度 | ||
* @returns 随机元素 | ||
*/ | ||
randomElement<T>(array: T[], from?: number, to?: number): T; | ||
/** | ||
* 获取随机uuid | ||
* @returns 随机uuid | ||
*/ | ||
uuid(): string; | ||
/** | ||
* 获取随机Hex颜色 | ||
* @returns 随机Hex颜色 | ||
*/ | ||
randomColor(): string; | ||
/** | ||
* 获取随机rgb颜色 | ||
* @returns 随机rgb颜色 | ||
*/ | ||
randomRGBColor(): string; | ||
/** | ||
* 获取随机rgba颜色 | ||
* @returns 随机rgba颜色 | ||
*/ | ||
randomRGBAColor(): string; | ||
/** 默认种子 */ | ||
static seed: number; | ||
/** | ||
* 获取随机数 0-1 | ||
* @param seed 种子 | ||
* @returns 随机数 | ||
*/ | ||
static random(seed?: string | number): number; | ||
/** | ||
* 根据最大值和最小值获取随机数 | ||
* @param min 最小值 | ||
* @param max 最大值 默认为最小值 | ||
* @param precision 精度 默认为0 | ||
* @param seed 种子 | ||
* @returns 整数随机数 | ||
*/ | ||
static randomNumber(min: number, max?: number, precision?: number, seed?: string | number): number; | ||
/** | ||
* 根据长度获取随机字符串 | ||
* @param length 长度 默认16 | ||
* @param chars 字符串 默认为0-9a-zA-Z | ||
* @param seed 种子 | ||
* @returns 随机字符串 | ||
*/ | ||
static randomString(length?: number, chars?: string, seed?: string | number): string; | ||
/** | ||
* 获取随机布尔值 | ||
* @param seed 种子 | ||
* @returns 随机布尔值 | ||
*/ | ||
static randomBoolean(seed?: string | number): boolean; | ||
/** | ||
* 根据数组获取随机元素 | ||
* @param array 数组 | ||
* @param from 开始位置 默认为0 | ||
* @param to 结束位置 默认为数组长度 | ||
* @param seed 种子 | ||
* @returns 随机元素 | ||
*/ | ||
static randomElement<T>(array: T[], from?: number, to?: number, seed?: string | number): T; | ||
/** | ||
* 获取随机uuid | ||
* @param seed 种子 | ||
* @returns 随机uuid | ||
*/ | ||
static uuid(seed?: string | number): string; | ||
/** | ||
* 获取随机Hex颜色 | ||
* @param seed 种子 | ||
* @returns 随机Hex颜色 | ||
*/ | ||
static randomColor(seed?: string | number): string; | ||
/** | ||
* 获取随机rgb颜色 | ||
* @param seed 种子 | ||
* @returns 随机rgb颜色 | ||
*/ | ||
static randomRGBColor(seed?: string | number): string; | ||
/** | ||
* 获取随机rgba颜色 | ||
* @param seed 种子 | ||
* @returns 随机rgba颜色 | ||
*/ | ||
static randomRGBAColor(seed?: string | number): string; | ||
} | ||
/** | ||
* 设置对象中指定路径的值 | ||
* @param object - 目标对象 | ||
* @param path - 路径字符串,用于指定要设置值的位置 | ||
* @param value - 要设置的值 | ||
* @returns 设置的值 | ||
*/ | ||
declare function set<T extends Record<string, unknown>, P extends string, V>(object: T, path: P, value: V): V; | ||
type SendHandlePromise = (data: string, resolve: (value: unknown) => void, reject: (value?: unknown) => void) => void; | ||
@@ -409,3 +420,3 @@ type EventListenerHandleCallback = (data: string, callback: UnknownFunction) => void; | ||
* socket 连接到服务器。 | ||
* @param url socket 地址(默认: window.location) | ||
* @param url socket 地址 | ||
* @param options socket 配置 | ||
@@ -455,20 +466,49 @@ */ | ||
type StorageParams = { | ||
key: string; | ||
handleGetStorage?: (key: string) => Record<string, unknown>; | ||
handleSetStorage?: (key: string, value: Record<string, unknown>) => void; | ||
declare const color: { | ||
isHexColor: (color: string) => boolean; | ||
rgbToHex: (r: number, g: number, b: number) => string; | ||
hexToRGB: (hex: string, opacity?: number) => string; | ||
colorIsDark: (color: string) => boolean | undefined; | ||
darken: (color: string, amount: number) => string; | ||
lighten: (color: string, amount: number) => string; | ||
calculateBestTextColor: (hexColor: string) => "#000000" | "#FFFFFF"; | ||
}; | ||
declare class Storage { | ||
#private; | ||
get storage(): Record<string, unknown>; | ||
constructor(params: StorageParams | StorageParams['key']); | ||
getItem<V>(path: string, defaultValue?: V): V extends undefined ? unknown : V; | ||
setItem(path: string, value: unknown, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
removeItem(path: string, options?: { | ||
ensure?: boolean; | ||
}): any; | ||
interface DebounceAsyncWorker<T extends AnyFunction> { | ||
(this: Any, ...args: Parameters<T>): void; | ||
} | ||
/** | ||
* 创建一个支持异步防抖动函数,该函数会从上一次被调用后,延迟 `wait` 毫秒后执行。 | ||
* @param func 需要防抖动的函数 | ||
* @param wait 执行延迟的毫秒数,可选,默认为 0 | ||
* @returns 新的防抖动函数 | ||
*/ | ||
declare function debounceAsync<T extends AnyFunction>(func: T, wait?: number): DebounceAsyncWorker<T>; | ||
/** | ||
* `get` 函数从给定的对象中获取指定路径的值。如果路径不存在,将返回默认值。 | ||
* | ||
* @param object - 要从中获取值的对象。 | ||
* @param path - 要获取的值的路径,以点分隔。 | ||
* @param defaultValue - 如果路径不存在,将返回的默认值。 | ||
* @returns 路径上的值,如果路径不存在,则返回默认值。 | ||
*/ | ||
declare function get<T extends Record<string, unknown>, P extends string, D extends T[P]>(object: T, path: P, defaultValue?: D): P extends keyof T ? T[P] : D; | ||
declare function groupBy<T extends AnyObject>(collection: T[], iteratee: (item: T, index: number) => string): Record<string, T[]>; | ||
declare function memoize<T, R, P extends Array<Any>>(func: (this: T, ...args: P) => R, resolver?: (this: T, ...args: P) => string): { | ||
(this: T, ...args: P): R; | ||
cache: Map<any, any>; | ||
}; | ||
/** | ||
* 设置对象中指定路径的值 | ||
* @param object - 目标对象 | ||
* @param path - 路径字符串,用于指定要设置值的位置 | ||
* @param value - 要设置的值 | ||
* @returns 设置的值 | ||
*/ | ||
declare function set<T extends Record<string, unknown>, P extends string, V>(object: T, path: P, value: V): V; | ||
declare function templateCompiled(template: string, options?: { | ||
@@ -480,24 +520,2 @@ escape?: RegExp; | ||
type HandleResult = { | ||
token: string; | ||
expires: number; | ||
}; | ||
type Handle = () => HandleResult | Promise<HandleResult>; | ||
declare class TokenHandle { | ||
key: string; | ||
handle: Handle; | ||
constructor(key: string, handle: Handle); | ||
getToken(): Promise<string>; | ||
setToken(token: string, options?: { | ||
expires?: number; | ||
}): Promise<void>; | ||
static getToken(options?: { | ||
key?: string; | ||
}): string | null; | ||
static setToken(token: string, options?: { | ||
expires?: number; | ||
key?: string; | ||
}): void; | ||
} | ||
type Node$2<T extends Record<string, unknown>, K extends string> = (Pick<T, Exclude<keyof T, K>> & { | ||
@@ -520,4 +538,2 @@ [Key in K]?: Array<Node$2<T, K>>; | ||
declare function uniqWith<T>(array: T[], iteratee: (item: T, compare: T) => boolean): T[]; | ||
declare function uniq(array: unknown[]): unknown[]; | ||
@@ -529,2 +545,4 @@ | ||
declare function uniqWith<T>(array: T[], iteratee: (item: T, compare: T) => boolean): T[]; | ||
declare function urlParams(scene: string): Record<string, string>; | ||
@@ -534,2 +552,34 @@ | ||
declare class LocalStorage extends Storage { | ||
protected _getStorage(key: string): Record<string, unknown>; | ||
protected _setStorage(key: string, value: Record<string, unknown>): void; | ||
} | ||
declare class LocalStorageToken extends CacheToken { | ||
static storage: LocalStorage; | ||
static getToken(options?: { | ||
key?: string; | ||
}): string | null; | ||
static setToken(token: string, options?: { | ||
expires?: number; | ||
key?: string; | ||
}): any; | ||
} | ||
declare class SessionStorage extends Storage { | ||
protected _getStorage(key: string): Record<string, unknown>; | ||
protected _setStorage(key: string, value: Record<string, unknown>): void; | ||
} | ||
declare class SessionStorageToken extends CacheToken { | ||
static storage: SessionStorage; | ||
static getToken(options?: { | ||
key?: string; | ||
}): string | null; | ||
static setToken(token: string, options?: { | ||
expires?: number; | ||
key?: string; | ||
}): any; | ||
} | ||
type Key = string; | ||
@@ -582,2 +632,2 @@ type Value = string; | ||
export { type Any, type AnyArray, type AnyFunction, type AnyObject, EventListener, type Exclude$1 as Exclude, type Extract, type Omit, Paging, PagingLazy, type Partial, type PartialDeep, type PartialKeys, type Pick$1 as Pick, type Primitive, PromiseTimeout, Queue, type Readonly, type ReadonlyDeep, type ReadonlyKeys, type Record$1 as Record, type Required, type RequiredDeep, type RequiredKeys, type ReturnPromiseType, SeededRandom, type SerializablePrimitive, SocketManager, Storage, TokenHandle, type Unknown, type UnknownArray, type UnknownFunction, type UnknownObject, cache, color, cookie, debounceAsync, get, groupBy, memoize, set, templateCompiled, tree, treeBy, treeFlat, uniq, uniqBy, uniqWith, urlParams, wrap }; | ||
export { type Any, type AnyArray, type AnyFunction, type AnyObject, Cache, CacheToken, EventListener, type Exclude$1 as Exclude, type Extract, LocalStorage, LocalStorageToken, type Omit, Paging, PagingLazy, type Partial, type PartialDeep, type PartialKeys, type Pick$1 as Pick, type Primitive, PromiseTimeout, Queue, type Readonly, type ReadonlyDeep, type ReadonlyKeys, type Record$1 as Record, type Required, type RequiredDeep, type RequiredKeys, type ReturnPromiseType, SeededRandom, type SerializablePrimitive, SessionStorage, SessionStorageToken, SocketManager, Storage, type Unknown, type UnknownArray, type UnknownFunction, type UnknownObject, color, cookie, debounceAsync, get, groupBy, memoize, set, templateCompiled, tree, treeBy, treeFlat, uniq, uniqBy, uniqWith, urlParams, wrap }; |
{ | ||
"name": "zf-utilz", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs", |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
235411
1608
6