tools_dj 1.0.4 → 1.0.8

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 CHANGED
@@ -83,3 +83,25 @@ export declare function setMeta(meta: any): void;
83
83
  * 色阶宽度
84
84
  */
85
85
  export declare function colorMix(color1: any, color2: any, weight: any): string;
86
+ /** 2023/6/19 2:18 User: DJ
87
+ * content: 源数组移动
88
+ */
89
+ export declare function sArrMove(arr: any, startIndex: any, endIndex: any): void;
90
+ /** 2023/6/19 2:21 User: DJ
91
+ * content: 数组元素位置移动返回新数组
92
+ */
93
+ export declare function rArrMove(arr: any, startIndex: any, endIndex: any): never[];
94
+ /** 2023/7/26 10:49 User: DJ
95
+ * content: 在数组任意位置插入数据
96
+ */
97
+ export declare function arrSet(arr: any, index: number, data: any): void;
98
+ /** 2023/7/26 9:49 User: DJ
99
+ * content: 生成随机颜色
100
+ */
101
+ export declare function randomColor(): string;
102
+ /** 2023/7/27 13:50 User: DJ
103
+ * content: 随机数字
104
+ * min: 最小值
105
+ * max: 最大值
106
+ */
107
+ export declare function randomNumber(min: any, max: any): any;
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(){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))}Object.defineProperty(exports,"__esModule",{value:!0}),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"),c=t.getHours().toString().padStart(2,"0"),s=t.getMinutes().toString().padStart(2,"0"),i={year:1,month:2,day:3,hour:4,minute:5},p="";for(let t=0;t<i[e];t++)0==t&&(p+=o),1==t&&(p+=n),2==t&&(p+=a),3==t&&(p+=c),4==t&&(p+=s),t!=i[e]-1&&(p+=r);return p},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"),c=t.getHours().toString().padStart(2,"0"),s=[];s=[{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:c},{group:2,connect:" ",format:"HH",data:c},{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:c>12?"下午":"上午"}];let i=0,p="";return s.forEach((function(t,r){if(-1!=e.indexOf(t.format)){let e="";0!=i&&(e=t.connect),p+=e+t.data,i++}})),p},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",c=o||"children";var s={},i={},p=[];for(let e of t){let t=e[a];null==s[t]&&(s[t]=[]),i[e[n]]=e,s[t].push(e)}for(let e of t){null==i[e[a]]&&p.push(e)}for(let t of p)u(t);function u(t){if(null!==s[t[n]]&&(t[c]=s[t[n]]),t[c])for(let e of t[c])u(e)}return p},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 c=`width=device-width,minimum-scale=${n},initial-scale=${n},user-scalable=${a}`;"no"==a&&(c+=`,maximum-scale=${n}`);const s=[{charset:"utf-8"},{name:"viewport",content:c}],i=document.createDocumentFragment();s.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),c=parseInt(e.substring(1,3),16),s=parseInt(e.substring(3,5),16),i=parseInt(e.substring(5,7),16),p=Math.round(o*(1-r)+c*r),u=Math.round(n*(1-r)+s*r),l=Math.round(a*(1-r)+i*r);return p=("0"+(p||0).toString(16)).slice(-2),u=("0"+(u||0).toString(16)).slice(-2),l=("0"+(l||0).toString(16)).slice(-2),"#"+p+u+l};
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.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},p="";for(let t=0;t<i[e];t++)0==t&&(p+=o),1==t&&(p+=n),2==t&&(p+=a),3==t&&(p+=s),4==t&&(p+=c),t!=i[e]-1&&(p+=r);return p},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,p="";return c.forEach((function(t,r){if(-1!=e.indexOf(t.format)){let e="";0!=i&&(e=t.connect),p+=e+t.data,i++}})),p},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={},p=[];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]]&&p.push(e)}for(let t of p)u(t);function u(t){if(null!==c[t[n]]&&(t[s]=c[t[n]]),t[s])for(let e of t[s])u(e)}return p},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),p=Math.round(o*(1-r)+s*r),u=Math.round(n*(1-r)+c*r),l=Math.round(a*(1-r)+i*r);return p=("0"+(p||0).toString(16)).slice(-2),u=("0"+(u||0).toString(16)).slice(-2),l=("0"+(l||0).toString(16)).slice(-2),"#"+p+u+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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tools_dj",
3
- "version": "1.0.4",
3
+ "version": "1.0.8",
4
4
  "description": "dj tools 工具库",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",