jcommon
Version:
JavaScript 常用纯函数工具库
1,288 lines (1,287 loc) • 36.5 kB
TypeScript
/**
* @description:
* @author: wxingheng
* @Date: 2023-06-13 16:08:46
* @param {*} private
* @param {*} private
* @return {*}
* @example:
*/
export declare class Typewriter {
private onConsume;
private onDone;
private queue;
private consuming;
private timer;
private strTemp;
constructor(onConsume: (str: string) => void, onDone: (str: string) => void);
dynamicSpeed(): number;
add(str: string): void;
consume(): void;
next(): void;
start(): void;
done(): void;
}
/**
* @category Array
*/
export type DoubleRankingOption = {
/**
* 一级过滤和排序的key
*/
filterRuleKey?: string;
/**
* 一级排序规则
*/
rule?: string[];
/**
* 二级正常排序的key
*/
sortKey?: string;
sortOrder?: number;
};
/**
* @category Array
* @description: 处理复杂数组的两级排序(一级按照自定义顺序,二级可正序倒序)
* @author: wuxh
* @Date: 2020-05-06 11:37:17
* @param {arr} 需要处理的数组
* @param {options} 额外参数
* @return: {Array} 排序后的数组
* ```
* doubleRanking(
* [
* {education: '本科', age: 26},
* {education: '小学', age: 25},
* {education: '本科', age: 24},
* {education: '小学', age: 23}
* ],
* {
* filterRuleKey: 'education',
* rule: ['小学', '本科'],
* sortKey: 'age',
* sortOrder: 1
* }
* )
* => [
* {education: '小学', age: 24},
* {education: '小学', age: 26}
* {education: '本科', age: 23},
* {education: '本科', age: 25},
* ]
* ```
*/
export declare const doubleRanking: (arr: {
[key: string]: any;
}[], options: DoubleRankingOption) => any[];
/**
* @category Array
* @description: 产生随机数据
* @author: wxingheng
* @Date: 2022-10-12 11:08:50
* @param {number} num 数量
* @param {Array} arr 每个元素对象的keys
* @return {*}
```
randomData(2, ['name', 'value'])
=> [{"name":"name323","value":"value699"},{"name":"name573","value":"value393"}]
```
*/
export declare const randomData: (num: number, arr: Array<string>) => Array<any>;
/**
* @category Array
* @description: 数值转对象 (常用于处理后台返回的枚举转换,工作中很常用)
* @author: wuxh
* @Date: 2020-05-06 11:51:49
* @param {object} arr 需要作为转换后对象的key需要转换的数组
* @param {string} key 需要作为转换后对象的key
* @param {*} v 对象的value取值,默认是数组的每一个元素作为值
* @return: Object
```
const arr = arr = [{name: 111, value: 222},{name: 333, value:444}]
arrByObj(arr, 'name') => {"111":{"name":111,"value":222},"333":{"name":333,"value":444}}
arrByObj(arr, 'name', value) => {"111":222,"333":444}
```
*/
export declare const arrByObj: (arr: {
[key: string]: any;
}[], key: string, v?: string) => {
[key: string]: any;
};
/**
* @category Array
* @description: 简单数组去重,Set 处理
* @author: wxingheng
* @Date: 2022-10-12 11:16:32
* @param {string} arr
* @return {*}
```
uniqueArray([1,1,1,1,1]) => [1]; uniqueArray([1,2,3,4,5]) => [1,2,3,4,5];
```
*/
export declare const uniqueArray: (arr: string | Iterable<any> | null | undefined) => any[];
/**
* @category Array
* @description: 数组交集
* @author: wxingheng
* @Date: 2022-05-18 10:56:47
* @param {Iterable} a
* @param {Iterable} b
* @return {*} Array
* ```
* difference([2,3,4,5], [1,2,3,4]) => [5, 1] ;
* difference([1,2,3,4], [2,3,4,5]) => [1, 5];
* difference([1,2,3,4], [1,2,3,4]) => [];
* difference([1,2,3,4], []) => [1, 2, 3, 4]
* ```
*/
export declare const difference: (a: Iterable<unknown> | null | undefined, b: Iterable<unknown> | null | undefined) => Array<any>;
/**
* @category Array
* @description: 数组元素是否相同
* @author: wxingheng
* @Date: 2022-05-18 10:56:04
* @param {any} arr1
* @param {any} arr2
* @return {*}
```
arrayCompare([2,3,4,5], [5,4,3,2]) => true ;
arrayCompare([2,3,4,5], [5,4,3,2,1]) => false;
arrayCompare([2,3,4,5], []) => true;
arrayCompare([], [1,2,3,4]) => false;
arrayCompare([1,2,3,4], []) => true;
```
*/
export declare const arrayCompare: (arr1: any[], arr2: any[]) => boolean;
/**
* @category Array
* @description: 数组排序的回调函数,用于sort方法,按照对象的某个属性进行中文排序
* @author: wxingheng
* @Date: 2022-09-30 11:43:11
* @param {string} key 排序的属性
* @return {*}
* ```
* arr.sort(sortCallBackChinese('name')) => [{name: '张三'}, {name: '李四'}]
* ```
*/
export declare const sortCallBackChinese: (key: string) => (a: any, b: any) => void;
/**
* @category Array
* @description:
* @author: wxingheng
* @Date: 2022-09-30 11:45:04
* @param {string} key 对象的key
* @param {boolean} desc 是否倒序, 默认是正序
* @return {*}
* ```
* arr.sort(sortCallBackNumber('age')) => [{age: 18}, {age: 20}]
* arr.sort(sortCallBackNumber('age', true)) => [{age: 20}, {age: 18}]
* ```
*/
export declare const sortCallBackTime: (key: string, desc?: boolean) => (a: any, b: any) => void;
/**
* @category Array
* @description: reduce方法,用于数组对象的求和
* @author: wxingheng
* @Date: 2022-09-30 11:51:39
* @param {string} key
* @return {*}
* ```
* arr.reduce(reduceSum('num'), 0) => 10
* ```
*/
export declare const reduceCallBackNumber: (key: string) => (acc: any, cur: any) => void;
/**
* @description: 转换Rh血型
* @author: wuxh
* @Date: 2021-09-07 13:44:36
* @param {*}
* @return {*}
* @example: formatRhBloodGroup('**D**') => 阳性
* formatRhBloodGroup('+') => 阳性
*
*/
export declare const formatRhBloodGroup: (input: string, optiongs?: {
format?: [string | number | boolean, string | number | boolean];
default?: string | number | boolean;
negative?: Array<string>;
positive?: Array<string>;
}) => string | number | boolean;
/**
* @description: 是否阴性
* @author: wuxh
* @Date: 2022-01-17 23:57:31
* @param {string} input
* @return {*}
* @example:
*/
export declare const isRhNegative: (input: string) => string | number | boolean;
/**
* @description: 是否阳性
* @author: wuxh
* @Date: 2022-01-17 23:57:19
* @param {string} input
* @return {*}
* @example:
*/
export declare const isRhPositive: (input: string) => string | number | boolean;
/**
* @description: sort []
* @author: wuxh
* @Date: 2021-09-07 14:12:06
* @param {string} key
* @return {*}
* @example:
* const arr = [{name: '666'}, {name: '333'}]
* arr.sorterCallBackString('name') => [{name: '333'}, {name: '666'}]
* arr.sorterCallBackString('name', false) => [{name: '666'}, {name: '333'}]
*/
export declare const sorterCallBack: (key: string, isAscend?: boolean) => (a: any, b: any) => 1 | -1;
export type getBrowserInfoResult = {
name: string | RegExp;
version: string;
};
/**
* @description: 获取浏览器相关信息
* @author: wuxh
* @Date: 2020-05-06 11:53:35
* @param {}
* @return: Object
* @example:
```
getBrowserInfo()
=> {name: "Chrome", version: "81.0.4044.129"}
```
*/
export declare const getBrowserInfo: () => getBrowserInfoResult;
/**
* @description: 删除
* @author: wuxh
* @Date: 2020-05-06 11:56:29
* @param {key}
* @return: undefined
* @example:
removeStorage('test')
=> undefined
*/
export declare const removeStorage: (key: any) => void;
/**
* @description: 保存
* @author: wuxh
* @Date: 2020-05-06 11:56:29
* @param {key}
* @param {value}
* @param {isJson}
* @return: undefined
* @example:
saveStorage('test', '001')
=> undefined
*/
export declare const saveStorage: (key: string, value: string) => void;
/**
* @description: 获取
* @author: wuxh
* @Date: 2020-05-06 12:00:37
* @param {key}
* @return: String
* @example:
getStorage('test')
=> '001'
*/
export declare const getStorage: (key: string) => any;
/**
* @description: 是否支持local
* @author: wuxh
* @Date: 2020-05-06 12:01:43
* @param
* @return: Boolean
* @example:
isSupportStorage()
=> true
*/
export declare const isSupportStorage: () => boolean;
/**
* @description: 获取cookie值
* @author: wuxh
* @Date: 2020-06-09 09:28:06
* @param {type}
* @return: string
* @example:
getCookie('name') => 123
*/
export declare const getCookie: (name: string) => string | null;
/**
* @description: 获取两个时间的间隔
* @author: wuxh
* @Date: 2020-05-06 12:04:39
* @param {st}
* @param {et}
* @return: String
* @example:
dateInterval(new Date().getTime(), 1589661011714)
=> 11天13小时46分钟21秒
*/
export declare const dateInterval: (st: number, et: number) => string;
/**
* @description: 字符串补0,目前提供给dateFormat使用
* @author: wuxh
* @Date: 2020-05-11 14:01:20
* @param {v} 需要处理的数据 String | Number
* @param {size} 期望得到的总位数
* @return: String
* @example:
addZero(12, 1) => 12
addZero(12, 2) => 12
addZero(12, 3) => 012
*/
export declare const addZero: (v: string | number, size: number) => string;
/**
* @description: 时间的转换(目前支持 年,月,日,时,分,秒,星期)
* @author: wuxh
* @Date: 2020-05-06 12:05:28
* @param {date}
* @param {formatStr}
* @return: String
* @example:
dateFormat(new Date(), '当前时间 YY-MM-DD HH:II:SS 星期W')
=> "当前时间 20-05-11 14:07:02 星期一"
*/
export declare const dateFormat: (date: Date, formatStr: string) => string;
/**
* @description: 时间的转换(目前支持 年,月,日,时,分,秒,星期), 与dateFormat的区别是,这个方法可以传入时间戳
* @author: wxingheng
* @Date: 2022-09-30 11:46:22
* @return {date}
* @example: convertDateToView(new Date(), '当前时间 YY-MM-DD HH:II:SS 星期W')
*/
export declare const convertDateToView: (date: string | Date | number, template?: string, defaultResult?: string) => string;
/**
* @description: 时间的转换 "YYYY-MM-DD HH:II:SS"
* @author: wxingheng
* @Date: 2022-09-30 11:48:15
* @param {string} date
* @return {*}
* @example: convertDateToStandard(new Date()) => "2021-09-30 11:48:15"
*/
export declare const convertDateToStandard: (date: string | Date | number) => string;
/**
* @description: 时间的转换 "YYYY-MM-DD"
* @author: wxingheng
* @Date: 2022-09-30 11:49:14
* @param {string} date
* @return {*}
* @example: convertDateToStandardDay(new Date()) => "2021-09-30"
*/
export declare const convertDateToStandardDay: (date: string | Date | number) => string;
/**
* @description: 时间的转换 "YYYY-MM-DD HH"
* @author: wxingheng
* @Date: 2022-09-30 11:49:37
* @param {string} date
* @return {*}
* @example: convertDateToStandardHours(new Date()) => "2021-09-30 11"
*/
export declare const convertDateToStandardHours: (date: string | Date | number) => string;
/**
* @description: 获取当前月份的天数
* @author: wuxh
* @Date: 2020-05-06 12:06:24
* @param {str}
* @return: Number
* @example:
dateMonthDays('2020-05-06')
=> 31
*/
export declare const dateMonthDays: (str: string) => number;
/**
* @description: 时间个性化输出功能
* @author: wuxh
* @Date: 2020-06-09 09:44:23
* @param {type}
* @return: string
* @example:
1、< 60s, 显示为“刚刚”
2、>= 1min && < 60 min, 显示与当前时间差“XX分钟前”
3、>= 60min && < 1day, 显示与当前时间差“今天 XX:XX”
4、>= 1day && < 1year, 显示日期“XX月XX日 XX:XX”
5、>= 1year, 显示具体日期“XXXX年XX月XX日 XX:XX”
timeFormat(new Date()) => '刚刚'
*/
export declare const timeFormat: (time: Date) => string;
/**
* @description: 获取当前月份天数
* @author: wuxh
* @Date: 2021-08-21 22:43:58
* @param {*} str YYYY-MM-DD mm:ss
* @return {*} number
* @example:
*/
export declare const getCountDays: (str: string | number | Date) => number;
/**
* @description: debounce 防抖, 固定时间内持续触发,只执行最后一次
* @author: wuxh
* @Date: 2021-09-02 21:30:44
* @param {*} Function 要进行debouce的函数
* @param {*} wait 等待时间,默认500ms
* @param {*} immediate 是否立即执行
* @return {*} Function
* @example:
* function onInput() {
console.log('1111')
}
const debounceOnInput = debounce(onInput)
document
.getElementById('input')
.addEventListener('input', debounceOnInput)
*
*/
export declare const debounce: (func: (...rest: any) => void, wait?: number, immediate?: boolean) => {
(...args: any): void;
cancel(): void;
};
/**
* @description: decoratorNonenumerable
* @author: wuxh
* @Date: 2021-11-10 11:43:45
* @param {*}
* @return {*}
* @example:
*/
export declare const decoratorNonenumerable: (_target: any, _name: any, descriptor: any) => any;
/**
* @description: 获取用户系统平台信息
* @author: wuxh
* @Date: 2020-05-06 12:07:03
* @param {e}
* @return: {os: "mac", version: "10.15.3"}
* @example:
```
osInfo()
=> {os: "mac", version: "10.15.3"}
```
*/
export type osInfoResult = {
os: string | RegExp;
version: string;
};
export declare const osInfo: (e: string) => osInfoResult;
/**
* @description: 下载一个链接文档
* @author: wuxh
* @Date: 2021-09-01 23:27:00
* @param {string} link
* @param {string} name
* @return {*}
* @example:
* download('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202008%2F04%2F20200804215427_fc3ff.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633102668&t=5f2cf4e9273be91527efb91ecd5cb6dd')
* 下载后端返回的流
*
*/
export declare const download: (link: string, name: string) => any;
/**
* @description: 在浏览器中自定义下载一些内容
* @author: wuxh
* @Date: 2021-09-01 23:32:30
* @param {string} name
* @param {BlobPart} content
* @return {*}
* @example: 场景:我想下载一些DOM内容,我想下载一个JSON文件
*
* downloadFile('1.txt','lalalallalalla')
downloadFile('1.json',JSON.stringify({name:'hahahha'}))
*/
export declare const downloadFile: (name: string, content: BlobPart) => any;
/**
* @description: 复制内容到剪贴板
* @author: wuxh
* @Date: 2021-09-02 22:22:03
* @param {string} value
* @return {*} boolean
* @example:
copyToBoard('lalallala') => true // 如果复制成功返回true
*/
export declare const copyToBoar: (value: string) => boolean;
/**
* @description: 拖拽滚动
* @author: wxingheng
* @Date: 2022-07-15 18:16:15
* @param {*} scrollDom
* @return {*}
* @example: 待增加惯性效果
*/
export declare const dragScroll: (scrollDom: any) => object;
/**
* @description: 获取图片的 base64
* @author: wxingheng
* @Date: 2022-09-30 10:53:33
* @param {File} file
* @return {*}
* @example: getBase64(file).then(res => console.log(res))
*/
export declare const getBase64: (file: File) => Promise<any>;
/**
* @description: 前端文件导入,JSON文件导入
* @author: wxingheng
* @Date: 2022-09-30 10:57:58
* @param {*} Object
* @return {*}
* @example: importJson() => {name: 'wxh'}
*/
export declare const importJson: () => object;
/**
* @description: JSON 对象导出为.json文件
* @author: wxingheng
* @Date: 2022-09-30 11:00:54
* @param {any} data
* @param {*} name
* @return {*}
* @example:
*/
export declare const exportJson: (data: any, name?: string) => any;
/**
* @description: EventBus class
* @author: wuxh
* @Date: 2021-08-24 11:19:07
* @example: const eventBus = new EventBus()
*/
export declare class EventBus {
private listeners;
private maxListener;
constructor();
addListener(event: string, cb: (...args: any[]) => any): void;
emit(event: string, ...args: any[]): void;
getListeners(event: string): Array<(...args: any[]) => any>;
setMaxListeners(maxListener: number): void;
removeListener(event: string, listener: (...args: any[]) => any): void;
removeAllListener(event: string): void;
once(event: string, cb: (...args: any[]) => any): void;
}
/**
* @description: 对象转化为FormData对象
* @author: wuxh
* @Date: 2021-09-02 22:52:34
* @param {object} object
* @return {FormData}
* @example:
let req={
file:xxx,
userId:1,
phone:'15198763636',
//...
}
fetch(getFormData(req))
*/
export declare const getFormData: (object: {
[x: string]: string | Blob;
}) => FormData;
declare class GlobalCache {
private static readonly instance;
private readonly cache;
private constructor();
static getInstance(): GlobalCache;
set<T>(key: string, value: T): void;
get<T>(key: string): T | undefined;
has(key: string): boolean;
delete(key: string): void;
clear(): void;
}
declare const globalCache: GlobalCache;
export { globalCache };
/**
* @description: 范围随机整数
* @author: wuxh
* @Date: 2020-05-06 12:09:34
* @param {str}
* @param {end}
* @return: Number
* @example:
scopeRandom(1, 10)
=> 3
*/
export declare const scopeRandom: (str: number, end: number) => number;
/**
* @description: 保留到小数点以后n位
* @author: wuxh
* @Date: 2021-09-02 22:54:36
* @param {number} number
* @param {*} no
* @return {*} Number
* @example:
cutNumber('3123.22312') => 3123.22
*/
export declare const cutNumber: (number: number, no?: number) => number;
/**
* @description: 获取嵌套数据,处理空值异常
* @author: wuxh
* @Date: 2020-05-06 12:13:59
* @param defaultResult 默认值
* @param args 属性访问路径
* @returns 目标值或默认值
* @example:
getV('', {name: {children: 123}}, 'name', 'children')
=> 123
*/
export declare const getV: <T>(defaultResult: T, ...args: any[]) => any;
/**
* @description: 深拷贝,克隆(只包含可遍历属性<常用>)
* @author: wuxh
* @Date: 2020-05-06 12:14:45
* @param {obj}
* @return: Object
* @example:
clone({name: 123})
=> {name: 123}
*/
export declare const cloneObj: (obj: any) => any;
/**
* @description: 简单的深拷贝
* @author: wuxh
* @Date: 2021-09-02 22:33:47
* @param {any} obj
* @return {any} obj
* @example:
const person={name:'xiaoming',child:{name:'Jack'}}
cloneJson(person) => {name:'xiaoming',child:{name:'Jack'}}
*/
export declare const cloneJson: (obj: any) => any;
/**
* @description: 深度合并对象(当前用于合并系统配置文件 app-data.json) 已存在的属性默认不覆盖
* @author: wuxh
* @Date: 2020-05-06 12:15:30
* @param {oldObj}
* @param {newObj}
* @param {keys} 强制覆盖属性的key组成的数组
* @return: Object
* @example:
mergeObj({name: 111}, {name:333, value: 222}, []) => {name: 111, value: 222}
mergeObj({name: 111}, {name:333, value: 222}, ['name']) => {name: 333, value: 222}
*/
export declare const mergeObj: (oldObj: {
[x: string]: any;
}, newObj: {
[x: string]: any;
}, keys: string | string[]) => {
[x: string]: any;
};
/**
* @description: 判断对象是否为空
* @author: wuxh
* @Date: 2021-08-21 23:08:42
* @param {string} obj
* @return {*} boolean
* @example: isEmptyObject({}) => true
*/
export declare const isEmptyObject: (obj: any) => boolean;
/**
* @description: cleanObject 去除对象中value为空(null,undefined,'')的属性
* @author: wuxh
* @Date: 2021-09-02 22:07:34
* @param {*} { [k: string]: any }
* @return {*} { [k: string]: any }
* @example:
cleanObject({
name: '',
pageSize: 10,
page: 1
}) => {
pageSize: 10,
page: 1
}
*/
export declare const cleanObject: (object: {
[k: string]: any;
}) => {
[k: string]: any;
};
/**
* @description: 深克隆 deepClone
* @author: wxingheng
* @Date: 2022-04-10 22:19:43
* @param {any} value
* @param {*} stack
* @return {*}
* @example: deepClone(obj) => new obj
*/
export declare const deepClone: (target: any) => any;
/**
* @description: 判断两个对象是否相等
* @author: wxingheng
* @Date: 2022-05-13 16:35:33
* @param {any} a
* @param {any} b
* @return {*}
* @example: isEqual({a: 1}, {a: 1}) => true; isEqual({a: 1}, {a: 2}) => false; isEqual({a: 1}, {b: 1}) => false
*/
export declare const isEqual: (a: any, b: any) => boolean;
/**
* @description: 将list转换为树结构
* @author: wxingheng
* @Date: 2022-09-30 11:37:32
* @return {*}
* @example: convertDataToTree(data) => treeData
*/
export declare const convertDataToTree: (data: any[], id?: string, pid?: string, children?: string) => any[];
/**
* @description: 将树结构转换为list
* @author: wxingheng
* @Date: 2022-09-30 11:40:43
* @param {any} tree 树结构
* @param {string} children 子节点字段
* @return {*}
* @example: convertTreeToList (treeData) => listData
*/
export declare const convertTreeToList: (tree: any[], children?: string) => any[];
/**
* @description: 数组的分类,根据某个字段分类,返回一个对象,key为字段值,value为数组
* @author: wxingheng
* @Date: 2022-09-30 11:53:38
* @param {any} arr
* @param {string} key
* @return {*}
* @example:
* const arr = [
* {type: 1, name: 'a'},
* {type: 2, name: 'b'},
* {type: 1, name: 'c'},
* {type: 2, name: 'd'},
* {type: 1, name: 'e'},
* {type: 2, name: 'f'},
* ]
* groupBy(arr, 'type') => {1: [{type: 1, name: 'a'}, {type: 1, name: 'c'}, {type: 1, name: 'e'}], 2: [{type: 2, name: 'b'}, {type: 2, name: 'd'}, {type: 2, name: 'f'}]}
*/
export declare const groupBy: (arr: any[], key: string) => any;
/**
* @description: 单击事件转换为多击事件
* @author: wxingheng
* @Date: 2022-05-04 14:20:22
* @param {*} wait
* @param {array} events
* @return {*}
* @example:
* // 连续点击一次触发,连续点击两次触发,连续点击三次触发
var oneClickToMoreClickCallBack = jcommon.oneClickToMoreClick(300, () => {
console.log(111)
}, () => {
console.log(222)
}, ()=> {
console.log(333)
})
dom.addEventListener('click', oneClickToMoreClickCallBack);
*/
export declare const oneClickToMoreClick: (wait?: number, ...events: ((...args: any[]) => void)[]) => () => void;
/**
* @description: 单击事件转换为多击事件
* @author: wxingheng
* @Date: 2022-08-09 14:03:34
* @param {Function} fun 回调函数
* @param {*} n 连续几次触发才触发回调函数
* @param {*} wait 两次之间的间隔时间
* @return {*}
* @example: const dobuleClick = moreClick(handleClick)
// 连续点击三次触发
var moreClickCallBack = jcommon.moreClick(() => {
console.log("moreClickCallBack")
}, 3)
dom.addEventListener('click', moreClickCallBack);
*/
export declare const moreClick: (fun: (...args: any) => void, n?: number, wait?: number) => (...args: any[]) => void;
/**
* @description: 产生一个随机颜色
* @author: wxingheng
* @Date: 2022-09-30 11:13:13
* @return {*}
* @example: randomColor() => "rgba(107, 35, 72, 1)";
*/
export declare const randomColor: () => any;
/**
* @description: 比例计算
* @author: wxingheng
* @Date: 2022-09-30 11:13:27
* @param {number} value 当前值
* @param {number} source 当前值所在的区间
* @param {number} target 目标区间
* @param {any} toFixedLength 保留小数位数
* @return {*}
* @example: scaleLinear(50, 100, 10, 2) => 5; scaleLinear(50, 100, 10, 0) => 5;
*/
export declare const scaleLinear: (value: number, source: number, target: number, toFixedLength?: any) => any;
/**
* @description: 转换请求为慢响应
* @param {*} func 请求函数
* @param {*} fastestTime 最快响应时间
* @return {*}
* @example: const data = await fetchToSlow(1000 * 2)(getKgDetail(kg_id));
*/
export declare const fetchToSlow: (fastestTime: number | undefined) => (func: any) => any;
/**
* @description: 处理流响应数据
* @author: wxingheng
* @Date: 2023-06-13 16:14:34
* @param {any} response
* @param {object} typewriter
* @return {*}
* @example:
*/
export declare const processStreamResponse: (response: any, typewriter: {
start: () => void;
done: () => void;
add: (arg0: any) => void;
}) => Promise<void>;
/**
* @description: Queue 队列 class
* @author: wuxh
* @Date: 2021-08-24 11:19:07
* @example: const queue = new Queue()
*/
export declare class Queue {
private items;
constructor(items: Array<never>);
enqueue(element: never): void;
dequeue(): void;
front(): never;
isEmpty(): boolean;
size(): number;
clear(): void;
print(): void;
}
/**
* @description: 是否是QQ平台
* @author: wuxh
* @Date: 2020-05-06 12:10:41
* @param
* @return: Boolean
* @example:
isQQ()
=> false
*/
export declare const isQQ: () => boolean;
/**
* @description: 是否是微信平台
* @author: wuxh
* @Date: 2020-05-06 12:10:41
* @param
* @return: Boolean
* @example:
isWX()
=> false
*/
export declare const isWX: () => boolean;
/**
* @description: 获取手机运营商
* @author: wuxh
* @Date: 2020-05-06 12:11:39
* @param {}
* @return: '移动' | '电信' | '联通' | '未知'
* @example:
operattelecom('13419595634') => 移动
*/
export declare const operattelecom: (e: string) => false | "未知" | "联通" | "电信" | "移动";
/**
* @description: 是否是安卓设备
* @author: wuxh
* @Date: 2020-06-09 09:31:04
* @param {type}
* @return: boolean
* @example:
isAndroidMobileDevice() => false
*/
export declare const isAndroidMobileDevice: () => boolean;
/**
* @description: 是否是苹果设备
* @author: wuxh
* @Date: 2020-06-09 09:31:55
* @param {type}
* @return: boolean
* @example:
isAppleMobileDevice() => true
*/
export declare const isAppleMobileDevice: () => boolean;
/**
* @description: 休眠多少毫秒
* @author: wuxh
* @Date: 2021-09-02 23:08:19
* @param {number} milliseconds
* @return {*}
* @example:
fetchData = async () => {
await sleep(1000)
}
*/
export declare const sleep: (milliseconds: number | undefined) => Promise<unknown>;
/**
* @description: 去除字符串空格, 默认去除前后空格 (常用)
* @author: wuxh
* @Date: 2020-05-06 13:43:52
* @param {str} String
* @param {global} Boolean
* @return: String
* @example:
trim(' 1 1 1 ') => '1 1 1'
trim(' 1 1 1 ', true) => '111'
*/
export declare const trim: (str: string, global?: boolean) => string;
/**
* @description: 身份证号码解析性别
* @author: wuxh
* @Date: 2020-06-09 09:16:28
* @param {type}
* @return: 'FEMALE' | 'MALE'
* @example:
getSexByIdNO('421182199409274710') => MALE
*/
export declare const getSexByIdNO: (IdNO: string) => 'FEMALE' | 'MALE' | '';
/**
* @description: 身份证号码解析出生日期
* @author: wuxh
* @Date: 2020-06-09 09:17:50
* @param {type}
* @return: string
* @example:
getBirthdatByIdNo('421182199409274710') => '1994-09-27'
*/
export declare const getBirthdatByIdNo: (iIdNo: string) => string;
/**
* @description: 隐藏身份证号码
* @author: wuxh
* @Date: 2020-06-09 09:19:26
* @param {type}
* @return: string
* @example:
hideIdNum('421182199409274710') => 4****************0
*/
export declare const hideIdNum: (str: string) => string;
/**
* @description: 随机数 + 时间戳
* @author: wuxh
* @Date: 2020-06-09 09:47:34
* @param {type}
* @return: string
* @example:
uniqueId() => '1591667193048544'
*/
export declare const uniqueId: () => string;
/**
* @description: 版本号累加
* @author: wuxh
* @Date: 2021-08-24 11:19:07
* @param {*} version : string
* @return {*} string
* @example: versionCount('0.0.1') => '0.0.2'
* versionCount('0.2.9') => '0.3.0'
* versionCount('0.2.9.1') => '0.2.9.2'
*/
export declare const versionCount: (version: string, maxNum?: number) => string;
/**
* @description: 获取文件后缀名
* @author: wuxh
* @Date: 2021-09-02 22:17:57
* @param {string} filename
* @return {*}
* @example:
getExt("1.mp4") => mp4
*/
export declare const getExt: (filename: string) => string | undefined;
/**
* 生成随机id
* @param {*} length
* @param {*} chars
*/
/**
* @description: 生成随机字符串,第一个参数指定位数,第二个字符串指定字符,都是可选参数,如果都不传,默认生成8位
* @author: wuxh
* @Date: 2021-09-02 22:29:02
* @param {number} length
* @param {string} chars
* @return {string}
* @example:
uuid() => 'ghijklmn'
*/
export declare const uuid: (length: number, chars: string | any[]) => string;
/**
* @description: 字符串判断结尾
* @author: wuxh
* @Date: 2021-11-10 11:35:30
* @param {string} str
* @param {string} endStr
* @return {*}
* @example: endWith('1231231', '21') => false ; endWith('1231231', '31') => true
*/
export declare const endWith: (str: string, endStr: string) => boolean;
/**
* @description: 计算两个字符串相似度
* @author: wxingheng
* @Date: 2022-07-25 10:07:23
* @param s 文本1
* @param t 文本2
* @param f 小数位精确度,默认2位
* @returns {string|number|*} 百分数前的数值,最大100. 比如 :90.32
* @example: similar("12", "12") => 100 ; similar("12", "123") => 75 ; similar("12", "1234") => 50
*/
export declare const similar: (s: string, t: string, f?: number) => number;
/**
* @description: 计算文本长度(中文算两个字符,英文算一个字符)
* @author: wxingheng
* @Date: 2022-09-30 10:49:41
* @param {string} str
* @return {number}
* @example: getStringLen("阿斯顿发123") => 11 ; getStringLen("asd123") => 6 ; getStringLen("asd123顿发") => 10
*/
export declare const getStringLen: (str: string) => number;
/**
* @description: 节流 多次调用方法,按照一定的时间间隔执行
* @author: wuxh
* @Date: 2021-09-02 21:46:38
* @param {*} func
* @param {*} wait
* @param {*} options: { leading: boolean; trailing: boolean }
* @return {*} Function
* @example:
*
leading,函数在每个等待时延的开始被调用,默认值为false
trailing,函数在每个等待时延的结束被调用,默认值是true
可以根据不同的值来设置不同的效果:
leading-false,trailing-true:默认情况,即在延时结束后才会调用函数
leading-true,trailing-true:在延时开始时就调用,延时结束后也会调用
leading-true, trailing-false:只在延时开始时调用
*/
export declare const throttle: (func: () => void, wait: number | undefined, options: {
leading: boolean;
trailing: boolean;
}) => (() => void);
/**
* @description: 获取浏览器url中的一个参数
* @author: wuxh
* @Date: 2020-05-06 13:46:28
* @param {name}
* @return: String
* @example:
getUrlQuery(age)
=> 25
*/
export declare const getUrlQuery: (name: string) => string;
/**
* @description: 去除值类型为string的前后空格
* @author: wuxh
* @Date: 2021-08-21 22:11:23
* @param {Array} data
* @return {*}
* @example: everyTrim({name: ' 123 ', arr: [' 33 ']}) => {name: '123': arr: ['33']}
*/
export declare const everyTrim: (data: Array<any> | object) => any;
/**
* @description: 格式化GET请求的请求头
* @author: wuxh
* @Date: 2020-05-06 13:47:40
* @param {obj}
* @return: String
* @example:
formatQueryParam({name: 1, value: 123})
=> "name=1&value=123"
*/
export declare const formatQueryParam: (obj: {
[key: string]: any;
}) => string;
/**
* @description: 处理url参数(window.location.search)转换为 {key: value}
* @author: wuxh
* @Date: 2020-05-06 13:48:36
* @param {params}
* @return: Object
* @example:
urlByObj(?ie=UTF-8&wd=asd)
=> {ie: UTF-8, wd: asd}
*/
export declare const urlByObj: (params: string) => {
[key: string]: string;
};
/**
* @description: 身份证号码校验(精准)
* @author: wuxh
* @Date: 2020-05-06 13:49:58
* @param {e}
* @return: String<msg> | Boolean
* @example:
isUserId('421182199409274710') => ''
isUserId('421182199409') => '身份证号码长度应该为18位'
*/
export declare const isUserId: (e: string) => "" | "身份证号码不能为空" | "身份证号码长度应该为18位" | "身份证格式错误" | "身份证生日无效。" | "身份证生日不在有效范围" | "身份证月份无效" | "身份证日期无效" | "身份证地区编码错误" | "不是合法的身份证号码";
/**
* @description: 精准判断数据类型
* @author: wuxh
* @Date: 2020-05-06 13:51:50
* @param {data} any
* @param {type} type 'String' | 'Number' | 'Boolean' | 'Undefined' | 'Null' | 'Function' | 'Date' | 'Array' | 'RegExp' | 'Error' | 'Object'
* @return: Boolean
* @example:
isType(123, 'String') => false
isType('123', 'String') => true
*/
export declare const isType: (data: any, type: string) => boolean;
/**
* @description: 判断String类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isString(123) => false
isString('') => true
*/
export declare const isString: (data: any) => boolean;
/**
* @description: 判断Number类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isNumber(123) => true
isNumber('') => false
*/
export declare const isNumber: (data: any) => boolean;
/**
* @description: 判断Boolean类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isBoolean(false) => true
isBoolean('false') => false
*/
export declare const isBoolean: (data: any) => boolean;
/**
* @description: 判断Undefined类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isUndefined(undefined) => true
isUndefined('undefined') => false
*/
export declare const isUndefined: (data: any) => boolean;
/**
* @description: 判断Null类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isNull(null) => true
isNull('null') => false
*/
export declare const isNull: (data: string) => boolean;
/**
* @description: 判断Function类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isFunc(() => 123) => true
isFunc(123) => false
*/
export declare const isFunc: (data: any) => boolean;
/**
* @description: 判断Date类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isDate(() => new Date()) => false
isDate(new Date()) => true
*/
export declare const isDate: (data: any) => boolean;
/**
* @description: 判断Array类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isArray([]) => true
isArray(![]) => false
*/
export declare const isArray: (data: any) => boolean;
/**
* @description: 判断RegExp类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isReg(new RegExp()) => true
isReg(![]) => false
*/
export declare const isReg: (data: any) => boolean;
/**
* @description: 判断Error类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isError(new Error()) => true
isError(![]) => false
*/
export declare const isError: (data: any) => boolean;
/**
* @description: 判断Object类型
* @author: wuxh
* @Date: 2020-05-06 13:53:16
* @param {data} any
* @return: Boolean
* @example:
isObject({}) => true
isObject(![]) => false
*/
export declare const isObject: (data: any) => boolean;
/**
* @description: 手机号校验
* @author: wuxh
* @Date: 2020-06-09 09:21:15
* @param {type}
* @return: boolean
* @example:
isPhone('13419595634') => true
*/
export declare const isPhone: (phone: string) => boolean;
/**
* @description: 校验是否为邮箱地址
* @author: wuxh
* @Date: 2020-06-09 09:49:29
* @param {type}
* @return: boolean
* @example:
isEmail('wxingheng@outlook.com') => true
*/
export declare const isEmail: (str: string) => boolean;
/**
* @description: 判断 js是否是false, 0除外。
* @author: wuxh
* @Date: 2021-09-02 22:01:50
* @param {any} value
* @return {*} value === 0 ? false : !value
* @example:
isFalsy('') => true
isFalsy(0) => false
isFalsy(null) => true
isFalsy(undefined) => true
*/
export declare const isFalsy: (value: any) => boolean;
/**
* @description: 判断是否为空 undefined || null || ""
* @author: wuxh
* @Date: 2021-09-02 22:03:36
* @param {any} value
* @return {*} boolean
* @example:
isVoid(0) => false
isVoid(undefined) => true
isVoid('') => true
isVoid(null) => true
isVoid() => true
*/
export declare const isVoid: (value: any) => boolean;