tools_dj 1.0.23 → 1.0.27
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/LICENCE.md +23 -23
- package/README.md +12 -12
- package/lib/index.d.ts +21 -0
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/LICENCE.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
The HDJ.
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Michael Mclaughlin
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
a copy of this software and associated documentation files (the
|
|
7
|
-
'Software'), to deal in the Software without restriction, including
|
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
-
the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
|
|
1
|
+
The HDJ.
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Michael Mclaughlin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# 工具库模板
|
|
2
|
-
|
|
3
|
-
## 介绍
|
|
4
|
-
tools工具库
|
|
5
|
-
后期可以直接安装和修改
|
|
6
|
-
|
|
7
|
-
## 安装
|
|
8
|
-
npm i tools_dj
|
|
9
|
-
|
|
10
|
-
## 使用
|
|
11
|
-
import {方法} from "tools_dj";
|
|
12
|
-
|
|
1
|
+
# 工具库模板
|
|
2
|
+
|
|
3
|
+
## 介绍
|
|
4
|
+
tools工具库
|
|
5
|
+
后期可以直接安装和修改
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
npm i tools_dj
|
|
9
|
+
|
|
10
|
+
## 使用
|
|
11
|
+
import {方法} from "tools_dj";
|
|
12
|
+
|
package/lib/index.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ export declare function formatTime(time: any, format?: string, type?: any): stri
|
|
|
27
27
|
* 如果日期相同 返回一天 开始日期大于结束日期,返回0
|
|
28
28
|
*/
|
|
29
29
|
export declare function getDaysBetween(date1: any, date2: any, negative?: any): number;
|
|
30
|
+
/** 2024/8/5 13:40 User: DJ
|
|
31
|
+
* content: 判断是否为空 为空返回true非空返回false
|
|
32
|
+
* @param obj 传入一个值
|
|
33
|
+
*/
|
|
30
34
|
export declare function is_empty(obj: any): boolean;
|
|
31
35
|
export declare function repalce(str: any, index: any, char: any): any;
|
|
32
36
|
export declare function param(data: any, isPrefix?: boolean): string | false;
|
|
@@ -179,3 +183,20 @@ export declare function arrayGroup(arr: any, groupKey?: string): any;
|
|
|
179
183
|
* @param decimalPlaces 保留多少位默认为1
|
|
180
184
|
*/
|
|
181
185
|
export declare function numberFixed(number: any, decimalPlaces?: any): any;
|
|
186
|
+
/** 2024-07-10 9:10 User: DJ
|
|
187
|
+
* content: 删除对象中的所有属性
|
|
188
|
+
* @param obj 需要删除的对象
|
|
189
|
+
* @param key 可选参数 只指定删除某个键
|
|
190
|
+
*/
|
|
191
|
+
export declare function delObj(obj: any, key?: any): void;
|
|
192
|
+
/** 2024-07-10 9:20 User: DJ
|
|
193
|
+
* content: 删除对象中的空属性
|
|
194
|
+
* @param obj 需要删除的对象
|
|
195
|
+
*/
|
|
196
|
+
export declare function delObjEmptyKey(obj: any): void;
|
|
197
|
+
/** 2024/8/5 13:33 User: DJ
|
|
198
|
+
* content: px 转rem
|
|
199
|
+
* @param pxValue 需要转的数据
|
|
200
|
+
* @param baseRem 基础值默认37.5
|
|
201
|
+
*/
|
|
202
|
+
export declare function pxToRem(pxValue: any, baseRem?: 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(t){return Object.prototype.toString.call(t).slice(8,-1)}function
|
|
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)};
|