tools_dj 1.0.42 → 1.0.43
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/auth.d.ts +34 -0
- package/lib/auth.js +1 -0
- package/lib/index.d.ts +0 -34
- package/lib/index.js +1 -1
- package/package.json +5 -2
package/lib/auth.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** 2025/2/20 16:42 User: DJ
|
|
2
|
+
* content: 权限自动判断
|
|
3
|
+
*/
|
|
4
|
+
export declare class auth {
|
|
5
|
+
authList: Array<any>;
|
|
6
|
+
authObj: any;
|
|
7
|
+
/** 2024/12/24 10:07 User: DJ
|
|
8
|
+
* content:权限处理
|
|
9
|
+
* @param authList 表格配置参数
|
|
10
|
+
*/
|
|
11
|
+
constructor(authList: any);
|
|
12
|
+
init(): void;
|
|
13
|
+
/** 2025/2/20 16:40 User: DJ
|
|
14
|
+
* content: 添加权限,arr需要添加的权限
|
|
15
|
+
*/
|
|
16
|
+
add(base: any, arr?: any): any;
|
|
17
|
+
/** 2025/2/20 16:40 User: DJ
|
|
18
|
+
* content: 删除权限
|
|
19
|
+
*/
|
|
20
|
+
del(base: any, arr?: any): any;
|
|
21
|
+
/** 2025/2/20 16:41 User: DJ
|
|
22
|
+
* content: 判断权限 必须全部存在 就返回true
|
|
23
|
+
*/
|
|
24
|
+
andHave(base: any, arr?: any): boolean;
|
|
25
|
+
/** 2025/2/20 16:41 User: DJ
|
|
26
|
+
* content: 或判断权限,只要有一个存在就返回true
|
|
27
|
+
*/
|
|
28
|
+
orHave(base: any, arr?: any): boolean;
|
|
29
|
+
/** 2025/2/21 15:39 User: DJ
|
|
30
|
+
* content: 从一个数字获取有那些权限
|
|
31
|
+
* @param number 数字
|
|
32
|
+
*/
|
|
33
|
+
getTxt(number: any): any;
|
|
34
|
+
}
|
package/lib/auth.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.auth=void 0;exports.auth=class{constructor(t){this.authList=[],this.authObj={},this.authList=t,new.target&&this.init()}init(){let t=this.authList.length;for(let s=0;s<t;s++){let t=1<<s,e=this.authList[s];this.authObj[e]=t}}add(t,s=[]){for(const e of s)t|=this.authObj[e];return t}del(t,s=[]){for(const e of s){t&=~this.authObj[e]}return t}andHave(t,s=[]){let e=!0;for(const h of s){if(!(t&this.authObj[h])){e=!1;break}}return e}orHave(t,s=[]){let e=!1;for(const h of s){if(t&this.authObj[h]){e=!0;break}}return e}getTxt(t){let s=[];for(const e of this.authList){t&this.authObj[e]&&s.push(e)}return s}};
|
package/lib/index.d.ts
CHANGED
|
@@ -256,37 +256,3 @@ export declare function inArr(arr: any | undefined, str: any, force?: any): any;
|
|
|
256
256
|
* @param iterations //迭代次数
|
|
257
257
|
*/
|
|
258
258
|
export declare function fnRuntime(fn: any, iterations?: number): void;
|
|
259
|
-
/** 2025/2/20 16:42 User: DJ
|
|
260
|
-
* content: 权限自动判断
|
|
261
|
-
*/
|
|
262
|
-
export declare class auth {
|
|
263
|
-
authList: Array<any>;
|
|
264
|
-
authObj: any;
|
|
265
|
-
/** 2024/12/24 10:07 User: DJ
|
|
266
|
-
* content: 表格处理
|
|
267
|
-
* @param authList 表格配置参数
|
|
268
|
-
*/
|
|
269
|
-
constructor(authList: any);
|
|
270
|
-
init(): void;
|
|
271
|
-
/** 2025/2/20 16:40 User: DJ
|
|
272
|
-
* content: 添加权限,arr需要添加的权限
|
|
273
|
-
*/
|
|
274
|
-
add(base: any, arr?: any): any;
|
|
275
|
-
/** 2025/2/20 16:40 User: DJ
|
|
276
|
-
* content: 删除权限
|
|
277
|
-
*/
|
|
278
|
-
del(base: any, arr?: any): any;
|
|
279
|
-
/** 2025/2/20 16:41 User: DJ
|
|
280
|
-
* content: 判断权限 必须全部存在 就返回true
|
|
281
|
-
*/
|
|
282
|
-
andHave(base: any, arr?: any): boolean;
|
|
283
|
-
/** 2025/2/20 16:41 User: DJ
|
|
284
|
-
* content: 或判断权限,只要有一个存在就返回true
|
|
285
|
-
*/
|
|
286
|
-
orHave(base: any, arr?: any): boolean;
|
|
287
|
-
/** 2025/2/21 15:39 User: DJ
|
|
288
|
-
* content: 从一个数字获取有那些权限
|
|
289
|
-
* @param number 数字
|
|
290
|
-
*/
|
|
291
|
-
getTxt(number: any): any;
|
|
292
|
-
}
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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 n(){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}function c(t){let e=Number(t);return!isNaN(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.auth=void 0,exports.del_repeat=t,exports.formatDate=function(t,e="day",r="-"){let n=t.getFullYear(),o=(t.getMonth()+1).toString().padStart(2,"0"),c=t.getDate().toString().padStart(2,"0"),i=t.getHours().toString().padStart(2,"0"),s=t.getMinutes().toString().padStart(2,"0"),a={year:1,month:2,day:3,hour:4,minute:5},u="";for(let t=0;t<a[e];t++)0==t&&(u+=n),1==t&&(u+=o),2==t&&(u+=c),3==t&&(u+=i),4==t&&(u+=s),t!=a[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",n="-"){var o;try{t=t.replaceAll("-","/")}catch(t){}let c=(t=new Date(t)).getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),s=t.getDate().toString().padStart(2,"0"),a=t.getHours().toString().padStart(2,"0"),u=t.getMinutes().toString().padStart(2,"0"),l=t.getSeconds().toString().padStart(2,"0"),p={0:"周日",1:"周一",2:"周二",3:"周三",4:"周四",5:"周五",6:"周六"}[t.getDay()],f=a>12?"下午":"上午",d=[];d=[{group:1,connect:"Object"==r(n)&&null!==(o=n.YYYY)&&void 0!==o?o:"",format:"YYYY",data:c},{group:1,connect:"",format:"yyyy",data:c},{group:1,connect:n,format:"MM",data:i},{group:1,connect:n,format:"DD",data:s},{group:1,connect:n,format:"dd",data:s},{group:2,connect:" ",format:"hh",data:a},{group:2,connect:" ",format:"HH",data:a},{group:2,connect:":",format:"mm",data:u},{group:2,connect:":",format:"ss",data:l},{group:3,connect:" ",format:"week",data:p},{group:4,connect:" ",format:"time_slot",data:f}];let h=0,g="";return d.forEach((function(t,r){if(-1!=e.indexOf(t.format)){let e="";0!=h&&(e=t.connect),g+=e+t.data,h++}})),g},exports.getDaysBetween=function(t,e,r=!1){var n=Date.parse(t),o=Date.parse(e),c=0;n>o&&(c=(n-o)/864e5);n<o&&(c=(o-n)/864e5,r&&(c=-c));return c},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?"?":"",n=[];for(let e in t){let r=t[e];["",void 0,null].includes(r)||(r.constructor===Array?r.forEach((t=>{n.push(encodeURIComponent(e)+"[]="+encodeURIComponent(t))})):n.push(encodeURIComponent(e)+"="+encodeURIComponent(r)))}return console.log(n.length?e+n.join("&"):""),n.length?e+n.join("&"):""}return console.log(!1),!1},exports.merge=function(e,r){const n=Object.prototype.toString.call(e);if("Array"==n.slice(8,-1))return e.push.apply(e,r),t(e);if("Object"==n.slice(8,-1))return Object.assign(e,r)},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,n,o){try{return t.find((function(t){return t[e]==r}))[n]=o,!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,n){const o={id:e||"id",parentId:r||"parentId",childrenList:n||"children"},c=new Map,i=new Map,s=[];let a=t.length;for(let e=0;e<a;e++){let r=t[e];const n=r[o.parentId];c.has(n)||c.set(n,[]),i.set(r[o.id],r),c.get(n).push(r)}for(let e=0;e<a;e++){let r=t[e];const n=r[o.parentId];i.has(n)||s.push(r)}const u=[...s];for(;u.length>0;){const t=u.pop(),e=c.get(t[o.id]);e&&(t[o.childrenList]=e,u.push(...e))}return s},exports.arrToTree=function(t,e={}){let{id:r="id",pKey:n="parentId",cKey:o="children",strict:c=!0,copy:i=!0}=e,s=[];s=i?JSON.parse(JSON.stringify(t)):t;return s.filter((t=>{const e=s.filter((e=>c?e[n]===t[r]:e[n]==t[r]));return e.length&&(t[o]=e),0===t[n]}))},exports.treeToArr=function(t,e={}){let r=[],{cKey:n="children",copy:o=!0}=e,c=[...t];for(;c.length;){let t=c.pop();if(t[n])if(c.push(...t[n]),o){let e={},o=Object.keys(t),c=o.length;for(let r=0;r<c;r++)o[r]!=n&&(e[o[r]]=t[o[r]]);r.push(e)}else r.push(t)}return r},exports.treeFor=function(t,r,n={}){let{cKey:o="children"}=n,c=[...t];for(;c.length;){let t=c.shift();e(t[o])?r&&r(t):c.push(...t[o])}},exports.treeStack=function(t,r,n={}){let{cKey:o="children"}=n,c=[...t];for(;c.length;){let t=c.shift();e(t[o])?r&&r(t):c.push(...t[o])}},exports.treeRecursion=function(t,e,r={}){},exports.treeFind=function(t,e={}){let r=[],{cKey:n="children",key:o="id",value:c,copy:i=!0}=e,s=[...t];for(;s.length;){let t=s.pop();if(t[n]&&s.push(...t[n]),t[o]==c)if(i){let e={},o=Object.keys(t),c=o.length;for(let r=0;r<c;r++)o[r]!=n&&(e[o[r]]=t[o[r]]);r.push(e)}else r.push(t)}return r},exports.base64Img=function(t,e){return r=function(t){for(var e=t.split(","),r=e[0].match(/:(.*?);/)[1],n=atob(e[1]),o=n.length,c=new Uint8Array(o);o--;)c[o]=n.charCodeAt(o);return new Blob([c],{type:r})}(t),n=e,new File([r],n);var r,n},exports.compareDate=function(t,e="up"){return function(r,n){return"up"==e?Date.parse(r[t])-Date.parse(n[t]):Date.parse(n[t])-Date.parse(r[t])}},exports.compare=function(t,e="up"){return function(r,n){return"up"==e?r[t]-n[t]:n[t]-r[t]}},exports.numberRepair=function(t="",e=2,r="0",n=!1){let o="",c=(""+t).length;if(c>e&&1==n)return c;{let n=e-c;if(n>0)for(let t=0;t<n;t++)o+=r;return(o+t).slice(-1*e)}},exports.isMobile=n,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 o=1,c="yes";t.cZoom&&(n()?t.cZoom.mobile&&(o=t.cZoom.mobile):t.cZoom.pc&&(o=t.cZoom.pc),t.cZoom.isScale&&(c=t.cZoom.isScale));let i=`width=device-width,minimum-scale=${o},initial-scale=${o},user-scalable=${c}`;"no"==c&&(i+=`,maximum-scale=${o}`);const s=[{charset:"utf-8"},{name:"viewport",content:i}],a=document.createDocumentFragment();s.forEach((t=>{a.append(r.cloneNode()),Object.entries(t).forEach((t=>{a.lastChild.setAttribute(t[0],t[1])}))})),e.forEach((t=>{document.head.removeChild(t)})),document.head.prepend(a)}},exports.colorMix=function(t,e,r){r=Math.max(Math.min(Number(r),1),0);let n=parseInt(t.substring(1,3),16),o=parseInt(t.substring(3,5),16),c=parseInt(t.substring(5,7),16),i=parseInt(e.substring(1,3),16),s=parseInt(e.substring(3,5),16),a=parseInt(e.substring(5,7),16),u=Math.round(n*(1-r)+i*r),l=Math.round(o*(1-r)+s*r),p=Math.round(c*(1-r)+a*r);return u=("0"+(u||0).toString(16)).slice(-2),l=("0"+(l||0).toString(16)).slice(-2),p=("0"+(p||0).toString(16)).slice(-2),"#"+u+l+p},exports.sArrMove=function(t,e,r){t.splice(r,0,t.splice(e,1)[0])},exports.rArrMove=function(t,e,r){let n=[].concat(t);return n.splice(r,0,n.splice(e,1)[0]),n},exports.arrSet=function(t,e,r){t.splice(e,0,r)},exports.randomColor=function(){let t=o(100,255),e=o(100,255),r=o(100,255);return"rgba("+t+","+e+","+r+",1)"},exports.randomNumber=o,exports.isDateInRange=function(t,e,r){const n=new Date(t),o=new Date(e),c=new Date(r);return n>=o&&n<=c},exports.throttle1=function(t,e){let r,n=0;return function(...o){const c=Date.now(),i=c-n;clearTimeout(r),i>=e?(t(...o),n=c):r=setTimeout((()=>{t(...o),n=Date.now()}),e-i)}},exports.throttle=function(t,e=1e3,r=!0){let n;return(...o)=>{n&&clearInterval(n),r?(n||t(...o),n=setTimeout((function(){n=null}),e)):n=setTimeout((()=>{t(...o)}),e)}},exports.debounce=function(t,e){let r;return function(...n){clearTimeout(r),r=setTimeout((()=>{t(...n)}),e)}},exports.arrayGroup=function(t,e="type"){return t.reduce(((t,r)=>{var n;return Object.assign(Object.assign({},t),{[r[e]]:[...null!==(n=t[r[e]])&&void 0!==n?n:[],r]})}),{})},exports.numberFixed=function(t,e=1){const r=t.toString(),n=r.indexOf(".");if(-1===n)return t;const o=r.slice(0,n+1+e);return parseFloat(o)},exports.delObj=function(t,n=""){try{if(e(n)){let e=Object.keys(t);for(let r of e)delete t[r]}else if("Array"==r(n))for(const e of n)delete t[e];else delete t[n]}catch(t){}},exports.delObjEmptyKey=function(t){try{let n=Object.keys(t);for(let o of n)"Number"!=r(t[o])&&e(t[o])&&delete t[o]}catch(t){}},exports.isNum=c,exports.pxToRem=function(t,e=37.5){let r=t;if(c(t)||-1!=t.indexOf("px")){r=(parseFloat(t)/e).toFixed(2)+"rem"}return r},exports.inArr=function(t=[],e,r=!1){if(r)return t.indexOf(e);{let r=-1,n=t.length;for(let o=0;o<n;o++)t[o]==e&&(r=o);return r}},exports.fnRuntime=function(t,e=1){let r=0;for(let n=0;n<e;n++){const e=performance.now();t();r+=performance.now()-e}const n=r/e;console.log(`平均执行时间 ${e} 次数: ${n.toFixed(6)} ms`)},Number.prototype.repair=function(t=2){let e="";for(let r=1;r<t;r++)e+="0";return(e+this).slice(-1*t)};exports.auth=class{constructor(t){this.authList=[],this.authObj={},this.authList=t,new.target&&this.init()}init(){let t=this.authList.length;for(let e=0;e<t;e++){let t=1<<e,r=this.authList[e];this.authObj[r]=t}}add(t,e=[]){for(const r of e)t|=this.authObj[r];return t}del(t,e=[]){for(const r of e){t&=~this.authObj[r]}return t}andHave(t,e=[]){let r=!0;for(const n of e){if(!(t&this.authObj[n])){r=!1;break}}return r}orHave(t,e=[]){let r=!1;for(const n of e){if(t&this.authObj[n]){r=!0;break}}return r}getTxt(t){let e=[];for(const r of this.authList){t&this.authObj[r]&&e.push(r)}return e}};
|
|
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 c(e){let t=Number(e);return!isNaN(t)}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"),c=e.getDate().toString().padStart(2,"0"),i=e.getHours().toString().padStart(2,"0"),a=e.getMinutes().toString().padStart(2,"0"),s={year:1,month:2,day:3,hour:4,minute:5},u="";for(let e=0;e<s[t];e++)0==e&&(u+=n),1==e&&(u+=o),2==e&&(u+=c),3==e&&(u+=i),4==e&&(u+=a),e!=s[t]-1&&(u+=r);return u},exports.time_change=function(e){return Date.parse(e)},exports.formatTime=function(e,t="YYYY-MM-DD hh:mm:ss",n="-"){var o;try{e=e.replaceAll("-","/")}catch(e){}let c=(e=new Date(e)).getFullYear(),i=(e.getMonth()+1).toString().padStart(2,"0"),a=e.getDate().toString().padStart(2,"0"),s=e.getHours().toString().padStart(2,"0"),u=e.getMinutes().toString().padStart(2,"0"),l=e.getSeconds().toString().padStart(2,"0"),p={0:"周日",1:"周一",2:"周二",3:"周三",4:"周四",5:"周五",6:"周六"}[e.getDay()],f=s>12?"下午":"上午",d=[];d=[{group:1,connect:"Object"==r(n)&&null!==(o=n.YYYY)&&void 0!==o?o:"",format:"YYYY",data:c},{group:1,connect:"",format:"yyyy",data:c},{group:1,connect:n,format:"MM",data:i},{group:1,connect:n,format:"DD",data:a},{group:1,connect:n,format:"dd",data:a},{group:2,connect:" ",format:"hh",data:s},{group:2,connect:" ",format:"HH",data:s},{group:2,connect:":",format:"mm",data:u},{group:2,connect:":",format:"ss",data:l},{group:3,connect:" ",format:"week",data:p},{group:4,connect:" ",format:"time_slot",data:f}];let g=0,h="";return d.forEach((function(e,r){if(-1!=t.indexOf(e.format)){let t="";0!=g&&(t=e.connect),h+=t+e.data,g++}})),h},exports.getDaysBetween=function(e,t,r=!1){var n=Date.parse(e),o=Date.parse(t),c=0;n>o&&(c=(n-o)/864e5);n<o&&(c=(o-n)/864e5,r&&(c=-c));return c},exports.is_empty=t,exports.repalce=function(e,t,r){return e.substring(0,t)+r+e.substring(t+1)},exports.param=function(e,r=!0){if(0==t(e)){let t=r?"?":"",n=[];for(let t in e){let r=e[t];["",void 0,null].includes(r)||(r.constructor===Array?r.forEach((e=>{n.push(encodeURIComponent(t)+"[]="+encodeURIComponent(e))})):n.push(encodeURIComponent(t)+"="+encodeURIComponent(r)))}return console.log(n.length?t+n.join("&"):""),n.length?t+n.join("&"):""}return console.log(!1),!1},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"},c=new Map,i=new Map,a=[];let s=e.length;for(let t=0;t<s;t++){let r=e[t];const n=r[o.parentId];c.has(n)||c.set(n,[]),i.set(r[o.id],r),c.get(n).push(r)}for(let t=0;t<s;t++){let r=e[t];const n=r[o.parentId];i.has(n)||a.push(r)}const u=[...a];for(;u.length>0;){const e=u.pop(),t=c.get(e[o.id]);t&&(e[o.childrenList]=t,u.push(...t))}return a},exports.arrToTree=function(e,t={}){let{id:r="id",pKey:n="parentId",cKey:o="children",strict:c=!0,copy:i=!0}=t,a=[];a=i?JSON.parse(JSON.stringify(e)):e;return a.filter((e=>{const t=a.filter((t=>c?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,c=[...e];for(;c.length;){let e=c.pop();if(e[n])if(c.push(...e[n]),o){let t={},o=Object.keys(e),c=o.length;for(let r=0;r<c;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,c=[...e];for(;c.length;){let e=c.shift();t(e[o])?r&&r(e):c.push(...e[o])}},exports.treeStack=function(e,r,n={}){let{cKey:o="children"}=n,c=[...e];for(;c.length;){let e=c.shift();t(e[o])?r&&r(e):c.push(...e[o])}},exports.treeRecursion=function(e,t,r={}){},exports.treeFind=function(e,t={}){let r=[],{cKey:n="children",key:o="id",value:c,copy:i=!0}=t,a=[...e];for(;a.length;){let e=a.pop();if(e[n]&&a.push(...e[n]),e[o]==c)if(i){let t={},o=Object.keys(e),c=o.length;for(let r=0;r<c;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,c=new Uint8Array(o);o--;)c[o]=n.charCodeAt(o);return new Blob([c],{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="",c=(""+e).length;if(c>t&&1==n)return c;{let n=t-c;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,c="yes";e.cZoom&&(n()?e.cZoom.mobile&&(o=e.cZoom.mobile):e.cZoom.pc&&(o=e.cZoom.pc),e.cZoom.isScale&&(c=e.cZoom.isScale));let i=`width=device-width,minimum-scale=${o},initial-scale=${o},user-scalable=${c}`;"no"==c&&(i+=`,maximum-scale=${o}`);const a=[{charset:"utf-8"},{name:"viewport",content:i}],s=document.createDocumentFragment();a.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),c=parseInt(e.substring(5,7),16),i=parseInt(t.substring(1,3),16),a=parseInt(t.substring(3,5),16),s=parseInt(t.substring(5,7),16),u=Math.round(n*(1-r)+i*r),l=Math.round(o*(1-r)+a*r),p=Math.round(c*(1-r)+s*r);return u=("0"+(u||0).toString(16)).slice(-2),l=("0"+(l||0).toString(16)).slice(-2),p=("0"+(p||0).toString(16)).slice(-2),"#"+u+l+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),c=new Date(r);return n>=o&&n<=c},exports.throttle1=function(e,t){let r,n=0;return function(...o){const c=Date.now(),i=c-n;clearTimeout(r),i>=t?(e(...o),n=c):r=setTimeout((()=>{e(...o),n=Date.now()}),t-i)}},exports.throttle=function(e,t=1e3,r=!0){let n;return(...o)=>{n&&clearInterval(n),r?(n||e(...o),n=setTimeout((function(){n=null}),t)):n=setTimeout((()=>{e(...o)}),t)}},exports.debounce=function(e,t){let r;return function(...n){clearTimeout(r),r=setTimeout((()=>{e(...n)}),t)}},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=c,exports.pxToRem=function(e,t=37.5){let r=e;if(c(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`)},Number.prototype.repair=function(e=2){let t="";for(let r=1;r<e;r++)t+="0";return(t+this).slice(-1*e)};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tools_dj",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"description": "dj tools 工具库",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -27,5 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"lib"
|
|
30
|
-
]
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"glob": "^11.0.1"
|
|
33
|
+
}
|
|
31
34
|
}
|