//#region ../../node_modules/.pnpm/base64-arraybuffer@1.0.2/node_modules/base64-arraybuffer/dist/types/index.d.ts declare const encode: (arraybuffer: ArrayBuffer) => string; declare const decode: (base64: string) => ArrayBuffer; //#endregion //#region src/env.d.ts /** 运行环境 */ type Env = "wx" | "qq" | "donut" | "js"; /** 运行环境 */ declare const env: Env; //#endregion //#region src/emitter.d.ts type EventType = string | symbol; type Handler = (event: T) => void | Promise; type WildcardHandler> = (type: keyof T, event: T[keyof T]) => void | Promise; type EventHandlerList = Handler[]; type WildCardEventHandlerList> = WildcardHandler[]; type EventHandlerMap = Map | WildCardEventHandlerList>; interface EmitterInstance { all: EventHandlerMap; on(type: Key, handler: Handler): void; on(type: "*", handler: WildcardHandler): void; off(type: Key, handler?: Handler): void; off(type: "*", handler: WildcardHandler): void; emit(type: Key, event: Events[Key]): void; emit(type: undefined extends Events[Key] ? Key : never): void; emitAsync(type: Key, event: Events[Key]): Promise; emitAsync(type: undefined extends Events[Key] ? Key : never): Promise; } /** * Tiny (~300b) functional event emitter / pubsub. * * @param all An optional event handler map to use as the backing store for the emitter's events. * Use * @returns Emitter */ declare const Emitter: (all?: EventHandlerMap) => EmitterInstance; //#endregion //#region src/error.d.ts interface MpErrorOptions { code?: number; message?: string; } declare class MpError extends Error { code: number | null; constructor({ code, message }: MpErrorOptions); toString(): string; } declare namespace logger_d_exports { export { debug, error, filter, info, warn }; } /** 写入普通日志 */ declare const debug: (...args: any[]) => void; /** 写入信息日志 */ declare const info: (...args: any[]) => void; /** 写入警告日志 */ declare const warn: (...args: any[]) => void; /** 写入错误日志 */ declare const error: (...args: any[]) => void; /** * 写入过滤信息 * * @param filterMsg 过滤信息 */ declare const filter: (filterMsg: string) => void; declare namespace query_d_exports { export { join, parse, stringify }; } /** * 字符串参数解析 * * @param queryString 需要解析的字符串 * @param splitter 分隔符 * @returns 参数对象 */ declare const parse: (queryString?: string, splitter?: string) => Record; /** * Query 对象转换字符串 * * @param params Query 对象 * @param splitter 分隔符 * @param unencoded 是否已经解码 * @returns 解析的字符串 */ declare const stringify: (params?: Record, splitter?: string, unencoded?: boolean) => string; /** * URL 添加 query * * @param path 前部分路径 * @param queries Query对象 * @param unencoded 是否已经解码,默认为否 * @returns 处理过的 url */ declare const join: (path: string, queries: Record, unencoded?: boolean) => string; //#endregion //#region src/type.d.ts /** * 获取变量类型 * * @param obj 需要辨别的变量 * @returns 对象的类型 */ declare const type: (obj: unknown) => string; declare const isFunction: (obj: unknown) => obj is T; //#endregion //#region src/utils.d.ts /** * 包装函数,先执行 wrapper ,然后执行原函数 * * @param original 原函数 * @param pre 预执行函数 * @returns 包装函数 E.g.: * * ```ts * const a = () => console.log("a"); * const b = () => console.log("b"); * const c = wrapFunction(a, b); * c(); // expect to output 'a', and then output 'b' * ``` */ declare function wrapFunction(original: ((this: ThisType, ...args: any[]) => void) | undefined, pre: (this: ThisType, ...args: any[]) => void): (this: ThisType, ...args: any[]) => void; declare function wrapFunction(original: ((this: ThisType, ...args: any[]) => Promise) | undefined, pre: (this: ThisType, ...args: any[]) => void): (this: ThisType, ...args: any[]) => Promise; /** * 锁定某个函数使其无法被再次执行直到函数自己解锁 * * @param fn 需要锁定的函数, 形式为 `(release: () => void, ...args: A) => R` * @param ctx 可选的上下文环境 * @returns 封装函数,形式为 `(...args: A) => R` * * ```ts * let count = 0; * const func = (release: () => void) => { * count += 1; * setTimeout(() => { * release(); * }, 10); * }; * const fn = tool.lock(func); * fn(); // count is 1 * fn(); // count is still 1 because it's not released * setTimeout(() => { * fn(); // count is 2 because it's released * fn(); // count is still 2 because it's locked again * }, 15); * ``` */ declare const lock: (fn: (this: ThisType, release: () => void, ...args: Args) => ReturnType, ctx?: ThisType) => ((this: ThisType, ...args: Args) => ReturnType | undefined); /** * 包装函数保证其之被调用一次 * * @param func 调用的函数 * @param ctx 可选的上下文环境 * @returns 包装过的函数 E.g.: * * ```ts * let count = 0; * const counter = once(() => count++); * counter(); // count is 1 * counter(); // count is still 1 * ``` */ declare const once: (func: (...args: Args) => ReturnType, ctx?: ThisType) => ((this: ThisType, ...args: Args) => ReturnType | undefined); interface Task { /** 函数本身 */ func: (this: This, next: () => void, ...args: ArgType) => void; /** 函数的运行上下文 */ ctx: This; /** 函数的参数 */ args: ArgType; } /** 一个队列,在上一个函数执行完毕后执行 `next()` 才会开始执行下一个函数。 */ declare class Queue { /** 允许同时并行的任务数 */ capacity: number; constructor(/** 允许同时并行的任务数 */ capacity?: number); /** 回调队列 */ funcQueue: Task[]; /** 正在运行的数量 */ running: number; /** 执行下一个函数 */ next(): void; /** * 添加函数 * * @param func 函数 * @param ctx 函数运行上下文 * @param args 函数参数 */ add(func: (next: () => void, ...args: Args) => void, ctx?: T, ...args: Args): void; /** 清除队列,不再执行尚未执行的函数 */ clear(): void; } /** * 在调用函数的时候启用队列,在上一个函数执行完毕后执行 `next()` 才会开始执行下一个函数。 * * @async * @param fn 处理的函数 * @param capacity 允许同时并行的任务数 * @returns 包装过的函数 */ declare const funcQueue: (fn: (next: () => void, ...args: Args) => void, capacity?: number) => ((this: T, ...args: Args) => void); interface PromiseQueue { /** * 运行队列中的函数,直到所有函数执行完毕或调用 `stop` 方法停止队列。 * * @async * @returns 一个 Promise,解析为一个对象,表示队列是否被中断以及中断时的消息(如果有的话)。 * * - 如果队列正常执行完毕,Promise 解析为 `{ interrupted: false }`。 * - 如果队列被 `stop` 方法中断,Promise 解析为 `{ interrupted: true; msg: T }`,其中 `msg` 是通过 `stop` 方法传递的消息。 */ run: () => Promise<{ interrupted: false; } | { interrupted: true; msg: StopMessage; }>; /** 停止队列,正在执行的函数会继续执行完毕,但尚未执行的函数将不再执行。 */ stop: (msg: StopMessage) => void; } /** * 一个队列,支持可控并发和中断 * * @param actionList 任务列表,形式为 `(() => Promise)[]` * @param capacity 允许同时并行的任务数 * @returns 拥有 `run` 和 `stop` 方法的对象 */ declare const createQueue: (actionList: (() => Promise)[], capacity?: number) => PromiseQueue; //#endregion export { Emitter, EmitterInstance, Env, EventHandlerList, EventHandlerMap, EventType, Handler, MpError, MpErrorOptions, PromiseQueue, Queue, Task, WildCardEventHandlerList, WildcardHandler, createQueue, decode as decodeBase64, encode as encodeBase64, env, funcQueue, isFunction, lock, logger_d_exports as logger, once, query_d_exports as query, type, wrapFunction }; //# sourceMappingURL=index.d.ts.map