tools_dj 1.0.27 → 1.0.31

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
@@ -186,14 +186,18 @@ export declare function numberFixed(number: any, decimalPlaces?: any): any;
186
186
  /** 2024-07-10 9:10 User: DJ
187
187
  * content: 删除对象中的所有属性
188
188
  * @param obj 需要删除的对象
189
- * @param key 可选参数 只指定删除某个键
189
+ * @param keys 可选参数 只指定删除某个键或者一个数组
190
190
  */
191
- export declare function delObj(obj: any, key?: any): void;
191
+ export declare function delObj(obj: any, keys?: any): void;
192
192
  /** 2024-07-10 9:20 User: DJ
193
193
  * content: 删除对象中的空属性
194
194
  * @param obj 需要删除的对象
195
195
  */
196
196
  export declare function delObjEmptyKey(obj: any): void;
197
+ /** 2024/8/5 17:01 User: DJ
198
+ * content: 判断是否是数字包括字符型
199
+ */
200
+ export declare function isNum(str: any): boolean;
197
201
  /** 2024/8/5 13:33 User: DJ
198
202
  * content: px 转rem
199
203
  * @param pxValue 需要转的数据
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}Object.defineProperty(exports,"__esModule",{value:!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"),a=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0"),s={year:1,month:2,day:3,hour:4,minute:5},u="";for(let t=0;t<s[e];t++)0==t&&(u+=n),1==t&&(u+=o),2==t&&(u+=c),3==t&&(u+=a),4==t&&(u+=i),t!=s[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(),a=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getDate().toString().padStart(2,"0"),s=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=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:a},{group:1,connect:n,format:"DD",data:i},{group:1,connect:n,format:"dd",data:i},{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 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 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){let o={id:e||"id",parentId:r||"parentId",childrenList:n||"children"};var c={},a={},i=[];for(let e of t){let t=e[o.parentId];null==c[t]&&(c[t]=[]),a[e[o.id]]=e,c[t].push(e)}for(let e of t){null==a[e[o.parentId]]&&i.push(e)}for(let t of i)s(t);function s(t){if(null!==c[t[o.id]]&&(t[o.childrenList]=c[t[o.id]]),t[o.childrenList])for(let e of t[o.childrenList])s(e)}return i},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 a=`width=device-width,minimum-scale=${o},initial-scale=${o},user-scalable=${c}`;"no"==c&&(a+=`,maximum-scale=${o}`);const i=[{charset:"utf-8"},{name:"viewport",content:a}],s=document.createDocumentFragment();i.forEach((t=>{s.append(r.cloneNode()),Object.entries(t).forEach((t=>{s.lastChild.setAttribute(t[0],t[1])}))})),e.forEach((t=>{document.head.removeChild(t)})),document.head.prepend(s)}},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),a=parseInt(e.substring(1,3),16),i=parseInt(e.substring(3,5),16),s=parseInt(e.substring(5,7),16),u=Math.round(n*(1-r)+a*r),l=Math.round(o*(1-r)+i*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(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(),a=c-n;clearTimeout(r),a>=e?(t(...o),n=c):r=setTimeout((()=>{t(...o),n=Date.now()}),e-a)}},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,r=""){try{if(e(r)){let e=Object.keys(t);for(let r of e)delete t[r]}else delete t[r]}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.pxToRem=function(t,e=37.5){let n=t;if("Number"==r(t)||-1!=t.indexOf("px")){n=(parseFloat(t)/e).toFixed(2)+"rem"}return n},Number.prototype.repair=function(t=2){let e="";for(let r=1;r<t;r++)e+="0";return(e+this).slice(-1*t)};
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.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"),a=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0"),s={year:1,month:2,day:3,hour:4,minute:5},u="";for(let t=0;t<s[e];t++)0==t&&(u+=n),1==t&&(u+=o),2==t&&(u+=c),3==t&&(u+=a),4==t&&(u+=i),t!=s[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(),a=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getDate().toString().padStart(2,"0"),s=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=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:a},{group:1,connect:n,format:"DD",data:i},{group:1,connect:n,format:"dd",data:i},{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 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 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){let o={id:e||"id",parentId:r||"parentId",childrenList:n||"children"};var c={},a={},i=[];for(let e of t){let t=e[o.parentId];null==c[t]&&(c[t]=[]),a[e[o.id]]=e,c[t].push(e)}for(let e of t){null==a[e[o.parentId]]&&i.push(e)}for(let t of i)s(t);function s(t){if(null!==c[t[o.id]]&&(t[o.childrenList]=c[t[o.id]]),t[o.childrenList])for(let e of t[o.childrenList])s(e)}return i},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 a=`width=device-width,minimum-scale=${o},initial-scale=${o},user-scalable=${c}`;"no"==c&&(a+=`,maximum-scale=${o}`);const i=[{charset:"utf-8"},{name:"viewport",content:a}],s=document.createDocumentFragment();i.forEach((t=>{s.append(r.cloneNode()),Object.entries(t).forEach((t=>{s.lastChild.setAttribute(t[0],t[1])}))})),e.forEach((t=>{document.head.removeChild(t)})),document.head.prepend(s)}},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),a=parseInt(e.substring(1,3),16),i=parseInt(e.substring(3,5),16),s=parseInt(e.substring(5,7),16),u=Math.round(n*(1-r)+a*r),l=Math.round(o*(1-r)+i*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(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(),a=c-n;clearTimeout(r),a>=e?(t(...o),n=c):r=setTimeout((()=>{t(...o),n=Date.now()}),e-a)}},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},Number.prototype.repair=function(t=2){let e="";for(let r=1;r<t;r++)e+="0";return(e+this).slice(-1*t)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tools_dj",
3
- "version": "1.0.27",
3
+ "version": "1.0.31",
4
4
  "description": "dj tools 工具库",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",