tools_dj 1.0.94 → 1.0.98
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.js +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +1 -1
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 s(e){let t=e+"";const r=Number(t);return!isNaN(r)&&t.length>0}function c(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}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.memoize=void 0,exports.del_repeat=e,exports.formatDate=function(e,t="day",r="-"){let n=e.getFullYear(),o=(e.getMonth()+1).toString().padStart(2,"0"),s=e.getDate().toString().padStart(2,"0"),c=e.getHours().toString().padStart(2,"0"),i=e.getMinutes().toString().padStart(2,"0"),a={year:1,month:2,day:3,hour:4,minute:5},l="";for(let e=0;e<a[t];e++)0==e&&(l+=n),1==e&&(l+=o),2==e&&(l+=s),3==e&&(l+=c),4==e&&(l+=i),e!=a[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,s=e.getFullYear(),c=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0"),a=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:s},{format:"yyyy",data:s},{format:"MM",data:c},{format:"DD",data:i},{format:"dd",data:i},{format:"hh",data:a},{format:"HH",data:a},{format:"mm",data:l},{format:"ss",data:u},{format:"week",data:p},{format:"time_slot",data:a>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),s=0;n>o&&(s=(n-o)/864e5);n<o&&(s=(o-n)/864e5,r&&(s=-s));return s},exports.is_empty=t,exports.repalce=function(e,t,r){return e.substring(0,t)+r+e.substring(t+1)},exports.toGetQuery=function(e,n={}){if(t(e))return"";{let{prefix:o="?"}=n,s=[],c=["",void 0,null];const i=(e,n="")=>{const o=Object.keys(e);for(const a of o){const o=e[a];if(c.includes(o))continue;let l=r(o),u=encodeURIComponent(a);if(t(n)||(u=`${n}[${u}]`),"Array"===l)for(const e of o)s.push(`${u}[]=${encodeURIComponent(e)}`);else if("Object"===l)i(o,u);else{let e=encodeURIComponent(o);s.push(`${u}=${e}`)}}};return i(e),s.length?o+s.join("&"):""}},exports.isLink=function(e){const t=e.indexOf("://");if(-1===t)return!1;const r=e.slice(0,t+1);return-1!==c(["http:","https:","ftp:","file:"],r.toLowerCase())},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"},s=new Map,c=new Map,i=[];let a=e.length;for(let t=0;t<a;t++){let r=e[t];const n=r[o.parentId];s.has(n)||s.set(n,[]),c.set(r[o.id],r),s.get(n).push(r)}for(let t=0;t<a;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=s.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:s=!0,copy:c=!0}=t,i=[];i=c?JSON.parse(JSON.stringify(e)):e;return i.filter((e=>{const t=i.filter((t=>s?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,s=[...e];for(;s.length;){let e=s.pop();if(e[n])if(s.push(...e[n]),o){let t={},o=Object.keys(e),s=o.length;for(let r=0;r<s;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,s=[...e];for(;s.length;){let e=s.shift();t(e[o])?r&&r(e):s.push(...e[o])}},exports.treeStack=function(e,r,n={}){let{cKey:o="children"}=n,s=[...e];for(;s.length;){let e=s.shift();t(e[o])?r&&r(e):s.push(...e[o])}},exports.treeRecursion=function(e,t,r={}){},exports.treeFind=function(e,t={}){let r=[],{cKey:n="children",key:o="id",value:s,copy:c=!0}=t,i=[...e];for(;i.length;){let e=i.pop();if(e[n]&&i.push(...e[n]),e[o]==s)if(c){let t={},o=Object.keys(e),s=o.length;for(let r=0;r<s;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,s=new Uint8Array(o);o--;)s[o]=n.charCodeAt(o);return new Blob([s],{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="",s=(""+e).length;if(s>t&&1==n)return s;{let n=t-s;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,s="yes";e.cZoom&&(n()?e.cZoom.mobile&&(o=e.cZoom.mobile):e.cZoom.pc&&(o=e.cZoom.pc),e.cZoom.isScale&&(s=e.cZoom.isScale));let c=`width=device-width,minimum-scale=${o},initial-scale=${o},user-scalable=${s}`;"no"==s&&(c+=`,maximum-scale=${o}`);const i=[{charset:"utf-8"},{name:"viewport",content:c}],a=document.createDocumentFragment();i.forEach((e=>{a.append(r.cloneNode()),Object.entries(e).forEach((e=>{a.lastChild.setAttribute(e[0],e[1])}))})),t.forEach((e=>{document.head.removeChild(e)})),document.head.prepend(a)}},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),s=parseInt(e.substring(5,7),16),c=parseInt(t.substring(1,3),16),i=parseInt(t.substring(3,5),16),a=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(s*(1-r)+a*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),s=new Date(r);return n>=o&&n<=s},exports.throttle1=function(e,t){let r,n=0;return function(...o){const s=Date.now(),c=s-n;clearTimeout(r),c>=t?(e(...o),n=s):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=s,exports.pxToRem=function(e,t=37.5){let r=e;if(s(e)||-1!=e.indexOf("px")){r=(parseFloat(e)/t).toFixed(2)+"rem"}return r},exports.inArr=c,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,t=!0){let n=new FormData;return function e(o,s="",c={}){let{level:i=0,pk:a="",type:l=""}=c,u=r(o);if(-1==["Array","Object"].indexOf(u)){if(null!=o){let e=s;t&&2==i&&"Array"==l&&(e=a),n.append(e,o)}}else if("Array"==u){let t=o.length;for(let r=0;r<t;r++){let t=`${s}[${r}]`,n={level:i+1,type:"Array",pk:s};e(o[r],t,n)}}else if("Object"==u){let t=Object.keys(o),r={level:i+1,type:"Object",pk:s};for(const n of t)e(o[n],`${s}${""==s?"":"."}${n}`,r)}}(e),n},exports.formatSize=function(e,t={}){let{decimals:r=2,sizes:n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],perUnit:o=1024}=t;if(0===e)return"0"+n[0];const s=r<0?0:r,c=Math.floor(Math.log(e)/Math.log(o));return parseFloat((e/Math.pow(o,c)).toFixed(s))+" "+n[c]},exports.arrToAryTree=function(e,t={}){let{idKey:r="id",pidKey:n="pid",rKey:o="rgt",lKey:s="lft",levelKey:c="level"}=t;const i={},a={};let l=e.length;for(let t=0;t<l;t++){let o=e[t],s=o[n],c=o[r];i[c]=Object.assign({},o),a[s]||(a[s]=[]),a[s].push(c)}const u=Object.keys(a),p=Object.keys(i),f=new Set(p);let d=[];u.filter((e=>{f.has(e)||d.push(...a[e])}));let h=1;const m=[],g=[];for(let e=d.length-1;e>=0;e--)m.push({[r]:d[e],[c]:1,processed:!1});for(;m.length>0;){const e=m.pop(),t=i[e[r]];if(e.processed)t[o]=h++,g.push(t);else if(t[s]=h++,t[c]=e[c],m.push({[r]:e[r],[c]:e[c],processed:!0}),a[e[r]])for(let t=a[e[r]].length-1;t>=0;t--)m.push({[r]:a[e[r]][t],[c]:e[c]+1,processed:!1})}return g},exports.mergeObj=function(e,t={}){let{callback:n=null,callType:o="",afterBack:s=null}=t,c={};function i(e,t){let c=Object.keys(e);for(const a of c){let c=r(e[a]);n&&c==o?t[a]=n(e,a):"Object"===c?(t[a]||(t[a]={}),i(e[a],t[a])):t[a]=e[a],s&&s(t,a)}}for(const t of e)i(t,c);return c},Number.prototype.repair=function(e=2){let t="";for(let r=1;r<e;r++)t+="0";return(t+this).slice(-1*e)};exports.memoize=(e,t={})=>{const{context:r=null,ttl:n=0}=t,o=new Map,s=e=>{if("object"==typeof e&&null!==e){if(Array.isArray(e))return`[${e.map(s).join(",")}]`;return`{${Object.keys(e).sort().map((t=>`${t}:${s(e[t])}`)).join(",")}}`}return String(e)};return(...t)=>{const c=s(t),i=o.get(c);if(i&&(0===n||Date.now()-i.timestamp<=n))return i.value;const a=r?e.apply(r,t):e(...t);return o.set(c,{value:a,timestamp:Date.now()}),a}};
|
|
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(){var e,t,r,n,o;try{const i=navigator,s=i.userAgent||"",c=i.maxTouchPoints||0,l=Math.min((null===(e=window.screen)||void 0===e?void 0:e.width)||1/0,(null===(t=window.screen)||void 0===t?void 0:t.height)||1/0);return!!((null===(r=i.userAgentData)||void 0===r?void 0:r.mobile)||/Android.+Mobile|iPhone|iPod|Windows Phone|IEMobile|BlackBerry|webOS|Opera Mini|Mobile|Fennec/i.test(s)||/iPad|Tablet|PlayBook|Silk|Kindle|Nexus 7|Nexus 10|SM-T|Lenovo TB|Mi Pad/i.test(s)||/Android/i.test(s)&&!/Mobile/i.test(s)&&c>1||"MacIntel"===i.platform&&c>1||(null===(o=null===(n=window.matchMedia)||void 0===n?void 0:n.call(window,"(pointer: coarse)"))||void 0===o?void 0:o.matches)&&c>1&&l<=1024)}catch(e){return!1}}function o(e,t){return Math.round(Math.random()*(t-e))+e}function i(e){let t=e+"";const r=Number(t);return!isNaN(r)&&t.length>0}function s(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}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.memoize=void 0,exports.del_repeat=e,exports.formatDate=function(e,t="day",r="-"){let n=e.getFullYear(),o=(e.getMonth()+1).toString().padStart(2,"0"),i=e.getDate().toString().padStart(2,"0"),s=e.getHours().toString().padStart(2,"0"),c=e.getMinutes().toString().padStart(2,"0"),l={year:1,month:2,day:3,hour:4,minute:5},a="";for(let e=0;e<l[t];e++)0==e&&(a+=n),1==e&&(a+=o),2==e&&(a+=i),3==e&&(a+=s),4==e&&(a+=c),e!=l[t]-1&&(a+=r);return a},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,i=e.getFullYear(),s=(e.getMonth()+1).toString().padStart(2,"0"),c=e.getDate().toString().padStart(2,"0"),l=e.getHours().toString().padStart(2,"0"),a=e.getMinutes().toString().padStart(2,"0"),u=e.getSeconds().toString().padStart(2,"0"),p=o[e.getDay()],f=t;return[{format:"YYYY",data:i},{format:"yyyy",data:i},{format:"MM",data:s},{format:"DD",data:c},{format:"dd",data:c},{format:"hh",data:l},{format:"HH",data:l},{format:"mm",data:a},{format:"ss",data:u},{format:"week",data:p},{format:"time_slot",data:l>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),i=0;n>o&&(i=(n-o)/864e5);n<o&&(i=(o-n)/864e5,r&&(i=-i));return i},exports.is_empty=t,exports.repalce=function(e,t,r){return e.substring(0,t)+r+e.substring(t+1)},exports.toGetQuery=function(e,n={}){if(t(e))return"";{let{prefix:o="?"}=n,i=[],s=["",void 0,null];const c=(e,n="")=>{const o=Object.keys(e);for(const l of o){const o=e[l];if(s.includes(o))continue;let a=r(o),u=encodeURIComponent(l);if(t(n)||(u=`${n}[${u}]`),"Array"===a)for(const e of o)i.push(`${u}[]=${encodeURIComponent(e)}`);else if("Object"===a)c(o,u);else{let e=encodeURIComponent(o);i.push(`${u}=${e}`)}}};return c(e),i.length?o+i.join("&"):""}},exports.isLink=function(e){const t=e.indexOf("://");if(-1===t)return!1;const r=e.slice(0,t+1);return-1!==s(["http:","https:","ftp:","file:"],r.toLowerCase())},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"},i=new Map,s=new Map,c=[];let l=e.length;for(let t=0;t<l;t++){let r=e[t];const n=r[o.parentId];i.has(n)||i.set(n,[]),s.set(r[o.id],r),i.get(n).push(r)}for(let t=0;t<l;t++){let r=e[t];const n=r[o.parentId];s.has(n)||c.push(r)}const a=[...c];for(;a.length>0;){const e=a.pop(),t=i.get(e[o.id]);t&&(e[o.childrenList]=t,a.push(...t))}return c},exports.arrToTree=function(e,t={}){let{id:r="id",pKey:n="parentId",cKey:o="children",strict:i=!0,copy:s=!0}=t,c=[];c=s?JSON.parse(JSON.stringify(e)):e;return c.filter((e=>{const t=c.filter((t=>i?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,i=[...e];for(;i.length;){let e=i.pop();if(e[n])if(i.push(...e[n]),o){let t={},o=Object.keys(e),i=o.length;for(let r=0;r<i;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,i=[...e];for(;i.length;){let e=i.shift();t(e[o])?r&&r(e):i.push(...e[o])}},exports.treeStack=function(e,r,n={}){let{cKey:o="children"}=n,i=[...e];for(;i.length;){let e=i.shift();t(e[o])?r&&r(e):i.push(...e[o])}},exports.treeRecursion=function(e,t,r={}){},exports.treeFind=function(e,t={}){let r=[],{cKey:n="children",key:o="id",value:i,copy:s=!0}=t,c=[...e];for(;c.length;){let e=c.pop();if(e[n]&&c.push(...e[n]),e[o]==i)if(s){let t={},o=Object.keys(e),i=o.length;for(let r=0;r<i;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,i=new Uint8Array(o);o--;)i[o]=n.charCodeAt(o);return new Blob([i],{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="",i=(""+e).length;if(i>t&&1==n)return i;{let n=t-i;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,i="yes";e.cZoom&&(n()?e.cZoom.mobile&&(o=e.cZoom.mobile):e.cZoom.pc&&(o=e.cZoom.pc),e.cZoom.isScale&&(i=e.cZoom.isScale));let s=`width=device-width,minimum-scale=${o},initial-scale=${o},user-scalable=${i}`;"no"==i&&(s+=`,maximum-scale=${o}`);const c=[{charset:"utf-8"},{name:"viewport",content:s}],l=document.createDocumentFragment();c.forEach((e=>{l.append(r.cloneNode()),Object.entries(e).forEach((e=>{l.lastChild.setAttribute(e[0],e[1])}))})),t.forEach((e=>{document.head.removeChild(e)})),document.head.prepend(l)}},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),i=parseInt(e.substring(5,7),16),s=parseInt(t.substring(1,3),16),c=parseInt(t.substring(3,5),16),l=parseInt(t.substring(5,7),16),a=Math.round(n*(1-r)+s*r),u=Math.round(o*(1-r)+c*r),p=Math.round(i*(1-r)+l*r);return a=("0"+(a||0).toString(16)).slice(-2),u=("0"+(u||0).toString(16)).slice(-2),p=("0"+(p||0).toString(16)).slice(-2),"#"+a+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),i=new Date(r);return n>=o&&n<=i},exports.throttle1=function(e,t){let r,n=0;return function(...o){const i=Date.now(),s=i-n;clearTimeout(r),s>=t?(e(...o),n=i):r=setTimeout((()=>{e(...o),n=Date.now()}),t-s)}},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=i,exports.pxToRem=function(e,t=37.5){let r=e;if(i(e)||-1!=e.indexOf("px")){r=(parseFloat(e)/t).toFixed(2)+"rem"}return r},exports.inArr=s,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,t=!0){let n=new FormData;return function e(o,i="",s={}){let{level:c=0,pk:l="",type:a=""}=s,u=r(o);if(-1==["Array","Object"].indexOf(u)){if(null!=o){let e=i;t&&2==c&&"Array"==a&&(e=l),n.append(e,o)}}else if("Array"==u){let t=o.length;for(let r=0;r<t;r++){let t=`${i}[${r}]`,n={level:c+1,type:"Array",pk:i};e(o[r],t,n)}}else if("Object"==u){let t=Object.keys(o),r={level:c+1,type:"Object",pk:i};for(const n of t)e(o[n],`${i}${""==i?"":"."}${n}`,r)}}(e),n},exports.formatSize=function(e,t={}){let{decimals:r=2,sizes:n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],perUnit:o=1024}=t;if(0===e)return"0"+n[0];const i=r<0?0:r,s=Math.floor(Math.log(e)/Math.log(o));return parseFloat((e/Math.pow(o,s)).toFixed(i))+" "+n[s]},exports.arrToAryTree=function(e,t={}){let{idKey:r="id",pidKey:n="pid",rKey:o="rgt",lKey:i="lft",levelKey:s="level"}=t;const c={},l={};let a=e.length;for(let t=0;t<a;t++){let o=e[t],i=o[n],s=o[r];c[s]=Object.assign({},o),l[i]||(l[i]=[]),l[i].push(s)}const u=Object.keys(l),p=Object.keys(c),f=new Set(p);let d=[];u.filter((e=>{f.has(e)||d.push(...l[e])}));let h=1;const m=[],g=[];for(let e=d.length-1;e>=0;e--)m.push({[r]:d[e],[s]:1,processed:!1});for(;m.length>0;){const e=m.pop(),t=c[e[r]];if(e.processed)t[o]=h++,g.push(t);else if(t[i]=h++,t[s]=e[s],m.push({[r]:e[r],[s]:e[s],processed:!0}),l[e[r]])for(let t=l[e[r]].length-1;t>=0;t--)m.push({[r]:l[e[r]][t],[s]:e[s]+1,processed:!1})}return g},exports.mergeObj=function(e,t={}){let{callback:n=null,callType:o="",afterBack:i=null}=t,s={};function c(e,t){let s=Object.keys(e);for(const l of s){let s=r(e[l]);n&&s==o?t[l]=n(e,l):"Object"===s?(t[l]||(t[l]={}),c(e[l],t[l])):t[l]=e[l],i&&i(t,l)}}for(const t of e)c(t,s);return s},Number.prototype.repair=function(e=2){let t="";for(let r=1;r<e;r++)t+="0";return(t+this).slice(-1*e)};exports.memoize=(e,t={})=>{const{context:r=null,ttl:n=0}=t,o=new Map,i=e=>{if("object"==typeof e&&null!==e){if(Array.isArray(e))return`[${e.map(i).join(",")}]`;return`{${Object.keys(e).sort().map((t=>`${t}:${i(e[t])}`)).join(",")}}`}return String(e)};return(...t)=>{const s=i(t),c=o.get(s);if(c&&(0===n||Date.now()-c.timestamp<=n))return c.value;const l=r?e.apply(r,t):e(...t);return o.set(s,{value:l,timestamp:Date.now()}),l}};
|
package/lib/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type RequestRedirect = 'follow' | 'manual' | 'error';
|
|
|
20
20
|
/** 引用策略类型 */
|
|
21
21
|
export type ReferrerPolicy = 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
|
|
22
22
|
/** 请求头类型 */
|
|
23
|
-
export type RequestHeaders = Record<string,
|
|
23
|
+
export type RequestHeaders = Record<string, any> | Headers;
|
|
24
24
|
/** 请求选项接口 */
|
|
25
25
|
export interface RequestOptions {
|
|
26
26
|
method?: HttpMethod;
|