UNPKG

@cmtlyt/base

Version:
1,019 lines (988 loc) 35.9 kB
export { i as functor } from './shared/base.Cv6pN22A.cjs'; import { T as TObject, a as TObjKeyType, b as TAnyFunc, c as TGetArgs, d as TGetReturnType, e as TFunc, E as ErrorResult, f as TArgsType, g as TFlatPromise, h as TReverseArray, j as TAllType, k as TExclude, l as TAppend, m as TLastBeforeTypes, n as TLastType } from './shared/base.CkkeeKUz.cjs'; export { P as ApplyCurry, x as TArrayItem, y as TArrayType, s as TCast, C as TConstructor, H as TDeepGetPropType, u as TDropHead, p as TFirstType, I as TGetArgsWithCount, J as TGetType, w as THeadTwoArg, o as THeadType, v as TLastTwoArg, t as TLength, F as TMany, A as TOptional, r as TPrepend, D as TPromiseConstructor, G as TPromiseValue, B as TRequired, q as TTailTypes, z as TUnwrapPromise, ax as TakeCurry, X as adjust, W as adjust_, Z as aperture, Y as aperture_, $ as append, _ as append_, Q as apply, S as applyTo, R as applyTo_, O as apply_, V as argNumLimit, U as argNumLimit_, a1 as collectBy, a0 as collectBy_, K as compose, L as curry, a3 as every, a2 as every_, a5 as filter, a4 as filter_, a7 as find, a9 as findIndex, a8 as findIndex_, a6 as find_, ab as groupBy, aa as groupBy_, ad as groupWith, ac as groupWith_, af as includes, ae as includes_, ah as join, ag as join_, aj as makeBy, ai as makeBy_, al as map, ak as map_, an as nth, am as nth_, ap as partition, ao as partition_, M as pipe, N as placeholderFunc, ar as reduce, aq as reduce_, at as replicate, as as replicate_, av as some, au as some_, ay as take, aw as take_, i as utils, aA as zip, az as zip_ } from './shared/base.CkkeeKUz.cjs'; declare const EMPTY: symbol; declare function warning(...args: any[]): void; declare class Calculator { #private; static group(func: (calc: Calculator) => void | Calculator | number, initValue?: number): number | Calculator; constructor(initValue?: number); add(value: number | Calculator): this; sub(value: number | Calculator): this; mut(value: number | Calculator): this; div(value: number | Calculator): this; getCurrValue(): number; valueOf(): number; } declare const clipboard: { copy: (text: string) => void; paste: () => Promise<string>; clear: () => void; readonly isCopyable: any; readonly isPasteable: any; readonly isClearable: any; }; interface ConcurrentQueueOptions { /** 最大并发数 */ maxConcurrent: number; /** * 是否在存在任务的时候自动执行 * 如果为 false, 则需要手动调用 run 方法 * @default true */ autoRun: boolean; } type PromiseResult<T> = T extends Promise<infer R> ? PromiseResult<R> : T; interface TaskItem { id: string; status: 'waiting' | 'running' | 'remove'; promise: Promise<any>; oriTask: () => Promise<any>; task: (task: TaskItem) => Promise<any>; resolve: (task: TaskItem, value: any) => void; reject: (reason?: any) => void; changeStatus: (task: TaskItem, status: TaskItem['status']) => void; } interface ExportTaskItem { id: string; status: TaskItem['status']; promise: TaskItem['promise']; task: TaskItem['task']; } interface AddOptions { return?: 'id' | 'promise'; } interface AddOptionsWithId extends AddOptions { return: 'id'; } declare class ConcurrentQueue { #private; static instanceMap: Record<string, ConcurrentQueue>; get finished(): Promise<void>; /** 队列状态 */ status: 'running' | 'finished' | 'stopped' | 'disposed'; /** 队列 id */ id: string; constructor(id: string, options?: Partial<ConcurrentQueueOptions>); /** * 添加任务到队列 * @param {() => Promise<any>} callback 任务回调 */ add<T extends Promise<any>, R = PromiseResult<T>>(callback: () => T): Promise<R>; /** * 添加任务到队列 * @param callback 任务回调 * @param {AddOptions?} options * @param {'id' | 'promise'} options.return 返回值类型 * @default options = { return: 'promise' } */ add<T extends Promise<any>, R = PromiseResult<T>, O extends AddOptions = AddOptions>(callback: () => T, options: O): O extends AddOptionsWithId ? string : Promise<R>; /** 移除等待中的任务 */ remove(id: string): boolean; remove(callback: () => Promise<any>): boolean; clear(): void; /** 获取任务信息 */ getTaskInfo(id: string): ExportTaskItem | undefined; getTaskInfo(callback: () => Promise<any>): ExportTaskItem | undefined; /** 手动运行任务 (仅在状态不为 running 时有效) */ run(): void; /** 停止任务 */ stop(): void; /** 卸载队列 */ dispose(): void; get remainingCount(): number; } declare function getAllQueueIds(): string[]; declare function getConcurrentQueue(options?: Partial<ConcurrentQueueOptions>, id?: string): ConcurrentQueue; type GetArray<T> = T extends any[] ? T : T[]; /** * 获取数组, 如果不是数组, 则会使用数组包裹, 类数组会使用 Array.from 转换 */ declare function getArray<T>(value?: T): GetArray<T>; /** * 获取数组切片 * @param array 原数组 * @param size 每个字数组的长度 * @param skip 跳过指定个数的元素 */ declare function getArraySlice<T>(array: T[], size?: number, skip?: number): T[][]; /** * 异步过滤数组 * @param arr 数组 * @param predicate 过滤函数 */ declare function asyncFilter<T>(arr: T[], predicate: (item: T, index: number) => Promise<boolean> | boolean): Promise<T[]>; /** * 深度克隆对象 */ declare function deepClone<T extends TObject<any>>(obj: T, hash?: WeakMap<WeakKey, any>): T; /** * 合并对象, 会直接修改 target * * 如不希望修改 target 对象, 请使用 cloneMerge */ declare function merge(target: any, ...source: any[]): any; /** * 合并对象, 返回新对象, 不影响原数据 */ declare function cloneMerge(target: any, ...source: any): any; declare const fromEntries: (entires: Iterable<readonly [PropertyKey, any]>) => any; /** * 遍历对象, 参考数组的 forEach * * @warning 不保证遍历顺序 */ declare const objectForEach: (obj: TObject<any>, callback: (value: any, key: string) => any) => void; /** * 遍历对象, 参考数组的 map * * @warning 不保证遍历顺序 */ declare const objectMap: (obj: TObject<any>, callback: (value: any, key: string) => any) => TObject<any>; /** * 遍历对象, 参考数组的 filter * * @warning 不保证遍历顺序 */ declare const objectFilter: (obj: TObject<any>, callback: (value: any, key: string) => boolean) => TObject<any>; /** * 遍历对象, 参考数组的 reduce * * @warning 不保证遍历顺序 */ declare const objectReduce: (obj: TObject<any>, callback: (previousValue: unknown, currentValue: any, currentKey: TObjKeyType, obj: TObject<any>) => any, initialValue: unknown) => unknown; /** * 遍历对象, 参考数组的 some * * @warning 不保证遍历顺序 */ declare const objectSome: (obj: TObject<any>, callback: (value: any, key: string) => boolean) => boolean; /** * 遍历对象, 参考数组的 every * * @warning 不保证遍历顺序 */ declare const objectEvery: (obj: TObject<any>, callback: (value: any, key: string) => boolean) => boolean; /** * 遍历对象, 参考数组的 find * * @warning 不保证遍历顺序 */ declare const objectFind: (obj: TObject<any>, callback: (value: any, key: string) => boolean) => any; /** * 异步替换字符串 * @param str 原字符串 * @param pattern 匹配正则或字符串 * @param replacer 替换函数 */ declare function asyncReplace(str: string, pattern: string | RegExp, replacer: ((matchString: string, ...args: string[]) => string | Promise<string>) | string): Promise<string>; /** * stream 转 string */ declare function streamToString(stream: ReadableStream): Promise<string>; /** * stream 转 arrayBuffer */ declare function streamToArrayBuffer(stream: ReadableStream): Promise<ArrayBuffer>; /** * arrayBuffer 转 base64 */ declare function arrayBufferToBase64String(arrayBuffer: ArrayBufferLike): string; /** * arrayBuffer 转 base64 * * 使用 arrayBufferToBase64String 代替, arrayBufferToBase64String 已兼容 chunk 方式 * * TODO: 后续大版本迭代会移除该方法 * @deprecated */ declare const arrayBufferToChunkBase64String: typeof arrayBufferToBase64String; /** * base64 转 Uint8Array */ declare function base64StringToUint8Array(base64String: string): Uint8Array<ArrayBuffer>; /** * base64 转 blob * * 使用 base64StringToBlob 代替, base64StringToBlob 已兼容 chunk 方式 * * TODO: 后续大版本迭代会移除该方法 * @deprecated */ declare function chunkBase64StringToBlob(base64String: string): Blob; /** * base64 转 blob */ declare function base64StringToBlob(base64String: string): Blob; /** * base64 转 arrayBuffer * * 使用 base64StringToArrayBuffer 代替, base64StringToArrayBuffer 已兼容 chunk 方式 * * TODO: 后续大版本迭代会移除该方法 * @deprecated */ declare const chunkBase64StringToArrayBuffer: typeof base64StringToArrayBuffer; /** * base64 转 arrayBuffer */ declare function base64StringToArrayBuffer(base64String: string): Promise<ArrayBuffer>; /** * string 转只读 stream */ declare function stringToStream(source: string): ReadableStream<any>; /** * string 转 Uint8Array */ declare function stringToBinary(source: string): Uint8Array<ArrayBufferLike>; /** * arrayBuffer 转 string */ declare function binaryToString(binary: AllowSharedBufferSource): string; /** * stream 转 base64 */ declare function streamToBase64String(stream: ReadableStream): Promise<string>; /** * stream 转 base64 * * 使用 streamToBase64String 代替 * * TODO: 后续大版本迭代会移除该方法 * @deprecated */ declare const streamToChunkBase64String: typeof streamToBase64String; /** * base64 转 stream * * 使用 base64StringToStream 代替, base64StringToStream 已兼容 chunk 方式 * * TODO: 后续大版本迭代会移除该方法 * @deprecated */ declare const chunkBase64StringToStream: typeof base64StringToStream; /** * base64 转 stream */ declare function base64StringToStream(source: string): ReadableStream<Uint8Array<ArrayBufferLike>>; /** * arrayBuffer 转 stream */ declare function arrayBufferToStream(source: AllowSharedBufferSource | ArrayBufferLike): ReadableStream<any>; /** * blob 转 base64 * * 使用 blobToBase64String 代替 * * TODO: 后续大版本迭代会移除该方法 * @deprecated */ declare const blobToChunkBase64String: typeof blobToBase64String; /** * blob 转 base64 */ declare function blobToBase64String(blob: Blob): Promise<string>; interface ParseUrlOptions { hashQueryToSearchParams?: boolean; } /** * 解析 url */ declare function parseUrl(path?: string, options?: ParseUrlOptions): URL; declare function parseSearch(search: string): URLSearchParams; declare function parseSearchObject(search: string | URLSearchParams): any; interface ObjectToStringOptions { /** * 是否使用单引号 * * @default false */ singleQuotes?: boolean; /** * 是否换行 * * @default false */ wrap?: boolean; /** 缩进使用字符, 默认空格 */ indentChar?: string; /** * 缩进数量, 默认 2 * * 如果 wrap 为 true, 则该值生效 */ indent?: number; } declare function toString(value: any, options?: Pick<ObjectToStringOptions, 'singleQuotes'>): any; declare function objectToString(obj: TObject<any>, options?: ObjectToStringOptions): string; declare function formatDate(date?: Date, format?: string): string; /** * 将函数转为只执行一次的函数, 后续调用将返回第一次调用的结果 * * 单纯缓存函数返回结果, 如果返回值为函数, 并且希望直接调用则使用 `cacheByReturn` */ declare function onceFunc<T extends TAnyFunc>(func: T): T; /** * 将函数转为只执行一次的函数, 后续调用将返回第一次调用的结果 * * @alias onceFunc */ declare const cacheReturnValue: typeof onceFunc; declare class MemoizeMap { #private; set(key: any, value: any): void; get(key: any): any; has(key: any): boolean; } /** * 将函数专为带缓存的函数 * * @warning 缓存的 key 默认为第一个参数, 如果需要自定义缓存参数, 请传入 resolver 函数 */ declare function memoize<F extends (...args: any[]) => any>(func: F, resolver?: (...args: TGetArgs<F>) => any): { (...args: TGetArgs<F>): TGetReturnType<F>; cache: MemoizeMap; }; /** * 缓存函数执行结果 * * 如果执行结果为函数, 则会调用函数 * * 如果执行结果为非函数, 则返回执行结果 * * 使用场景: 缓存的是函数, 并且每次都需要调用函数, 如果单纯为了缓存返回值, 请使用 `cacheReturnValue` 或 `onceFunc` */ declare const cacheByReturn: <T extends () => any, R = ReturnType<T>>(cacheLoad: T) => (...args: TGetArgs<R>) => TGetReturnType<R>; /** * try catch 的封装, 如果函数内报错, 则会被 catcher 捕获, 如果为传递, 则会直接抛出错误 * 支持异步函数 */ declare function tryCall<F extends TAnyFunc>(runner: F, catcher?: (e: any) => void): ReturnType<F> | void; /** * 安全的执行函数, 如果函数内出现报错, 则返回错误对象而不是抛出错误 */ declare function completion<T, A extends any[]>(func: (...args: A) => T, ...args: A): T | Error; /** * 立即执行函数 */ declare function iife<R>(func: TFunc<[], R>): R; declare function iife<T extends any[], R>(func: TFunc<T, R>, args: T): R; /** * 调用函数, 返回包装过的结果对象 * * 如果需要异步支持, 请使用 `tryOrErrorAsync` * * @param func 需要执行的函数 */ declare function tryOrError<R>(func: TFunc<any[], R>): ErrorResult<R>; /** * 调用函数, 返回包装过的结果对象 (异步版本) * * @param func */ declare function tryOrErrorAsync<R>(func: TFunc<any[], R>): Promise<ErrorResult<R>>; /** * 获取 promise 结果, 返回包装过的结果对象 * * @param promise */ declare function resultOrError<R>(promise: Promise<R>): Promise<ErrorResult<Awaited<R>>>; /** * promise 休眠 * @param time 休眠时间 (ms) */ declare const sleep: (time: number) => Promise<unknown>; /** * 同步休眠 * @param time 休眠时间 (ms) */ declare function sleepSync(time: number): void; /** * 防抖函数 (返回 Promise) * @param func 需要防抖的函数 * @param time 延迟时间 (ms) * @param immediately 是否立即执行 */ declare function debounceAsync<F extends TAnyFunc>(func: F, time?: number, immediately?: boolean): (...args: TArgsType<F>) => TFlatPromise<ReturnType<F>>; /** * 防抖函数 * @param func 需要防抖的函数 * @param time 延迟时间 (ms) * @param immediately 是否立即执行 */ declare function debounce<F extends TAnyFunc>(func: F, time?: number, immediately?: boolean): (...args: TArgsType<F>) => void; /** * 节流函数 * @param func 需要节流的函数 * @param time 延迟时间 (ms) * @param immediately 是否立即执行 */ declare function throttle<F extends TAnyFunc>(func: F, time?: number, immediately?: boolean): (...args: TArgsType<F>) => void; /** * 分片执行任务 * @param task 需要执行的函数 */ declare function chunkTask<F extends TAnyFunc>(task: F): (datas: Parameters<F>[] | number) => Promise<ReturnType<F>[]>; /** * 反转函数参数, 返回新函数 * @param callback 需要转换的函数 */ declare function reverseArgs<F extends TAnyFunc>(callback: F): (...args: TReverseArray<Parameters<F>>) => ReturnType<F>; /** * 返回一个支持传参的使用 try catch 包裹的函数 * @see tryCall * @param runner * @param catcher */ declare function tryCallFunc<F extends TAnyFunc>(runner: F, catcher?: (e: any) => void): TFunc<Parameters<F>, ReturnType<F>>; /** * 返回一个支持传参的使用 try catch 包裹的函数 * * @see tryOrError * @param func */ declare function tryOrErrorFunc<T extends any[], R>(func: TFunc<T, R>): (...args: T) => ErrorResult<R>; /** * 返回一个支持传参和异步的使用 try catch 包裹的函数 * * @see tryOrErrorAsync * @param func */ declare function tryOrErrorAsyncFunc<T extends any[], R>(func: TFunc<T, R>): (...args: T) => Promise<ErrorResult<R>>; /** * 空函数 */ declare const noop: (...args: any[]) => any; /** * 获取当前时间 */ declare const getNow: () => number; /** * 安全的获取全局对象 */ declare const safeGetGlobal: () => any; interface CookieOptions { duration?: number; expires?: string | Date; domain?: string; maxAge?: number; path?: string; } /** * 生成 cookie 字符串 */ declare function generateCookieInfo(options?: CookieOptions): string; /** * 获取 promise 的 resolve 和 reject 函数和 promise 本身 */ declare function withResolvers<T>(func?: (resolve: (value: T) => void, reject: (reason?: any) => void) => any): { resolve: (value: T) => void; reject: (reason?: any) => void; promise: Promise<T>; }; /** * 获取 AliApp 版本和名称 */ declare const getAliAppEnv: () => { appName: string; appVersion: string; }; /** * 获取设备信息 */ declare const getDeviceInfo: () => { appName: string; appVersion: string; screenWidth: number; screenHeight: number; devicePixelRatio: number; platform: string; userAgent: string; }; /** * 生成随机字符串 */ declare function getRandomString(len?: number): string; /** * 生成 blob 链接 */ declare function createLinkByString(resource: BlobPart): string; type GCArgs = string | (undefined | null | string | Record<string, boolean>)[] | Record<string, boolean> | undefined | null; /** * 生成 class 字符串 */ declare function generateClassName(...args: GCArgs[]): string; /** * 生成 class 字符串 * * @alias generateClassName */ declare const gc: typeof generateClassName; /** * 获取操作系统类型 */ declare const getOsType: () => "android" | "ios" | "openHarmony" | "mac" | "windows" | "linux" | "aix" | "freebsd" | "haiku" | "openbsd" | "sunos" | "cygwin" | "netbsd" | "other"; /** * 获取真实类型 */ declare function getType(value: any): TAllType; /** * 获取 userAgent */ declare const getUserAgent: () => string; /** * 获取空格 */ declare function getSpace(length?: number): string; /** * 获取字符 */ declare function getChar(char: string, length?: number): string; /** 判断是否为浏览器环境 */ declare const isWeb: () => boolean; /** 判断是否为 iframe 环境 */ declare const isInIframe: () => boolean; /** 判断是否为 node 环境 */ declare const isNode: () => boolean; /** 小程序环境 */ declare const isMiniApp: () => boolean; /** 阿里小程序 */ declare const isAliMiniApp: () => boolean; /** 字节小程序 */ declare const isByteDanceMicroApp: () => boolean; /** 微信小程序 */ declare const isWeChatMiniProgram: () => boolean; /** weex 环境 */ declare const isWeex: () => boolean; /** ios */ declare const isIOS: () => boolean; /** 安卓 */ declare const isAndroid: () => boolean; /** 鸿蒙 */ declare const isOpenHarmony: () => boolean; /** chrome */ declare const isChrome: () => boolean; /** firefox */ declare const isFirefox: () => boolean; /** safari */ declare const isSafari: () => boolean; /** 新 edge */ declare const isNewEdge: () => boolean; /** 旧 edge */ declare const isOldEdge: () => boolean; /** edge */ declare const isEdge: () => boolean; /** kraken 环境 */ declare const isKraken: () => boolean; /** 快应用 */ declare const isQuickApp: () => boolean; /** 淘宝 */ declare const isTBWeb: () => boolean; /** 淘特 */ declare const isLTWeb: () => boolean; /** 点淘 */ declare const isTbLive: () => boolean; /** 所有淘宝 web 环境 */ declare const isTbWebEnv: () => boolean; /** 微信 */ declare const isWechatWeb: () => boolean; /** 支付宝 */ declare const isAliPayWeb: () => boolean; /** 钉钉 */ declare const isWebInDingding: () => boolean; /** 淘宝买菜团长端 */ declare const isTuan: () => boolean; /** 零售通 */ declare const isLST: () => boolean; /** 零销宝 */ declare const isLXB: () => boolean; /** 阿里 app */ declare const isAliAppWeb: () => boolean; /** 钉钉小程序 */ declare const isDingdingMiniapp: () => boolean; /** 淘系小程序 */ declare const isTaobaoMiniapp: () => boolean; /** 支付宝 | 菜鸟小程序 */ declare const isAlipayMiniapp: () => boolean; /** 阿里小程序 */ declare const isTBMiniapp: () => boolean; /** 淘特小程序 */ declare const isLTMiniapp: () => boolean; /** 淘菜菜小程序 */ declare const isMMCMiniapp: () => boolean; /** 犀鸟小程序 */ declare const isXiNiaoapp: () => boolean; /** 菜鸟小程序 */ declare const isCaiNiaoApp: () => boolean; /** 支付宝小程序 */ declare const isAlipayApp: () => boolean; /** 百度小程序 */ declare const isBaiduSmartProgram: () => boolean; /** 快手小程序 */ declare const isKuaiShouMiniProgram: () => boolean; /** 小程序 */ declare const isAliMiniappPlatform: () => boolean; /** 淘宝 */ declare const isTBNode: () => boolean; /** 淘特 */ declare const isLTNode: () => boolean; /** 微信 */ declare const isWechatNode: () => boolean; /** 淘宝 */ declare const isTB: () => boolean; /** 淘特 */ declare const isLT: () => boolean; /** 支付宝 */ declare const isAliPay: () => boolean; /** 天猫 */ declare const isTmall: () => boolean; /** 阿里app */ declare const isAliApp: () => boolean; /** 微信端 */ declare const isWechat: () => boolean; /** 菜鸟商业版本App,内嵌团长端小程序 */ declare const isCaiNiaoBusiness: () => boolean; /** 菜鸟商业版本App */ declare const isCaiNiao: () => boolean; /** 阿里系app */ declare const isAliUa: () => boolean; /** 盒马 */ declare const isHmApp: () => boolean; /** 优酷 */ declare const isYouKu: () => boolean; /** 支付宝 webview */ declare const isAlipayMiniWeb: () => boolean; /** 淘特的 webview */ declare const isLTMiniWeb: () => boolean; /** 【历史兼容】淘宝的 webview */ declare const isLBMiniWeb: () => boolean; /** 淘宝的 webview */ declare const isTBMiniWeb: () => boolean; /** 钉钉 webview */ declare const isDingTalk: () => boolean; /** 团长小程序 webview 嵌套的 h5 */ declare const isTuanWebview: () => boolean; /** 微信小程序 webview */ declare const isWechatMiniWeb: () => boolean; /** 微信 h5 */ declare const isWechatH5: () => boolean; /** 小程序 webview */ declare const isWebInMiniApp: () => boolean; /** 阿里小程序 webview */ declare const isAliWebInMiniApp: () => boolean; /** 阿里应用小程序 */ declare const isAliAppMiniApp: () => boolean; /** * mini 系列 780 * * iPhone X / iPhone XS / iphone 11 pro 812 * * iphone 11, 11 pro max 896 * * iphone 12, 13, 14 844 * * iphone 12, 13, 14 plus 926 * * iphone 14 pro 852 * * iphone 14 pro max 932 * * 如果要判断是否为「刘海屏」,建议使用 `isIOSNotchScreen` */ declare const isIPhoneX: () => boolean; /** * 是否 iPhone XS Max (2688 x 1242) */ declare const isIPhoneXSMax: () => boolean; /** * 是否 iPhone XR (1792 x 828) */ declare const isIPhoneXR: () => boolean; /** * 是否 iPhone14 pro max */ declare const isIPhone14PM: () => boolean; /** * 是否为 iOS 的「刘海屏」,用于针对顶部状态栏做特殊处理 * * 目前 iOS 所有的「刘海屏」的适配方案是一样的 */ declare const isIOSNotchScreen: () => boolean; /** * 判断是否为数组或类数组 */ declare function isArrayLike(data: any): boolean; /** * 判断是否为数组 */ declare function isArray(value: any): value is Array<any>; declare function isArray<T>(value: T[]): value is T[]; /** * 判断是否为 null 或 undefined */ declare function isNull(value: any): value is null; /** * 判断是否为 NaN */ declare function isNaN(value: any): value is typeof Number.NaN; /** * 判断是否为数字 */ declare function isNumber(value: any): value is number; /** * 判断是否为 http 链接 */ declare function isHttpUrlString(value: any): boolean; /** * 判断是否为 https 链接 */ declare function isHttpsUrlString(value: any): boolean; /** * 判断是否为 blob 链接 */ declare function isBlobUrlString(value: any): boolean; /** * 判断是否为 data 链接 */ declare function isDataUrlString(value: any): boolean; /** * 判断是否为 url */ declare function isUrl(value: any): boolean; /** * 判断是否为 true 或字符串 true */ declare function isTrue(value: any): value is true; /** * 判断是否为 false 或字符串 false */ declare function isFalse(value: any): value is false; /** * 判断是否为空值 (通常用于 io 数据的判断) * * @warning 对于对象来说, 调用的是 Object.keys 获取长度, 所以只判断可枚举属性 */ declare function isEmpty(value: any): boolean; /** * 判断是否为字符串 */ declare function isString(value: any): value is string; /** * 判断是否为 undefined 或字符串 undefined */ declare function isUndef(value: any): value is undefined; /** * 判断是否支持某个 css 特性 */ declare function caniuseCSSFeature(feature: string): boolean; /** * 判断是否支持某个 js 特性 */ declare function caniuse(feature: keyof typeof window): boolean; /** * 判断是否为函数 */ declare function isFunc(value: any): value is (...args: any) => any; /** * 判断是否为异步函数 */ declare function isAsyncFunc(value: any): value is (...args: any[]) => Promise<any>; /** * 判断是否为构造函数 */ declare function isConstructor(obj: any): boolean; /** * 判断是否为 Promise */ declare function isPromise(value: any): value is Promise<any>; declare function isPromise<T>(value: Promise<T>): value is Promise<T>; /** * 判断是否为 File */ declare const isFile: (...args: [] | [value: any]) => boolean; /** * 判断是否为 Blob */ declare const isBlob: (...args: [] | [value: any]) => boolean; /** * 判断是否为引用类型数据 * @param value */ declare function isObject(value: any): value is object; /** * 判断是否为普通对象 * @param value */ declare function isPlainObject(value: any): value is Record<string, unknown>; declare const cookie: { get(key: string): any; set(key: string, value: string, options?: CookieOptions): void; remove(key: string): void; }; interface StoreItem<T> { data: () => T | undefined; unUse: () => void; } declare class Pool<T> { #private; static getPool<T>(poolId?: string | symbol, size?: number, initFunction?: (idx: number) => T): Pool<any> | Pool<T>; usableCount: number; isClose: boolean; constructor(size?: number, initFunction?: (idx: number) => any, poolId?: string | symbol); put(data: T): void; get(): Promise<StoreItem<T>>; close(callback: (data: T) => void): void; } type PoolType<T = any> = Pool<T>; declare function createPool<T>(initFunction: (idx: number) => T, size?: number, poolId?: string | symbol): PoolType<T>; declare function getPool<T>(poolId?: string | symbol): PoolType<T>; type HeadersHandler = (data: { chunkIdx: number; customOption: any; currentHeanders: Record<string, any>; }) => Promise<Record<string, any>>; type BodyHandler = (options: { chunk: Blob; chunkIdx: number; customOption: any; }) => Promise<Record<string, any>>; interface RequestInit { headers?: Record<string, string>; } interface UploadOptions { url: string; maxConcurrent?: number; concurrentNode?: 'chunk' | 'file'; chunkSize?: number; dataType?: 'FormData' | 'binary'; dataKey?: string; responseType?: 'json' | 'string'; retryCount?: number; requestMethod?: 'POST' | 'PUT'; headers?: Record<string, string>; headersHandler?: HeadersHandler; bodyHandler?: BodyHandler; requestOptions?: RequestInit; } interface UploadFinishInfo { data?: any; status?: 'finished'; message?: string; chunks?: number[]; errorChunks?: number[]; } type FileLive = Blob | File | string; interface UploadProgressInfo { chunkIdx: number; status: 'loading' | 'success' | 'fail' | 'error'; response: any; } interface UploadOptionsProp { onProgress?: (progress: UploadProgressInfo) => void; customOption?: any; } declare class UploadController { #private; static getInstance(options: UploadOptions, forceCreate?: boolean): UploadController; /** * @param {UploadOptions} options */ constructor(options: UploadOptions); retry(file: FileLive, chunkIdxs: number[], options: UploadOptionsProp): Promise<UploadFinishInfo>; upload(file: FileLive, options?: UploadOptionsProp): Promise<UploadFinishInfo> | undefined; abort(file: FileLive): boolean; clear(): void; close(): void; } /** * @param {UploadOptions} options * @param {boolean} forceCreate */ declare function createUploader(options: UploadOptions, forceCreate?: boolean): UploadController; interface EventFuncs { on: <T extends any[]>(callback: (...data: T) => void) => void; remove: (callback: TAnyFunc) => void; clearOn: () => void; onOnce: <T extends any[]>(callback: (...data: T) => void) => void; emit: (data: any) => void; } interface WorkerFuncs<F extends TAnyFunc, A extends any[] = Parameters<F>, R = ReturnType<F>> extends TExclude<EventFuncs, 'emit'> { run: (...args: A) => TFlatPromise<R>; dispose: () => void; } interface CreateWorkerFuncOptions { reuse?: boolean; needPost?: boolean; } declare function createWorkerFunc<F extends TAnyFunc>(func: F, importScripts?: (string | TAnyFunc)[], options?: CreateWorkerFuncOptions): WorkerFuncs<F>; interface BaseTypeMap { string: string; number: number; boolean: boolean; object: object; function: (...args: any[]) => any; any: any; unknown: unknown; undefined: undefined; void: void; null: null; } /** promise 字符串的实际类型 */ type PromiseArgsType<T> = T extends `promise<${infer K}>` | `Promise<${infer K}>` ? K extends keyof BaseTypeMap ? Promise<BaseTypeMap[K]> : Promise<any> : T extends `promise` | `Promise` ? Promise<void> : never; /** promise 类型 */ type PromiseTypeMap = { [K in `promise<${keyof BaseTypeMap}>` | `Promise<${keyof BaseTypeMap}>`]: PromiseArgsType<K>; }; type BasePromiseTypeMap = BaseTypeMap & PromiseTypeMap; /** 获取数组和剩余数组的实际类型 */ type ArrayArgsType<T> = T extends `...${infer K}` | `${infer K}[]` ? K extends keyof BasePromiseTypeMap ? BasePromiseTypeMap[K][] : any[] : any[]; /** 剩余类型 */ type ExtendsTypeMap = { [K in `...${keyof BasePromiseTypeMap}`]: ArrayArgsType<K>; }; /** 数组类型 */ type ArrayTypeMap = { [K in `${keyof BasePromiseTypeMap}[]`]: ArrayArgsType<K>; }; /** 支持的类型映射 */ type TypeMap = BasePromiseTypeMap & ExtendsTypeMap & ArrayTypeMap; /** 支持的类型 */ type TypeMapKeys = keyof TypeMap; /** 辅助包装类型 */ interface Pick$1<T extends any[]> { _: T; } /** 获取类型字符对应的实际类型 */ type GetCompType<H> = H extends keyof ExtendsTypeMap ? Pick$1<TypeMap[H]> : TypeMap[H]; /** 函数类型信息 */ type FuncTypes<A extends any[], R extends any[] = []> = A extends [infer H, ...infer L] ? FuncTypes<L, TAppend<GetCompType<H>, R>> : R; /** 判断函数是否在多态映射中 */ type FuncInMap<F extends TAnyFunc, M extends TAnyFunc> = M extends F ? F : never; /** 参数解析 */ type ArgsParse<T extends any[], R extends any[] = []> = T extends [infer H, ...infer L] ? H extends Pick$1<infer V> ? [...R, ...V] : ArgsParse<L, TAppend<H, R>> : R; /** 回调函数类型 */ type Callback<T extends any[]> = (...args: ArgsParse<TLastBeforeTypes<T>>) => TLastType<T, void>; interface RegisterFunc<M extends TAnyFunc> { /** * 注册一个重载实现 * * @warning promise 只判断是否是 promise, 对 promise 的返回值不进行校验, 所以 Promise\<number> 和 Promise\<string> 在函数匹配时是等价的 */ <A extends TypeMapKeys[], T extends any[] = FuncTypes<A>, F extends Callback<T> = Callback<T>>(func: FuncInMap<F, M>, ...args: A): PolymorphismInstance<M>; /** * 注册一个重载实现 * * @warning promise 只判断是否是 promise, 对 promise 的返回值不进行校验, 所以 Promise\<number> 和 Promise\<string> 在函数匹配时是等价的 */ <A extends TypeMapKeys[], T extends any[] = FuncTypes<A>, F extends Callback<T> = Callback<T>>(func: FuncInMap<F, M>, matchFunc: (args: any[], types: A) => boolean, ...args: A): PolymorphismInstance<M>; } interface PolymorphismController<M extends TAnyFunc> { register: RegisterFunc<M>; } type PolymorphismInstance<T extends TAnyFunc> = T & PolymorphismController<T>; declare function typesMatch(types: TypeMapKeys[], inputTypes: TypeMapKeys[]): boolean; /** * 创建一个支持重载的函数 */ declare function createOverloadFunc<T extends TAnyFunc = (...args: any) => any>(): PolymorphismInstance<T>; export { Calculator, type CookieOptions, EMPTY, ErrorResult, type PolymorphismInstance, type PoolType, TAllType, TAnyFunc, TAppend, TArgsType, TExclude, TFlatPromise, TFunc, TGetArgs, TGetReturnType, TLastBeforeTypes, TLastType, TObjKeyType, TObject, TReverseArray, type WorkerFuncs, arrayBufferToBase64String, arrayBufferToChunkBase64String, arrayBufferToStream, asyncFilter, asyncReplace, base64StringToArrayBuffer, base64StringToBlob, base64StringToStream, base64StringToUint8Array, binaryToString, blobToBase64String, blobToChunkBase64String, cacheByReturn, cacheReturnValue, caniuse, caniuseCSSFeature, chunkBase64StringToArrayBuffer, chunkBase64StringToBlob, chunkBase64StringToStream, chunkTask, clipboard, cloneMerge, completion, cookie, createLinkByString, createOverloadFunc, createOverloadFunc as createPolymorphismFunc, createPool, createUploader, createWorkerFunc, debounce, debounceAsync, deepClone, formatDate, fromEntries, gc, generateClassName, generateCookieInfo, getAliAppEnv, getAllQueueIds, getArray, getArraySlice, getChar, getConcurrentQueue, getDeviceInfo, getNow, getOsType, getPool, getRandomString, getSpace, getType, getUserAgent, iife, isAliApp, isAliAppMiniApp, isAliAppWeb, isAliMiniApp, isAliMiniappPlatform, isAliPay, isAliPayWeb, isAliUa, isAliWebInMiniApp, isAlipayApp, isAlipayMiniWeb, isAlipayMiniapp, isAndroid, isArray, isArrayLike, isAsyncFunc, isBaiduSmartProgram, isBlob, isBlobUrlString, isByteDanceMicroApp, isCaiNiao, isCaiNiaoApp, isCaiNiaoBusiness, isChrome, isConstructor, isDataUrlString, isDingTalk, isDingdingMiniapp, isEdge, isEmpty, isFalse, isFile, isFirefox, isFunc, isHmApp, isHttpUrlString, isHttpsUrlString, isIOS, isIOSNotchScreen, isIPhone14PM, isIPhoneX, isIPhoneXR, isIPhoneXSMax, isInIframe, isKraken, isKuaiShouMiniProgram, isLBMiniWeb, isLST, isLT, isLTMiniWeb, isLTMiniapp, isLTNode, isLTWeb, isLXB, isMMCMiniapp, isMiniApp, isNaN, isNewEdge, isNode, isNull, isNumber, isObject, isOldEdge, isOpenHarmony, isPlainObject, isPromise, isQuickApp, isSafari, isString, isTB, isTBMiniWeb, isTBMiniapp, isTBNode, isTBWeb, isTaobaoMiniapp, isTbLive, isTbWebEnv, isTmall, isTrue, isTuan, isTuanWebview, isUndef, isUrl, isWeChatMiniProgram, isWeb, isWebInDingding, isWebInMiniApp, isWechat, isWechatH5, isWechatMiniWeb, isWechatNode, isWechatWeb, isWeex, isXiNiaoapp, isYouKu, memoize, merge, noop, objectEvery, objectFilter, objectFind, objectForEach, objectMap, objectReduce, objectSome, objectToString, onceFunc, parseSearch, parseSearchObject, parseUrl, resultOrError, reverseArgs, safeGetGlobal, sleep, sleepSync, streamToArrayBuffer, streamToBase64String, streamToChunkBase64String, streamToString, stringToBinary, stringToStream, throttle, toString, tryCall, tryCallFunc, tryOrError, tryOrErrorAsync, tryOrErrorAsyncFunc, tryOrErrorFunc, typesMatch, warning, withResolvers };