tools_dj 1.0.10 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +12 -0
- package/lib/index.js +1 -1
- package/package.json +3 -2
package/lib/index.d.ts
CHANGED
|
@@ -110,3 +110,15 @@ export declare function randomNumber(min: any, max: any): any;
|
|
|
110
110
|
* return bool
|
|
111
111
|
*/
|
|
112
112
|
export declare function isDateInRange(date: any, startDate: any, endDate: any): boolean;
|
|
113
|
+
/** 2023/8/9 14:39 User: DJ
|
|
114
|
+
* content: 节流
|
|
115
|
+
* 1.触发高频事件后,但在n秒内函数只会执行一次
|
|
116
|
+
* 简单的说也就是一定时间内的无论点击多少次,都只会执行第一次,其余的直接return
|
|
117
|
+
*/
|
|
118
|
+
export declare function throttle<T extends any[]>(func: (...args: T) => void, delay: number): (...args: T) => void;
|
|
119
|
+
/** 2023/8/9 14:39 User: DJ
|
|
120
|
+
* content: 防抖
|
|
121
|
+
* 1.触发高频事件后n秒内函数只会执行一次,如果在n秒内高频事件再次被触发,则重新计算时间。
|
|
122
|
+
* 简单的说也就是一定时间段的无论点击多少次,只会执行最后一次的调用。前面的会被清除
|
|
123
|
+
*/
|
|
124
|
+
export declare function debounce<T extends any[]>(func: (...args: T) => void, delay: number): (...args: T) => void;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function t(t){let e={};return t.forEach((function(t){e[JSON.stringify(t)]=t})),t=Object.keys(e).map((function(t){if("undefined"!=t)return JSON.parse(t)}))}function e(t){let e=!1;switch(Object.prototype.toString.call(t).slice(8,-1)){case"Undefined":case"Null":e=!0;break;case"String":e=0===t.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,"").length;break;case"Boolean":e=!t;break;case"Array":e=0===t.length;break;case"Number":e=0===t||isNaN(t);break;case"Object":e=0===Object.keys(t).length}return e}function r(){return!e(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))}function o(t,e){return Math.round(Math.random()*(e-t))+t}Object.defineProperty(exports,"__esModule",{value:!0}),exports.debounce=exports.throttle=exports.isDateInRange=exports.randomNumber=exports.randomColor=exports.arrSet=exports.rArrMove=exports.sArrMove=exports.colorMix=exports.setMeta=exports.isMobile=exports.numberRepair=exports.compare=exports.compareDate=exports.base64Img=exports.handleTree=exports.selectObjData=exports.setObjData=exports.findByIndex=exports.last=exports.first=exports.unique=exports.is=exports.merge=exports.param=exports.repalce=exports.is_empty=exports.getDaysBetween=exports.formatTime=exports.time_change=exports.formatDate=exports.del_repeat=void 0,exports.del_repeat=t,exports.formatDate=function(t,e="day",r="-"){let o=t.getFullYear(),n=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),s=t.getHours().toString().padStart(2,"0"),c=t.getMinutes().toString().padStart(2,"0"),i={year:1,month:2,day:3,hour:4,minute:5},u="";for(let t=0;t<i[e];t++)0==t&&(u+=o),1==t&&(u+=n),2==t&&(u+=a),3==t&&(u+=s),4==t&&(u+=c),t!=i[e]-1&&(u+=r);return u},exports.time_change=function(t){return Date.parse(t)},exports.formatTime=function(t,e="YYYY-MM-DD hh:mm:ss",r="-"){try{t=t.replaceAll("-","/")}catch(t){}let o=(t=new Date(t)).getFullYear(),n=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),s=t.getHours().toString().padStart(2,"0"),c=[];c=[{group:1,connect:"",format:"YYYY",data:o},{group:1,connect:"",format:"yyyy",data:o},{group:1,connect:r,format:"MM",data:n},{group:1,connect:r,format:"DD",data:a},{group:1,connect:r,format:"dd",data:a},{group:2,connect:" ",format:"hh",data:s},{group:2,connect:" ",format:"HH",data:s},{group:2,connect:":",format:"mm",data:t.getMinutes().toString().padStart(2,"0")},{group:2,connect:":",format:"ss",data:t.getSeconds().toString().padStart(2,"0")},{group:3,connect:" ",format:"week",data:{0:"周日",1:"周一",2:"周二",3:"周三",4:"周四",5:"周五",6:"周六"}[t.getDay()]},{group:4,connect:" ",format:"time_slot",data:s>12?"下午":"上午"}];let i=0,u="";return c.forEach((function(t,r){if(-1!=e.indexOf(t.format)){let e="";0!=i&&(e=t.connect),u+=e+t.data,i++}})),u},exports.getDaysBetween=function(t,e,r=!1){var o=Date.parse(t),n=Date.parse(e),a=0;return o>n&&(a=(o-n)/864e5),o<n&&(a=(n-o)/864e5,r&&(a=-a)),a},exports.is_empty=e,exports.repalce=function(t,e,r){return t.substring(0,e)+r+t.substring(e+1)},exports.param=function(t,r=!0){if(0==e(t)){let e=r?"?":"",o=[];for(let e in t){let r=t[e];["",void 0,null].includes(r)||(r.constructor===Array?r.forEach((t=>{o.push(encodeURIComponent(e)+"[]="+encodeURIComponent(t))})):o.push(encodeURIComponent(e)+"="+encodeURIComponent(r)))}return console.log(o.length?e+o.join("&"):""),o.length?e+o.join("&"):""}return console.log(!1),!1},exports.merge=function(e,r){const o=Object.prototype.toString.call(e);return"Array"==o.slice(8,-1)?(e.push.apply(e,r),t(e)):"Object"==o.slice(8,-1)?Object.assign(e,r):void 0},exports.is=function(t){return Object.prototype.toString.call(t).slice(8,-1)},exports.unique=function(r){if(0==e(r)){let e=t(r);return console.log(e),e}return console.log(!1),!1},exports.first=function(t){if(0!=e(t))return console.log(!1),!1;if("[object Object]"===Object.prototype.toString.call(t))for(const e of t)return console.log(e),e;else console.log(t[0])},exports.last=function(t){if(0!=e(t))return console.log(!1),!1;if("[object Object]"===Object.prototype.toString.call(t))for(const e of t)console.log(e);else console.log(t[t.length-1])},exports.findByIndex=function(t,e,r){return(t||[]).findIndex((t=>t[e]===r))},exports.setObjData=function(t,e,r,o,n){try{return t.find((function(t){return t[e]==r}))[o]=n,!0}catch(t){return!1}},exports.selectObjData=function(t,e,r){try{return t.find((function(t){return t[e]==r}))}catch(t){return""}},exports.handleTree=function(t,e,r,o){let n=e||"id",a=r||"parentId",s=o||"children";var c={},i={},u=[];for(let e of t){let t=e[a];null==c[t]&&(c[t]=[]),i[e[n]]=e,c[t].push(e)}for(let e of t){null==i[e[a]]&&u.push(e)}for(let t of u)p(t);function p(t){if(null!==c[t[n]]&&(t[s]=c[t[n]]),t[s])for(let e of t[s])p(e)}return u},exports.base64Img=function(t,e){let r=function(t){for(var e=t.split(","),r=e[0].match(/:(.*?);/)[1],o=atob(e[1]),n=o.length,a=new Uint8Array(n);n--;)a[n]=o.charCodeAt(n);return new Blob([a],{type:r})}(t);return new File([r],e)},exports.compareDate=function(t,e="up"){return function(r,o){return"up"==e?Date.parse(r[t])-Date.parse(o[t]):Date.parse(o[t])-Date.parse(r[t])}},exports.compare=function(t,e="up"){return function(r,o){return"up"==e?r[t]-o[t]:o[t]-r[t]}},exports.numberRepair=function(t="",e=2,r="0",o=!1){let n="",a=(""+t).length;if(a>e&&1==o)return a;{let o=e-a;if(o>0)for(let t=0;t<o;t++)n+=r;return(n+t).slice(-1*e)}},Number.prototype.repair=function(t=2){let e="";for(let r=1;r<t;r++)e+="0";return(e+this).slice(-1*t)},exports.isMobile=r,exports.setMeta=function(t){if(!e(t)){let e=[];document.head.childNodes.forEach((r=>{switch(r.tagName){case"META":e.push(r);break;case"TITLE":document.title=t.title||"模板测试"}}));const o=document.createElement("META");let n=1,a="yes";t.cZoom&&(r()?t.cZoom.mobile&&(n=t.cZoom.mobile):t.cZoom.pc&&(n=t.cZoom.pc),t.cZoom.isScale&&(a=t.cZoom.isScale));let s=`width=device-width,minimum-scale=${n},initial-scale=${n},user-scalable=${a}`;"no"==a&&(s+=`,maximum-scale=${n}`);const c=[{charset:"utf-8"},{name:"viewport",content:s}],i=document.createDocumentFragment();c.forEach((t=>{i.append(o.cloneNode()),Object.entries(t).forEach((t=>{i.lastChild.setAttribute(t[0],t[1])}))})),e.forEach((t=>{document.head.removeChild(t)})),document.head.prepend(i)}},exports.colorMix=function(t,e,r){r=Math.max(Math.min(Number(r),1),0);let o=parseInt(t.substring(1,3),16),n=parseInt(t.substring(3,5),16),a=parseInt(t.substring(5,7),16),s=parseInt(e.substring(1,3),16),c=parseInt(e.substring(3,5),16),i=parseInt(e.substring(5,7),16),u=Math.round(o*(1-r)+s*r),p=Math.round(n*(1-r)+c*r),l=Math.round(a*(1-r)+i*r);return u=("0"+(u||0).toString(16)).slice(-2),p=("0"+(p||0).toString(16)).slice(-2),l=("0"+(l||0).toString(16)).slice(-2),"#"+u+p+l},exports.sArrMove=function(t,e,r){t.splice(r,0,t.splice(e,1)[0])},exports.rArrMove=function(t,e,r){let o=[].concat(t);return o.splice(r,0,o.splice(e,1)[0]),o},exports.arrSet=function(t,e,r){t.splice(e,0,r)},exports.randomColor=function(){return"rgba("+o(100,255)+","+o(100,255)+","+o(100,255)+",1)"},exports.randomNumber=o,exports.isDateInRange=function(t,e,r){const o=new Date(t),n=new Date(e),a=new Date(r);return o>=n&&o<=a},exports.throttle=function(t,e){let r,o=0;return function(...n){const a=Date.now(),s=a-o;clearTimeout(r),s>=e?(t(...n),o=a):r=setTimeout((()=>{t(...n),o=Date.now()}),e-s)}},exports.debounce=function(t,e){let r;return function(...o){clearTimeout(r),r=setTimeout((()=>{t(...o)}),e)}};
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tools_dj",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "dj tools 工具库",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "rollup -c",
|
|
10
|
-
"serve": "rollup -c -w"
|
|
10
|
+
"serve": "rollup -c -w",
|
|
11
|
+
"publish": "npm run build && npm version patch --force && npm publish"
|
|
11
12
|
},
|
|
12
13
|
"author": "dj_h",
|
|
13
14
|
"license": "ISC",
|