lazy-js-utils
Version:
A collection of lazy-loaded JavaScript utilities for efficient development
1,897 lines (1,652 loc) • 68.2 kB
text/typescript
import { a as ISignature, M as MaybeElement, D as Direction, b as DotTextCanvasOptions, c as ImageData$1, d as DateString, T as TimeUnit, e as DragEvent, f as MutationObserverInit, U as UseTimeoutReturn, g as IsESModule, E as EventBus, h as DeviceType, i as ParsedURL, F as FileSpliceOptions, C as ChunkDetail, L as LRU, j as ChunkInfo, k as IFetchConfig, l as IFetchOptions, R as ResponseType, m as Position, n as Lang, J as JSCookie, o as TrimType } from './types-D4gI4rGL.mjs';
export { B as BodyType, q as Cache, t as Credentials, y as Deadline, x as FileChunk, w as FileMD5, v as FileType, u as IFetchInterceptors, I as IShellMessage, z as Merge, s as Method, r as Mode, N as NodeWorkerPayload, P as PkgTool, p as Redirect } from './types-D4gI4rGL.mjs';
import { Element as Element$1 } from 'domhandler';
import { Options as Options$3 } from 'tsup';
interface Options$2 {
compare?: 'same' | 'different';
result?: 'value' | 'index';
}
/**
*
* @param { any[] } array1 数组1
* @param { any[] } array2 数组2
* @param { Options } [options] {}
* @param { 'same' | 'different' } [options.compare] 'same' | 'different'
* @param { 'value' | 'index' } [options.compresultare] 'value' | 'index'
* @returns 返回相同项或不同项的索引或值
*/
declare function diff(array1: any[], array2: any[], options?: Options$2): any[];
interface ForEachCallback<T> {
(value: T, index: number, array: T[]): any;
}
/**
*
* @param { any[] } array 数组
* @param { Function } callback ForEachCallback
* @returns
*/
declare function forEach<T>(array: T[], callback: ForEachCallback<T>): any;
/**
*
* @param { number[] } array 数字数组
* @param { number } fraction 保留几位小数
* @returns 平均值
*/
declare function getAverage(array: number[], fraction?: number): string;
/**
*
* @param { any[] } array 数组
* @param { string | Array<string> } key 过滤条件
* @returns
*/
declare function quickFilter(array: any[], key: string | Array<string>): any[];
/**
*
* @param { T[] } array 数组
* @param { string | number } id 主键
* @returns
*/
declare function quickFind<T>(array: T[], id: T[keyof T]): QuickFind<T>;
declare class QuickFind<T> {
array: T[];
indexMap: Map<any, number>;
id: T[keyof T];
constructor(array: T[], indexMap: Map<any, number>, id: T[keyof T]);
find(id: T[keyof T]): T | undefined;
_update(id: T[keyof T], key: keyof T | T, value: any): T[];
delete(id: T[keyof T]): T[] | undefined;
set(id: T[keyof T], key: keyof T | T, value?: any): T[];
}
/**
*
* @param { any[] } array 数组
* @param { Array<string | number> | number | string } match 匹配条件
* @returns
*/
declare function sort<T>(array: T[], match: Array<string | number> | number | string): T[];
/**
*
* @param { any[] } sortArr 数组
* @param { string[] } order 顺序
* @param { string } prop 按照哪个属性
* @returns
*/
declare function sortByOrder<T>(sortArr: T[], order: string[], prop?: string): T[];
/**
*
* @param { any[] } array 数组
* @returns 去重后的数组
*/
declare function uniqueArray(array: any[]): any[];
/**
*
* @param { T[] } arr 数组
* @param { number } size 以多少为基准分割
* @returns 分割后的数组
*/
declare function chunk<T>(arr: T[], size?: number): T[][];
/**
*
* @param { any[] } array 数组
* @param { Function } iterator 迭代数组函数
* @returns 结果的个数
*/
declare function countBy<T extends Record<string, any>>(array: T[], iterator: (item: T) => any): Record<string, number>;
/**
*
* @param { Record<string, any> | Record<string, any>[] } o 对象或者数组
* @param { string }flattenProps 展开的属性默认为children
* @param { boolean }onlyLastNode 只保留最后一层级的数据
* @returns 一层的数组
*/
declare function flatten<T extends Record<string, any>>(o: T | T[], flattenProps?: string, onlyLastNode?: boolean, result?: T[]): T[];
/**
*
* @param { any[] } array 数组
* @returns 过滤空值后的数组
*/
declare function filterEmpty<T>(array: T[]): T[];
declare class Canvas {
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D;
constructor(width?: number, height?: number);
}
declare class CreateSignatureCanvas implements ISignature {
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D;
stop: (() => void)[];
active: boolean;
historyStack: ImageData[];
resetStack: ImageData[];
color: string;
bg: string;
constructor(lineWidth?: number, w?: number, h?: number, color?: string, bg?: string);
createCanvas(lineWidth: number | undefined, w: number, h: number): void;
clearCanvas(): void;
mount(el: MaybeElement): this;
setColor(color: string): void;
setBgColor(color: string): void;
unmount(): void;
listen(): void;
undo(): void;
redo(): void;
erase(lineWidth?: number): void;
unerased(): void;
save(type?: string, quality?: number): string;
}
declare class DotImageCanvas {
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D;
points: Map<string, Record<string, any>>;
originSrc: string;
color: string;
fontWeight: number;
status: string;
bgColor?: string;
stop: () => void;
direction: Direction;
allTasks: Function[];
completedTaskIndex: number;
isReverting: boolean;
drawnPoints: Array<{
x: number;
y: number;
color: any;
}[]>;
clearTasks: Function[];
isPreferred: boolean;
mounted: boolean;
constructor(src: string, color: string, fontWeight: number, bgColor?: string, direction?: Direction);
createDotImage(img: HTMLImageElement): (string | number | undefined)[][];
createImage(): Promise<unknown> | undefined;
hasImage(): boolean;
executor(): Promise<this>;
/**
* 创建绘制和清除任务的辅助方法 - 保持原有实现方式
*/
createDrawAndClearTasks(pointsGenerator: () => {
x: number;
y: number;
color: any;
}[], size: number): {
drawTask: () => void;
clearTask: () => void;
};
getCanvas(imagePointSet: (string | number | undefined)[][]): void;
startAnimation(): this;
revert(): this;
continue(): this;
initOptions(src: string, color: string, fontWeight: number, bgColor: string, direction?: Direction): void;
repaint(src: string, color: string, fontWeight: number, bgColor?: string, direction?: Direction): Promise<this>;
clearCanvas(): void;
append(container: MaybeElement): this;
destory(): void;
}
declare class DotTextCanvas {
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D;
points: Map<string, Array<number[]>>;
originText: string;
fontSize: number;
color: string;
fontWeight: number;
direction: Direction;
charSpacing: number;
charSpacings: number[];
textPointSet: Array<number[]>;
status: string;
container?: HTMLElement;
stop: () => void;
mounted: boolean;
isPreferred: boolean;
private _textCanvas?;
private _textCtx?;
constructor(textOrOptions: string | DotTextCanvasOptions, fontSize?: number, color?: string, fontWeight?: number, direction?: Direction, isPreferred?: boolean, charSpacing?: number, charSpacings?: number[]);
createTextPoint(text: string): number[][];
executor(): void;
getText(text: string): number[][] | undefined;
combineText(): number[][];
getPointsForDirection(h: number, w: number): Array<[number, number]>;
getCanvas(): void;
createDrawTasks(pointsToDraw: Array<[number, number]>, batchSize: number, getPoint: Function, size: number): Function[];
createBatchDrawTask(points: Array<[number, number]>, getPoint: Function, size: number): () => void;
startDrawing(tasks: Array<Function>): void;
repaint(this: any, textOrOptions: string | Partial<DotTextCanvasOptions>, fontSize?: number, color?: string, fontWeight?: number, direction?: Direction): DotTextCanvas;
clearCanvas(): void;
append(container: MaybeElement): this;
destory(): void;
}
declare function getImageData(src: string): Promise<ImageData$1>;
declare function removeRoundSpace(data: number[][]): number[][];
declare function sliderValidation(url: string, container: HTMLElement | string, l: number | (() => void) | undefined, callback: () => void): Promise<void>;
declare class Line {
ctx: CanvasRenderingContext2D;
color: string;
isFill: boolean;
constructor(ctx: CanvasRenderingContext2D, color?: string, isFill?: boolean);
draw(points: number[][], color?: string): void;
}
declare class Point {
r: number;
ctx: CanvasRenderingContext2D;
color: string;
constructor(ctx: CanvasRenderingContext2D, r?: number, color?: string);
draw(x: number, y: number, color?: string, r?: number): void;
}
declare class Square {
ctx: CanvasRenderingContext2D;
r: number;
color: string;
isFill: boolean;
constructor(ctx: CanvasRenderingContext2D, r?: number, color?: string, isFill?: boolean);
draw(x: number, y: number, r?: number): void;
}
declare function compressCss(s: string): string;
type CompressImageOptionsType = 'base64' | 'blob';
interface CompressImageOptions {
quality?: number;
maxWidth?: number;
maxHeight?: number;
type?: CompressImageOptionsType;
}
declare function compressImage(source: string | File, options?: CompressImageOptions): Promise<unknown>;
declare const classesReg: RegExp;
declare function getClasses(str: string, callback: (classes: string, block: string, index: number) => string): string;
declare function getCssVar(element: MaybeElement, style: string, callback: (css: string) => void): void;
declare function hasClassName(element: Element, className: string): boolean;
declare function setCssVar(element: MaybeElement, styleObj: Record<string, string>): void;
declare function useNamespace(defaultNamespace: string): (block: string) => {
namespace: string;
b: (blockSuffix?: string) => string;
e: (element?: string) => string;
m: (modifier?: string) => string;
be: (blockSuffix?: string, element?: string) => string;
em: (element?: string, modifier?: string) => string;
bm: (blockSuffix?: string, modifier?: string) => string;
bem: (blockSuffix?: string, element?: string, modifier?: string) => string;
is: {
(name: string, state: boolean | undefined): string;
(name: string): string;
};
cssVar: (object: Record<string, string>) => Record<string, string>;
cssVarName: (name: string) => string;
cssVarBlock: (object: Record<string, string>) => Record<string, string>;
cssVarBlockName: (name: string) => string;
};
declare function setStyle(el: HTMLElement | string, styleObj: Record<string, any>): void;
declare function removeStyle(el: HTMLElement | string, styles: string[] | string): void;
/**
*
* @param { string } rule '#blanc { color: white }'
* @param { number } [index] cssRules 中的位置
*/
declare function addRules(rule: string, index?: number): void;
/**
* dom上添加class
* @param { MaybeElement } selector 元素
* @param { string } className class类
* @returns
*/
declare function addClass(selector: MaybeElement, className: string): void;
/**
* dom上删除class
* @param { MaybeElement } selector 元素
* @param { string } className class类
* @returns
*/
declare function removeClass(selector: MaybeElement, className: string): void;
declare function formateDate(datetime: Date, fmt?: string): string;
/**
* Generates a list of dates starting from a given date.
*
* @param {string} start - The start date in the format 'YYYY-MM-DD' or 'YYYY/MM/DD'.
* @param {number} [day] - The number of days to generate. If negative, dates will be generated in reverse order.
* @returns {string[]} An array of date strings in the format 'YYYY-MM-DD'.
*
* @example
* ```typescript
* getDateList('2023-01-01', 5);
* // Returns ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05', '2023-01-06']
* ```
*/
declare function getDateList(start: string, day?: number): string[];
/**
* Returns the number of days in a given month.
*
* @param {number} currentMonth - The month for which to get the number of days (0-based, where 0 = January, 11 = December).
* @returns {number} The number of days in the specified month.
*/
declare function getDaysOfMonth(currentMonth: number): number;
/**
* 返回当前月份的日历数组信息
* @param currentMonth 今天的月份-1 从0开始
* @returns number[][]
*/
declare function createCalendar(currentMonth: number): unknown[][];
/**
* 比较2个月份的大小
* @param date1 '2021-02-01' | '2021/02/01'
* @param date2 '2021-03-02' | '2021/03/02'
* @param separator '-' | '/' 默认 '-'
* @returns -1 | 1 | 0
*/
declare function compareDate(date1: DateString, date2: DateString, separator?: '-' | '/'): 0 | 1 | -1;
/**
* 比较两个时间的大小
*
* 该函数接受两个时间字符串,格式为 'HH:MM',并比较它们的大小。
* 返回值为 0 表示两个时间相同,1 表示第一个时间大于第二个时间,-1 表示第一个时间小于第二个时间。
*
* @param {string} time1 - 第一个时间字符串,格式为 'HH:MM'
* @param {string} time2 - 第二个时间字符串,格式为 'HH:MM'
* @returns {number} - 返回 0 表示两个时间相同,1 表示第一个时间大于第二个时间,-1 表示第一个时间小于第二个时间
*/
declare function compareTime(time1: string, time2: string): 0 | 1 | -1;
/**
* 比较2个日期时间的大小
* @param date1 '2021-02-01 12:00:01' | '2021/02/01 12:00:01'
* @param date2 '2021-03-02 12:00:00' | '2021/03/02 12:00:00'
* @param separator '-' | '/' 默认 '-'
* @returns -1 | 1 | 0
*/
declare function compareDateTime(date1: DateString, date2: DateString): 0 | 1 | -1;
/**
* 获取当前周的周一日期
* @returns
*/
declare function getFirstDay(): string;
declare function getDifferenceDays(date1: Date | string, date2?: Date | string, unit?: TimeUnit): number;
/**
* 创建dom元素
* @param { string } tag 创建的标签元素
* @param { Record<string, string> } [attributes] 属性 {}
* @param { string } [innerHTML] 插入的内容innerHTML
* @param { ElementCreationOptions } [options] 通过 customElements.define() 定义的自定义元素的标签名称
* @returns
*/
declare function createElement<T extends keyof HTMLElementTagNameMap>(tag: T, attributes?: Record<string, string>, innerHTML?: string, options?: ElementCreationOptions): HTMLElementTagNameMap[T];
/**
* 创建fragment
* @returns
*/
declare function createFragment(): DocumentFragment;
/**
* 拖砖
* @param { HTMLElement | string } target 元素
* @param { DragEvent } options {}
* @param { (e: any) => void } options.dragStart 开始拖拽callback
* @param { (e: any) => void } options.dragMove 拖拽过程callback
* @param { (e: any) => void } options.dragEnd 拖拽结束callback
* @param trigger
* @returns
*/
declare function dragEvent(target: HTMLElement | string, options?: DragEvent, trigger?: boolean): () => true | undefined;
/**
* 查找元素
* @param { string | string[] } selector 选择器
* @param { boolean } [all] 是否获取所有节点
* @param { HTMLElement | Document } [currentNode] 在哪个节点下查找
*/
declare function findElement(selector: string | string[]): HTMLElement | null;
declare function findElement<T extends boolean | HTMLElement>(selector: string | string[], all?: T, currentNode?: HTMLElement | Document): T extends true ? NodeListOf<Element> | undefined : HTMLElement | null;
/**
* 插入元素
* @param { HTMLElement | string } parent 父元素
* @param { HTMLElement | DocumentFragment | string } element 将被插入的元素
* @param { HTMLElement } target 插入在这个元素之前
* @returns
*/
declare function insertElement(parent: HTMLElement | string, element: HTMLElement | DocumentFragment | string, target?: HTMLElement | null): void;
/**
* 删除元素
* @param { HTMLElement | ChildNode | DocumentFragment | string } el 待被删除的节点
* @returns 父节点
*/
declare function removeElement(el: HTMLElement | ChildNode | DocumentFragment | string): HTMLElement | null;
/**
* 点击事件
* @param { MaybeElement } target 元素
* @param { (e: MouseEvent) => void } callback 点击回调
* @returns 停止
*/
declare function useClick(target: MaybeElement | Document, callback: (e: MouseEvent) => void): () => true | undefined;
/**
* getBoundingClientRect
* @param { Element | string } element 元素
* @param { (rect: DOMRect) => void } callback 位置变化回调函数
* @returns 停止
*/
declare function useElementBounding(element: Element | string, callback: (rect: DOMRect) => void): () => void;
/**
* 事件监听
* @param { Window | Document | Element | string } target 元素
* @param { T } eventName 事件名
* @param { (e: (WindowEventMap & DocumentEventMap)[T]) => void } callback 回调
* @param { boolean | AddEventListenerOptions } useCapture 捕获
* @param { boolean } autoRemove 是否自动被移除
* @returns 停止
*/
declare function useEventListener<T extends keyof (WindowEventMap & DocumentEventMap)>(target: Window | Document | Element | MediaQueryList | string, eventName: T, callback: (e: (WindowEventMap & DocumentEventMap)[T]) => void, useCapture?: boolean | AddEventListenerOptions, autoRemove?: boolean): () => void;
/**
* input聚焦
* @param { MaybeElement } target 元素
*/
declare function useFocus(target?: MaybeElement): void;
/**
* 元素hover事件
* @param { MaybeElement } target 元素
* @param { (isHover: boolean, e: MouseEvent) => void } callback hover回调
* @returns
*/
declare function useHover(target: MaybeElement, callback: (isHover: boolean, e: MouseEvent) => void): () => void;
interface IntersectionObserverOptions {
root?: Element | Document | string | null;
rootMargin?: string;
threshold?: number | number[];
}
/**
* 检测物体可见
* @param { Element | string } element 元素
* @param { (entries: IntersectionObserverEntry[]) => void } callback 元素可见回调
* @param { IntersectionObserverOptions } options {}
* @param { Element | Document | string | null } options.root 相对容器节点
* @param { string } options.rootMargin 相对容器节点位置"10px 20px 30px 40px"
* @param { number | number[] } options.threshold 相对容器节点百分比 [0, 0.25, 0.5, 0.75, 1]
* @returns
*/
declare function useIntersectionObserver(element: Element | string, callback: (entries: IntersectionObserverEntry[]) => void, options?: IntersectionObserverOptions): () => void;
type UseIntervalReturn<T> = T extends Function ? () => void : undefined;
/**
* setInterval
* @param { Function } fn 函数
* @param { number } duration 间隔时间
* @returns 停止
*/
declare function useInterval<T>(fn: T, duration: number): UseIntervalReturn<T>;
/**
* 检测指定按键
* @param { string } c 按键字符串
* @param { Function } callback 按键与案件字符串一致时的回调
* @returns 停止
*/
declare function useKeyBoard(c: string, callback: (code: string) => void): () => void;
/**
* 检测鼠标移动
* @param { Function } callback 坚挺鼠标移动回调
* @param { number } delay 间隔多久触发
* @returns 停止
*/
declare function useMouse(callback: (e: MouseEvent) => void, delay?: number): () => void;
/**
* 检测元素变化
* @param { Element | string | ParentNode | null } element 元素
* @param { MutationCallback } callback 默认 { childList: true }
* @param { boolean } [callback.childList] 是否监听孩子元素
* @param { boolean } [callback.attributes] 是否监听属性
* @param { boolean } [callback.characterData] 是否监听内容
* @param { boolean } [callback.subtree] 是否监听树节点
* @param { boolean } [callback.attributeOldValue] 是否监听旧属性
* @param { string[] } [callback.attributeFilter] 属性过滤
* @param options
* @returns
*/
declare function useMutationObserver(element: Element | string | ParentNode | Text | null, callback: MutationCallback, options?: MutationObserverInit): (() => true | undefined) | undefined;
/**
* 检测视口变化
* @param { Function } callback 浏览器尺寸变化回调
* @returns
*/
declare function useResizeObserver(callback: (width: number, height: number) => void): () => void;
/**
* 检测浏览器滚动
* @param { Function } callback 坚挺浏览器滚动条位置变化回调
* @returns 停止
*/
declare function useWindowScroll(callback: (left: number, top: number) => void): () => void;
/**
* setTimeout
* @param { Function } fn 函数
* @param { number } duration 间隔时长
* @returns 停止
*/
declare function useTimeout<T>(fn: T, duration?: number): UseTimeoutReturn<T>;
/**
* 检测2个物体是否碰撞
* @param { MaybeElement } o1 元素1
* @param { MaybeElement } o2 元素2
* @returns
*/
declare function collisionDetection(o1: MaybeElement, o2: MaybeElement): boolean;
/**
* 下载
* @param { string } href 链接
* @param { string } download 名字
*/
declare function download(href: string, download?: string): void;
interface IMeta {
name: 'description' | 'viewport' | 'keywords' | 'robots' | string;
content: string;
}
interface IScript {
src: string;
type: 'async' | 'module' | 'nomodule' | 'defer';
}
interface ILink {
rel: 'stylesheet' | 'preload' | 'icon' | 'prefetch' | string;
href: string;
}
interface HeadOptions {
title?: string | (() => string);
meta?: IMeta[];
script?: IScript[];
link?: ILink[];
}
/**
* 创建head相关标签
* @param { HeadOptions } options
* @param { string | (() => string) } options.title 返回一个title字符串
* @param { IMeta[] } options.meta 'description' | 'viewport' | 'keywords' | 'robots' | string
* @param { IScript[] } options.script 'async' | 'module' | 'nomodule' | 'defer'
* @param { ILink[] } options.link 'stylesheet' | 'preload' | 'icon' | 'prefetch' | string
* @returns 移除函数
*/
declare function useHead(options: HeadOptions): HTMLElement | null;
/**
* 检测元素鼠标长按
* @param { MaybeElement } el 元素
* @param { number } ms 时长
* @param { Function } callback 回调
* @returns 停止
*/
declare function useLongPress(el: MaybeElement, ms: number, callback: () => void): () => void;
/**
* 失去焦点
* @param { MaybeElement } el 元素
* @param { Function } callback 失去焦点时的回调
* @returns 停止
*/
declare function useBlur(el: MaybeElement, callback: () => void): () => true | undefined;
declare function createTextNode(text: string): Text;
/**
* 获取target元素所在位置最后的位置
* 注意如果外容器有偏移量,需要减去偏移量
* @param target
* @returns
*/
declare function useRange(target: Node): DOMRect;
/**
* 创建图片瀑布流
* @param { string[] } imageList 图片列表
* @param { string } target mount元素 默认 body
* @param { number } width 图片宽度 默认 200
* @param { number } space 图片间距 默认 20
* @returns
*/
declare function waterfall(imageList: string[], target: MaybeElement | number, width?: number, space?: number): (imageList: string[]) => void;
/**
* 转义html
* @param { string } s 字符串
* @returns
*/
declare function escapeHtml(s: string): string;
interface Update {
setAttribs: (key: string, value?: string) => void;
beforeInsert: (str: string) => void;
afterInsert: (s: string) => void;
renameAttribs: (key: string, value: string) => void;
}
type HtmlTransformOptions = Record<string, (node: Element$1, update: Update) => void>;
/**
* htmlparser
* @param { string } s 字符串
* @param options {}
* @param { (key: string, value?: string) => void } options.setAttribs 设置属性
* @param { (str: string) => void } options.beforeInsert 插入前
* @param { (s: string) => void } options.afterInsert 插入后
* @param { (key: string, value?: string) => void } options.renameAttribs 重命名
* @returns
*/
declare function htmlTransform(s?: string, options?: HtmlTransformOptions): Promise<string>;
/**
* 反转义html
* @param { string } s 字符串
* @returns
*/
declare function unescapeHtml(s: string): string;
declare const stylesReg: RegExp;
/**
*
* @param { string } str 字符串模板
* @param { Function } callback 读取style时的回调
* @returns
*/
declare function getStyles(str: string, callback: (style: string, block: string, index: number) => string): string;
/**
* http重定向到https
*/
declare function httpsRedirect(): void;
/**
* 判断是否是绝对路径
* @param url
* @returns
*/
declare function isAbsolute(url: string): boolean;
/**
* 判断是否是数组
*/
declare const isArray: (arg: any) => arg is any[];
/**
* 判断是否是blob
* @param o
* @returns
*/
declare function isBlob(o: any): o is Blob;
/**
* 判断是否是boolean类型
* @param value
* @returns
*/
declare function isBool(value: any): value is boolean;
/**
* 判断滚动条到达窗口底部
* @param distance
* @returns
*/
declare function isBottom(distance?: number): boolean;
declare const isBrowser: boolean;
/**
* 判断是否包含中文
* @param s
* @returns
*/
declare function isContainCn(s: string): boolean;
/**
* 判断是否是日期格式
* @param d
* @returns
*/
declare function isDate(d: any): d is Date;
/**
* 判断元素不是undefined
* @param v
* @returns
*/
declare function isDef<T = any>(v: T): v is T extends undefined ? never : T;
/**
* 判断元素是HTMLElement
* @param element
* @returns
*/
declare function isElement(element: any): element is HTMLElement;
/**
* 判断2个对象是否相等
* @param { any } o1 对象1
* @param { any } o2 对象2
* @returns
*/
declare function isEqual(o1: any, o2: any): boolean;
/**
* 判断对象是ESModule
* @param obj
* @returns
*/
declare function isESModule(obj: any): obj is IsESModule;
/**
* 判断是否是false
* @param v
* @returns
*/
declare function isFalse(v: any): v is false;
/**
* 判断文件类型
* @param { string } file 文件路径
* @param { string } appendix 文件类型
* @returns
*/
declare function isFileType(file: string, appendix: string): boolean;
/**
* 判读是否是函数
* @param o
* @returns
*/
declare function isFn(o: any): o is Function;
/**
* 判断是否是ipv4
* @param ip
* @returns
*/
declare function isIPv4(ip: string): boolean;
/**
* 判断是否是ipv6
*/
declare function isIPv6(ip: string): boolean;
/**
* 判断是否是身份证
* @param s
* @returns
*/
declare function isIdCard(s: string): boolean;
/**
* 判断是否是闰年
*/
declare function isLeapYear(year: number): boolean;
/**
* 判断是否是Map
*/
declare function isMap(o: any): o is Map<any, any>;
/**
* 判断是否是手机号
*/
declare function isMobile(s: string): boolean;
/**
* 判断是否是NaN
*/
declare function isNaN(o: any): boolean;
/**
* 判断是否是null或undefined
*/
declare function isNil(value: any): value is null | undefined;
/**
* 判断是否是null
*/
declare function isNull(o: any): o is null;
/**
* 判断是否是number类型
*/
declare function isNum(o: any): o is number;
/**
* 判断是否是对象
*/
declare function isObject(value: any): boolean;
/**
* 判断是否是{}类型
*/
declare function isPlainObject(o: any): o is Record<any, any>;
/**
* 判断是否是邮编
*/
declare function isPostCode(s: string | number): boolean;
/**
* 判断是否是promise
*/
declare function isPromise(o: any): o is Promise<any>;
/**
* 判断是否是正则
*/
declare function isReg(o: any): o is RegExp;
/**
* 判断是否是相对路径
*/
declare function isRelative(str: string): boolean;
/**
* 判断是否是同一天
* @param { Date } dateLeft 日期一
* @param { Date } dateRight 日期二
*/
declare function isSameDay(dateLeft: Date, dateRight: Date): boolean;
/**
* 判断是否是Set
*/
declare function isSet(o: any): o is Set<any>;
/**
* 判断是否是字符串类型
*/
declare function isStr(o: any): o is string;
/**
* 判断是否支持调用摄像头
*/
declare function isSupportCamera(): boolean;
/**
* 判断是否支持webp格式
*/
declare function isSupportWebp(): boolean;
/**
* 判断是否是symbol类型
*/
declare function isSymbol(o: any): o is symbol;
/**
* 判断是否是true
*/
declare function isTrue(v: any): v is true;
/**
* 判断对象类型
*/
declare function isType<T>(s: T, type: string): boolean;
/**
* 判断是否是undefined
*/
declare function isUndef(o: any): o is undefined;
/**
* 判断是否是url
*/
declare function isUrl(url: string): boolean;
/**
* 判断是否是video
*/
declare function isVideo(filepath: string): boolean;
/**
* 判断是否是WeakMap
*/
declare function isWeakMap(o: any): o is WeakMap<any, any>;
/**
* 判断是否是WeakSet
*/
declare function isWeakSet(o: any): o is WeakSet<any>;
/**
* 判断是windows电脑
*/
declare function isWin(): boolean;
/**
* 判断是否是websocket地址
*/
declare function isSocketUrl(url: string): boolean;
/**
* 判断是否是base64格式
* @param { string } base64
* @returns
*/
declare function isBase64(base64: string): boolean;
/**
* 判断是否是火车号
*/
declare const isTrainNumber: (s: string) => boolean;
/**
* 判断输入的是中文
*/
declare const isNameCn: (s: string) => boolean;
/**
* 判断输入的是否是英文
*/
declare function isNameEn(s: string): boolean;
/**
* 判断是否是军官证
*/
declare function isSoldierId(s: string): boolean;
/**
* 判断是否是版本号
*/
declare function isVersion(version: string): boolean;
declare function isDivElement(target: unknown): target is HTMLDivElement;
declare function isIFrameElement(target: unknown): target is HTMLIFrameElement;
declare function isImageElement(target: unknown): target is HTMLImageElement;
declare function isNode(target: unknown): target is Node;
declare function isProxyDocument(target: unknown): target is Document;
declare function isScriptElement(target: unknown): target is HTMLScriptElement;
declare function isShadowRoot(target: unknown): target is ShadowRoot;
declare function isStyleElement(target: unknown): target is HTMLStyleElement;
/**
* 判断文件是不是.vue
* @param { string } src 文件路径
* @returns
*/
declare function isVue(src: string): boolean;
/**
* 判断是否是<! -- xxx -->注释
* @param { string } s 字符串
* @returns
*/
declare function isComment(s: string): boolean;
/**
* 判断当前页面是否处于活跃状态
* @returns
*/
declare function isActive(): boolean;
/**
* 判断是否是文件
* @param o
* @returns
*/
declare function isFile(o: Blob | string): o is File;
/**
* 监听目标元素的子元素变化的栈
* @param { string | Element } target 元素
* @returns
*/
declare function listenStack(target: string | Element): (() => true | undefined) | undefined;
/**
* 获取电脑粘贴板的内容
* @param { string } s 内容
* @returns
*/
declare function copy(s: string): boolean;
/**
* 柯里化
* @param { Function } f 函数
* @returns 函数
*/
declare function curry(f: Function): (...args: any[]) => any;
/**
* 等待函数
* @param { number } ms 延迟秒数
* @returns
*/
declare function sleep(ms: number): Promise<unknown>;
/**
* 并行执行
* @param { any[] } tasks 数组
* @param { (...args: any[]) => any } fn 函数
* @returns
*/
declare function parallel(tasks: any[], fn: (...args: any[]) => any): Promise<any[]>;
/**
*
* @param { Function } fn 函数 | 异步函数
* @param { Function } finalFn 函数
* @returns
*/
declare function promiseFinally(fn: Promise<any> | Function, finalFn: Function): Promise<any>;
/**
* 超时函数
* @param { Function } fn 函数
* @param { number } ms 时间
* @param { string } msg 错误消息
* @returns
*/
declare const timeout: (fn: Function, ms: number, msg: string) => Promise<any>;
declare function noop(): void;
/**
* 链式调用
* @param { Function[] } fns 函数数组
* @returns
*/
declare function chainFns(...fns: Function[]): Function;
/**
*
* @param { () => any } flushCallbacks 函数
* @returns
*/
declare function nextTick(flushCallbacks: () => any): void;
/**
* 单例模式
*/
declare function singleModel(className: any): any;
/**
* webWorker
* @param { string } [url] url自定义worker文件路径 或者 worker函数
*/
declare function useWebWorker(url: string): any;
declare function useWebWorker(useWebWorkerThread: () => void): any;
/**
*
* @param url url自定义worker文件路径 或者 worker函数
* @param { RegistrationOptions } options {
* scope?: string;
* type?: WorkerType;
* updateViaCache?: ServiceWorkerUpdateViaCache;
* }
* @returns
*/
declare function useServiceWorker(url: string | (() => void), options: RegistrationOptions): Promise<ServiceWorkerRegistration>;
declare const noopFalse: () => boolean;
/**
* 用户停留在老页面但是已经有新的版本
*/
/**
* 检测首页中script src是否存在更新
* @param { number } s 检测时间间隔 默认 2000
* @param callback 如果页面检测出有更新则会被调用
* @returns
*/
declare function updateDetection(s: number | undefined, callback: () => void): () => void;
/**
* 将流文件转为base64
* @param { ArrayBuffer } stream 流
* @returns
*/
declare function streamToUrl(stream: ArrayBuffer): Promise<string>;
/**
* 读取ReadableStream
* @param { ReadableStreamDefaultReader<Uint8Array> } reader getReader() 的结果
* @param { Function } callback 每片读取的回调
* @returns
*/
declare function useReader(reader: ReadableStreamDefaultReader<Uint8Array>, callback?: (value?: any) => any): Promise<string>;
declare function useSwitch(options: any[]): () => any;
declare function catchAwait<T, U = Error>(promise: Promise<T> | any, errorExt?: object): Promise<[U, undefined] | [undefined, T]>;
declare function executeStr(str: string): any;
/**
* handleImageError
* @param errorImageSrc string[] - Array of image sources to use as fallback
* @returns (event: Event) => void - Function to handle error event on image element
*/
declare function handleImageError(errorImageSrc: string[]): (event: Event) => void;
declare function replaceAsync(str: string, searchValue: string | RegExp, replaceValue: string | ((...args: any[]) => string | Promise<string>)): Promise<string>;
declare function reduceAsync<T, K>(arr: K[], reducer: (acc: T, item: K, index: number, arr: K[]) => any, initialValue: T): Promise<T>;
declare function retryAsync<T>(fn: () => Promise<T>, retries: number): Promise<T>;
declare function throwError(scope: string, m: string): never;
declare function debugWarn(err: Error): void;
declare function debugWarn(scope: string, message: string): void;
/**
* 全局错误捕获
*/
declare function globalErrorCapture(): () => void;
declare function interceptError(fn: Function): Promise<unknown>;
/**
* 日志输出
* @param { string } s 内容
* @param { Record<string, string | number> } styleObj 样式
* @param { string } type 类型 'warn' | 'error' | 'log'
*/
declare function log(s: string | number, options?: {
type?: 'warn' | 'error' | 'log';
style?: Record<string, string | number> | string;
args?: any[];
}): void;
/**
* eventbus
*/
declare function createEventBus(): EventBus;
/**
* 跨标签页通信通过storage事件实现
* @param { (type: string, newValue: any, oldValue: any) => void } callback storage数据更新回调
* @returns
*/
declare function useStorageListen(callback: (type: string, newValue: any, oldValue: any) => void): () => void;
declare function sendStorage(type: string, value: any): void;
/**
* WebSocket
* @param { string } url 要连接的 URL;这应该是 WebSocket 服务器将响应的 URL。
* @param { string | string[] } [protocols] 一个协议字符串或者一个包含协议字符串的数组。
* @returns
*/
declare function useSocket(url: string, protocols?: string | string[]): {
socket: WebSocket;
receive: (callback: (event: MessageEvent<any>) => void) => void;
send: (data: string | Blob | ArrayBufferLike | ArrayBufferView) => void;
open: (callback: (event: Event) => void) => void;
close: (callback: (event: Event) => void) => void;
error: (callback: (event: Event) => void) => void;
};
type Channel = BroadcastChannel & {
listeners: Set<number>;
id: number;
};
declare function createChannel(name: string): Channel;
declare function calFps(): () => void;
/**
* 获取当前环境设备信息 os 手机设备 dev 浏览器环境
* @returns {DeviceType} 设备信息
*/
declare function getDevice(): DeviceType;
/**
* 检测性能指标
* @returns {Record<string, number> | null} 返回性能指标对象,如果不支持则返回null
*/
declare function monitorPef(): Record<string, number> | null;
/**
* 检测函数执行耗时
* @param { Function } fn 函数
* @returns number
*/
declare function timeCost(fn: Function): number;
/**
*
* @param { boolean } [enableHighAccuracy] 开启高精度模式 默认 false
* @param { number } [timeout] 超时时间 默认 5000
* @param { number } [maximumAge] 最大缓存位置时间 默认 0
* @returns
*/
declare function getLocation(enableHighAccuracy?: boolean, timeout?: number, maximumAge?: number): Promise<GeolocationCoordinates>;
/**
* add 数字求和
* sub 数字求差
* mul 数字相乘
* div 数字相除
*/
declare const calNum: {
add(...args: (number | string)[]): number;
sub(...args: (number | string)[]): number;
mul(...args: (number | string)[]): number;
div(...args: (number | string)[]): number;
};
/**
* 数字格式化
* @param { number } number 数字
* @param { number } decimals 小数位
* @param { 'floor' | 'ceil' } integer 向上截取 | 向下截取 默认 'ceil'
* @returns
*/
declare function formateNum(number: number | string, decimals?: number, integer?: 'floor' | 'ceil'): string;
/**
* 大写数字
* @param { number } n 数字
* @returns 返回大写数字
*/
declare function uppercaseNum(n: number): string;
/**
* 乘倍
* @param { number | string } i
* @param { number } multiple 倍数
* @returns
*/
declare function multiply(i: number | string, multiple: number): string | number;
/**
* 判断偶数
* @param { number } n 数字
* @returns
*/
declare function isEven(n: number | string): boolean;
/**
* 深合并
* @param target 对象
* @param sources 其他对象
* @returns
*/
declare function deepMerge(target: Record<any, any>, ...sources: Record<any, any>[]): Record<any, any>;
declare function generateKeyObject(o: Record<string, any>, key: string, mapKey: string): {};
declare function mapTransform(o: Record<string, any>, map: Record<string, string>, keepRest?: boolean): Record<string, any>;
declare function mapTransformBack(o: Record<string, any>, map: Record<string, string>, keepRest?: boolean): Record<string, any>;
interface StringifyOptions {
sep?: string;
eq?: string;
hyp?: boolean;
px?: boolean;
encode?: boolean;
}
/**
* 对象序列化
* @param { Record<string, string | number> } o {}
* @param { StringifyOptions } options {}
* @param { string } [options.sep] 分割字符 默认 &
* @param { string } [options.eq] 连接字符 默认 =
* @param { boolean } [options.hyp] aBb属性名转为a-bb
* @param { boolean } [options.px] 自动给数字添加px
* @param { boolean } [options.encode] 将结果encode
* @returns
*/
declare function stringify(o: Record<string, string | number>, options?: StringifyOptions): string;
declare function transformKey(target: Record<string, any> | Record<string, any>[], options: Record<string, string>, deleteEmpty?: boolean): Record<string, any>;
/**
* 通过函数的方式获取对象中指定的数据
* @param { Record<any, any> | any[] } target 对象或数组
* @param { Record<string, Function> } options {}
* @returns
*/
declare function traverse<T extends Record<any, any> | any[]>(target: T, options?: Record<string, (res: any, i: number, target: T) => void>): T;
/**
* 神拷贝
* @param { any } target 克隆的目标
* @returns
*/
declare function deepClone(target: any): any;
/**
* 深比较
* @param { any } comp1 对象1
* @param { any } comp2 对象2
* @param { string[] | RegExp } ignoreKeys 忽律某项属性的比较
* @returns
*/
declare function deepCompare(comp1: any, comp2: any, ignoreKeys?: string[] | RegExp, error?: string[], errorMsg?: string[], name?: string, index?: string): {
error: string[];
errorMsg: string[];
};
declare function objectToMap(obj: Record<string, any>): Map<any, any>;
declare function mapToObject(map: Map<any, any>): Record<string, any>;
interface ParseOptions {
sep?: string;
eq?: string;
camel?: boolean;
}
/**
*
* @param { string } str 字符串
* @param { ParseOptions } options {
sep?: string
eq?: string
camel?: boolean
}
* @param { string } options.seq 默认 &
* @param { string } options.eq 默认 =
* @param { string } options.camel 默认 false
* @returns
*/
declare function parse(str: string, options?: ParseOptions): Record<string, string>;
/**
* 解析css转换为对象
* @param { string } str
* @returns
*/
declare function parseCss(str: string): Record<string, string>;
declare function hasProtocol(inputStr: string, acceptProtocolRelative?: boolean): boolean;
/**
* 解析URL
* @param { string } input 链接
* @param defaultProto
* @returns
*/
declare function parseURL(input?: string, defaultProto?: string): ParsedURL;
declare function parsePath(input?: string): ParsedURL;
/**
* 防抖函数
* @param { Function } fn 函数
* @param { number } time 时间
* @returns
*/
declare function debounce(fn: Function, time: number): (this: any, e?: any) => void;
/**
*
* @param { File } _file 文件
* @param { number } _chunkSize 切分大小 默认 1024 * 100
* @returns
*/
declare function fileSplice(options: FileSpliceOptions): Promise<ChunkDetail[]>;
/**
*
* @param max 最大存储量 默认 50
* @returns
*/
declare function getLru(max?: number): LRU;
/**
*
* @param { MaybeElement } element 元素
* @param { string } loadingUrl 懒加载的loading图
* @returns
*/
declare function lazyLoad(element: MaybeElement, loadingUrl?: string): void;
/**
* 函数缓存结果
* @param { Function } fn 函数
* @param { Map<string, any> } cache 缓存对象
* @param { number } maxSize 最大缓存条目数,默认为100
* @returns { Function } 带缓存的函数
*/
declare function memorizeFn(fn: Function, cache?: Map<string, any>, maxSize?: number): (...args: any[]) => any;
/**
* 图片视频预加载函数
* @param { string[] } list 图片数组
* @param { string } style 设置样式
* @returns
*/
declare function preload(list: string[] | string, style?: string): HTMLImageElement[];
/**
* 借助浏览器空闲时间去加载一些图片资源
* @param { string[] } list 图片或视频地址数组
* @param { number } timeRemaining 浏览器空闲时间大于多少去加载
* @returns stop 取消副作用
*/
declare function prefetch(list: string[], timeRemaining?: number): () => void;
/**
* 截流函数
* @param { Function } fn 函数
* @param { number } stop 时间
* @returns
*/
declare function throttle(fn: Function, stop: number): (this: any, ...args: any[]) => any;
/**
* 使用 requestAnimationFrame 执行一个函数,并提供停止执行的功能。
*
* @param {function(number): void} fn - 在每一帧调用的函数,参数是时间戳。
* @param {object} [options] - 配置选项。
* @param {number} [options.delta] - 两次调用之间的最小时间间隔(毫秒)。
* @param {boolean} [options.autoStop] - 是否在首次调用后自动停止。
* @param {boolean} [options.immediate] - 是否在首次调用时立即执行。
* @returns {function(): void} - 停止执行的函数。
*/
declare function useRaf(fn: (timestamp: number) => void, options?: {
delta?: number;
autoStop?: boolean;
immediate?: boolean;
}): () => void;
interface Options$1 {
timeRemaining?: number;
timeout?: number;
callback?: (taskArr: any[]) => void;
}
/**
* 浏览器空闲时期被调用
* @param { Function[] } tasks 函数队列
* @param { number } timeRemaining 剩余时间大于多少才继续执行
* @param { number } timeout 超时时间
* @param { Function } callback 回调
* @returns
*/
declare function useRic(tasks: Function[], options?: Options$1): () => void;
/**
* 只执行一次函数
* @param { Function } fn 函数
* @returns
*/
declare function once(fn: Function): Function;
declare function createChunk(file: File, index: number, chunkSize: number): Promise<ChunkInfo>;
type Options<T, K> = T extends HTMLCanvasElement ? {
errorCorrectionLevel: 'H';
} : K extends true ? {
errorCorrectionLevel?: 'H';
type?: 'image/png' | 'image/jpeg' | 'image/webp';
quality?: number;
margin?: number;
color?: {
dark: string;
light: string;
};
} : {
type?: 'terminal' | 'utf8' | 'svg';
};
/**
* 生成二维码
* @param { string | HTMLCanvasElement } content 元素
* @param { boolean } base64 生成base64格式
* @param options
* @returns
*/
declare function generateQRCode<T extends string | HTMLCanvasElement, K extends boolean>(content: T, base64?: K, options?: Options<T, K>): Promise<unknown>;
/**
* 随机日期函数
* @param { string } start 开始日期 默认 '1999/01/1
* @param { string } [end] 截止日期
* @returns
*/
declare function randomDate(start?: string, end?: string): Date;
/**
* 随机hex颜色
* @returns
*/
declare function randomHexColor(): string;
/**
* 获取随机范围值
* @param min 最小值 默认 MIN_SAFE_INTEGER
* @param max 最大值 默认 MAX_VALUE
* @returns
*/
declare function randomRange(min?: number, max?: number): number;
/**
* 随机rgba颜色
* @param { number } [opacity] 透明度 默认 1
* @returns
*/
declare function randomRgba(opacity?: number): string;
/**
* 随机打乱数组
* @param array any[]
* @returns array
*/
declare function randomArray(array: any[]): any[];
/**
* 生成uuid
* @param { number } len 长度
* @param { number | 'hex' } radix number | 'hex'
* @returns
*/
declare function uuid(len?: number, radix?: number | 'hex'): string;
/**
* Class fetch请求封装
*/
declare class VFetch {
config: IFetchConfig;
constructor(baseOptions?: IFetchOptions);
init(this: VFetch, options: IFetchConfig): Promise<any>;
request(this: VFetch): Promise<any>;
getResponseData(response: Response, responseType?: ResponseType): Promise<any> | undefined;
get(this: VFetch, url: string, options?: IFetchConfig): Promise<any>;
get(this: VFetch, options: IFetchConfig): Promise<any>;
post(this: VFetch, url: string, options?: IFetchConfig): Promise<any>;
post(this: VFetch, options: IFetchConfig): Promise<any>;
put(this: VFetch, url: string, options?: IFetchConfig): Promise<any>;
put(this: VFetch, options: IFetchConfig): Promise<any>;
delete(this: VFetch, url: string, options?: IFetchConfig): Promise<any>;
delete(this: VFetch, options: IFetchConfig): Promise<any>;
}
/**
* 并行执行任务
* @param { number } limit 并行数量 默认 4
* @param { Function[] } tasks 任务队列
* @returns
*/
declare function asyncPool(limit: number | undefined, tasks: Function[]): Promise<any[]>;
/**
* 将分析数据发送到 Web 服务器
* @param { string } url 接收数据的 URL
* @param { BodyInit } [analyticsData] ArrayBuffer 、 TypedArray 、 DataView 、 Blob 、字符串文字或对象、包含要发送的数据的 FormData 或 URLSearchParams 对象。
* @returns
*/
declare function sendBeacon(url: string | URL, analyticsData?: BodyInit | null): () => void;
/**
* 退出全屏模式
* @returns
*/
declare function exitFullscreen(): Error | undefined;
/**
* 全屏模式
* @returns
*/
declare function fullScreen(): Error | undefined;
/**
* 画中画模式
* @param { HTMLVideoElement | string } video video元素
* @returns
*/
declare function picInPic(video: HTMLVideoElement | string): () => Promise<void>;
/**
* 分享屏幕
* @param { MaybeElement } container 容器
* @param { Function } callback 停止回调
* @returns
*/
declare function shareScreen(container: MaybeElement, callback: (msg: string) => void): Promise<unknown>;
interface IVideo {
width: number;
height: number;
}
/**
* 录像功能
* @param video 容器大小 默认{ width: 640, height: 480 }
* @param container 容器
* @param autoplay 是否自动播放
* @returns
*/
declare function useCamera(video?: IVideo | boolean, container?: string | HTMLVideoElement, autoplay?: boolean): void | (() => true | void | Promise<void>);
/**
* 分享内容
* @param options files?: File[];
text?: string;
title?: string;
url?: string;
* @returns
*/
declare function useShare(options?: ShareData): Promise<void> | undefined;
interface Sources {
src: string;
type: string;
}
interface VideoOptions {
container: HTMLElement | string;
controls?: boolean;
width?: number;
height?: number;
className?: string;
style?: string;
}
/**
* 操作video
* @param sources {
src: string
type: string
}
* @param videoOptions {
container: HTMLElement | string
controls?: boolean
width?: number
height?: number
className?: string
style?: string
}
* @returns
*/
declare function useVideo(sources: Sources[] | undefined, videoOptions: VideoOptions): {
play(): void;
playReset: () => void;
playRate(rate?: number): void;
playTime(timing?: number): void;
playProgress(currentTime?: number): void;
};
/**
* 录制功能
* @param fileName
* @returns
*/
declare function useRecorder(fileName?: string): Promise<() => void>;
interface UseVideoSubtitle {
start: number;
duration?: number;
end?: number;
left: number;
top: number;
content: string;
}
/**
* 生成弹幕内容
* @param options
* @param name
*/
declare function useVideoSubtitle(options: UseVideoSubtitle[], name?: string): string;
/**
* 录音功能
* @param { string | HTMLAudioElement } container 容器
* @returns
*/
declare function useAudio(container: string | HTMLAudioElement): void | {
toggle(): true | void;
download(): void;
};
interface FrequencyOptions {
audio: MaybeElement;
fftSize?: number;
}
/**
* 处理audio获取频域数组
* @param { FrequencyOptions } options { audio: 目标元素, fftSize: 分析细粒度 2^n 默认 512 }
* @param { ( dataArray: Uint8Array, audioCtx: AudioContext, analyser: AnalyserNode ) => void } callback 回调
*/
declare function useFrequency(options: FrequencyOptions, callback: (dataArray: Uint8Array, audioCtx: AudioContext, analyser: AnalyserNode) => void): void;
/**
* head添加link标签
* @param { string } href css路径
* @returns
*/
declare function addLink(href: string): () => void;
/**
* head添加script标签
* @param { string } src 路径
* @returns
*/
declare function addScript(src: string): () => void;
/**
* 将style添加到head
* @param { string } s style
* @param { string } scoped 独立作用域 针对局部组件生效<div data-v-xxx></div>, 传入data-v-xxx
* @returns
*/
type StyleObject = Record<string, Record<string, string | number>>;
declare function addStyle(s: string | StyleObject, scoped?: string): () => HTMLElement | null;
declare function addStyleScoped(s: string, scoped: string): string;
/**
* 获取滚动条位置
* @param el 默认window
* @returns Position
*/
declare function getScrollPosition(el?: Window): Position;
/**
* 滚动到顶部
*/
declare function scrollToTop(): void;
/**
* 滚动到可视区域
* @param { Element | string | null } e 元素
* @param { ScrollIntoViewOptions } options {
* block?: ScrollLogicalPosition;
* inline?: ScrollLogicalPosition;
* }
* @returns void
*/
declare function scrollToView(e: Element | string | null, options?: ScrollIntoViewOptions): void;
declare function getScrollProgress(callback: (percent: string) => void, time?: number): () => void;
interface SpeechOptions {
text: string;
voice?: SpeechSynthesisVoice | null;
rate?: number;
pitch?: number;
volume?: number;
lang?: Lang;
}
interface SpeechResult {
cancel: () => void;
pause: () => void;
resume: () => void;
speak: (options?: string | SpeechOptions) => void;
isSpeaking: () => boolean;
}
declare function speech(text?: string): SpeechResult;
declare function speech(options?: SpeechOptions): SpeechResult;
interface SpeechToTextOptions {
continuous: boolean;
interimResults: boolean;
lang: Lang;
maxAlternatives: number;
}
/**
* 语音转文字
* @param { SpeechOptions } options {
continuous: boolean // 每次识别都返回连续结果
interimResults: boolean // 返回临时结果的设置
lang: Lang
maxAlternatives: number
}
* @param { (result: any) => any } callback 结果回调函数
* @returns { { toggle: () => void, abort: () => void } }
*/
declare function speechToText(options?: SpeechToTextOptions | ((result: any) => any), callback?: (result: any) => any): {
toggle: () => void;
abort: () => any;
};
/**
* 快速操作indexedDB
* @returns get set remove
*/
declare function dbStorage(): Promise<unknown>;
/**
* 快速操作cookie
*/
declare const jsCookie: JSCookie;
/**
* 快速操纵localstorage
* @returns get set delete clear
*/
declare function jsLocal(): {
set(key: string | Record<string, string>, value?: string): void;
get(key: string): string | null;
delete(key: string | string[]): void;
clear(): void;
};
/**
* 快速操纵session
* @returns get set delete clear
*/
declare function jsSession(): {
set(key: string | Record<string, string>, value?: string): void;
get(key: string): string | null;
delete(key: string | string[]): void;
clear(): void;
};
/**
* 将xx-xx转为xxXx 大驼峰格式
* @param { string } s 字符串
* @returns string
*/
declare function camelize(s: string): string;
/**
* 获取url中的参数
* @param { string } s url地址
* @returns Record<string, string> | undefined
*/
declare function getUrlParam(s?: string): Record<string, string> | undefined;
/**
* 将大驼峰转为xx-xx
* @param { string } s 字符串
* @returns string
*/
declare function hyphenate(s: string): string;
/**
* 检测字符串强度
* @param { string | number } s 字符串
* @param { number } minimum 长度 默认 6
*