jcommon文档库 / Exports
JavaScript 常用纯函数工具库 (当前版本已在项目中使用,后续更新会向前兼容) 持续丰富中...
在日常工作中,会经常用到一些日期格式化
,url相关操作
,浏览器类型判断
,常用验证格式
等等函数,虽然大部分只需谷歌/百度一下就能找到,但是大多数都存在着一些问题,于是整理了网上和自己平常用到的工具类,方便大家以后的使用,提升开发效率。
# 安装
$ npm install jcommon
# 引入
import { isObject, isArray } from 'jcommon'
or
const { isObject, isArray } = require('jcommon')
or
<script type="text/javascript" src="./dist/jcommon.js"></script>
<script>
jcommon.isObject({})
</script>
- 完全的按需引用,我们只导出纯函数
- 不同于传统 js 工具库导出一整个大模块(moment, utils, ...)
- 支持 npm 安装方式
- 支持 script 标签直接引入(考虑通过全局一个模块的方式,jcommon,避免全局命名空间污染)
- TypeScript支持
- dom
- 增加单元测试
- 根据 .d.ts 文件自动生成文档
- lint
- typedoc
- 文档自动部署,Github page
jcommon文档库 - v1.9.36 / Exports
@description: @author: wxingheng @Date: 2022-09-30 11:45:04 Functions
@description: reduce方法,用于数组对象的求和 @author: wxingheng @Date: 2022-09-30 11:51:39 Functions
@description: 数组排序的回调函数,用于sort方法,按照对象的某个属性进行中文排序 @author: wxingheng @Date: 2022-09-30 11:43:11 Functions
@description: 处理复杂数组的两级排序(一级按照自定义顺序,二级可正序倒序) @author: wuxh @Date: 2020-05-06 11:37:17 Functions
@description: 数值转对象 (常用于处理后台返回的枚举转换,工作中很常用) @author: wuxh @Date: 2020-05-06 11:51:49 Functions
@description: 数组交集 @author: wxingheng @Date: 2022-05-18 10:56:47 Functions
@description: 数组元素是否相同 @author: wxingheng @Date: 2022-05-18 10:56:04 Functions
@description: 简单数组去重,Set 处理 @author: wxingheng @Date: 2022-10-12 11:16:32 Functions
@description: 产生随机数据 @author: wxingheng @Date: 2022-10-12 11:08:50 Functions
- addZero
- cleanObject
- cloneJson
- cloneObj
- convertDataToTree
- convertDateToStandard
- convertDateToStandardDay
- convertDateToStandardHours
- convertDateToView
- convertTreeToList
- copyToBoar
- cutNumber
- dateFormat
- dateInterval
- dateMonthDays
- debounce
- deepClone
- download
- downloadFile
- dragScroll
- endWith
- everyTrim
- exportJson
- fetchToSlow
- formatQueryParam
- formatRhBloodGroup
- getBase64
- getBirthdatByIdNo
- getBrowserInfo
- getCookie
- getCountDays
- getExt
- getFormData
- getSexByIdNO
- getStorage
- getStringLen
- getUrlQuery
- getV
- groupBy
- hideIdNum
- importJson
- isAndroidMobileDevice
- isAppleMobileDevice
- isArray
- isBoolean
- isDate
- isEmail
- isEmptyObject
- isEqual
- isError
- isFalsy
- isFunc
- isNull
- isNumber
- isObject
- isPhone
- isQQ
- isReg
- isRhNegative
- isRhPositive
- isString
- isSupportStorage
- isType
- isUndefined
- isUserId
- isVoid
- isWX
- mergeObj
- moreClick
- oneClickToMoreClick
- operattelecom
- osInfo
- processStreamResponse
- randomColor
- removeStorage
- saveStorage
- scaleLinear
- scopeRandom
- similar
- sleep
- sorterCallBack
- throttle
- timeFormat
- trim
- uniqueId
- urlByObj
- uuid
- versionCount
Ƭ DoubleRankingOption: Object
Name | Type | Description |
---|---|---|
filterRuleKey? |
string |
一级过滤和排序的key |
rule? |
string [] |
一级排序规则 |
sortKey? |
string |
二级正常排序的key |
sortOrder? |
number |
- |
Ƭ getBrowserInfoResult: Object
Name | Type |
---|---|
name |
string | RegExp |
version |
string |
Ƭ osInfoResult: Object
@description: 获取用户系统平台信息 @author: wuxh @Date: 2020-05-06 12:07:03
Param
{os: "mac", version: "10.15.3"} @example:
osInfo()
=> {os: "mac", version: "10.15.3"}
Name | Type |
---|---|
os |
string | RegExp |
version |
string |
• Const
globalCache: GlobalCache
@description: @author: wxingheng @Date: 2022-09-30 11:45:04 Functions
▸ sortCallBackTime(key
, desc?
): (a
: any
, b
: any
) => void
Name | Type | Default value | Description |
---|---|---|---|
key |
string |
undefined |
对象的key |
desc |
boolean |
false |
是否倒序, 默认是正序 |
fn
arr.sort(sortCallBackNumber('age')) => [{age: 18}, {age: 20}]
arr.sort(sortCallBackNumber('age', true)) => [{age: 20}, {age: 18}]
▸ (a
, b
): void
Name | Type |
---|---|
a |
any |
b |
any |
void
@description: reduce方法,用于数组对象的求和 @author: wxingheng @Date: 2022-09-30 11:51:39 Functions
▸ reduceCallBackNumber(key
): (acc
: any
, cur
: any
) => void
Name | Type |
---|---|
key |
string |
fn
arr.reduce(reduceSum('num'), 0) => 10
▸ (acc
, cur
): void
Name | Type |
---|---|
acc |
any |
cur |
any |
void
@description: 数组排序的回调函数,用于sort方法,按照对象的某个属性进行中文排序 @author: wxingheng @Date: 2022-09-30 11:43:11 Functions
▸ sortCallBackChinese(key
): (a
: any
, b
: any
) => void
Name | Type | Description |
---|---|---|
key |
string |
排序的属性 |
fn
arr.sort(sortCallBackChinese('name')) => [{name: '张三'}, {name: '李四'}]
▸ (a
, b
): void
Name | Type |
---|---|
a |
any |
b |
any |
void
@description: 处理复杂数组的两级排序(一级按照自定义顺序,二级可正序倒序) @author: wuxh @Date: 2020-05-06 11:37:17 Functions
▸ doubleRanking(arr
, options
): any
[]
Name | Type |
---|---|
arr |
{ [key: string] : any ; }[] |
options |
DoubleRankingOption |
any
[]
@description: 数值转对象 (常用于处理后台返回的枚举转换,工作中很常用) @author: wuxh @Date: 2020-05-06 11:51:49 Functions
▸ arrByObj(arr
, key
, v?
): Object
Name | Type | Default value | Description |
---|---|---|---|
arr |
{ [key: string] : any ; }[] |
undefined |
需要作为转换后对象的key需要转换的数组 |
key |
string |
undefined |
需要作为转换后对象的key |
v |
string |
'' |
对象的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} |
Object
@description: 数组交集 @author: wxingheng @Date: 2022-05-18 10:56:47 Functions
▸ difference(a
, b
): any
[]
Name | Type |
---|---|
a |
undefined | null | Iterable <unknown > |
b |
undefined | null | Iterable <unknown > |
any
[]
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]
@description: 数组元素是否相同 @author: wxingheng @Date: 2022-05-18 10:56:04 Functions
▸ arrayCompare(arr1
, arr2
): boolean
Name | Type |
---|---|
arr1 |
any [] |
arr2 |
any [] |
boolean
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;
@description: 简单数组去重,Set 处理 @author: wxingheng @Date: 2022-10-12 11:16:32 Functions
▸ uniqueArray(arr
): any
[]
Name | Type |
---|---|
arr |
undefined | null | string | Iterable <any > |
any
[]
uniqueArray([1,1,1,1,1]) => [1]; uniqueArray([1,2,3,4,5]) => [1,2,3,4,5];
@description: 产生随机数据 @author: wxingheng @Date: 2022-10-12 11:08:50 Functions
▸ randomData(num
, arr
): any
[]
Name | Type | Description |
---|---|---|
num |
number |
数量 |
arr |
string [] |
每个元素对象的keys |
any
[]
randomData(2, ['name', 'value'])
=> [{"name":"name323","value":"value699"},{"name":"name573","value":"value393"}]
▸ addZero(v
, size
): string
@description: 字符串补0,目前提供给dateFormat使用 @author: wuxh @Date: 2020-05-11 14:01:20
Name | Type |
---|---|
v |
string | number |
size |
number |
string
▸ cleanObject(object
): Object
@description: cleanObject 去除对象中value为空(null,undefined,'')的属性 @author: wuxh @Date: 2021-09-02 22:07:34
Name | Type |
---|---|
object |
Object |
Object
{ [k: string]: any } @example: cleanObject({ name: '', pageSize: 10, page: 1 }) => { pageSize: 10, page: 1 }
▸ cloneJson(obj
): any
@description: 简单的深拷贝 @author: wuxh @Date: 2021-09-02 22:33:47
Name | Type |
---|---|
obj |
any |
any
obj @example: const person={name:'xiaoming',child:{name:'Jack'}} cloneJson(person) => {name:'xiaoming',child:{name:'Jack'}}
▸ cloneObj(obj
): any
@description: 深拷贝,克隆(只包含可遍历属性<常用>) @author: wuxh @Date: 2020-05-06 12:14:45
Name | Type |
---|---|
obj |
any |
any
▸ convertDataToTree(data
, id?
, pid?
, children?
): any
[]
@description: 将list转换为树结构 @author: wxingheng @Date: 2022-09-30 11:37:32
Name | Type | Default value |
---|---|---|
data |
any [] |
undefined |
id |
string |
'id' |
pid |
string |
'pid' |
children |
string |
'children' |
any
[]
@example: convertDataToTree(data) => treeData
▸ convertDateToStandard(date
): string
@description: 时间的转换 "YYYY-MM-DD HH:II:SS" @author: wxingheng @Date: 2022-09-30 11:48:15
Name | Type |
---|---|
date |
string | number | Date |
string
@example: convertDateToStandard(new Date()) => "2021-09-30 11:48:15"
▸ convertDateToStandardDay(date
): string
@description: 时间的转换 "YYYY-MM-DD" @author: wxingheng @Date: 2022-09-30 11:49:14
Name | Type |
---|---|
date |
string | number | Date |
string
@example: convertDateToStandardDay(new Date()) => "2021-09-30"
▸ convertDateToStandardHours(date
): string
@description: 时间的转换 "YYYY-MM-DD HH" @author: wxingheng @Date: 2022-09-30 11:49:37
Name | Type |
---|---|
date |
string | number | Date |
string
@example: convertDateToStandardHours(new Date()) => "2021-09-30 11"
▸ convertDateToView(date
, template?
, defaultResult?
): string
@description: 时间的转换(目前支持 年,月,日,时,分,秒,星期), 与dateFormat的区别是,这个方法可以传入时间戳 @author: wxingheng @Date: 2022-09-30 11:46:22
Name | Type | Default value |
---|---|---|
date |
string | number | Date |
undefined |
template |
string |
"YYYY-MM-DD HH:II:SS" |
defaultResult |
string |
"" |
string
@example: convertDateToView(new Date(), '当前时间 YY-MM-DD HH:II:SS 星期W')
▸ convertTreeToList(tree
, children?
): any
[]
@description: 将树结构转换为list @author: wxingheng @Date: 2022-09-30 11:40:43
Name | Type | Default value | Description |
---|---|---|---|
tree |
any [] |
undefined |
树结构 |
children |
string |
'children' |
子节点字段 |
any
[]
@example: convertTreeToList (treeData) => listData
▸ copyToBoar(value
): boolean
@description: 复制内容到剪贴板 @author: wuxh @Date: 2021-09-02 22:22:03
Name | Type |
---|---|
value |
string |
boolean
boolean @example: copyToBoard('lalallala') => true // 如果复制成功返回true
▸ cutNumber(number
, no?
): number
@description: 保留到小数点以后n位 @author: wuxh @Date: 2021-09-02 22:54:36
Name | Type | Default value |
---|---|---|
number |
number |
undefined |
no |
number |
2 |
number
Number @example: cutNumber('3123.22312') => 3123.22
▸ dateFormat(date
, formatStr
): string
@description: 时间的转换(目前支持 年,月,日,时,分,秒,星期) @author: wuxh @Date: 2020-05-06 12:05:28
Name | Type |
---|---|
date |
Date |
formatStr |
string |
string
▸ dateInterval(st
, et
): string
@description: 获取两个时间的间隔 @author: wuxh @Date: 2020-05-06 12:04:39
Name | Type |
---|---|
st |
number |
et |
number |
string
▸ dateMonthDays(str
): number
@description: 获取当前月份的天数 @author: wuxh @Date: 2020-05-06 12:06:24
Name | Type |
---|---|
str |
string |
number
▸ debounce(func
, wait?
, immediate?
): (...args
: any
) => void
@description: debounce 防抖, 固定时间内持续触发,只执行最后一次 @author: wuxh @Date: 2021-09-02 21:30:44
Name | Type | Default value | Description |
---|---|---|---|
func |
(...rest : any ) => void |
undefined |
- |
wait |
number |
500 |
等待时间,默认500ms |
immediate |
boolean |
false |
是否立即执行 |
fn
Function @example: function onInput() { console.log('1111') } const debounceOnInput = debounce(onInput) document .getElementById('input') .addEventListener('input', debounceOnInput)
▸ (...args
): void
Name | Type |
---|---|
...args |
any |
void
Name | Type |
---|---|
cancel |
() => void |
▸ deepClone(target
): any
@description: 深克隆 deepClone @author: wxingheng @Date: 2022-04-10 22:19:43
Name | Type |
---|---|
target |
any |
any
@example: deepClone(obj) => new obj
▸ download(link
, name
): any
@description: 下载一个链接文档 @author: wuxh @Date: 2021-09-01 23:27:00
Name | Type |
---|---|
link |
string |
name |
string |
any
▸ downloadFile(name
, content
): any
@description: 在浏览器中自定义下载一些内容 @author: wuxh @Date: 2021-09-01 23:32:30
Name | Type |
---|---|
name |
string |
content |
BlobPart |
any
@example: 场景:我想下载一些DOM内容,我想下载一个JSON文件
downloadFile('1.txt','lalalallalalla') downloadFile('1.json',JSON.stringify({name:'hahahha'}))
▸ dragScroll(scrollDom
): object
@description: 拖拽滚动 @author: wxingheng @Date: 2022-07-15 18:16:15
Name | Type |
---|---|
scrollDom |
any |
object
@example: 待增加惯性效果
▸ endWith(str
, endStr
): boolean
@description: 字符串判断结尾 @author: wuxh @Date: 2021-11-10 11:35:30
Name | Type |
---|---|
str |
string |
endStr |
string |
boolean
@example: endWith('1231231', '21') => false ; endWith('1231231', '31') => true
▸ everyTrim(data
): any
@description: 去除值类型为string的前后空格 @author: wuxh @Date: 2021-08-21 22:11:23
Name | Type |
---|---|
data |
object | any [] |
any
@example: everyTrim({name: ' 123 ', arr: [' 33 ']}) => {name: '123': arr: ['33']}
▸ exportJson(data
, name?
): any
@description: JSON 对象导出为.json文件 @author: wxingheng @Date: 2022-09-30 11:00:54
Name | Type | Default value |
---|---|---|
data |
any |
undefined |
name |
string |
"data" |
any
@example:
▸ fetchToSlow(fastestTime
): (func
: any
) => any
@description: 转换请求为慢响应
Name | Type | Description |
---|---|---|
fastestTime |
undefined | number |
最快响应时间 |
fn
@example: const data = await fetchToSlow(1000 * 2)(getKgDetail(kg_id));
▸ (func
): any
Name | Type |
---|---|
func |
any |
any
▸ formatQueryParam(obj
): string
@description: 格式化GET请求的请求头 @author: wuxh @Date: 2020-05-06 13:47:40
Name | Type |
---|---|
obj |
Object |
string
▸ formatRhBloodGroup(input
, optiongs?
): string
| number
| boolean
@description: 转换Rh血型 @author: wuxh @Date: 2021-09-07 13:44:36
Name | Type |
---|---|
input |
string |
optiongs? |
Object |
optiongs.default? |
string | number | boolean |
optiongs.format? |
[string | number | boolean , string | number | boolean ] |
optiongs.negative? |
string [] |
optiongs.positive? |
string [] |
string
| number
| boolean
@example: formatRhBloodGroup('D') => 阳性 formatRhBloodGroup('+') => 阳性
▸ getBase64(file
): Promise
<any
>
@description: 获取图片的 base64 @author: wxingheng @Date: 2022-09-30 10:53:33
Name | Type |
---|---|
file |
File |
Promise
<any
>
@example: getBase64(file).then(res => console.log(res))
▸ getBirthdatByIdNo(iIdNo
): string
@description: 身份证号码解析出生日期 @author: wuxh @Date: 2020-06-09 09:17:50
Name | Type |
---|---|
iIdNo |
string |
string
▸ getBrowserInfo(): getBrowserInfoResult
@description: 获取浏览器相关信息 @author: wuxh @Date: 2020-05-06 11:53:35
▸ getCookie(name
): null
| string
@description: 获取cookie值 @author: wuxh @Date: 2020-06-09 09:28:06
Name | Type |
---|---|
name |
string |
null
| string
▸ getCountDays(str
): number
@description: 获取当前月份天数 @author: wuxh @Date: 2021-08-21 22:43:58
Name | Type | Description |
---|---|---|
str |
string | number | Date |
YYYY-MM-DD mm:ss |
number
number @example:
▸ getExt(filename
): undefined
| string
@description: 获取文件后缀名 @author: wuxh @Date: 2021-09-02 22:17:57
Name | Type |
---|---|
filename |
string |
undefined
| string
@example: getExt("1.mp4") => mp4
▸ getFormData(object
): FormData
@description: 对象转化为FormData对象 @author: wuxh @Date: 2021-09-02 22:52:34
Name | Type |
---|---|
object |
Object |
FormData
@example: let req={ file:xxx, userId:1, phone:'15198763636', //... } fetch(getFormData(req))
▸ getSexByIdNO(IdNO
): ""
| "FEMALE"
| "MALE"
@description: 身份证号码解析性别 @author: wuxh @Date: 2020-06-09 09:16:28
Name | Type |
---|---|
IdNO |
string |
""
| "FEMALE"
| "MALE"
▸ getStorage(key
): any
@description: 获取 @author: wuxh @Date: 2020-05-06 12:00:37
Name | Type |
---|---|
key |
string |
any
▸ getStringLen(str
): number
@description: 计算文本长度(中文算两个字符,英文算一个字符) @author: wxingheng @Date: 2022-09-30 10:49:41
Name | Type |
---|---|
str |
string |
number
@example: getStringLen("阿斯顿发123") => 11 ; getStringLen("asd123") => 6 ; getStringLen("asd123顿发") => 10
▸ getUrlQuery(name
): string
@description: 获取浏览器url中的一个参数 @author: wuxh @Date: 2020-05-06 13:46:28
Name | Type |
---|---|
name |
string |
string
▸ getV<T
>(defaultResult
, ...args
): any
@description: 获取嵌套数据,处理空值异常 @author: wuxh @Date: 2020-05-06 12:13:59
Name |
---|
T |
Name | Type | Description |
---|---|---|
defaultResult |
T |
默认值 |
...args |
any [] |
属性访问路径 |
any
目标值或默认值 @example: getV('', {name: {children: 123}}, 'name', 'children') => 123
▸ groupBy(arr
, key
): any
@description: 数组的分类,根据某个字段分类,返回一个对象,key为字段值,value为数组 @author: wxingheng @Date: 2022-09-30 11:53:38
Name | Type |
---|---|
arr |
any [] |
key |
string |
any
@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'}]}
▸ hideIdNum(str
): string
@description: 隐藏身份证号码 @author: wuxh @Date: 2020-06-09 09:19:26
Name | Type |
---|---|
str |
string |
string
▸ importJson(): object
@description: 前端文件导入,JSON文件导入 @author: wxingheng @Date: 2022-09-30 10:57:58
object
@example: importJson() => {name: 'wxh'}
▸ isAndroidMobileDevice(): boolean
@description: 是否是安卓设备 @author: wuxh @Date: 2020-06-09 09:31:04
boolean
▸ isAppleMobileDevice(): boolean
@description: 是否是苹果设备 @author: wuxh @Date: 2020-06-09 09:31:55
boolean
▸ isArray(data
): boolean
@description: 判断Array类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isBoolean(data
): boolean
@description: 判断Boolean类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isDate(data
): boolean
@description: 判断Date类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isEmail(str
): boolean
@description: 校验是否为邮箱地址 @author: wuxh @Date: 2020-06-09 09:49:29
Name | Type |
---|---|
str |
string |
boolean
▸ isEmptyObject(obj
): boolean
@description: 判断对象是否为空 @author: wuxh @Date: 2021-08-21 23:08:42
Name | Type |
---|---|
obj |
any |
boolean
boolean @example: isEmptyObject({}) => true
▸ isEqual(a
, b
): boolean
@description: 判断两个对象是否相等 @author: wxingheng @Date: 2022-05-13 16:35:33
Name | Type |
---|---|
a |
any |
b |
any |
boolean
@example: isEqual({a: 1}, {a: 1}) => true; isEqual({a: 1}, {a: 2}) => false; isEqual({a: 1}, {b: 1}) => false
▸ isError(data
): boolean
@description: 判断Error类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isFalsy(value
): boolean
@description: 判断 js是否是false, 0除外。 @author: wuxh @Date: 2021-09-02 22:01:50
Name | Type |
---|---|
value |
any |
boolean
value === 0 ? false : !value @example: isFalsy('') => true isFalsy(0) => false isFalsy(null) => true isFalsy(undefined) => true
▸ isFunc(data
): boolean
@description: 判断Function类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isNull(data
): boolean
@description: 判断Null类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
string |
boolean
▸ isNumber(data
): boolean
@description: 判断Number类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isObject(data
): boolean
@description: 判断Object类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isPhone(phone
): boolean
@description: 手机号校验 @author: wuxh @Date: 2020-06-09 09:21:15
Name | Type |
---|---|
phone |
string |
boolean
▸ isQQ(): boolean
@description: 是否是QQ平台 @author: wuxh @Date: 2020-05-06 12:10:41
boolean
▸ isReg(data
): boolean
@description: 判断RegExp类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isRhNegative(input
): string
| number
| boolean
@description: 是否阴性 @author: wuxh @Date: 2022-01-17 23:57:31
Name | Type |
---|---|
input |
string |
string
| number
| boolean
@example:
▸ isRhPositive(input
): string
| number
| boolean
@description: 是否阳性 @author: wuxh @Date: 2022-01-17 23:57:19
Name | Type |
---|---|
input |
string |
string
| number
| boolean
@example:
▸ isString(data
): boolean
@description: 判断String类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isSupportStorage(): boolean
@description: 是否支持local @author: wuxh @Date: 2020-05-06 12:01:43
boolean
▸ isType(data
, type
): boolean
@description: 精准判断数据类型 @author: wuxh @Date: 2020-05-06 13:51:50
Name | Type | Description |
---|---|---|
data |
any |
- |
type |
string |
'String' | 'Number' | 'Boolean' | 'Undefined' | 'Null' | 'Function' | 'Date' | 'Array' | 'RegExp' | 'Error' | 'Object' @return: Boolean @example: isType(123, 'String') => false isType('123', 'String') => true |
boolean
▸ isUndefined(data
): boolean
@description: 判断Undefined类型 @author: wuxh @Date: 2020-05-06 13:53:16
Name | Type |
---|---|
data |
any |
boolean
▸ isUserId(e
): ""
| "身份证号码不能为空"
| "身份证号码长度应该为18位"
| "身份证格式错误"
| "身份证生日无效。"
| "身份证生日不在有效范围"
| "身份证月份无效"
| "身份证日期无效"
| "身份证地区编码错误"
| "不是合法的身份证号码"
@description: 身份证号码校验(精准) @author: wuxh @Date: 2020-05-06 13:49:58
Name | Type |
---|---|
e |
string |
""
| "身份证号码不能为空"
| "身份证号码长度应该为18位"
| "身份证格式错误"
| "身份证生日无效。"
| "身份证生日不在有效范围"
| "身份证月份无效"
| "身份证日期无效"
| "身份证地区编码错误"
| "不是合法的身份证号码"
▸ isVoid(value
): boolean
@description: 判断是否为空 undefined || null || "" @author: wuxh @Date: 2021-09-02 22:03:36
Name | Type |
---|---|
value |
any |
boolean
boolean @example: isVoid(0) => false isVoid(undefined) => true isVoid('') => true isVoid(null) => true isVoid() => true
▸ isWX(): boolean
@description: 是否是微信平台 @author: wuxh @Date: 2020-05-06 12:10:41
boolean
▸ mergeObj(oldObj
, newObj
, keys
): Object
@description: 深度合并对象(当前用于合并系统配置文件 app-data.json) 已存在的属性默认不覆盖 @author: wuxh @Date: 2020-05-06 12:15:30
Name | Type |
---|---|
oldObj |
Object |
newObj |
Object |
keys |
string | string [] |
Object
▸ moreClick(fun
, n?
, wait?
): (...args
: any
[]) => void
@description: 单击事件转换为多击事件 @author: wxingheng @Date: 2022-08-09 14:03:34
Name | Type | Default value | Description |
---|---|---|---|
fun |
(...args : any ) => void |
undefined |
回调函数 |
n |
number |
2 |
连续几次触发才触发回调函数 |
wait |
number |
300 |
两次之间的间隔时间 |
fn
@example: const dobuleClick = moreClick(handleClick) // 连续点击三次触发 var moreClickCallBack = jcommon.moreClick(() => { console.log("moreClickCallBack") }, 3) dom.addEventListener('click', moreClickCallBack);
▸ (...args
): void
Name | Type |
---|---|
...args |
any [] |
void
▸ oneClickToMoreClick(wait?
, ...events
): () => void
@description: 单击事件转换为多击事件 @author: wxingheng @Date: 2022-05-04 14:20:22
Name | Type | Default value |
---|---|---|
wait |
number |
300 |
...events |
(...args : any []) => void [] |
undefined |
fn
@example: // 连续点击一次触发,连续点击两次触发,连续点击三次触发 var oneClickToMoreClickCallBack = jcommon.oneClickToMoreClick(300, () => { console.log(111) }, () => { console.log(222) }, ()=> { console.log(333) }) dom.addEventListener('click', oneClickToMoreClickCallBack);
▸ (): void
void
▸ operattelecom(e
): false
| "联通"
| "电信"
| "移动"
| "未知"
@description: 获取手机运营商 @author: wuxh @Date: 2020-05-06 12:11:39
Name | Type |
---|---|
e |
string |
false
| "联通"
| "电信"
| "移动"
| "未知"
▸ osInfo(e
): osInfoResult
Name | Type |
---|---|
e |
string |
▸ processStreamResponse(response
, typewriter
): Promise
<void
>
@description: 处理流响应数据 @author: wxingheng @Date: 2023-06-13 16:14:34
Name | Type |
---|---|
response |
any |
typewriter |
Object |
typewriter.add |
(arg0 : any ) => void |
typewriter.done |
() => void |
typewriter.start |
() => void |
Promise
<void
>
@example:
▸ randomColor(): any
@description: 产生一个随机颜色 @author: wxingheng @Date: 2022-09-30 11:13:13
any
@example: randomColor() => "rgba(107, 35, 72, 1)";
▸ removeStorage(key
): void
@description: 删除 @author: wuxh @Date: 2020-05-06 11:56:29
Name | Type |
---|---|
key |
any |
void
▸ saveStorage(key
, value
): void
@description: 保存 @author: wuxh @Date: 2020-05-06 11:56:29
Name | Type |
---|---|
key |
string |
value |
string |
void
▸ scaleLinear(value
, source
, target
, toFixedLength?
): any
@description: 比例计算 @author: wxingheng @Date: 2022-09-30 11:13:27
Name | Type | Default value | Description |
---|---|---|---|
value |
number |
undefined |
当前值 |
source |
number |
undefined |
当前值所在的区间 |
target |
number |
undefined |
目标区间 |
toFixedLength |
any |
2 |
保留小数位数 |
any
@example: scaleLinear(50, 100, 10, 2) => 5; scaleLinear(50, 100, 10, 0) => 5;
▸ scopeRandom(str
, end
): number
@description: 范围随机整数 @author: wuxh @Date: 2020-05-06 12:09:34
Name | Type |
---|---|
str |
number |
end |
number |
number
▸ similar(s
, t
, f?
): number
@description: 计算两个字符串相似度 @author: wxingheng @Date: 2022-07-25 10:07:23
Name | Type | Default value | Description |
---|---|---|---|
s |
string |
undefined |
文本1 |
t |
string |
undefined |
文本2 |
f |
number |
2 |
小数位精确度,默认2位 |
number
百分数前的数值,最大100. 比如 :90.32 @example: similar("12", "12") => 100 ; similar("12", "123") => 75 ; similar("12", "1234") => 50
▸ sleep(milliseconds
): Promise
<unknown
>
@description: 休眠多少毫秒 @author: wuxh @Date: 2021-09-02 23:08:19
Name | Type |
---|---|
milliseconds |
undefined | number |
Promise
<unknown
>
@example: fetchData = async () => { await sleep(1000) }
▸ sorterCallBack(key
, isAscend?
): (a
: any
, b
: any
) => 1
| -1
@description: sort [] @author: wuxh @Date: 2021-09-07 14:12:06
Name | Type | Default value |
---|---|---|
key |
string |
undefined |
isAscend |
boolean |
true |
fn
@example: const arr = [{name: '666'}, {name: '333'}] arr.sorterCallBackString('name') => [{name: '333'}, {name: '666'}] arr.sorterCallBackString('name', false) => [{name: '666'}, {name: '333'}]
▸ (a
, b
): 1
| -1
Name | Type |
---|---|
a |
any |
b |
any |
1
| -1
▸ throttle(func
, wait?
, options
): () => void
@description: 节流 多次调用方法,按照一定的时间间隔执行 @author: wuxh @Date: 2021-09-02 21:46:38
Name | Type | Default value |
---|---|---|
func |
() => void |
undefined |
wait |
number |
500 |
options |
Object |
undefined |
options.leading |
boolean |
undefined |
options.trailing |
boolean |
undefined |
fn
Function @example:
leading,函数在每个等待时延的开始被调用,默认值为false trailing,函数在每个等待时延的结束被调用,默认值是true 可以根据不同的值来设置不同的效果: leading-false,trailing-true:默认情况,即在延时结束后才会调用函数 leading-true,trailing-true:在延时开始时就调用,延时结束后也会调用 leading-true, trailing-false:只在延时开始时调用
▸ (): void
void
▸ timeFormat(time
): string
@description: 时间个性化输出功能 @author: wuxh @Date: 2020-06-09 09:44:23
Name | Type |
---|---|
time |
Date |
string
▸ trim(str
, global?
): string
@description: 去除字符串空格, 默认去除前后空格 (常用) @author: wuxh @Date: 2020-05-06 13:43:52
Name | Type | Default value |
---|---|---|
str |
string |
undefined |
global |
boolean |
false |
string
▸ uniqueId(): string
@description: 随机数 + 时间戳 @author: wuxh @Date: 2020-06-09 09:47:34
string
▸ urlByObj(params
): Object
@description: 处理url参数(window.location.search)转换为 {key: value} @author: wuxh @Date: 2020-05-06 13:48:36
Name | Type |
---|---|
params |
string |
Object
▸ uuid(length
, chars
): string
@description: 生成随机字符串,第一个参数指定位数,第二个字符串指定字符,都是可选参数,如果都不传,默认生成8位 @author: wuxh @Date: 2021-09-02 22:29:02
Name | Type |
---|---|
length |
number |
chars |
string | any [] |
string
@example: uuid() => 'ghijklmn'
▸ versionCount(version
, maxNum?
): string
@description: 版本号累加 @author: wuxh @Date: 2021-08-24 11:19:07
Name | Type | Default value | Description |
---|---|---|---|
version |
string |
undefined |
: string |
maxNum |
number |
99 |
- |
string
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'
jcommon文档库 - v1.9.36 / Exports / EventBus
@description: EventBus class @author: wuxh @Date: 2021-08-24 11:19:07 @example: const eventBus = new EventBus()
• new EventBus()
▸ addListener(event
, cb
): void
Name | Type |
---|---|
event |
string |
cb |
(...args : any []) => any |
void
▸ emit(event
, ...args
): void
Name | Type |
---|---|
event |
string |
...args |
any [] |
void
▸ getListeners(event
): any
Name | Type |
---|---|
event |
string |
any
▸ once(event
, cb
): void
Name | Type |
---|---|
event |
string |
cb |
(...args : any []) => any |
void
▸ removeAllListener(event
): void
Name | Type |
---|---|
event |
string |
void
▸ removeListener(event
, listener
): void
Name | Type |
---|---|
event |
string |
listener |
(...args : any []) => any |
void
▸ setMaxListeners(maxListener
): void
Name | Type |
---|---|
maxListener |
number |
void
jcommon文档库 - v1.9.36 / Exports / Queue
@description: Queue 队列 class @author: wuxh @Date: 2021-08-24 11:19:07 @example: const queue = new Queue()
• new Queue(items
)
Name | Type |
---|---|
items |
never [] |
▸ clear(): void
void
▸ dequeue(): void
void
▸ enqueue(element
): void
Name | Type |
---|---|
element |
never |
void
▸ front(): never
never
▸ isEmpty(): boolean
boolean
▸ print(): void
void
▸ size(): number
number