tools_dj 1.0.62 → 1.0.63
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 +4 -1
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -215,7 +215,10 @@ export declare function throttle1<T extends any[]>(func: (...args: T) => void, d
|
|
|
215
215
|
* @param delay 超时
|
|
216
216
|
* @param immediate 是否在触发事件后 在时间段n开始,立即执行,否则是时间段n结束,才执行
|
|
217
217
|
*/
|
|
218
|
-
export declare function throttle(fn: Function, delay?: number, immediate?: boolean):
|
|
218
|
+
export declare function throttle(fn: Function, delay?: number, immediate?: boolean): {
|
|
219
|
+
(...args: any): void;
|
|
220
|
+
cancel(): void;
|
|
221
|
+
};
|
|
219
222
|
/** 2023/8/9 14:39 User: DJ
|
|
220
223
|
* content: 防抖
|
|
221
224
|
* 1.触发高频事件后n秒内函数只会执行一次,如果在n秒内高频事件再次被触发,则重新计算时间。
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){let t={};return e.forEach((function(e){t[JSON.stringify(e)]=e})),e=Object.keys(t).map((function(e){if("undefined"!=e)return JSON.parse(e)}))}function t(e){let t=!1;switch(Object.prototype.toString.call(e).slice(8,-1)){case"Undefined":case"Null":t=!0;break;case"String":t=0===e.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,"").length;break;case"Boolean":t=!e;break;case"Array":t=0===e.length;break;case"Number":t=0===e||isNaN(e);break;case"Object":t=0===Object.keys(e).length}return t}function r(e){return Object.prototype.toString.call(e).slice(8,-1)}function n(){return!t(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(e,t){return Math.round(Math.random()*(t-e))+e}function
|
|
1
|
+
function e(e){let t={};return e.forEach((function(e){t[JSON.stringify(e)]=e})),e=Object.keys(t).map((function(e){if("undefined"!=e)return JSON.parse(e)}))}function t(e){let t=!1;switch(Object.prototype.toString.call(e).slice(8,-1)){case"Undefined":case"Null":t=!0;break;case"String":t=0===e.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,"").length;break;case"Boolean":t=!e;break;case"Array":t=0===e.length;break;case"Number":t=0===e||isNaN(e);break;case"Object":t=0===Object.keys(e).length}return t}function r(e){return Object.prototype.toString.call(e).slice(8,-1)}function n(){return!t(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(e,t){return Math.round(Math.random()*(t-e))+e}function a(e){let t=e+"";const r=Number(t);return!isNaN(r)&&t.length>0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.del_repeat=e,exports.formatDate=function(e,t="day",r="-"){let n=e.getFullYear(),o=(e.getMonth()+1).toString().padStart(2,"0"),a=e.getDate().toString().padStart(2,"0"),c=e.getHours().toString().padStart(2,"0"),i=e.getMinutes().toString().padStart(2,"0"),s={year:1,month:2,day:3,hour:4,minute:5},l="";for(let e=0;e<s[t];e++)0==e&&(l+=n),1==e&&(l+=o),2==e&&(l+=a),3==e&&(l+=c),4==e&&(l+=i),e!=s[t]-1&&(l+=r);return l},exports.time_change=function(e){return Date.parse(e)},exports.formatTime=function(e,t="YYYY-MM-DD hh:mm:ss",r={}){try{e=e.replaceAll("-","/")}catch(e){}e=new Date(e);let n={0:"周日",1:"周一",2:"周二",3:"周三",4:"周四",5:"周五",6:"周六"},{weeks:o=n}=r,a=e.getFullYear(),c=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0"),s=e.getHours().toString().padStart(2,"0"),l=e.getMinutes().toString().padStart(2,"0"),u=e.getSeconds().toString().padStart(2,"0"),p=o[e.getDay()],f=t;return[{format:"YYYY",data:a},{format:"yyyy",data:a},{format:"MM",data:c},{format:"DD",data:i},{format:"dd",data:i},{format:"hh",data:s},{format:"HH",data:s},{format:"mm",data:l},{format:"ss",data:u},{format:"week",data:p},{format:"time_slot",data:s>12?"下午":"上午"}].forEach((function(e,r){-1!=t.indexOf(e.format)&&(f=f.replace(e.format,""+e.data))})),f},exports.getDaysBetween=function(e,t,r=!1){var n=Date.parse(e),o=Date.parse(t),a=0;n>o&&(a=(n-o)/864e5);n<o&&(a=(o-n)/864e5,r&&(a=-a));return a},exports.is_empty=t,exports.repalce=function(e,t,r){return e.substring(0,t)+r+e.substring(t+1)},exports.toGetQuery=function(e,r={}){if(t(e))return"";{let{prefix:t="?"}=r,n=[],o=["",void 0,null];for(let t in e){let r=e[t];o.includes(r)||(r.constructor===Array?r.forEach((e=>{n.push(encodeURIComponent(t)+"[]="+encodeURIComponent(e))})):n.push(encodeURIComponent(t)+"="+encodeURIComponent(r)))}return n.length?t+n.join("&"):""}},exports.merge=function(t,r){const n=Object.prototype.toString.call(t);if("Array"==n.slice(8,-1))return t.push.apply(t,r),e(t);if("Object"==n.slice(8,-1))return Object.assign(t,r)},exports.is=r,exports.unique=function(r){if(0==t(r)){let t=e(r);return console.log(t),t}return console.log(!1),!1},exports.first=function(e){if(0!=t(e))return console.log(!1),!1;if("[object Object]"===Object.prototype.toString.call(e))for(const t of e)return console.log(t),t;else console.log(e[0])},exports.last=function(e){if(0!=t(e))return console.log(!1),!1;if("[object Object]"===Object.prototype.toString.call(e))for(const t of e)console.log(t);else console.log(e[e.length-1])},exports.findByIndex=function(e,t,r){return(e||[]).findIndex((e=>e[t]===r))},exports.setObjData=function(e,t,r,n,o){try{return e.find((function(e){return e[t]==r}))[n]=o,!0}catch(e){return!1}},exports.selectObjData=function(e,t,r){try{return e.find((function(e){return e[t]==r}))}catch(e){return""}},exports.handleTree=function(e,t,r,n){const o={id:t||"id",parentId:r||"parentId",childrenList:n||"children"},a=new Map,c=new Map,i=[];let s=e.length;for(let t=0;t<s;t++){let r=e[t];const n=r[o.parentId];a.has(n)||a.set(n,[]),c.set(r[o.id],r),a.get(n).push(r)}for(let t=0;t<s;t++){let r=e[t];const n=r[o.parentId];c.has(n)||i.push(r)}const l=[...i];for(;l.length>0;){const e=l.pop(),t=a.get(e[o.id]);t&&(e[o.childrenList]=t,l.push(...t))}return i},exports.arrToTree=function(e,t={}){let{id:r="id",pKey:n="parentId",cKey:o="children",strict:a=!0,copy:c=!0}=t,i=[];i=c?JSON.parse(JSON.stringify(e)):e;return i.filter((e=>{const t=i.filter((t=>a?t[n]===e[r]:t[n]==e[r]));return t.length&&(e[o]=t),0===e[n]}))},exports.treeToArr=function(e,t={}){let r=[],{cKey:n="children",copy:o=!0}=t,a=[...e];for(;a.length;){let e=a.pop();if(e[n])if(a.push(...e[n]),o){let t={},o=Object.keys(e),a=o.length;for(let r=0;r<a;r++)o[r]!=n&&(t[o[r]]=e[o[r]]);r.push(t)}else r.push(e)}return r},exports.treeFor=function(e,r,n={}){let{cKey:o="children"}=n,a=[...e];for(;a.length;){let e=a.shift();t(e[o])?r&&r(e):a.push(...e[o])}},exports.treeStack=function(e,r,n={}){let{cKey:o="children"}=n,a=[...e];for(;a.length;){let e=a.shift();t(e[o])?r&&r(e):a.push(...e[o])}},exports.treeRecursion=function(e,t,r={}){},exports.treeFind=function(e,t={}){let r=[],{cKey:n="children",key:o="id",value:a,copy:c=!0}=t,i=[...e];for(;i.length;){let e=i.pop();if(e[n]&&i.push(...e[n]),e[o]==a)if(c){let t={},o=Object.keys(e),a=o.length;for(let r=0;r<a;r++)o[r]!=n&&(t[o[r]]=e[o[r]]);r.push(t)}else r.push(e)}return r},exports.base64Img=function(e,t){return r=function(e){for(var t=e.split(","),r=t[0].match(/:(.*?);/)[1],n=atob(t[1]),o=n.length,a=new Uint8Array(o);o--;)a[o]=n.charCodeAt(o);return new Blob([a],{type:r})}(e),n=t,new File([r],n);var r,n},exports.compareDate=function(e,t="up"){return function(r,n){return"up"==t?Date.parse(r[e])-Date.parse(n[e]):Date.parse(n[e])-Date.parse(r[e])}},exports.compare=function(e,t="up"){return function(r,n){return"up"==t?r[e]-n[e]:n[e]-r[e]}},exports.numberRepair=function(e="",t=2,r="0",n=!1){let o="",a=(""+e).length;if(a>t&&1==n)return a;{let n=t-a;if(n>0)for(let e=0;e<n;e++)o+=r;return(o+e).slice(-1*t)}},exports.isMobile=n,exports.setMeta=function(e){if(!t(e)){let t=[];document.head.childNodes.forEach((r=>{switch(r.tagName){case"META":t.push(r);break;case"TITLE":document.title=e.title||"模板测试"}}));const r=document.createElement("META");let o=1,a="yes";e.cZoom&&(n()?e.cZoom.mobile&&(o=e.cZoom.mobile):e.cZoom.pc&&(o=e.cZoom.pc),e.cZoom.isScale&&(a=e.cZoom.isScale));let c=`width=device-width,minimum-scale=${o},initial-scale=${o},user-scalable=${a}`;"no"==a&&(c+=`,maximum-scale=${o}`);const i=[{charset:"utf-8"},{name:"viewport",content:c}],s=document.createDocumentFragment();i.forEach((e=>{s.append(r.cloneNode()),Object.entries(e).forEach((e=>{s.lastChild.setAttribute(e[0],e[1])}))})),t.forEach((e=>{document.head.removeChild(e)})),document.head.prepend(s)}},exports.colorMix=function(e,t,r){r=Math.max(Math.min(Number(r),1),0);let n=parseInt(e.substring(1,3),16),o=parseInt(e.substring(3,5),16),a=parseInt(e.substring(5,7),16),c=parseInt(t.substring(1,3),16),i=parseInt(t.substring(3,5),16),s=parseInt(t.substring(5,7),16),l=Math.round(n*(1-r)+c*r),u=Math.round(o*(1-r)+i*r),p=Math.round(a*(1-r)+s*r);return l=("0"+(l||0).toString(16)).slice(-2),u=("0"+(u||0).toString(16)).slice(-2),p=("0"+(p||0).toString(16)).slice(-2),"#"+l+u+p},exports.sArrMove=function(e,t,r){e.splice(r,0,e.splice(t,1)[0])},exports.rArrMove=function(e,t,r){let n=[].concat(e);return n.splice(r,0,n.splice(t,1)[0]),n},exports.arrSet=function(e,t,r){e.splice(t,0,r)},exports.randomColor=function(){let e=o(100,255),t=o(100,255),r=o(100,255);return"rgba("+e+","+t+","+r+",1)"},exports.randomNumber=o,exports.isDateInRange=function(e,t,r){const n=new Date(e),o=new Date(t),a=new Date(r);return n>=o&&n<=a},exports.throttle1=function(e,t){let r,n=0;return function(...o){const a=Date.now(),c=a-n;clearTimeout(r),c>=t?(e(...o),n=a):r=setTimeout((()=>{e(...o),n=Date.now()}),t-c)}},exports.throttle=function(e,t=1e3,r=!0){let n;const o=(...o)=>{n&&clearInterval(n),r?(n||e(...o),n=setTimeout((function(){n=null}),t)):n=setTimeout((()=>{e(...o)}),t)};return o.cancel=()=>{n&&(clearTimeout(n),n=null)},o},exports.debounce=function(e,t){let r;const n=function(...n){clearTimeout(r),r=setTimeout((()=>{e(...n)}),t)};return n.cancel=()=>{r&&(clearTimeout(r),r=null)},n},exports.arrayGroup=function(e,t="type"){return e.reduce(((e,r)=>{var n;return Object.assign(Object.assign({},e),{[r[t]]:[...null!==(n=e[r[t]])&&void 0!==n?n:[],r]})}),{})},exports.numberFixed=function(e,t=1){const r=e.toString(),n=r.indexOf(".");if(-1===n)return e;const o=r.slice(0,n+1+t);return parseFloat(o)},exports.delObj=function(e,n=""){try{if(t(n)){let t=Object.keys(e);for(let r of t)delete e[r]}else if("Array"==r(n))for(const t of n)delete e[t];else delete e[n]}catch(e){}},exports.delObjEmptyKey=function(e){try{let n=Object.keys(e);for(let o of n)"Number"!=r(e[o])&&t(e[o])&&delete e[o]}catch(e){}},exports.isNum=a,exports.pxToRem=function(e,t=37.5){let r=e;if(a(e)||-1!=e.indexOf("px")){r=(parseFloat(e)/t).toFixed(2)+"rem"}return r},exports.inArr=function(e=[],t,r=!1){if(r)return e.indexOf(t);{let r=-1,n=e.length;for(let o=0;o<n;o++)e[o]==t&&(r=o);return r}},exports.fnRuntime=function(e,t=1){let r=0;for(let n=0;n<t;n++){const t=performance.now();e();r+=performance.now()-t}const n=r/t;console.log(`平均执行时间 ${t} 次数: ${n.toFixed(6)} ms`)},exports.objToFormData=function(e){let t=new FormData;return function e(n,o=""){let a=r(n);if(-1==["Array","Object"].indexOf(a))null!=n&&t.append(`${o}`,n);else if("Array"==a){let t=n.length;for(let r=0;r<t;r++)e(n[r],`${o}[${r}]`)}else if("Object"==a){let t=Object.keys(n);for(const r of t)e(n[r],`${o}${""==o?"":"."}${r}`)}}(e),t},exports.formatSize=function(e,t={}){if(0===e)return"0 Bytes";let{decimals:r=2,sizes:n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"]}=t;const o=r<0?0:r,a=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,a)).toFixed(o))+" "+n[a]},Number.prototype.repair=function(e=2){let t="";for(let r=1;r<e;r++)t+="0";return(t+this).slice(-1*e)};
|