diff --git a/README.md b/README.md index bc118aa..1da6d3e 100644 --- a/README.md +++ b/README.md @@ -62,17 +62,6 @@ or - [arrByObj](#arrByObj) 数值转对象 (常用于处理后台返回的枚举转换,工作中很常用) - [uniqueArray](#uniqueArray) undefined -### 浏览器相关 - -- [getBrowserInfo](#getBrowserInfo) 获取浏览器相关信息 - -### 血袋相关工具函数 - -- [formatRhBloodGroup](#formatRhBloodGroup) 转换Rh血型 -- [isRhNegative](#isRhNegative) 是否阴性 -- [isRhPositive](#isRhPositive) 是否阳性 -- [sorterCallBack](#sorterCallBack) sort [] - ### 数据持久化,缓存 - [removeStorage](#removeStorage) 删除 @@ -84,6 +73,17 @@ or - [getCookie](#getCookie) 获取cookie值 +### 血袋相关工具函数 + +- [formatRhBloodGroup](#formatRhBloodGroup) 转换Rh血型 +- [isRhNegative](#isRhNegative) 是否阴性 +- [isRhPositive](#isRhPositive) 是否阳性 +- [sorterCallBack](#sorterCallBack) sort [] + +### 浏览器相关 + +- [getBrowserInfo](#getBrowserInfo) 获取浏览器相关信息 + ### 时间相关 - [dateInterval](#dateInterval) 获取两个时间的间隔 @@ -93,17 +93,13 @@ or - [timeFormat](#timeFormat) 时间个性化输出功能 - [getCountDays](#getCountDays) 获取当前月份天数 -### - -- [decoratorNonenumerable](#decoratorNonenumerable) decoratorNonenumerable - ### 防抖 - [debounce](#debounce) debounce 防抖, 固定时间内持续触发,只执行最后一次 -### 用户设备相关(客户端系统) +### -- [osInfo](#osInfo) 获取用户系统平台信息 +- [decoratorNonenumerable](#decoratorNonenumerable) decoratorNonenumerable ### 浏览器 DOM 相关 @@ -114,6 +110,10 @@ or ### +### 用户设备相关(客户端系统) + +- [osInfo](#osInfo) 获取用户系统平台信息 + ### - [getFormData](#getFormData) 对象转化为FormData对象 @@ -141,6 +141,17 @@ or - [cleanObject](#cleanObject) cleanObject 去除对象中value为空(null,undefined,'')的属性 - [deepClone](#deepClone) 深克隆 deepClone +### + +- [oneClickToMoreClick](#oneClickToMoreClick) 单击事件转换为多击事件 + +### Queue 队列 + + +### 休眠 + +- [sleep](#sleep) 休眠多少毫秒 + ### 字符串处理相关 - [trim](#trim) 去除字符串空格, 默认去除前后空格 (常用) @@ -153,24 +164,10 @@ or - [uuid](#uuid) 生成随机字符串,第一个参数指定位数,第二个字符串指定字符,都是可选参数,如果都不传,默认生成8位 - [endWith](#endWith) 字符串判断结尾 -### Queue 队列 - - -### 休眠 - -- [sleep](#sleep) 休眠多少毫秒 - ### 节流 - [throttle](#throttle) 节流 多次调用方法,按照一定的时间间隔执行 -### url处理相关 - -- [getUrlQuery](#getUrlQuery) 获取浏览器url中的一个参数 -- [everyTrim](#everyTrim) 去除值类型为string的前后空格 -- [formatQueryParam](#formatQueryParam) 格式化GET请求的请求头 -- [urlByObj](#urlByObj) 处理url参数(window.location.search)转换为 {key: value} - ### 校验相关 - [isUserId](#isUserId) 身份证号码校验(精准) @@ -190,6 +187,13 @@ or - [isEmail](#isEmail) 校验是否为邮箱地址 - [isFalsy](#isFalsy) 判断 js是否是false, 0除外。 +### url处理相关 + +- [getUrlQuery](#getUrlQuery) 获取浏览器url中的一个参数 +- [everyTrim](#everyTrim) 去除值类型为string的前后空格 +- [formatQueryParam](#formatQueryParam) 格式化GET请求的请求头 +- [urlByObj](#urlByObj) 处理url参数(window.location.search)转换为 {key: value} + ## API 说明 ### formatRhBloodGroup @@ -245,62 +249,18 @@ or * arr.sorterCallBackString('name', false) => [{name: '666'}, {name: '333'}] ``` -### removeStorage - - 删除 - - ```javascript - wuxh - * @Date: 2020-05-06 11:56:29 - * @param {key} - * @return: undefined - * @example: - removeStorage('test') - => undefined -``` - -### saveStorage - - 保存 - - ```javascript - wuxh - * @Date: 2020-05-06 11:56:29 - * @param {key} - * @param {value} - * @param {isJson} - * @return: undefined - * @example: - saveStorage('test', '001') - => undefined -``` - -### getStorage - - 获取 - - ```javascript - wuxh - * @Date: 2020-05-06 12:00:37 - * @param {key} - * @return: String - * @example: - getStorage('test') - => '001' -``` - -### isSupportStorage +### getBrowserInfo - 是否支持local + 获取浏览器相关信息 ```javascript wuxh - * @Date: 2020-05-06 12:01:43 - * @param - * @return: Boolean + * @Date: 2020-05-06 11:53:35 + * @param {} + * @return: Object * @example: - isSupportStorage() - => true + getBrowserInfo() + => {name: "Chrome", version: "81.0.4044.129"} ``` ### doubleRanking @@ -381,45 +341,75 @@ or uniqueArray([1,1,1,1,1]) => [1] ``` -### getBrowserInfo +### removeStorage - 获取浏览器相关信息 + 删除 ```javascript wuxh - * @Date: 2020-05-06 11:53:35 - * @param {} - * @return: Object + * @Date: 2020-05-06 11:56:29 + * @param {key} + * @return: undefined * @example: - getBrowserInfo() - => {name: "Chrome", version: "81.0.4044.129"} + removeStorage('test') + => undefined ``` -### getCookie +### saveStorage - 获取cookie值 + 保存 ```javascript wuxh - * @Date: 2020-06-09 09:28:06 - * @param {type} - * @return: string + * @Date: 2020-05-06 11:56:29 + * @param {key} + * @param {value} + * @param {isJson} + * @return: undefined * @example: - getCookie('name') => 123 + saveStorage('test', '001') + => undefined ``` -### osInfo +### getStorage - 获取用户系统平台信息 + 获取 ```javascript wuxh - * @Date: 2020-05-06 12:07:03 - * @param {e} - * @return: {os: "mac", version: "10.15.3"} + * @Date: 2020-05-06 12:00:37 + * @param {key} + * @return: String * @example: - osInfo() - => {os: "mac", version: "10.15.3"} + getStorage('test') + => '001' +``` + +### isSupportStorage + + 是否支持local + + ```javascript + wuxh + * @Date: 2020-05-06 12:01:43 + * @param + * @return: Boolean + * @example: + isSupportStorage() + => true +``` + +### getCookie + + 获取cookie值 + + ```javascript + wuxh + * @Date: 2020-06-09 09:28:06 + * @param {type} + * @return: string + * @example: + getCookie('name') => 123 ``` ### dateInterval @@ -546,6 +536,20 @@ or * @example: ``` +### osInfo + + 获取用户系统平台信息 + + ```javascript + 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"} +``` + ### download 下载一个链接文档 @@ -809,6 +813,19 @@ fetch(getFormData(req)) * @example: deepClone(obj) => new obj ``` +### oneClickToMoreClick + + 单击事件转换为多击事件 + + ```javascript + wxingheng + * @Date: 2022-05-04 14:20:22 + * @param {*} wait + * @param {array} events + * @return {*} + * @example: oneClickToMoreClick(300, clickOneCallBack, clickTwoCallBack, clickThreeCallBack, clickFourCallBack, ...) +``` + ### sleep 休眠多少毫秒 @@ -966,60 +983,6 @@ leading-true,trailing-true:在延时开始时就调用,延时结束后也 leading-true, trailing-false:只在延时开始时调用 ``` -### getUrlQuery - - 获取浏览器url中的一个参数 - - ```javascript - wuxh - * @Date: 2020-05-06 13:46:28 - * @param {name} - * @return: String - * @example: - getUrlQuery(age) - => 25 -``` - -### everyTrim - - 去除值类型为string的前后空格 - - ```javascript - wuxh - * @Date: 2021-08-21 22:11:23 - * @param {Array} data - * @return {*} - * @example: everyTrim({name: ' 123 ', arr: [' 33 ']}) => {name: '123': arr: ['33']} -``` - -### formatQueryParam - - 格式化GET请求的请求头 - - ```javascript - wuxh - * @Date: 2020-05-06 13:47:40 - * @param {obj} - * @return: String - * @example: - formatQueryParam({name: 1, value: 123}) - => "name=1&value=123" -``` - -### urlByObj - - 处理url参数(window.location.search)转换为 {key: value} - - ```javascript - wuxh - * @Date: 2020-05-06 13:48:36 - * @param {params} - * @return: Object - * @example: - urlByObj(?ie=UTF-8&wd=asd) - => {ie: UTF-8, wd: asd} -``` - ### isUserId 身份证号码校验(精准) @@ -1245,6 +1208,60 @@ leading-true, trailing-false:只在延时开始时调用 isFalsy(undefined) => true ``` +### getUrlQuery + + 获取浏览器url中的一个参数 + + ```javascript + wuxh + * @Date: 2020-05-06 13:46:28 + * @param {name} + * @return: String + * @example: + getUrlQuery(age) + => 25 +``` + +### everyTrim + + 去除值类型为string的前后空格 + + ```javascript + wuxh + * @Date: 2021-08-21 22:11:23 + * @param {Array} data + * @return {*} + * @example: everyTrim({name: ' 123 ', arr: [' 33 ']}) => {name: '123': arr: ['33']} +``` + +### formatQueryParam + + 格式化GET请求的请求头 + + ```javascript + wuxh + * @Date: 2020-05-06 13:47:40 + * @param {obj} + * @return: String + * @example: + formatQueryParam({name: 1, value: 123}) + => "name=1&value=123" +``` + +### urlByObj + + 处理url参数(window.location.search)转换为 {key: value} + + ```javascript + wuxh + * @Date: 2020-05-06 13:48:36 + * @param {params} + * @return: Object + * @example: + urlByObj(?ie=UTF-8&wd=asd) + => {ie: UTF-8, wd: asd} +``` + ## 建议,交流,推荐,反馈 联系我 wxingheng@outlook.com diff --git a/example/base/yarn.lock b/example/base/yarn.lock index f7a40db..e436535 100644 --- a/example/base/yarn.lock +++ b/example/base/yarn.lock @@ -608,7 +608,7 @@ component-emitter@^1.2.1: concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" - integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= + integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg== concat-stream@^1.5.0: version "1.6.2" @@ -1567,9 +1567,9 @@ minimalistic-crypto-utils@^1.0.1: integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo= minimatch@^3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" - integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== + version "3.1.2" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" + integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== dependencies: brace-expansion "^1.1.7" diff --git a/package.json b/package.json index 0223df6..1212a96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jcommon", - "version": "1.9.8", + "version": "1.9.9", "description": "JavaScript 常用纯函数工具库", "main": "lib/index.js", "module": "es/index.js", @@ -63,7 +63,7 @@ "webpack": "^4.46.0", "webpack-cli": "^3.3.12" }, - "time": "220410224321", + "time": "220504142738", "dependencies": { "jcommon": "^1.8.8" } diff --git a/src/index.ts b/src/index.ts index 8c4daa4..5aa8f21 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ /* * @Author: wuxh * @Date: 2021-08-22 12:46:08 - * @LastEditTime: 2022-04-10 22:29:15 + * @LastEditTime: 2022-05-04 14:21:32 * @LastEditors: wxingheng * @Description: * @FilePath: /jcommon/src/index.ts @@ -116,6 +116,8 @@ export * from "./dom/index"; export * from "./sleep/index"; export * from "./form/index"; export * from "./blood/index"; +export * from "./other/index"; + export { Queue } from './queue/index' export { EventBus } from './eventBus/index' diff --git a/src/other/index.ts b/src/other/index.ts new file mode 100644 index 0000000..8db4910 --- /dev/null +++ b/src/other/index.ts @@ -0,0 +1,38 @@ +/* + * @Author: wxingheng + * @Date: 2022-05-04 11:40:27 + * @LastEditTime: 2022-05-04 14:22:31 + * @LastEditors: wxingheng + * @Description: + * @FilePath: /jcommon/src/other/index.ts + */ + +/** + * @description: 单击事件转换为多击事件 + * @author: wxingheng + * @Date: 2022-05-04 14:20:22 + * @param {*} wait + * @param {array} events + * @return {*} + * @example: oneClickToMoreClick(300, clickOneCallBack, clickTwoCallBack, clickThreeCallBack, clickFourCallBack, ...) + */ +export const oneClickToMoreClick = function(wait = 300, ...events: Array): Function { + let timer: any = null; + let lastTime = 0; + let count = 0; + return (...args: any[]) => { + clearTimeout(timer); + const currentTime = new Date().getTime(); + count = currentTime - lastTime < wait ? count + 1 : 0; + lastTime = new Date().getTime(); + events.forEach((event, i) => { + if(i === count){ + timer = setTimeout(() => { + count = 0; + lastTime = 0; + event(...args); + }, wait); + } + }) + }; +}; \ No newline at end of file