tools_dj 1.0.98 → 3.0.3

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/README.md CHANGED
@@ -53,7 +53,7 @@ const http = new Request({
53
53
  is([1, 2, 3]); // "Array"
54
54
  is({}); // "Object"
55
55
  is("hello"); // "String"
56
- ```[README.md](README.md)
56
+ ```
57
57
 
58
58
  #### `is_empty(obj: any): boolean`
59
59
  判断值是否为空,支持所有数据类型
@@ -121,12 +121,6 @@ formatTime('2024-03-24', 'YYYY年MM月DD日'); // "2024年03月24日"
121
121
  formatTime(new Date(), 'YYYY-MM-DD week'); // "2024-03-24 周日"
122
122
  ```
123
123
 
124
- #### `getDaysBetween(date1: string, date2: string, negative?: boolean): number`
125
- 计算两个日期之间的天数
126
- ```typescript
127
- getDaysBetween('2024-01-01', '2024-01-05'); // 4
128
- ```
129
-
130
124
  #### `isDateInRange(date: string, startDate: string, endDate: string): boolean`
131
125
  判断日期是否在指定范围内
132
126
  ```typescript
@@ -366,14 +360,6 @@ treeStack(treeData, (node) => {
366
360
  });
367
361
  ```
368
362
 
369
- #### `treeRecursion(data: any[], callBack: Function, option?: object): void`
370
- 树递归循环返回子项
371
- ```typescript
372
- treeRecursion(treeData, (node) => {
373
- console.log('节点:', node);
374
- });
375
- ```
376
-
377
363
  #### `treeFind(data: any[], option?: object): any[]`
378
364
  树中查找节点
379
365
  - `option.cKey` - 子节点字段名,默认'children'
@@ -433,14 +419,6 @@ events.sort(compareDate('date', 'up')); // 按日期升序
433
419
 
434
420
  ### 函数工具
435
421
 
436
- #### `throttle1(func: Function, delay: number): Function`
437
- 节流函数(备选实现)
438
- ```typescript
439
- const throttled = throttle1(() => {
440
- console.log('执行');
441
- }, 1000);
442
- ```
443
-
444
422
  #### `fnRuntime(fn: Function, iterations?: number): void`
445
423
  测量函数执行时间
446
424
  - `iterations` - 迭代次数,默认1
@@ -761,4 +739,3 @@ serve方法参数:
761
739
  ## 许可证
762
740
 
763
741
  MIT License
764
-
package/lib/auth.js CHANGED
@@ -1 +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}};
1
+ class t{constructor(t){this.authList=[],this.authObj={},this.authList=t,new.target&&this.init()}init(){let t=this.authList.length;for(let h=0;h<t;h++){let t=1<<h,s=this.authList[h];this.authObj[s]=t}}add(t,h=[]){for(const s of h)t|=this.authObj[s];return t}del(t,h=[]){for(const s of h){t&=~this.authObj[s]}return t}andHave(t,h=[]){let s=!0;for(const i of h){if(!(t&this.authObj[i])){s=!1;break}}return s}orHave(t,h=[]){let s=!1;for(const i of h){if(t&this.authObj[i]){s=!0;break}}return s}getTxt(t){let h=[];for(const s of this.authList){t&this.authObj[s]&&h.push(s)}return h}}export{t as auth};
package/lib/clipboard.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.copyText=function(t){return e.__awaiter(this,void 0,void 0,(function*(){if(!t)return!1;try{return navigator.clipboard&&window.isSecureContext?(yield navigator.clipboard.writeText(t),!0):function(e){try{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-999999px",t.style.top="-999999px",document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange(0,99999);const r=document.execCommand("copy");return document.body.removeChild(t),!!r}catch(e){return console.error("降级复制方案失败:",e),!1}}(t)}catch(e){return console.error("复制到剪贴板失败:",e),!1}}))},exports.isClipboardSupported=function(){return!(!navigator.clipboard||!window.isSecureContext)},exports.readText=function(){return e.__awaiter(this,void 0,void 0,(function*(){try{if(navigator.clipboard&&window.isSecureContext)return yield navigator.clipboard.readText();throw new Error("当前环境不支持剪贴板读取")}catch(e){throw console.error("读取剪贴板失败:",e),e}}))};const e=require("tslib");
1
+ function t(t,e,n,o){return new(n||(n=Promise))(function(r,i){function c(t){try{a(o.next(t))}catch(t){i(t)}}function u(t){try{a(o.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(c,u)}a((o=o.apply(t,e||[])).next())})}function e(e){return t(this,void 0,void 0,function*(){if(!e)return!1;try{return navigator.clipboard&&window.isSecureContext?(yield navigator.clipboard.writeText(e),!0):function(t){try{const e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.left="-999999px",e.style.top="-999999px",document.body.appendChild(e),e.focus(),e.select(),e.setSelectionRange(0,99999);const n=document.execCommand("copy");return document.body.removeChild(e),!!n}catch(t){return console.error("降级复制方案失败:",t),!1}}(e)}catch(t){return console.error("复制到剪贴板失败:",t),!1}})}function n(){return!(!navigator.clipboard||!window.isSecureContext)}function o(){return t(this,void 0,void 0,function*(){try{if(navigator.clipboard&&window.isSecureContext)return yield navigator.clipboard.readText();throw new Error("当前环境不支持剪贴板读取")}catch(t){throw console.error("读取剪贴板失败:",t),t}})}"function"==typeof SuppressedError&&SuppressedError;export{e as copyText,n as isClipboardSupported,o as readText};
package/lib/data.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.getDeepData=function(t,i,r){if((0,e.is_empty)(t)||"Object"!=(0,e.is)(t)||(0,e.is_empty)(i))return r;const s=i.split(".");let n=t;for(const t of s){if((0,e.is_empty)(n)||"Object"!=(0,e.is)(n)||!(t in n))return r;n=n[t]}return void 0===n?r:n};const e=require("./index");
1
+ import{is_empty as t,is as r}from"./index.js";function n(n,o,e){if(t(n)||"Object"!=r(n)||t(o))return e;const i=o.split(".");let f=n;for(const n of i){if(t(f)||"Object"!=r(f)||!(n in f))return e;f=f[n]}return void 0===f?e:f}export{n as getDeepData};
package/lib/date.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.contrast=void 0,exports.carbon=r;const t=require("./index");class e{constructor(e){if("Date"!==(0,t.is)(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");this.date=e.getTime()}Gt(e){if("Date"!==(0,t.is)(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date>r}Lt(e){if("Date"!==(0,t.is)(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date<r}Eq(e){if("Date"!==(0,t.is)(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date==r}Ne(e){if("Date"!==(0,t.is)(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date!=r}Gte(e){if("Date"!==(0,t.is)(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date>=r}Lte(e){if("Date"!==(0,t.is)(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date<=r}Between(e,r){if("Date"!==(0,t.is)(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");if("Date"!==(0,t.is)(r))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let a=e.getTime(),i=r.getTime();return this.date>=a&&this.date<=i||this.date>=i&&this.date<=a}}function r(t){return new e(t)}exports.contrast=e,exports.default={carbon:r,contrast:e};
1
+ import{is as t}from"./index.js";class e{constructor(e){if("Date"!==t(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");this.date=e.getTime()}Gt(e){if("Date"!==t(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date>r}Lt(e){if("Date"!==t(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date<r}Eq(e){if("Date"!==t(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date==r}Ne(e){if("Date"!==t(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date!=r}Gte(e){if("Date"!==t(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date>=r}Lte(e){if("Date"!==t(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=e.getTime();return this.date<=r}Between(e,r){if("Date"!==t(e))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");if("Date"!==t(r))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let a=e.getTime(),i=r.getTime();return this.date>=a&&this.date<=i||this.date>=i&&this.date<=a}}function r(t){return new e(t)}var a={carbon:r,contrast:e};export{r as carbon,e as contrast,a as default};
package/lib/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { formatSizeOptions } from "./types";
3
3
  * content: 删除数组重复的元素
4
4
  * let newArr = del_repeat(Arr)
5
5
  */
6
- export declare function del_repeat(obj: any): any;
6
+ export declare function del_repeat(obj: any): any[];
7
7
  /** 2024-07-08 12:52 User: DJ
8
8
  * content: 格式化时间
9
9
  * 格式化参数format=[ year month day hour minute],type=- /
@@ -21,13 +21,6 @@ export declare function time_change(data: any): number;
21
21
  * @param option .weeks:{0:周一}
22
22
  */
23
23
  export declare function formatTime(time: any, format?: any, option?: any): any;
24
- /**
25
- * 计算两个日期之间的天数
26
- * date1 开始日期 yyyy-MM-dd
27
- * date2 结束日期 yyyy-MM-dd
28
- * 如果日期相同 返回一天 开始日期大于结束日期,返回0
29
- */
30
- export declare function getDaysBetween(date1: any, date2: any, negative?: any): number;
31
24
  /** 2024/8/5 13:40 User: DJ
32
25
  * content: 判断是否为空 为空返回true非空返回false
33
26
  * @param obj 传入一个值
@@ -60,7 +53,7 @@ export declare function is(obj: any): any;
60
53
  * 传入一个数组
61
54
  * return 一个数组出去
62
55
  */
63
- export declare function unique(obj: any): any;
56
+ export declare function unique(obj: any): false | any[];
64
57
  /** 2024-07-08 12:44 User: DJ
65
58
  * content: 输出数组对象的最后一个元素
66
59
  * 传入一个数组对象
@@ -74,7 +67,7 @@ export declare function first(obj: any): any;
74
67
  * return一个对象或是数组
75
68
  * 为空返回false
76
69
  */
77
- export declare function last(obj: any): false | undefined;
70
+ export declare function last(obj: any): any;
78
71
  /** 2022/7/15 16:45 User: DJ
79
72
  * content: 二维数组查找返回他所在的下标
80
73
  */
@@ -126,13 +119,6 @@ export declare function treeFor(data: any, callBack: any, option?: {}): void;
126
119
  * @param option //{cKey='children'}
127
120
  */
128
121
  export declare function treeStack(data: any, callBack: any, option?: {}): void;
129
- /** 2024/12/30 23:14 User: DJ
130
- * content: 树递归循环返回子项
131
- * @param data 数组
132
- * @param callBack 回调函数
133
- * @param option //{cKey='children'}
134
- */
135
- export declare function treeRecursion(data: any, callBack: any, option?: {}): void;
136
122
  /** 2024/12/30 23:14 User: DJ
137
123
  * content: 树解构
138
124
  * @param data 数组
@@ -203,12 +189,6 @@ export declare function randomNumber(min: any, max: any): any;
203
189
  * return bool
204
190
  */
205
191
  export declare function isDateInRange(date: any, startDate: any, endDate: any): boolean;
206
- /** 2023/8/9 14:39 User: DJ
207
- * content: 节流
208
- * 1.触发高频事件后,但在n秒内函数只会执行一次
209
- * 简单的说也就是一定时间内的无论点击多少次,都只会执行第一次,其余的直接return
210
- */
211
- export declare function throttle1<T extends any[]>(func: (...args: T) => void, delay: number): (...args: T) => void;
212
192
  /** 2024-07-08 12:35 User: DJ
213
193
  * content: 节流
214
194
  * 1.触发高频事件后,但在n秒内函数只会执行一次
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(){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}};
1
+ function t(t){const e=new Set,n=[];return t.forEach(function(t){const r=JSON.stringify(t);void 0===r||e.has(r)||(e.add(r),n.push(JSON.parse(r)))}),n}function e(t,e="day",n="-"){let r=t.getFullYear(),o=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getDate().toString().padStart(2,"0"),c=t.getHours().toString().padStart(2,"0"),l=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+=r),1==t&&(u+=o),2==t&&(u+=i),3==t&&(u+=c),4==t&&(u+=l),t!=a[e]-1&&(u+=n);return u}function n(t){return Date.parse(t)}function r(t,e="YYYY-MM-DD hh:mm:ss",n={}){try{t=t.replaceAll("-","/")}catch(t){}t=new Date(t);let r={0:"周日",1:"周一",2:"周二",3:"周三",4:"周四",5:"周五",6:"周六"},{weeks:o=r}=n,i=t.getFullYear(),c=(t.getMonth()+1).toString().padStart(2,"0"),l=t.getDate().toString().padStart(2,"0"),a=t.getHours().toString().padStart(2,"0"),u=t.getMinutes().toString().padStart(2,"0"),s=t.getSeconds().toString().padStart(2,"0"),f=o[t.getDay()],p=e;return[{format:"YYYY",data:i},{format:"yyyy",data:i},{format:"MM",data:c},{format:"DD",data:l},{format:"dd",data:l},{format:"hh",data:a},{format:"HH",data:a},{format:"mm",data:u},{format:"ss",data:s},{format:"week",data:f},{format:"time_slot",data:a>12?"下午":"上午"}].forEach(function(t,n){-1!=e.indexOf(t.format)&&(p=p.replace(t.format,""+t.data))}),p}function o(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 i(t,e,n){return t.substring(0,e)+n+t.substring(e+1)}function c(t,e={}){if(o(t))return"";{let{prefix:n="?"}=e,r=[],i=["",void 0,null];const c=(t,e="")=>{const n=Object.keys(t);for(const l of n){const n=t[l];if(i.includes(n))continue;let a=u(n),s=encodeURIComponent(l);if(o(e)||(s=`${e}[${s}]`),"Array"===a)for(const t of n)r.push(`${s}[]=${encodeURIComponent(t)}`);else if("Object"===a)c(n,s);else{let t=encodeURIComponent(n);r.push(`${s}=${t}`)}}};return c(t),r.length?n+r.join("&"):""}}function l(t){const e=t.indexOf("://");if(-1===e)return!1;return-1!==J(["http:","https:","ftp:","file:"],t.slice(0,e+1).toLowerCase())}function a(e,n){const r=Object.prototype.toString.call(e);return"Array"==r.slice(8,-1)?(e.push.apply(e,n),t(e)):"Object"==r.slice(8,-1)?Object.assign(e,n):void 0}function u(t){return Object.prototype.toString.call(t).slice(8,-1)}function s(e){if(0==o(e)){return t(e)}return!1}function f(t){if(0!=o(t))return!1;if("[object Object]"!==Object.prototype.toString.call(t))return t[0];for(const e of t)return e}function p(t){if(0!=o(t))return!1;if("[object Object]"!==Object.prototype.toString.call(t))return t[t.length-1];for(const e of t)return e}function d(t,e,n){return(t||[]).findIndex(t=>t[e]===n)}function h(t,e,n,r,o){try{return t.find(function(t){return t[e]==n})[r]=o,!0}catch(t){return!1}}function m(t,e,n){try{return t.find(function(t){return t[e]==n})}catch(t){return""}}function g(t,e,n,r){const o=e||"id",i=n||"parentId",c=r||"children",l=new Map,a=new Map,u=[];let s=t.length;for(let e=0;e<s;e++){let n=t[e];const r=n[i];l.has(r)||l.set(r,[]),a.set(n[o],n),l.get(r).push(n)}for(let e=0;e<s;e++){let n=t[e];const r=n[i];a.has(r)||u.push(n)}const f=[...u];for(;f.length>0;){const t=f.pop(),e=l.get(t[o]);e&&(t[c]=e,f.push(...e))}return u}function y(t,e={}){let{id:n="id",pKey:r="parentId",cKey:o="children",strict:i=!0,copy:c=!0}=e,l=[];return l=c?JSON.parse(JSON.stringify(t)):t,l.filter(t=>{const e=l.filter(e=>i?e[r]===t[n]:e[r]==t[n]);return e.length&&(t[o]=e),0===t[r]})}function b(t,e={}){let n=[],{cKey:r="children",copy:o=!0}=e,i=[...t];for(;i.length;){let t=i.pop();if(t[r])if(i.push(...t[r]),o){let e={},o=Object.keys(t),i=o.length;for(let n=0;n<i;n++)o[n]!=r&&(e[o[n]]=t[o[n]]);n.push(e)}else n.push(t)}return n}function S(t,e,n={}){let{cKey:r="children"}=n,i=[...t];for(;i.length;){let t=i.shift();o(t[r])?e&&e(t):i.push(...t[r])}}function O(t,e,n={}){let{cKey:r="children"}=n,i=[...t];for(;i.length;){let t=i.shift();o(t[r])?e&&e(t):i.push(...t[r])}}function w(t,e={}){let n=[],{cKey:r="children",key:o="id",value:i,copy:c=!0}=e,l=[...t];for(;l.length;){let t=l.pop();if(t[r]&&l.push(...t[r]),t[o]==i)if(c){let e={},o=Object.keys(t),i=o.length;for(let n=0;n<i;n++)o[n]!=r&&(e[o[n]]=t[o[n]]);n.push(e)}else n.push(t)}return n}function M(t,e){let n=function(t){for(var e=t.split(","),n=e[0].match(/:(.*?);/)[1],r=atob(e[1]),o=r.length,i=new Uint8Array(o);o--;)i[o]=r.charCodeAt(o);return new Blob([i],{type:n})}(t);return new File([n],e)}function j(t,e="up"){return function(n,r){return"up"==e?Date.parse(n[t])-Date.parse(r[t]):Date.parse(r[t])-Date.parse(n[t])}}function k(t,e="up"){return function(n,r){return"up"==e?n[t]-r[t]:r[t]-n[t]}}function v(t="",e=2,n="0",r=!1){let o="",i=(""+t).length;if(i>e&&1==r)return i;{let r=e-i;if(r>0)for(let t=0;t<r;t++)o+=n;return(o+t).slice(-1*e)}}function $(){var t,e,n,r,o;try{const i=navigator,c=i.userAgent||"",l=i.maxTouchPoints||0,a=Math.min((null===(t=window.screen)||void 0===t?void 0:t.width)||1/0,(null===(e=window.screen)||void 0===e?void 0:e.height)||1/0);return!!((null===(n=i.userAgentData)||void 0===n?void 0:n.mobile)||/Android.+Mobile|iPhone|iPod|Windows Phone|IEMobile|BlackBerry|webOS|Opera Mini|Mobile|Fennec/i.test(c)||/iPad|Tablet|PlayBook|Silk|Kindle|Nexus 7|Nexus 10|SM-T|Lenovo TB|Mi Pad/i.test(c)||/Android/i.test(c)&&!/Mobile/i.test(c)&&l>1||"MacIntel"===i.platform&&l>1||(null===(o=null===(r=window.matchMedia)||void 0===r?void 0:r.call(window,"(pointer: coarse)"))||void 0===o?void 0:o.matches)&&l>1&&a<=1024)}catch(t){return!1}}function D(t){if(!o(t)){let e=[];document.head.childNodes.forEach(n=>{switch(n.tagName){case"META":e.push(n);break;case"TITLE":document.title=t.title||"模板测试"}});const n=document.createElement("META");let r=1,o="yes";t.cZoom&&($()?t.cZoom.mobile&&(r=t.cZoom.mobile):t.cZoom.pc&&(r=t.cZoom.pc),t.cZoom.isScale&&(o=t.cZoom.isScale));let i=`width=device-width,minimum-scale=${r},initial-scale=${r},user-scalable=${o}`;"no"==o&&(i+=`,maximum-scale=${r}`);const c=[{charset:"utf-8"},{name:"viewport",content:i}],l=document.createDocumentFragment();c.forEach(t=>{l.append(n.cloneNode()),Object.entries(t).forEach(t=>{l.lastChild.setAttribute(t[0],t[1])})}),e.forEach(t=>{document.head.removeChild(t)}),document.head.prepend(l)}}function A(t,e,n){n=Math.max(Math.min(Number(n),1),0);let r=parseInt(t.substring(1,3),16),o=parseInt(t.substring(3,5),16),i=parseInt(t.substring(5,7),16),c=parseInt(e.substring(1,3),16),l=parseInt(e.substring(3,5),16),a=parseInt(e.substring(5,7),16),u=Math.round(r*(1-n)+c*n),s=Math.round(o*(1-n)+l*n),f=Math.round(i*(1-n)+a*n);return u=("0"+(u||0).toString(16)).slice(-2),s=("0"+(s||0).toString(16)).slice(-2),f=("0"+(f||0).toString(16)).slice(-2),"#"+u+s+f}function x(t,e,n){t.splice(n,0,t.splice(e,1)[0])}function N(t,e,n){let r=[].concat(t);return r.splice(n,0,r.splice(e,1)[0]),r}function T(t,e,n){t.splice(e,0,n)}function B(){return"rgba("+I(100,255)+","+I(100,255)+","+I(100,255)+",1)"}function I(t,e){return Math.round(Math.random()*(e-t))+t}function K(t,e,n){const r=new Date(t),o=new Date(e),i=new Date(n);return r>=o&&r<=i}function E(t,e=1e3,n=!0){let r;const o=(...o)=>{r&&clearTimeout(r),n?(r||t(...o),r=setTimeout(function(){r=null},e)):r=setTimeout(()=>{t(...o)},e)};return o.cancel=()=>{r&&(clearTimeout(r),r=null)},o}function F(t,e){let n;const r=function(...r){clearTimeout(n),n=setTimeout(()=>{t(...r)},e)};return r.cancel=()=>{n&&(clearTimeout(n),n=null)},r}function Y(t,e="type"){return t.reduce((t,n)=>{const r=n[e];return t[r]||(t[r]=[]),t[r].push(n),t},{})}function P(t,e=1){const n=t.toString(),r=n.indexOf(".");if(-1===r)return t;const o=n.slice(0,r+1+e);return parseFloat(o)}function Z(t,e=""){try{if(o(e)){let e=Object.keys(t);for(let n of e)delete t[n]}else if("Array"==u(e))for(const n of e)delete t[n];else delete t[e]}catch(t){}}function C(t){try{let e=Object.keys(t);for(let n of e)"Number"!=u(t[n])&&o(t[n])&&delete t[n]}catch(t){}}function U(t){let e=t+"";const n=Number(e);return!isNaN(n)&&e.length>0}function H(t,e=37.5){let n=t;if(U(t)||-1!=t.indexOf("px")){n=(parseFloat(t)/e).toFixed(2)+"rem"}return n}function J(t=[],e,n=!1){if(n)return t.indexOf(e);{let n=-1,r=t.length;for(let o=0;o<r;o++)t[o]==e&&(n=o);return n}}function L(t,e=1){let n=0;for(let r=0;r<e;r++){const e=performance.now();t();n+=performance.now()-e}const r=n/e;console.log(`平均执行时间 ${e} 次数: ${r.toFixed(6)} ms`)}function R(t,e=!0){let n=new FormData;return function t(r,o="",i={}){let{level:c=0,pk:l="",type:a=""}=i,s=u(r);if(-1==["Array","Object"].indexOf(s)){if(null!=r){let t=o;e&&2==c&&"Array"==a&&(t=l),n.append(t,r)}}else if("Array"==s){let e=r.length;for(let n=0;n<e;n++){let e=`${o}[${n}]`,i={level:c+1,type:"Array",pk:o};t(r[n],e,i)}}else if("Object"==s){let e=Object.keys(r),n={level:c+1,type:"Object",pk:o};for(const i of e)t(r[i],`${o}${""==o?"":"."}${i}`,n)}}(t),n}function z(t,e={}){let{decimals:n=2,sizes:r=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],perUnit:o=1024}=e;if(0===t)return"0"+r[0];const i=n<0?0:n,c=Math.floor(Math.log(t)/Math.log(o));return parseFloat((t/Math.pow(o,c)).toFixed(i))+" "+r[c]}function G(t,e={}){let{idKey:n="id",pidKey:r="pid",rKey:o="rgt",lKey:i="lft",levelKey:c="level"}=e;const l={},a={};let u=t.length;for(let e=0;e<u;e++){let o=t[e],i=o[r],c=o[n];l[c]=Object.assign({},o),a[i]||(a[i]=[]),a[i].push(c)}const s=Object.keys(a),f=Object.keys(l),p=new Set(f);let d=[];s.filter(t=>{p.has(t)||d.push(...a[t])});let h=1;const m=[],g=[];for(let t=d.length-1;t>=0;t--)m.push({[n]:d[t],[c]:1,processed:!1});for(;m.length>0;){const t=m.pop(),e=l[t[n]];if(t.processed)e[o]=h++,g.push(e);else if(e[i]=h++,e[c]=t[c],m.push({[n]:t[n],[c]:t[c],processed:!0}),a[t[n]])for(let e=a[t[n]].length-1;e>=0;e--)m.push({[n]:a[t[n]][e],[c]:t[c]+1,processed:!1})}return g}Number.prototype.repair=function(t=2){let e="";for(let n=1;n<t;n++)e+="0";return(e+this).slice(-1*t)};const W=(t,e={})=>{const{context:n=null,ttl:r=0}=e,o=new Map,i=t=>{if("object"==typeof t&&null!==t){if(Array.isArray(t))return`[${t.map(i).join(",")}]`;return`{${Object.keys(t).sort().map(e=>`${e}:${i(t[e])}`).join(",")}}`}return String(t)};return(...e)=>{const c=i(e),l=o.get(c);if(l&&(0===r||Date.now()-l.timestamp<=r))return l.value;const a=n?t.apply(n,e):t(...e);return o.set(c,{value:a,timestamp:Date.now()}),a}};function _(t,e={}){let{callback:n=null,callType:r="",afterBack:o=null}=e,i={};function c(t,e){let i=Object.keys(t);for(const l of i){let i=u(t[l]);n&&i==r?e[l]=n(t,l):"Object"===i?(e[l]||(e[l]={}),c(t[l],e[l])):e[l]=t[l],o&&o(e,l)}}for(const e of t)c(e,i);return i}export{T as arrSet,G as arrToAryTree,y as arrToTree,Y as arrayGroup,M as base64Img,A as colorMix,k as compare,j as compareDate,F as debounce,Z as delObj,C as delObjEmptyKey,t as del_repeat,d as findByIndex,f as first,L as fnRuntime,e as formatDate,z as formatSize,r as formatTime,g as handleTree,J as inArr,u as is,K as isDateInRange,l as isLink,$ as isMobile,U as isNum,o as is_empty,p as last,W as memoize,a as merge,_ as mergeObj,P as numberFixed,v as numberRepair,R as objToFormData,H as pxToRem,N as rArrMove,B as randomColor,I as randomNumber,i as repalce,x as sArrMove,m as selectObjData,D as setMeta,h as setObjData,E as throttle,n as time_change,c as toGetQuery,w as treeFind,S as treeFor,O as treeStack,b as treeToArr,s as unique};
package/lib/msg.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.pageSend=o,exports.pageRead=s;const e=require("tslib");let t=new BroadcastChannel("msgCenter");const n=e.__importDefault(require("mitt")),a=(0,n.default)();function o(e,n){t.postMessage({type:e,data:n})}function s(e,n){t.onmessage=({data:t})=>{e==t.type&&n&&n(t.data)}}exports.default={pageSend:o,pageRead:s,storeRead:function(e,t){e.$subscribe(((e,n)=>{t&&t(n)}))},busSend:function(e,t){a.emit(e,t)},busRead:function(e,t){t&&a.on(e,t)},mitt:n.default,busOff:function(e,t){a.off(e,t)},busDown:function(e){a.off(e)},bus:a};
1
+ function n(n){return{all:n=n||new Map,on:function(t,e){var a=n.get(t);a?a.push(e):n.set(t,[e])},off:function(t,e){var a=n.get(t);a&&(e?a.splice(a.indexOf(e)>>>0,1):n.set(t,[]))},emit:function(t,e){var a=n.get(t);a&&a.slice().map(function(n){n(e)}),(a=n.get("*"))&&a.slice().map(function(n){n(t,e)})}}}let t=new BroadcastChannel("msgCenter");const e=n();function a(n,e){t.postMessage({type:n,data:e})}function o(n,e){t.onmessage=({data:t})=>{n==t.type&&e&&e(t.data)}}var f={pageSend:a,pageRead:o,storeRead:function(n,t){n.$subscribe((n,e)=>{t&&t(e)})},busSend:function(n,t){e.emit(n,t)},busRead:function(n,t){t&&e.on(n,t)},mitt:n,busOff:function(n,t){e.off(n,t)},busDown:function(n){e.off(n)},bus:e};export{f as default,o as pageRead,a as pageSend};
package/lib/request.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});const e=require("./index");exports.default=class{constructor(e={},t={}){this.options={},this.conf={baseUrl:"",timeout:6e3},this.options=e,Object.assign(this.conf,t)}serve(t="",o={},c={}){const n=(0,e.mergeObj)([this.conf,c]);let r=(0,e.mergeObj)([this.options,o],{callback:function(e,t){if(e[t])return e[t](e,t)},callType:"Function",afterBack:function(t,o){"Undefined"===(0,e.is)(t[o])&&delete t[o]}});const{timeout:s=6e3,baseUrl:i}=n;(0,e.isLink)(t)||(t=i+t);const a=new AbortController,l=a.signal;n.abController&&n.abController(a),n.beforeBack&&n.beforeBack(r);const b=setTimeout((()=>{a.abort()}),s);return fetch(t,Object.assign(Object.assign({},r),{signal:l})).then((e=>(clearTimeout(b),n.callback?n.callback(e,n):e))).catch((e=>{throw n.errBack&&n.errBack(e),clearTimeout(b),e}))}};
1
+ import{mergeObj as t,isLink as e,is as o}from"./index.js";class c{constructor(t={},e={}){this.options={},this.conf={baseUrl:"",timeout:6e3},this.options=t,Object.assign(this.conf,e)}serve(c="",n={},r={}){const s=t([this.conf,r]);let a=t([this.options,n],{callback:function(t,e){if(t[e])return t[e](t,e)},callType:"Function",afterBack:function(t,e){"Undefined"===o(t[e])&&delete t[e]}});const{timeout:i=6e3,baseUrl:l}=s;e(c)||(c=l+c);const b=new AbortController,f=b.signal;s.abController&&s.abController(b),s.beforeBack&&s.beforeBack(a);const u=setTimeout(()=>{b.abort()},i);return fetch(c,Object.assign(Object.assign({},a),{signal:f})).then(t=>(clearTimeout(u),s.callback?s.callback(t,s):t)).catch(t=>{throw s.errBack&&s.errBack(t),clearTimeout(u),t})}}export{c as default};
package/lib/types.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});
1
+
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "tools_dj",
3
- "version": "1.0.98",
3
+ "version": "3.0.3",
4
4
  "description": "dj tools 工具库",
5
+ "type": "module",
5
6
  "main": "./lib/index.js",
6
7
  "module": "./lib/index.js",
7
8
  "types": "./lib/index.d.ts",
@@ -17,14 +18,14 @@
17
18
  "tool"
18
19
  ],
19
20
  "devDependencies": {
20
- "@rollup/plugin-alias": "^5.0.0",
21
- "@rollup/plugin-node-resolve": "^15.0.2",
22
- "@rollup/plugin-typescript": "^11.1.0",
23
- "rollup": "^2.79.1",
21
+ "@rollup/plugin-alias": "^5.1.1",
22
+ "@rollup/plugin-node-resolve": "^15.3.1",
23
+ "@rollup/plugin-typescript": "^11.1.6",
24
+ "glob": "^11.1.0",
25
+ "rollup": "^2.80.0",
24
26
  "rollup-plugin-terser": "^7.0.2",
25
- "tslib": "^2.5.0",
26
- "typescript": "^5.0.3",
27
- "glob": "^11.0.1"
27
+ "tslib": "^2.8.1",
28
+ "typescript": "^5.9.3"
28
29
  },
29
30
  "files": [
30
31
  "lib"