tools_dj 1.0.22 → 1.0.23
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 +47 -2
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
+
/** 2024-07-08 12:49 User: DJ
|
|
2
|
+
* content: 删除数组重复的元素
|
|
3
|
+
* let newArr = del_repeat(Arr)
|
|
4
|
+
*/
|
|
1
5
|
export declare function del_repeat(obj: any): any;
|
|
6
|
+
/** 2024-07-08 12:52 User: DJ
|
|
7
|
+
* content: 格式化时间
|
|
8
|
+
* 格式化参数format=[ year month day hour minute],type=- /
|
|
9
|
+
*/
|
|
2
10
|
export declare function formatDate(time: any, format?: string, type?: string): string;
|
|
11
|
+
/** 2024-07-08 12:52 User: DJ
|
|
12
|
+
* content: 时间格式yyyy-MM-dd HH:mm 返回时间戳
|
|
13
|
+
*/
|
|
3
14
|
export declare function time_change(data: any): number;
|
|
4
15
|
/** 2022/8/11 9:14 User: DJ
|
|
5
16
|
* content: 时间转换
|
|
17
|
+
* @param time
|
|
18
|
+
* @param format
|
|
19
|
+
* @param type 前缀 可以是字符/对象
|
|
6
20
|
* time 时间格式 YYYY-MM-DD hh:mm:ss week time_slot
|
|
7
21
|
*/
|
|
8
|
-
export declare function formatTime(time: any, format?: string, type?:
|
|
22
|
+
export declare function formatTime(time: any, format?: string, type?: any): string;
|
|
9
23
|
/**
|
|
10
24
|
* 计算两个日期之间的天数
|
|
11
25
|
* date1 开始日期 yyyy-MM-dd
|
|
@@ -17,9 +31,31 @@ export declare function is_empty(obj: any): boolean;
|
|
|
17
31
|
export declare function repalce(str: any, index: any, char: any): any;
|
|
18
32
|
export declare function param(data: any, isPrefix?: boolean): string | false;
|
|
19
33
|
export declare function merge(obj1: any, obj2: any): any;
|
|
34
|
+
/** 2024-07-08 12:46 User: DJ
|
|
35
|
+
* content: 判断类型
|
|
36
|
+
* 传入任意一个参数
|
|
37
|
+
* 返回他的类型
|
|
38
|
+
*/
|
|
20
39
|
export declare function is(obj: any): any;
|
|
40
|
+
/** 2024-07-08 12:45 User: DJ
|
|
41
|
+
* content: 去除数组中的重复元素
|
|
42
|
+
* 传入一个数组
|
|
43
|
+
* return 一个数组出去
|
|
44
|
+
*/
|
|
21
45
|
export declare function unique(obj: any): any;
|
|
46
|
+
/** 2024-07-08 12:44 User: DJ
|
|
47
|
+
* content: 输出数组对象的最后一个元素
|
|
48
|
+
* 传入一个数组对象
|
|
49
|
+
* return一个对象或是数组
|
|
50
|
+
* 为空返回false
|
|
51
|
+
*/
|
|
22
52
|
export declare function first(obj: any): any;
|
|
53
|
+
/** 2024-07-08 12:43 User: DJ
|
|
54
|
+
* content: 输出数组对象的最后一个元素
|
|
55
|
+
* 传入一个数组对象
|
|
56
|
+
* return一个对象或是数组
|
|
57
|
+
* 为空返回false
|
|
58
|
+
*/
|
|
23
59
|
export declare function last(obj: any): false | undefined;
|
|
24
60
|
/** 2022/7/15 16:45 User: DJ
|
|
25
61
|
* content: 二维数组查找返回他所在的下标
|
|
@@ -115,7 +151,16 @@ export declare function isDateInRange(date: any, startDate: any, endDate: any):
|
|
|
115
151
|
* 1.触发高频事件后,但在n秒内函数只会执行一次
|
|
116
152
|
* 简单的说也就是一定时间内的无论点击多少次,都只会执行第一次,其余的直接return
|
|
117
153
|
*/
|
|
118
|
-
export declare function
|
|
154
|
+
export declare function throttle1<T extends any[]>(func: (...args: T) => void, delay: number): (...args: T) => void;
|
|
155
|
+
/** 2024-07-08 12:35 User: DJ
|
|
156
|
+
* content: 节流
|
|
157
|
+
* 1.触发高频事件后,但在n秒内函数只会执行一次
|
|
158
|
+
* 简单的说也就是一定时间内的无论点击多少次,都只会执行第一次,其余的直接return
|
|
159
|
+
* @param fn 方法
|
|
160
|
+
* @param delay 超时
|
|
161
|
+
* @param immediate 是否在触发事件后 在时间段n开始,立即执行,否则是时间段n结束,才执行
|
|
162
|
+
*/
|
|
163
|
+
export declare function throttle(fn: Function, delay?: number, immediate?: boolean): (...args: any) => void;
|
|
119
164
|
/** 2023/8/9 14:39 User: DJ
|
|
120
165
|
* content: 防抖
|
|
121
166
|
* 1.触发高频事件后n秒内函数只会执行一次,如果在n秒内高频事件再次被触发,则重新计算时间。
|
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(t){return Object.prototype.toString.call(t).slice(8,-1)}function o(){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 n(t,e){return Math.round(Math.random()*(e-t))+t}Object.defineProperty(exports,"__esModule",{value:!0}),exports.numberFixed=exports.arrayGroup=exports.debounce=exports.throttle=exports.throttle1=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",o="-"){var n;try{t=t.replaceAll("-","/")}catch(t){}let a=(t=new Date(t)).getFullYear(),s=(t.getMonth()+1).toString().padStart(2,"0"),c=t.getDate().toString().padStart(2,"0"),i=t.getHours().toString().padStart(2,"0"),u=t.getMinutes().toString().padStart(2,"0"),p=t.getSeconds().toString().padStart(2,"0"),l={0:"周日",1:"周一",2:"周二",3:"周三",4:"周四",5:"周五",6:"周六"}[t.getDay()],f=i>12?"下午":"上午",d=[];d=[{group:1,connect:"Object"==r(o)&&null!==(n=o.YYYY)&&void 0!==n?n:"",format:"YYYY",data:a},{group:1,connect:"",format:"yyyy",data:a},{group:1,connect:o,format:"MM",data:s},{group:1,connect:o,format:"DD",data:c},{group:1,connect:o,format:"dd",data:c},{group:2,connect:" ",format:"hh",data:i},{group:2,connect:" ",format:"HH",data:i},{group:2,connect:":",format:"mm",data:u},{group:2,connect:":",format:"ss",data:p},{group:3,connect:" ",format:"week",data:l},{group:4,connect:" ",format:"time_slot",data:f}];let m=0,g="";return d.forEach((function(t,r){if(-1!=e.indexOf(t.format)){let e="";0!=m&&(e=t.connect),g+=e+t.data,m++}})),g},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=r,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=o,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 r=document.createElement("META");let n=1,a="yes";t.cZoom&&(o()?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(r.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("+n(100,255)+","+n(100,255)+","+n(100,255)+",1)"},exports.randomNumber=n,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.throttle1=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.throttle=function(t,e=1e3,r=!0){let o;return(...n)=>{o&&clearInterval(o),r?(o||t(...n),o=setTimeout((function(){o=null}),e)):o=setTimeout((()=>{t(...n)}),e)}},exports.debounce=function(t,e){let r;return function(...o){clearTimeout(r),r=setTimeout((()=>{t(...o)}),e)}},exports.arrayGroup=function(t,e="type"){return t.reduce(((t,r)=>{var o;return Object.assign(Object.assign({},t),{[r[e]]:[...null!==(o=t[r[e]])&&void 0!==o?o:[],r]})}),{})},exports.numberFixed=function(t,e=1){const r=t.toString(),o=r.indexOf(".");if(-1===o)return t;const n=r.slice(0,o+1+e);return parseFloat(n)};
|