UNPKG

wj-common-fn

Version:

常用函数

287 lines 9.18 kB
/// <reference types="node" /> import { ArrayDesc, CookieOptions } from "./types"; /** * @description 深度克隆 * @param o */ export declare function deepCopy(o: any): any; /** * @description 是否为空 * @param val */ export declare function isEmpty(val: any): boolean; /** * @description 节流 * @param fn * @param wait */ export declare function throttle(fn: Function, wait: number): () => void; /** * @description 防抖 * @param fn * @param wait */ export declare function debounce(fn: Function, wait: number): () => void; /** * @description 将文件转换成base64 * @param {*} file * @returns Promise<unknown> */ export declare function getBase64(file: any): Promise<unknown>; /** * @description 设置cookie * @param {String} name 关键字 * @param {String} value 要存储的指 * @param { CookieOptions } config { type: "天", expires: 1 } */ export declare function setCookie(name: string, value: string, config?: CookieOptions): void; /** * @description 获取cookie * @param {String} key 关键字 */ export declare function getCookie(key: string): string | false; /** * @description 删除cookie * @param { String } key */ export declare function delCookie(key: string): void; /** * @description 返回一个在范围内的随机数 * @param { Number } n1 起始 * @param { Number } n2 结束 * @returns { Number } */ export declare function randomNumber(n1: number, n2: number): number; /** * @description 字母大小写切换 * @param { String } str * @param { Number } type 数字 1:首字母大写、2:首母小写、3:大小写转换、4:全部大写、5:全部小写 * @returns { String } */ export declare function changeCase(str: string, type: number): string; /** * @description 数组排序 * @param arr 数组 * @param desc 排序方式 'asc'升序,'desc'降序 */ export declare function arraySort(arr: number[], desc?: ArrayDesc): number[]; /** * @description 对象数组快速排序 * @param arr * @param key 排序依据关键字 * @param desc 排序方式 'asc'升序,'desc'降序 * @returns any */ export declare function arrayObjSort(arr: any[], key: string, desc?: ArrayDesc): any; /** * @description 数组去重 * @param arr * @returns any[] */ export declare function arrayUnique(arr: any[]): any[]; /** * @description 数组的交集 * @param arr1 * @param arr2 * @returns any[] */ export declare function arrayIntersection(arr1: any[], arr2: any[]): any[]; /** * @description 数组的差集 arr1-arr2 * @param arr1 * @param arr2 * @returns any[] */ export declare function arrayMinus(arr1: any[], arr2: any[]): any[]; /** * @description 数组的并集,参数可以使多个 * @returns any[] */ export declare function arrayUnion(...args: any[]): any[]; /** * @description 是否是一个类 * @param obj * @param { Boolean } strict 是否严格模式 * @returns boolean */ export declare function isClass(obj: any, strict?: boolean): boolean; /** * @description 判断是否是正则表达式 * @param value * @returns boolean */ export declare function isRegExp(value: any): boolean; /** * @description 判断是否是日期对象 * @param value * @returns boolean */ export declare function isDate(value: any): boolean; /** * @description 判断value是否是浏览器内置对象 * @param value * @returns boolean */ export declare function isNative(value: any): boolean; /** * @description cached:记忆函数:缓存函数的运算结果 * @param fn (str: any) => any * @returns (str: any) => any */ export declare function cached(fn: (str: any) => any): (str: any) => any; /** * @description 横线转驼峰命名 * @param str * @returns string */ export declare function camelize(str: string): string; /** * @description 下划线转驼峰命名 * @param str * @returns string */ export declare function _2camelize(str: string): string; /** * @description 驼峰命名转横线命名:拆分字符串,使用 - 相连,并且转换为小写 * @param str * @returns string */ export declare function hyphenate(str: string): string; /** * @description 获取浏览器信息 * @returns { type: string; version: number; } */ export declare function getExplorerInfo(): { type: string; version: number; }; /** * @description 检测是否为PC端浏览器模式 * @returns boolean */ export declare function isPCBroswer(): boolean; /** * @description base64数据导出文件,文件下载 * @param { String } filename 下载后的文件名称 * @param { String } data 要下载的base64数据 */ export declare function downloadFile(filename: string, data: string): void; /** * @description 浏览器放大全屏 */ export declare function toFullScreen(): void; /** * @description 浏览器退出全屏 */ export declare function exitFullscreen(): void; export declare const requestAnimationFrame: (callback: FrameRequestCallback) => void; export declare const cancelAnimationFrame: ((handle: number) => void) & typeof webkitCancelAnimationFrame; /** * @description 实现将项目的图片路径转化成base64 * @param { String } img 图片路径 * @returns Promise<unknown> */ export declare function getBase64ByUrl(img: string): Promise<unknown>; /** * @description 将DOM元素img转换为base4的主要方法 * @param { HTMLImageElement } img DOM元素img * @param { Number } width * @param { Number } height * @returns { String } base64 */ export declare function getBase64Image(img: HTMLImageElement, width?: number, height?: number): string; /** * @description base64转Blob * @param { String } base64 * @returns { Blob } */ export declare function convertBase64ToBlob(base64: string): Blob; /** * @description 将图片路径转换成file文件类型 * @param { String } url 图片路径 * @param { String } name 转换后的图片名称 * @returns { Promise<unknown> } */ export declare function toFileByUrl(url: string, name?: string): Promise<unknown>; /** * @description 判断是否是json数据 * @param { any } obj * @returns { Boolean } */ export declare function isJson(obj: any): boolean; /** * @description 隐藏制定的所有元素 * @param el * @returns void */ export declare function hideElements(...el: HTMLElementTagNameMap[keyof HTMLElementTagNameMap][]): void; /** * @description 元素是否具有指定的类 * @param el * @param className * @returns { boolean } */ export declare function hasClassName(el: HTMLElementTagNameMap[keyof HTMLElementTagNameMap], className: string): boolean; /** * @description 获取当前页面的滚动位置 * @param { HTMLElement } el dom元素 * @returns { x: any, y: any } */ export declare function getScrollPosition(el?: any | Window): { x: any; y: any; }; /** * @description 滚动到顶部 * @returns { void } */ export declare function scrollToTop(): void; /** * @description 父元素是否包含子元素 * @param { HTMLElementTagNameMap[keyof HTMLElementTagNameMap] } parent 父级元素 * @param { HTMLElementTagNameMap[keyof HTMLElementTagNameMap] } child 子元素 * @returns { boolean } */ export declare function elementContains(parent: HTMLElementTagNameMap[keyof HTMLElementTagNameMap], child: HTMLElementTagNameMap[keyof HTMLElementTagNameMap]): boolean; /** * @description 指定元素是否在视口可见 * @param { HTMLElementTagNameMap[keyof HTMLElementTagNameMap] } el * @param { boolean } partiallyVisible * @returns { boolean } */ export declare function elementIsVisibleInViewport(el: HTMLElementTagNameMap[keyof HTMLElementTagNameMap], partiallyVisible?: boolean): boolean; /** * @description 分辨设备是移动设备还是桌面设备 * @returns { "Mobile" | "Desktop" } */ export declare function detectDeviceType(): "Mobile" | "Desktop"; /** * @description 获取当前 URL参数的对象 * @param { String } url 地址 * @returns { {} } */ export declare function getURLParameters(url: string): {}; /** * @description 获取两个日期之间的天数间隔 * @param { number } dateInitial * @param { number } dateFinal * @returns { number } */ export declare function getDaysDiffBetweenDates(dateInitial: number, dateFinal: number): number; /** * @description 为指定选择器创建具有指定范围、步长和持续时间的计时器 * @param { number } selector 选择器 * @param { number } start 开始数字 * @param { number } end 结束数字 * @param { number } step 步长 * @param { number } duration 持续时间,毫秒 * @returns { NodeJS.Timeout } */ export declare function counter(selector: string, start: number, end: number, step?: number, duration?: number): NodeJS.Timeout; /** * @description 将一个字符串复制到剪贴板 * @param { string } str * @returns { Promise<unkown> } */ export declare function copyToClipboard(str: string): Promise<void>; //# sourceMappingURL=index.d.ts.map