import dayjs from 'dayjs'; export { default as dayjs } from 'dayjs'; /** * promise 结果转数组 */ declare function to(promise: Promise): Promise<[any, any]>; interface IRequestOptions { method?: string; headers?: Record; credentials?: RequestCredentials; body?: Record; query?: Record; contentType?: "json" | "text" | "blob"; requestMiddlewares?: Array<(data: IFetchOptions) => IFetchOptions>; responseMiddlewares?: Array<(res: any) => any>; timeout?: number; signal?: AbortSignal; signType?: number; [key: string]: any; } interface IFetchOptions { method: string; headers: Record; credentials?: RequestCredentials; body?: string; signal: AbortSignal; } declare const request: { (url: string, options?: IRequestOptions): Promise; post(url: string, options?: IRequestOptions): Promise; get(url: string, options?: IRequestOptions): Promise; }; /** * 把任务集合转换为串行任务 * 串行执行时可指定每次同时(并发)可执行任务的条数 * @param {Array} items 任务列表 * @param {Number} length 每次并发任务的条数 * @return {Promise} Promise对象按切片执行结果 */ declare const parallelToSerial: (items: Array<() => Promise>, length?: number) => Promise; /** * 统计字数,英文算1个,中文算2个 * @param {string} str [description] * @return {number} [description] */ declare const getStrLength: (str: string) => number; type waterMarkOptions = { text: string; size?: [number, number]; angle?: number; globalAlpha?: number; }; /** * 设置水印 * 该函数用于在页面或元素中设置文本水印,通过创建水印实例并渲染来实现 * 注意:需要获取dom树加载完毕后调用 * @param options {object} - 水印配置项 * @property options.markText {string} - 文本 * @property options.size {Array} - 尺寸,默认值[400, 200] * @property options.angle {number} - 旋转角度,默认值为 -30 度 * @property options.platform {string} - 显示端,默认值为web,可选h5 * @property options.globalAlpha {numer} - 透明度,默认值0.1,最大值1 * @returns {Promise<{ destroy: () => void }>} - 返回一个包含销毁水印方法的对象 */ declare const setWaterMark: (options: waterMarkOptions) => { destroy: () => void; }; declare function genUUID(): string; declare function genTimeBasedId(randomLength?: number): string; declare function genRandomStringId(length?: number): string; declare function splitOnFirst(string: string, separator: string): string[]; declare function rafInterval(callback: () => void, delay?: number): { clear: () => void; }; declare function rafTimeout(callback: () => void, delay?: number): { clear: () => void; }; /** * 延时 Promise * @param ms 毫秒 */ declare const sleep: (ms: number) => Promise; /** * 失败重试 * @param fn 异步函数 * @param times 重试次数,默认 3 * @param delay 重试间隔毫秒,默认 1000 */ declare const retry: (fn: () => Promise, times?: number, delay?: number) => Promise; /** * 节流函数(leading-edge) * @param fn 原函数 * @param delay 间隔毫秒 */ declare const throttle: void>(fn: T, delay: number) => T; /** * 函数结果缓存 * @param fn 原函数 * @returns 带缓存的函数 */ declare const memoize: any>(fn: T) => T; interface FileDownloadOptions { /** 下载模式:link(默认)、fetch(blob下载)、iframe */ mode?: "link" | "fetch" | "iframe"; /** 文件名(link/fetch 模式有效) */ fileName?: string; /** 进度回调 `0~1`(仅 fetch 模式) */ onProgress?: (progress: number) => void; /** 请求头(仅 fetch 模式) */ headers?: Record; /** 请求超时毫秒(仅 fetch 模式,默认 60000) */ timeout?: number; } /** * 文件下载,支持多种下载模式 * * @example * // 默认 标签下载 * fileDownload('https://example.com/file.pdf') * * // fetch blob 下载(支持进度回调) * fileDownload('https://example.com/file.pdf', { * mode: 'fetch', * fileName: 'myfile.pdf', * onProgress: (p) => console.log(`${Math.round(p * 100)}%`), * }) * * // iframe 下载 * fileDownload('https://example.com/file.pdf', { mode: 'iframe' }) */ declare const fileDownload: (url: string, options?: FileDownloadOptions) => Promise; /** * 获取时间对象 * @returns dateObject */ declare const getDateObject: (date: string | number | Date | dayjs.Dayjs | null | undefined) => { year: number; month: number; day: number; week: 0 | 1 | 3 | 2 | 4 | 5 | 6; hour: number; minute: number; second: number; }; declare enum DateRangeTypeEnum { "one-minute" = "one-minute", "five-minute" = "five-minute", "fiftten-minute" = "fiftten-minute", "one-hour" = "one-hour", "four-hour" = "four-hour", "one-day" = "one-day", "today" = "today", "yesterday" = "yesterday", "one-week" = "one-week", "week" = "week", "last-week" = "last-week", "seven-day" = "seven-day", "thirty-day" = "thirty-day", "month" = "month", "last-month" = "last-month", "three-month" = "three-month", "six-month" = "six-month", "twelve-month" = "twelve-month" } declare const DATE_RANGE_TYPE_OPTIONS: { value: DateRangeTypeEnum; label: string; refresh: boolean; time: () => dayjs.Dayjs[]; }[]; declare const getDateRange: (rangeType: DateRangeTypeEnum) => dayjs.Dayjs[] | null; /** * @description 判断是否为 null */ declare const isNull: (value: any) => boolean; /** * 是否是空值 * @param value * @returns {boolean} */ declare const isEmpty: (value: any) => boolean; /** * 对象判断 */ declare const isObject: (value: any) => boolean; /** * @description 判断是否为对象 */ declare const isObjectLike: (value: any) => boolean; /** * @description 判断是否是长度 */ declare const isLength: (value: any) => boolean; declare const isArrayLike: (value: any) => boolean; declare const isSet: (value: any) => boolean; declare const isMap: (value: any) => boolean; /** * 判断是否是数字 */ declare const isNumber: (value: any) => boolean; /** * 判断是否是移动端 */ declare const isMobile: () => boolean; /** * 判断是否是IOS * @returns {boolean} * MSStream是IE11中的一个对象 */ declare const isIOS: () => boolean; /** * 判断是否是安卓 * @returns {boolean} */ declare const isAndroid: () => boolean; /** * 判断是否是微信环境 * @returns {boolean} */ declare const isWX: () => boolean; /** * 判断是否是支付宝环境 * @returns {boolean} */ declare const isAlipay: () => boolean; /** * 判断是否在线 */ declare function isOnline(): boolean; /** * 拷贝到剪贴板 */ declare function copyToClipboard(text: string): Promise; declare const qs: { parse: (input: string) => Record; stringify: (params: Record) => string; join: (url: string, params: Record) => string; }; declare const isURL: (value: string) => boolean; /** * is http url */ declare function isHttpUrl(url: string): boolean; /** * 转驼峰命名 * foo-bar → fooBar */ declare const camelCase: (str: string) => string; /** * 转短横线命名 * fooBar → foo-bar */ declare const kebabCase: (str: string) => string; /** * 截断字符串并加省略号 * @param str 原字符串 * @param maxLen 最大长度 */ declare const truncate: (str: string, maxLen: number) => string; /** * 首字母大写 */ declare const capitalize: (str: string) => string; /** * 转义 HTML 特殊字符 */ declare const escapeHtml: (str: string) => string; /** * 数组去重 */ declare const uniq: (arr: T[]) => T[]; /** * 数组扁平化 * @param arr 原数组 * @param depth 展开深度,默认 1 */ declare const flatten: (arr: any[], depth?: number) => T[]; /** * 按固定大小切分数组 * @param arr 原数组 * @param size 每块大小 */ declare const chunk: (arr: T[], size: number) => T[][]; /** * 按 key 分组 * @param arr 原数组 * @param key 分组依据,可以是属性名或返回键的函数 */ declare const groupBy: (arr: T[], key: keyof T | ((item: T) => string)) => Record; /** * Fisher-Yates 洗牌算法 */ declare const shuffle: (arr: T[]) => T[]; /** * 生成数字范围数组 * @param start 起始值 * @param end 结束值(不包含) * @param step 步长,默认 1 */ declare const range: (start: number, end: number, step?: number) => number[]; /** * 深拷贝,兼容循环引用 */ declare const deepClone: (obj: T, cache?: WeakMap) => T; /** * 从对象中选取指定属性 * @param obj 原对象 * @param keys 要选取的键数组 */ declare const pick: , K extends keyof T>(obj: T, keys: K[]) => Pick; /** * 排除对象中的指定属性 * @param obj 原对象 * @param keys 要排除的键数组 */ declare const omit: , K extends keyof T>(obj: T, keys: K[]) => Omit; /** * 按路径安全取值 * @param obj 原对象 * @param path 路径,如 "a.b.c" * @param defaultValue 默认值 */ declare const get: (obj: any, path: string, defaultValue?: T) => T; /** * 版本号比较 * @returns 1: v1 > v2, -1: v1 < v2, 0: v1 === v2 */ declare const versionCompare: (v1: string, v2: string) => number; /** * 钳制数字在范围内 * @param num 输入数字 * @param min 最小值 * @param max 最大值 */ declare const clamp: (num: number, min: number, max: number) => number; /** * 千分位格式化 * @example formatThousands(1000) → "1,000" */ declare const formatThousands: (num: number) => string; /** * 区间随机整数 [min, max] */ declare const random: (min: number, max: number) => number; /** * 从 localStorage 取值,自动 JSON.parse */ declare const getItem: (key: string) => T | null; /** * 存储数据到 localStorage,自动 JSON.stringify */ declare const setItem: (key: string, value: any) => void; /** * 移除 localStorage 中的数据 */ declare const removeItem: (key: string) => void; /** * 文件大小格式化 * @example formatFileSize(1024) → "1 KB" */ declare const formatFileSize: (bytes: number) => string; /** * 毫秒转时间格式 * @example formatDuration(3661000) → "01:01:01" */ declare const formatDuration: (ms: number) => string; export { DATE_RANGE_TYPE_OPTIONS, DateRangeTypeEnum, camelCase, capitalize, chunk, clamp, copyToClipboard, deepClone, escapeHtml, fileDownload, flatten, formatDuration, formatFileSize, formatThousands, genRandomStringId, genTimeBasedId, genUUID, get, getDateObject, getDateRange, getItem, getStrLength, groupBy, isAlipay, isAndroid, isArrayLike, isEmpty, isHttpUrl, isIOS, isLength, isMap, isMobile, isNull, isNumber, isObject, isObjectLike, isOnline, isSet, isURL, isWX, kebabCase, memoize, omit, parallelToSerial, pick, qs, rafInterval, rafTimeout, random, range, removeItem, request, retry, setItem, setWaterMark, shuffle, sleep, splitOnFirst, throttle, to, truncate, uniq, versionCompare }; export type { FileDownloadOptions, IFetchOptions, IRequestOptions, waterMarkOptions };