Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zf-utilz

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zf-utilz - npm Package Compare versions

Comparing version 0.1.10 to 0.1.11

dist/business.cjs

22

dist/browser.d.ts

@@ -28,2 +28,3 @@ type StorageParams = {

}
declare const localStorage: LocalStorage;

@@ -60,11 +61,11 @@ declare class Cache<K = any, V = any> {

constructor(key: string, handle?: Handle);
getToken(): Promise<string | null>;
setToken(token: string, options?: {
get(): Promise<string | null>;
set(token: string, options?: {
expires?: number;
}): Promise<void>;
static cache: Cache<string, string>;
static getToken(options?: {
static get(options?: {
key?: string;
}): string | null;
static setToken(token: string, options?: {
static set(token: string, options?: {
expires?: number;

@@ -77,6 +78,6 @@ key?: string;

static storage: LocalStorage;
static getToken(options?: {
static get(options?: {
key?: string;
}): string | null;
static setToken(token: string, options?: {
static set(token: string, options?: {
expires?: number;

@@ -86,2 +87,3 @@ key?: string;

}
declare const localStorageToken: LocalStorageToken;

@@ -92,9 +94,10 @@ declare class SessionStorage extends Storage {

}
declare const sessionStorage: SessionStorage;
declare class SessionStorageToken extends CacheToken {
static storage: SessionStorage;
static getToken(options?: {
static get(options?: {
key?: string;
}): string | null;
static setToken(token: string, options?: {
static set(token: string, options?: {
expires?: number;

@@ -104,2 +107,3 @@ key?: string;

}
declare const sessionStorageToken: SessionStorageToken;

@@ -153,2 +157,2 @@ type Key = string;

export { LocalStorage, LocalStorageToken, SessionStorage, SessionStorageToken, cookie };
export { LocalStorage, LocalStorageToken, SessionStorage, SessionStorageToken, cookie, localStorage, localStorageToken, sessionStorage, sessionStorageToken };

@@ -8,450 +8,3 @@ export { default as clone } from 'lodash-es/clone';

export { default as throttle } from 'lodash-es/throttle';
import { AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig, AxiosStatic } from 'axios';
import { MessageOptions } from 'element-plus';
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 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;
}): void;
removeItem(path: string, options?: {
ensure?: boolean;
}): void;
clear(): void;
key(index: number): string;
}
type Any = any
type AnyFunction = (this: any, ...args: any[]) => any
type AnyObject = Record$1<string, any>
type UnknownFunction = (this: unknown, ...args: unknown[]) => unknown
// Record 它可以根据给定的键 K 和值 T 创建一个新的类型。
type Record$1<K extends keyof any, T> = { [P in K]: T }
/** 事件监听器 */
declare class EventListener {
#private;
/**
* 返回监听器全部 Key
*/
keys(): string[];
/**
* 返回监听器数组
* @param name 事件名
*/
listeners(name: string): UnknownFunction[];
/**
* 注册事件
* @param name 事件名
* @param listener 回调函数
*/
addEventListener(name: string, listener: UnknownFunction): void;
/**
* 注销事件
* @param name 事件名
* @param listener 回调函数
*/
removeEventListener(name: string, listener?: UnknownFunction): void;
/**
* 手动触发事件
* @param name 事件名
* @param args 参数
*/
dispatchEvent(name: string, ...args: unknown[]): void;
/**
* 注册事件,与 addEventListener 相同
* @param name 事件名
* @param listener 回调函数
*/
on(name: string, listener: UnknownFunction): void;
/**
* 注销事件,与 removeEventListener 相同
* @param name 事件名
* @param listener 回调函数
*/
off(name: string, listener?: UnknownFunction): void;
/**
* 注册只触发一次的事件
* @param name 事件名
* @param listener 回调函数
*/
once(name: string, listener: UnknownFunction): void;
}
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;
}
type Service<RecordItem extends Any> = (page: number, size: number) => Promise<{
total: number;
records: RecordItem[];
}>;
declare class Paging<RecordItem extends Any> {
/** 请求ID */
private _requestId;
/** 当前页数 */
private _page;
get page(): number;
/** 每页数量 */
private _size;
get size(): number;
/** 总记录数 */
private _total;
get total(): number;
/** 总页数 */
get totalPage(): number;
/** 范围 */
private _records;
get records(): RecordItem[];
/** 是否加载中 */
private _loading;
get loading(): boolean;
/** 加载失败错误对象 */
private _error;
get error(): Error | null;
/** 加载失败错误信息 */
private _errorMessage;
get errorMessage(): string | null;
/** 请求服务 */
private _service;
/** 构造函数 */
constructor(service: Service<RecordItem>, size?: number);
/** 设置页数 */
setPage(page: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 设置每页数量 */
setSize(size: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 跳转到 page 页 */
go(page: number, size?: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 刷新 */
refresh(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 重置 */
reset(): Promise<{
total: number;
records: RecordItem[];
}>;
}
declare class PagingLazy<RecordItem extends Any> extends Paging<RecordItem> {
/** 列表 */
private _list;
get list(): RecordItem[];
/** 是否加载完成 */
private _finished;
get finished(): boolean;
/** 是否为空 */
get isEmpty(): boolean;
/** 加载更多的状态 */
get loadStatus(): 'more' | 'loading' | 'noMore';
/** 跳转到 page 页 */
go(page: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 更新当前页面 */
refresh(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 重置刷新 */
reset(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 加载下一页 */
next(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 加载 */
load(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 加载全部 */
loadAll(): Promise<RecordItem[]>;
}
type PromiseTimeoutResolve<T> = (value: T) => void;
type PromiseTimeoutReject = (reason: unknown) => void;
type PromiseTimeoutExecutor<T> = (resolve: PromiseTimeoutResolve<T>, reject: PromiseTimeoutReject) => unknown;
declare class PromiseTimeout<T> extends Promise<T> {
constructor(executor: PromiseTimeoutExecutor<T>, time?: number);
}
type SendHandlePromise = (data: string, resolve: (value: unknown) => void, reject: (value?: unknown) => void) => void;
type EventListenerHandleCallback = (data: string, callback: UnknownFunction) => void;
type SocketManagerOptions = {
sendTimeout?: number;
sendHandlePromise: SendHandlePromise;
eventListenerHandleCallback: EventListenerHandleCallback;
};
declare class SocketManager {
#private;
sendTimeout: number;
sendHandlePromise: SendHandlePromise;
eventListenerHandleCallback: EventListenerHandleCallback;
constructor(options: SocketManagerOptions);
/**
* socket 是否连接到服务器。
*/
get connected(): boolean;
/**
* socket 是否与服务器断开连接。
*/
get disconnected(): boolean;
/**
* socket 连接到服务器。
* @param url socket 地址
* @param options socket 配置
*/
connect(url: string, protocols?: string | string[]): Promise<unknown>;
/**
* 关闭 socket 连接。
*/
disconnect(): Promise<this>;
/**
* 发送消息事件。
* @param data 消息参数
* @param options 附加配置
*/
send(data: string, options?: {
handlePromise?: SendHandlePromise;
timeout?: number;
}): Promise<unknown>;
/**
* socket 确保连接到服务器。
*/
ready(callback?: UnknownFunction): unknown;
addEventListener(event: string, callback: (...args: unknown[]) => void): void;
removeEventListener(event: string, callback: (...args: unknown[]) => void): void;
/**
* 监听一个具名的消息事件。
* @param event 事件名称
* @param callback 事件回调
*/
on(event: string, callback: (...args: unknown[]) => void, options?: {
handleCallback: EventListenerHandleCallback;
}): this;
/**
* 监听一个具名的消息事件,只监听一次。
* @param event 事件名称
* @param callback 事件回调
*/
once(event: string, callback: (...args: unknown[]) => void): this;
/**
* 注销一个具名的消息事件。
* @param event 事件名称
* @param callback 事件回调
*/
off(event: string, callback: (...args: unknown[]) => void): this;
}
declare const color: {

@@ -467,2 +20,9 @@ isHexColor: (color: string) => boolean;

type Any = any
type AnyFunction = (this: any, ...args: any[]) => any
type AnyObject = Record$1<string, any>
// Record 它可以根据给定的键 K 和值 T 创建一个新的类型。
type Record$1<K extends keyof any, T> = { [P in K]: T }
interface DebounceAsyncWorker<T extends AnyFunction> {

@@ -540,73 +100,2 @@ (this: Any, ...args: Parameters<T>): void;

type Override<P, S> = Omit<P, keyof S> & S
type RequestConfig = Override<AxiosRequestConfig, {
formData?: boolean
errorMessage?: string | boolean | MessageOptions
}>
type InternalRequestConfig = Override<InternalAxiosRequestConfig, {
formData?: boolean
errorMessage?: string | boolean | MessageOptions
}>
type RequestResult = string | number | boolean | null | undefined | Array<RequestResult> | { [key: string]: RequestResult }
type RequestError = {
code?: number | string
message: string
data?: unknown
config?: InternalRequestConfig
}
type RequestInstance = Override<AxiosInstance, {
<T = RequestResult>(config: RequestConfig): Promise<T>,
request<T = RequestResult>(config: RequestConfig): Promise<T>,
get<T = RequestResult>(url: string, config?: RequestConfig): Promise<T>,
delete<T = RequestResult>(url: string, config?: RequestConfig): Promise<T>,
head<T = RequestResult>(url: string, config?: RequestConfig): Promise<T>,
post<T = RequestResult>(
url: RequestConfig['url'],
data?: RequestConfig['data'],
config?: RequestConfig
): Promise<T>,
put<T = RequestResult>(
url: RequestConfig['url'],
data?: RequestConfig['data'],
config?: RequestConfig
): Promise<T>,
patch<T = RequestResult>(
url: RequestConfig['url'],
data?: RequestConfig['data'],
config?: RequestConfig
): Promise<T>
}>
type DefineRequestOptions = {
/** API 请求接口基础路径 */
baseURL: string,
/** API 请求是否启用 Mock */
useMock?: boolean,
/** API 请求格式 Code Key */
formatCodeKey?: string,
/** API 请求格式提示消息 Key */
formatMessageKey?: string,
/** API 请求格式数据 Key */
formatDataKey?: string,
/** API 请求成功 Code */
successCode?: string | number | (string | number)[],
/** API 请求认证失败需要鉴权 Code */
errorAuthCode?: string | number | (string | number)[],
/** API 请求认证失败处理方法 */
errorAuthHandle?: (error: RequestError) => void
/** API 请求错误忽略提示消息 Code */
errorIgnoreMessageCode?: string | number | (string | number)[],
/** API 请求错误消息翻译 */
errorMessageTranslation?: Record<string, string>
}
type DefineRequestGetOptions = (() => DefineRequestOptions)
declare function defineRequest(axios: AxiosStatic, options: DefineRequestOptions | DefineRequestGetOptions): RequestInstance;
export { Cache, CacheToken, EventListener, Paging, PagingLazy, PromiseTimeout, Queue, SeededRandom, SocketManager, Storage, color, debounceAsync, defineRequest, get, groupBy, memoize, set, templateCompiled, tree, treeBy, treeFlat, uniq, uniqBy, uniqWith, urlParams, wrap };
export { color, debounceAsync, get, groupBy, memoize, set, templateCompiled, tree, treeBy, treeFlat, uniq, uniqBy, uniqWith, urlParams, wrap };

@@ -8,3 +8,3 @@ export { default as clone } from 'lodash-es/clone';

export { default as throttle } from 'lodash-es/throttle';
import { AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig, AxiosStatic } from 'axios';
import { AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios';
import { MessageOptions } from 'element-plus';

@@ -60,2 +60,84 @@

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";
};
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?: {
escape?: RegExp;
interpolate?: RegExp;
evaluate?: RegExp;
}): string;
type Node$2<T extends Record<string, unknown>, K extends string> = (Pick<T, Exclude<keyof T, K>> & {
[Key in K]?: Array<Node$2<T, K>>;
});
declare function tree<T extends Node$2<T, CK>, IK extends keyof T, CK extends string = 'children'>(array: T[], akey: IK, bKey: IK, childrenKey?: CK): (Pick<T, Exclude<keyof T, CK>> & { [Key in CK]?: (Pick<T, Exclude<keyof T, CK>> & any)[] | undefined; })[];
type Node$1<T extends Record<string, unknown>, K extends string> = (Pick<T, Exclude<keyof T, K>> & {
[Key in K]?: Array<Node$1<T, K>>;
});
type Iteratee<T> = (item: T, compare: T) => boolean;
declare function treeBy<T extends Node$1<T, K>, K extends string = 'children'>(array: T[], iteratee: Iteratee<T>, childrenKey?: K): Array<Node$1<T, K>>;
type Item$1<T extends Record<string, unknown>, K extends string> = Pick<T, Exclude<keyof T, K>>;
type Node<T extends Record<string, unknown>, K extends string> = (Pick<T, Exclude<keyof T, K>> & {
[Key in K]?: Array<Node<T, K>>;
});
declare function treeFlat<T extends Node<T, K>, K extends string = 'children'>(array: T[], childrenKey?: K): Item$1<T, K>[];
declare function uniq(array: unknown[]): unknown[];
type Item = Record<string, unknown>;
declare function uniqBy<T extends Item>(array: T[], iteratee: string): T[];
declare function uniqBy<T extends Item>(array: T[], iteratee: (item: T) => boolean): T[];
declare function uniqWith<T>(array: T[], iteratee: (item: T, compare: T) => boolean): T[];
declare function urlParams(scene: string): Record<string, string>;
declare function wrap<T extends (...args: any) => any, R>(value: T, wrapper: (value: T, ...args: Parameters<T>) => R): (...args: Parameters<T>) => R;
declare class Cache<K = any, V = any> {

@@ -91,11 +173,11 @@ readonly _cacheMap: Map<any, any>;

constructor(key: string, handle?: Handle);
getToken(): Promise<string | null>;
setToken(token: string, options?: {
get(): Promise<string | null>;
set(token: string, options?: {
expires?: number;
}): Promise<void>;
static cache: Cache<string, string>;
static getToken(options?: {
static get(options?: {
key?: string;
}): string | null;
static setToken(token: string, options?: {
static set(token: string, options?: {
expires?: number;

@@ -106,2 +188,199 @@ key?: 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;
}): void;
removeItem(path: string, options?: {
ensure?: boolean;
}): void;
clear(): void;
key(index: number): string;
}
type Service<RecordItem extends Any> = (page: number, size: number) => Promise<{
total: number;
records: RecordItem[];
}>;
declare class Paging<RecordItem extends Any> {
/** 请求ID */
private _requestId;
/** 当前页数 */
private _page;
get page(): number;
/** 每页数量 */
private _size;
get size(): number;
/** 总记录数 */
private _total;
get total(): number;
/** 总页数 */
get totalPage(): number;
/** 范围 */
private _records;
get records(): RecordItem[];
/** 是否加载中 */
private _loading;
get loading(): boolean;
/** 加载失败错误对象 */
private _error;
get error(): Error | null;
/** 加载失败错误信息 */
private _errorMessage;
get errorMessage(): string | null;
/** 请求服务 */
private _service;
/** 构造函数 */
constructor(service: Service<RecordItem>, size?: number);
/** 设置页数 */
setPage(page: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 设置每页数量 */
setSize(size: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 跳转到 page 页 */
go(page: number, size?: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 刷新 */
refresh(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 重置 */
reset(): Promise<{
total: number;
records: RecordItem[];
}>;
}
declare class PagingLazy<RecordItem extends Any> extends Paging<RecordItem> {
/** 列表 */
private _list;
get list(): RecordItem[];
/** 是否加载完成 */
private _finished;
get finished(): boolean;
/** 是否为空 */
get isEmpty(): boolean;
/** 加载更多的状态 */
get loadStatus(): 'more' | 'loading' | 'noMore';
/** 跳转到 page 页 */
go(page: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 更新当前页面 */
refresh(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 重置刷新 */
reset(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 加载下一页 */
next(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 加载 */
load(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 加载全部 */
loadAll(): Promise<RecordItem[]>;
}
type handleSendDataStringify = (sentMessage: any) => string | ArrayBufferLike | Blob | ArrayBufferView;
type HandleSendPromise = (sentMessage: string, receivedMessage: string, resolve: (value: unknown) => void, reject: (value?: unknown) => void) => void;
type EventListenerHandleCallback = (name: string, receivedMessage: string, callback: UnknownFunction) => void;
type SocketManagerOptions = {
sendTimeout?: number;
handleSendDataStringify?: handleSendDataStringify;
handleSendPromise?: HandleSendPromise;
eventListenerHandleCallback?: EventListenerHandleCallback;
};
declare class SocketManager {
#private;
sendTimeout: number;
handleSendDataStringify: handleSendDataStringify | null;
handleSendPromise: HandleSendPromise | null;
eventListenerHandleCallback: EventListenerHandleCallback | null;
constructor(options: SocketManagerOptions);
/**
* socket 是否连接到服务器。
*/
get connected(): boolean;
/**
* socket 是否与服务器断开连接。
*/
get disconnected(): boolean;
/**
* socket 连接到服务器。
* @param url socket 地址
* @param options socket 配置
*/
connect(url: string, protocols?: string | string[]): Promise<unknown>;
/**
* 关闭 socket 连接。
*/
disconnect(): Promise<this>;
/**
* 发送消息事件。
* @param data 消息参数
* @param options 附加配置
*/
send(data: any, options?: {
handleDataStringify?: handleSendDataStringify;
handlePromise?: HandleSendPromise;
timeout?: number;
}): Promise<unknown>;
/**
* socket 确保连接到服务器。
*/
ready(): Promise<true>;
ready(callback: UnknownFunction): void;
addEventListener(event: string, callback: (...args: unknown[]) => void): void;
removeEventListener(event: string, callback: (...args: unknown[]) => void): void;
/**
* 监听一个具名的消息事件。
* @param event 事件名称
* @param callback 事件回调
*/
on(event: string, callback: (...args: unknown[]) => void, options?: {
handleCallback?: EventListenerHandleCallback;
}): this;
/**
* 监听一个具名的消息事件,只监听一次。
* @param event 事件名称
* @param callback 事件回调
*/
once(event: string, callback: (...args: unknown[]) => void): this;
/**
* 注销一个具名的消息事件。
* @param event 事件名称
* @param callback 事件回调
*/
off(event: string, callback: (...args: unknown[]) => void): this;
}
/**

@@ -232,25 +511,2 @@ * 基于种子的随机数生成器

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;
}): void;
removeItem(path: string, options?: {
ensure?: boolean;
}): void;
clear(): void;
key(index: number): string;
}
/** 事件监听器 */

@@ -325,103 +581,2 @@ declare class EventListener {

type Service<RecordItem extends Any> = (page: number, size: number) => Promise<{
total: number;
records: RecordItem[];
}>;
declare class Paging<RecordItem extends Any> {
/** 请求ID */
private _requestId;
/** 当前页数 */
private _page;
get page(): number;
/** 每页数量 */
private _size;
get size(): number;
/** 总记录数 */
private _total;
get total(): number;
/** 总页数 */
get totalPage(): number;
/** 范围 */
private _records;
get records(): RecordItem[];
/** 是否加载中 */
private _loading;
get loading(): boolean;
/** 加载失败错误对象 */
private _error;
get error(): Error | null;
/** 加载失败错误信息 */
private _errorMessage;
get errorMessage(): string | null;
/** 请求服务 */
private _service;
/** 构造函数 */
constructor(service: Service<RecordItem>, size?: number);
/** 设置页数 */
setPage(page: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 设置每页数量 */
setSize(size: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 跳转到 page 页 */
go(page: number, size?: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 刷新 */
refresh(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 重置 */
reset(): Promise<{
total: number;
records: RecordItem[];
}>;
}
declare class PagingLazy<RecordItem extends Any> extends Paging<RecordItem> {
/** 列表 */
private _list;
get list(): RecordItem[];
/** 是否加载完成 */
private _finished;
get finished(): boolean;
/** 是否为空 */
get isEmpty(): boolean;
/** 加载更多的状态 */
get loadStatus(): 'more' | 'loading' | 'noMore';
/** 跳转到 page 页 */
go(page: number): Promise<{
total: number;
records: RecordItem[];
}>;
/** 更新当前页面 */
refresh(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 重置刷新 */
reset(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 加载下一页 */
next(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 加载 */
load(): Promise<{
total: number;
records: RecordItem[];
}>;
/** 加载全部 */
loadAll(): Promise<RecordItem[]>;
}
type PromiseTimeoutResolve<T> = (value: T) => void;

@@ -434,152 +589,2 @@ type PromiseTimeoutReject = (reason: unknown) => void;

type SendHandlePromise = (data: string, resolve: (value: unknown) => void, reject: (value?: unknown) => void) => void;
type EventListenerHandleCallback = (data: string, callback: UnknownFunction) => void;
type SocketManagerOptions = {
sendTimeout?: number;
sendHandlePromise: SendHandlePromise;
eventListenerHandleCallback: EventListenerHandleCallback;
};
declare class SocketManager {
#private;
sendTimeout: number;
sendHandlePromise: SendHandlePromise;
eventListenerHandleCallback: EventListenerHandleCallback;
constructor(options: SocketManagerOptions);
/**
* socket 是否连接到服务器。
*/
get connected(): boolean;
/**
* socket 是否与服务器断开连接。
*/
get disconnected(): boolean;
/**
* socket 连接到服务器。
* @param url socket 地址
* @param options socket 配置
*/
connect(url: string, protocols?: string | string[]): Promise<unknown>;
/**
* 关闭 socket 连接。
*/
disconnect(): Promise<this>;
/**
* 发送消息事件。
* @param data 消息参数
* @param options 附加配置
*/
send(data: string, options?: {
handlePromise?: SendHandlePromise;
timeout?: number;
}): Promise<unknown>;
/**
* socket 确保连接到服务器。
*/
ready(callback?: UnknownFunction): unknown;
addEventListener(event: string, callback: (...args: unknown[]) => void): void;
removeEventListener(event: string, callback: (...args: unknown[]) => void): void;
/**
* 监听一个具名的消息事件。
* @param event 事件名称
* @param callback 事件回调
*/
on(event: string, callback: (...args: unknown[]) => void, options?: {
handleCallback: EventListenerHandleCallback;
}): this;
/**
* 监听一个具名的消息事件,只监听一次。
* @param event 事件名称
* @param callback 事件回调
*/
once(event: string, callback: (...args: unknown[]) => void): this;
/**
* 注销一个具名的消息事件。
* @param event 事件名称
* @param callback 事件回调
*/
off(event: string, callback: (...args: unknown[]) => void): this;
}
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";
};
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?: {
escape?: RegExp;
interpolate?: RegExp;
evaluate?: RegExp;
}): string;
type Node$2<T extends Record<string, unknown>, K extends string> = (Pick<T, Exclude<keyof T, K>> & {
[Key in K]?: Array<Node$2<T, K>>;
});
declare function tree<T extends Node$2<T, CK>, IK extends keyof T, CK extends string = 'children'>(array: T[], akey: IK, bKey: IK, childrenKey?: CK): (Pick<T, Exclude<keyof T, CK>> & { [Key in CK]?: (Pick<T, Exclude<keyof T, CK>> & any)[] | undefined; })[];
type Node$1<T extends Record<string, unknown>, K extends string> = (Pick<T, Exclude<keyof T, K>> & {
[Key in K]?: Array<Node$1<T, K>>;
});
type Iteratee<T> = (item: T, compare: T) => boolean;
declare function treeBy<T extends Node$1<T, K>, K extends string = 'children'>(array: T[], iteratee: Iteratee<T>, childrenKey?: K): Array<Node$1<T, K>>;
type Item$1<T extends Record<string, unknown>, K extends string> = Pick<T, Exclude<keyof T, K>>;
type Node<T extends Record<string, unknown>, K extends string> = (Pick<T, Exclude<keyof T, K>> & {
[Key in K]?: Array<Node<T, K>>;
});
declare function treeFlat<T extends Node<T, K>, K extends string = 'children'>(array: T[], childrenKey?: K): Item$1<T, K>[];
declare function uniq(array: unknown[]): unknown[];
type Item = Record<string, unknown>;
declare function uniqBy<T extends Item>(array: T[], iteratee: string): T[];
declare function uniqBy<T extends Item>(array: T[], iteratee: (item: T) => boolean): T[];
declare function uniqWith<T>(array: T[], iteratee: (item: T, compare: T) => boolean): T[];
declare function urlParams(scene: string): Record<string, string>;
declare function wrap<T extends (...args: any) => any, R>(value: T, wrapper: (value: T, ...args: Parameters<T>) => R): (...args: Parameters<T>) => R;
type Override<P, S> = Omit<P, keyof S> & S

@@ -632,4 +637,2 @@

baseURL: string,
/** API 请求是否启用 Mock */
useMock?: boolean,
/** API 请求格式 Code Key */

@@ -641,4 +644,4 @@ formatCodeKey?: string,

formatDataKey?: string,
/** API 请求成功 Code */
successCode?: string | number | (string | number)[],
/** API 校验请求成功 Code */
checkSuccessCode?: string | number | (string | number)[] | ((code: string | number) => boolean),
/** API 请求认证失败需要鉴权 Code */

@@ -648,6 +651,8 @@ errorAuthCode?: string | number | (string | number)[],

errorAuthHandle?: (error: RequestError) => void
/** API 请求错误忽略提示消息 Code */
errorIgnoreMessageCode?: string | number | (string | number)[],
/** API 请求错误消息翻译 */
errorMessageTranslation?: Record<string, string>
errorMessageTranslation?: Record<string, string>,
/** API 处理 请求错误 */
handleErrorMessage?: (code: string | number, message: string) => void,
/** API 处理 Token */
handleToken?: (config: AxiosRequestConfig, storageToken: InstanceType<LocalStorageToken>) => void,
}

@@ -657,3 +662,3 @@

declare function defineRequest(axios: AxiosStatic, options: DefineRequestOptions | DefineRequestGetOptions): RequestInstance;
declare function defineRequest(options: DefineRequestOptions | DefineRequestGetOptions): RequestInstance;

@@ -664,9 +669,10 @@ declare class LocalStorage extends Storage {

}
declare const localStorage: LocalStorage;
declare class LocalStorageToken extends CacheToken {
declare class LocalStorageToken$1 extends CacheToken {
static storage: LocalStorage;
static getToken(options?: {
static get(options?: {
key?: string;
}): string | null;
static setToken(token: string, options?: {
static set(token: string, options?: {
expires?: number;

@@ -676,2 +682,3 @@ key?: string;

}
declare const localStorageToken: LocalStorageToken$1;

@@ -682,9 +689,10 @@ declare class SessionStorage extends Storage {

}
declare const sessionStorage: SessionStorage;
declare class SessionStorageToken extends CacheToken {
static storage: SessionStorage;
static getToken(options?: {
static get(options?: {
key?: string;
}): string | null;
static setToken(token: string, options?: {
static set(token: string, options?: {
expires?: number;

@@ -694,2 +702,3 @@ key?: string;

}
declare const sessionStorageToken: SessionStorageToken;

@@ -743,2 +752,2 @@ type Key = string;

export { type Any, type AnyArray, type AnyFunction, type AnyObject, Cache, CacheToken, EventListener, type Exclude$1 as Exclude, type Extract, LocalStorage, LocalStorageToken, type Omit$1 as 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, defineRequest, 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$1 as LocalStorageToken, type Omit$1 as 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, defineRequest, get, groupBy, localStorage, localStorageToken, memoize, sessionStorage, sessionStorageToken, set, templateCompiled, tree, treeBy, treeFlat, uniq, uniqBy, uniqWith, urlParams, wrap };
{
"name": "zf-utilz",
"version": "0.1.10",
"version": "0.1.11",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc