fish-helper 0.0.56 → 0.0.58
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 +21 -21
- package/dist/cjs/index.js +1 -1
- package/dist/es/index.js +1 -1
- package/dist/types/index.d.ts +24 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,24 +6,24 @@ npm install fish-helper
|
|
|
6
6
|
const helper = require("fish-helper");
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
| Method
|
|
10
|
-
|
|
|
11
|
-
| `add(hour, start)`
|
|
12
|
-
| `offset_time(date, type)`
|
|
13
|
-
| `before_lt_hour(date, hour)`
|
|
14
|
-
| `before_gt_hour(date, hour)`
|
|
15
|
-
| `after_lt_hour(date, hour)`
|
|
16
|
-
| `after_gt_hour(date, hour)`
|
|
17
|
-
| `is_current_year(date)`
|
|
18
|
-
| `get_time_obj(date)`
|
|
19
|
-
| `format_count({num, divide, suffix, show_suffix_always})`
|
|
20
|
-
| `format_num2date(timestamp)`
|
|
21
|
-
| `count_down(date, fn)`
|
|
22
|
-
| `count_down_by_remain_seconds(fn, seconds)`
|
|
23
|
-
| `format_thousandth(num)`
|
|
24
|
-
| `is_empty(data)`
|
|
25
|
-
| `poll(fn, minute)`
|
|
26
|
-
| `is_equal(a, b, exact)`
|
|
27
|
-
| contains(largeRangeData, smallRangeData, exact)
|
|
28
|
-
| `sleep(ms)`
|
|
29
|
-
| `
|
|
9
|
+
| Method | Description |
|
|
10
|
+
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| `add(hour, start)` | Add hour from start date, return timestamp. |
|
|
12
|
+
| `offset_time(date, type)` | The time difference (absolute value), returns the corresponding string. |
|
|
13
|
+
| `before_lt_hour(date, hour)` | The date is less than now, and the date is less than hour from now. |
|
|
14
|
+
| `before_gt_hour(date, hour)` | The date is less than now, and the date is greater than hour from now. |
|
|
15
|
+
| `after_lt_hour(date, hour)` | The date is greater than now, and the date is less than hour from now. |
|
|
16
|
+
| `after_gt_hour(date, hour)` | The date is greater than now, and the date is greater than hour from now. |
|
|
17
|
+
| `is_current_year(date)` | Return boolean. |
|
|
18
|
+
| `get_time_obj(date)` | Return object that includes keys: year, month, day, hour, minute, seconds, day_of_week. |
|
|
19
|
+
| `format_count({num, divide, suffix, show_suffix_always})` | Return num or string or 0. |
|
|
20
|
+
| `format_num2date(timestamp)` | Convert time to object; return object that includes keys: day, hour, minute, seconds. |
|
|
21
|
+
| `count_down(date, fn)` | End time countdown, end time can be passed in by itself; fn is a callback function that takes a remaining time argument; return a function to stop the timer. |
|
|
22
|
+
| `count_down_by_remain_seconds(fn, seconds)` | 60-second countdown. Time can pass by itself. |
|
|
23
|
+
| `format_thousandth(num)` | Format the data as a string with thousands of bits. |
|
|
24
|
+
| `is_empty(data)` | Determines whether the data is empty. |
|
|
25
|
+
| `poll(fn, minute)` | Execute fn function every minute, return function to stop the fn. |
|
|
26
|
+
| `is_equal(a, b, exact)` | Return boolean, compare a and b; a and b are any type of data. |
|
|
27
|
+
| contains(largeRangeData, smallRangeData, exact) | Return boolean. |
|
|
28
|
+
| `sleep(ms)` | Suspend |
|
|
29
|
+
| `checkPattern({likeStr, str, separator, symbol, caseSensitive})` | Return boolean. Check if str matches likeStr pattern. |
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(t,e,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(t):s?s.value:e.get(t)}function e(t,e,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(t,r):i?i.value=r:e.set(t,r),r}var r,s,i,n,l,a,o,h,u,c,f,d,m;Object.defineProperty(exports,"__esModule",{value:!0}),"function"==typeof SuppressedError&&SuppressedError;const _=()=>null;r=new WeakMap,s=new WeakMap,i=new WeakMap,n=new WeakMap,l=new WeakMap,a=new WeakMap,o=new WeakMap,h=new WeakMap,u=new WeakMap,c=new WeakMap,f=new WeakMap,d=new WeakMap,m=new WeakMap;const p=new class{constructor(){r.set(this,1e3),s.set(this,36e5),i.set(this,null),n.set(this,null),l.set(this,t=>Object.prototype.toString.call(t).slice(8,-1)),a.set(this,t=>{if(!t)return Date.now();let e=null;e="string"==typeof t?t.replace(/(\-|\_)/g,"/"):new Date(t);let r=new Date(e);return"Invalid Date"===r.toString()&&(r=new Date(t)),r.getTime()}),o.set(this,e=>"Function"===t(this,l,"f").call(this,e)),h.set(this,e=>"Array"===t(this,l,"f").call(this,e)),u.set(this,e=>"Object"===t(this,l,"f").call(this,e)),c.set(this,t=>String(t).padStart(2,"0")),f.set(this,({date:e,hour:r=1,type:i="before_lt_hour"})=>{let n=t(this,a,"f").call(this,e);const l=new Date(n).getTime(),o=Date.now(),h=l<o,u=l>o;return"before_lt_hour"===i?h&&l+t(this,s,"f")*r>o:"before_gt_hour"===i?h&&l+t(this,s,"f")*r<o:"after_lt_hour"===i?u&&o+t(this,s,"f")*r>l:"after_gt_hour"===i&&(u&&o+t(this,s,"f")*r<l)}),this.offset_time=(e,r="minute")=>{const s=Math.abs(Date.now()-t(this,a,"f").call(this,e)),i=this.format_num2date(s);return"day"===r?t(this,c,"f").call(this,i.day):"hour"===r?t(this,c,"f").call(this,i.hour):"minute"===r?t(this,c,"f").call(this,i.minute):"second"===r?t(this,c,"f").call(this,i.seconds):"The second parameter has an error"},d.set(this,(s=0,i=_,l=t(this,r,"f"),a=0,o=Date.now())=>{if(s<=0)return clearTimeout(t(this,n,"f")),void e(this,n,null,"f");clearTimeout(t(this,n,"f")),e(this,n,setTimeout(()=>{a+=1,s-=t(this,r,"f");let e=this.format_timestamp_to_day_hour_minute_second(s);i({remain:s,obj:e});const n=Date.now()-(o+a*t(this,r,"f"));let l=t(this,r,"f")-n;l<0&&(l=0),t(this,d,"f").call(this,s,i,l,a,o)},l),"f")}),m.set(this,(s=0,n=_,l=t(this,r,"f"),a=0,o=Date.now())=>{if(s<=0)return clearTimeout(t(this,i,"f")),void e(this,i,null,"f");clearTimeout(t(this,i,"f")),e(this,i,setTimeout(()=>{a+=1,s-=t(this,r,"f");let e=this.format_num2date(s);n({remain:s,obj:e});const i=Date.now()-(o+a*t(this,r,"f"));let l=t(this,r,"f")-i;l<0&&(l=0),t(this,m,"f").call(this,s,n,l,a,o)},l),"f")}),this.sleep=t=>new Promise(e=>setTimeout(e,t)),this.roxFormatThousandth=(t,e="万")=>t<1e4?t:(Math.floor(t/1e3)/10).toFixed(1)+e,this.chunk=(t,e,r=!1)=>{if(!Array.isArray(t)||e<=0)return[];const s=[];for(let i=0;i<t.length;i+=e){const n=t.slice(i,i+e);r?n.length===e&&s.push(n):s.push(n)}return s},this.debounce=(t,e=200,r=!1)=>{let s,i=null;return function(...n){const l=this,a=r&&!i;return i&&clearTimeout(i),i=setTimeout(()=>{i=null,r||(s=t.apply(l,n))},e),a&&(s=t.apply(l,n)),s}},this.flatten=(t,e=!1)=>{let r=[];return t.forEach(t=>{e&&Array.isArray(t)?r=r.concat(this.flatten(t,e)):r.push(t)}),r},this.safeRequest=(t,e)=>t&&t.then?t.catch?t.then(t=>[null,t]).catch(t=>(e&&Object.assign(t,e),[t,void 0])):t.then(t=>[null,t]):Promise.resolve([null,t]),this.checkPattern=t=>{const{str:e,likeStr:r,separator:s="-",caseSensitive:i=!1,symbol:n=""}=t,l=(r||"").split(s),a=(e||"").split(s);return l.every((t,e)=>t===n||(i?t===a[e]:a[e]&&t.toLowerCase()===a[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:s=[],skuArrField:i,checkedIndexArr:n=[],combineSkuArr:l=[],disabledArr:a=[],combineSeparator:o="-",combineSkuField:h="id"}=t;for(let t=0;t<s.length;t++){const u=i?(null===(e=s[t])||void 0===e?void 0:e[i])||[]:s[t]||[];Array.isArray(r[t])||(r[t]=[]);for(let e=0;e<u.length;e++){const s=n.slice(0,t),i=n.slice(t+1),u=s.concat(e).concat(i).join(o),c=l.filter(t=>this.checkPattern({str:t[h],likeStr:u,separator:o})),f=a.map(t=>{const{field:e,disabledFun:r,disabledFieldValue:s}=t,i=c.some(t=>r(t));return{[e]:i?s:!s}}).reduce((t,e)=>Object.assign(Object.assign({},t),e),{});r[t][e]=f}}return r}}before_lt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"before_lt_hour"})}before_gt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"before_gt_hour"})}after_lt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"after_lt_hour"})}after_gt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"after_gt_hour"})}is_current_year(e){const r=t(this,a,"f").call(this,e);return(new Date).getFullYear()===new Date(r).getFullYear()}get_time_obj(e){const r=t(this,a,"f").call(this,e),s=new Date(r),i=t(this,c,"f").call(this,s.getMonth()+1),n=t(this,c,"f").call(this,s.getDate()),l=t(this,c,"f").call(this,s.getHours()),o=t(this,c,"f").call(this,s.getMinutes()),h=t(this,c,"f").call(this,s.getSeconds());return{year:String(s.getFullYear()),month:i,day:n,hour:l,minute:o,seconds:h,day_of_week:String(s.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:s="万",show_suffix_always:i=!1}){if(!t)return 0;if(r<=0||e<0)return i?`${t} ${s}`:t;const n=parseFloat(t);if(n<=0)return i?`${n} ${s}`:n;if(n>0&&n<r)return i?`${n} ${s}`:n;const[l,a]=(n/r).toFixed(e).split(".");return a&&0!==parseFloat(a)?`${l}.${a} ${s}`:`${l} ${s}`}format_num2date(e=Date.now()){const r=parseInt(e/1e3/60/60/24%24),s=parseInt(e/1e3/60/60%24),i=parseInt(e/1e3/60%60),n=parseInt(e/1e3%60);return{day:t(this,c,"f").call(this,r),hour:t(this,c,"f").call(this,s),minute:t(this,c,"f").call(this,i),seconds:t(this,c,"f").call(this,n)}}count_down_by_remain_seconds(t=_,e=60){let r;clearTimeout(r);let s=1e3*e,i=this.format_num2date(s),n={remain:s,obj:i};t(n);let l=this;return function t(e=0,a=_,o=1e3,h=0,u=Date.now()){if(e<=0)return clearTimeout(r),l=null,r=null,s=null,i=null,n=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(r),r=setTimeout(()=>{h+=1,e-=1e3;let r=l.format_num2date(e);a({remain:e,obj:r});let s=1e3-(Date.now()-(u+1e3*h));s<0&&(s=0),t(e,a,s,h,u)},o)}(s,t,1e3),()=>{clearTimeout(r),l=null,r=null,s=null,i=null,n=null}}format_timestamp_to_day_hour_minute_second(e=Date.now()){const r=Math.floor(e/864e5),s=Math.floor(e%864e5/36e5),i=Math.floor(e%36e5/6e4),n=Math.floor(e%6e4/1e3);return{day:t(this,c,"f").call(this,r),hour:t(this,c,"f").call(this,s),minute:t(this,c,"f").call(this,i),seconds:t(this,c,"f").call(this,n)}}count_down(e=Date.now(),r=_){let s;clearTimeout(s);let i=this,n=t(this,a,"f").call(this,e),l=n-Date.now(),o=this.format_timestamp_to_day_hour_minute_second(l),h={remain:l,obj:o};return r(h),function t(e=0,r=_,a=1e3,u=0,c=Date.now()){if(e<=0)return clearTimeout(s),s=null,i=null,n=null,l=null,o=null,h=null,void r({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(s),s=setTimeout(()=>{u+=1,e-=1e3;let s=i.format_timestamp_to_day_hour_minute_second(e);r({remain:e,obj:s});let n=1e3-(Date.now()-(c+1e3*u));n<0&&(n=0),t(e,r,n,u,c)},a)}(l,r,1e3),()=>{clearTimeout(s),s=null,i=null,n=null,l=null,o=null,h=null}}add(e=1,r=Date.now()){return t(this,a,"f").call(this,r)+60*e*60*1e3}format_thousandth(t,e=2){try{const r=parseFloat(t),s=r.toString().split(".");let i=!1,n="";s[1]&&(n=s[1].replace(/0+$/,""),i=n.length>0);let l=0;i&&(l=void 0!==e?e:n.length);const a=r.toFixed(l).split("."),o=(a[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return a[1]?`${o}.${a[1]}`:o}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const r=(null===(e=t.toString().split(".")[1])||void 0===e?void 0:e.length)||0;let s=t.toString().replace(/\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,function(t){return t+","})});return r&&(s=s.replace(/\d+\.\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+\.)/g,function(t){return t+","})})),s}catch(t){return 0}}is_empty(e){return null==e||("String"===t(this,l,"f").call(this,e)?!e.trim():"Array"===t(this,l,"f").call(this,e)?!e.length:"Object"===t(this,l,"f").call(this,e)&&!Object.keys(e).length)}poll(e,r=1){let s;if(!t(this,o,"f").call(this,e))return()=>{clearTimeout(s),s=void 0};const i=60*r*1e3,n=()=>{e(),s=setTimeout(n,i)};return n(),()=>{clearTimeout(s),s=void 0}}is_equal(e,r,s=!1){const i=t(this,h,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,h,"f").call(this,r)||t(this,u,"f").call(this,r);if(!i||!n)return s?e===r:e==r;const l=Object.keys(e),a=Object.keys(r);return 0===l.length&&0===a.length||l.length===a.length&&l.every(i=>{const n=t(this,h,"f").call(this,e[i])||t(this,u,"f").call(this,e[i]),l=t(this,h,"f").call(this,r[i])||t(this,u,"f").call(this,r[i]);return n&&l?this.is_equal(e[i],r[i],s):s?e[i]===r[i]:e[i]==r[i]})}contains(e,r,s=!1){const i=t(this,h,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,h,"f").call(this,r)||t(this,u,"f").call(this,r);if(!i||!n)return s?e===r:e==r;const l=Object.keys(e),a=Object.keys(r);return 0===a.length||!(0===l.length||l.length<a.length)&&a.every(i=>{if(l.indexOf(i)<0)return!1;const n=t(this,h,"f").call(this,e[i])||t(this,u,"f").call(this,e[i]),a=t(this,h,"f").call(this,r[i])||t(this,u,"f").call(this,r[i]);return n&&a?this.contains(e[i],r[i],s):s?e[i]===r[i]:e[i]==r[i]})}};exports.default=p,exports.helper=p;
|
|
1
|
+
"use strict";function t(t,e,r,i){return new(r||(r=Promise))(function(n,o){function s(t){try{a(i.next(t))}catch(t){o(t)}}function _(t){try{a(i.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,_)}a((i=i.apply(t,e||[])).next())})}Object.defineProperty(exports,"__esModule",{value:!0}),"function"==typeof SuppressedError&&SuppressedError;const e=()=>null;function r(e,r,i){return t(this,void 0,void 0,function*(){const t=[];let i=0;const n=10485760;let o=new Uint8Array(n),s=0;for(;;){const{done:r,value:_}=yield e.read();if(_&&(s+_.length>n&&(t.push(o.slice(0,s)),o=new Uint8Array(n),s=0),o.set(_,s),s+=_.length,i+=_.length),r)break}s>0&&t.push(o.slice(0,s));!function(t,e){const r=URL.createObjectURL(t),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),setTimeout(()=>{document.body.removeChild(i),URL.revokeObjectURL(r)},100)}(new Blob(t,{type:"application/pdf"}),r)})}const i=new class{constructor(){this.__interval=1e3,this.__an_hour=36e5,this.__ticker=null,this.__ticker2=null,this.__get_type=t=>Object.prototype.toString.call(t).slice(8,-1),this.__date2timestamp=t=>{if(!t)return Date.now();let e=null;e="string"==typeof t?t.replace(/(\-|\_)/g,"/"):new Date(t);let r=new Date(e);return"Invalid Date"===r.toString()&&(r=new Date(t)),r.getTime()},this.__is_function=t=>"Function"===this.__get_type(t),this.__is_array=t=>"Array"===this.__get_type(t),this.__is_object=t=>"Object"===this.__get_type(t),this.__get_suffix2=t=>String(t).padStart(2,"0"),this.__compare_time=({date:t,hour:e=1,type:r="before_lt_hour"})=>{let i=this.__date2timestamp(t);const n=new Date(i).getTime(),o=Date.now(),s=n<o,_=n>o;return"before_lt_hour"===r?s&&n+this.__an_hour*e>o:"before_gt_hour"===r?s&&n+this.__an_hour*e<o:"after_lt_hour"===r?_&&o+this.__an_hour*e>n:"after_gt_hour"===r&&(_&&o+this.__an_hour*e<n)},this.offset_time=(t,e="minute")=>{const r=Math.abs(Date.now()-this.__date2timestamp(t)),i=this.format_num2date(r);return"day"===e?this.__get_suffix2(i.day):"hour"===e?this.__get_suffix2(i.hour):"minute"===e?this.__get_suffix2(i.minute):"second"===e?this.__get_suffix2(i.seconds):"The second parameter has an error"},this.__loop_time2=(t=0,r=e,i=this.__interval,n=0,o=Date.now())=>{if(t<=0)return clearTimeout(this.__ticker2),void(this.__ticker2=null);clearTimeout(this.__ticker2),this.__ticker2=setTimeout(()=>{n+=1,t-=this.__interval;let e=this.format_timestamp_to_day_hour_minute_second(t);r({remain:t,obj:e});const i=Date.now()-(o+n*this.__interval);let s=this.__interval-i;s<0&&(s=0),this.__loop_time2(t,r,s,n,o)},i)},this.__loop_time=(t=0,r=e,i=this.__interval,n=0,o=Date.now())=>{if(t<=0)return clearTimeout(this.__ticker),void(this.__ticker=null);clearTimeout(this.__ticker),this.__ticker=setTimeout(()=>{n+=1,t-=this.__interval;let e=this.format_num2date(t);r({remain:t,obj:e});const i=Date.now()-(o+n*this.__interval);let s=this.__interval-i;s<0&&(s=0),this.__loop_time(t,r,s,n,o)},i)},this.sleep=t=>new Promise(e=>setTimeout(e,t)),this.roxFormatThousandth=(t,e="万")=>t<1e4?t:(Math.floor(t/1e3)/10).toFixed(1)+e,this.chunk=(t,e,r=!1)=>{if(!Array.isArray(t)||e<=0)return[];const i=[];for(let n=0;n<t.length;n+=e){const o=t.slice(n,n+e);r?o.length===e&&i.push(o):i.push(o)}return i},this.debounce=(t,e=200,r=!1)=>{let i,n=null;return function(...o){const s=this,_=r&&!n;return n&&clearTimeout(n),n=setTimeout(()=>{n=null,r||(i=t.apply(s,o))},e),_&&(i=t.apply(s,o)),i}},this.flatten=(t,e=!1)=>{let r=[];return t.forEach(t=>{e&&Array.isArray(t)?r=r.concat(this.flatten(t,e)):r.push(t)}),r},this.safeRequest=(t,e)=>t&&t.then?t.catch?t.then(t=>[null,t]).catch(t=>(e&&Object.assign(t,e),[t,void 0])):t.then(t=>[null,t]):Promise.resolve([null,t]),this.checkPattern=t=>{const{str:e,likeStr:r,separator:i="-",caseSensitive:n=!1,symbol:o=""}=t,s=(r||"").split(i),_=(e||"").split(i);return s.every((t,e)=>t===o||(n?t===_[e]:_[e]&&t.toLowerCase()===_[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:i=[],skuArrField:n,checkedIndexArr:o=[],combineSkuArr:s=[],disabledArr:_=[],combineSeparator:a="-",combineSkuField:l="id"}=t;for(let t=0;t<i.length;t++){const u=n?(null===(e=i[t])||void 0===e?void 0:e[n])||[]:i[t]||[];Array.isArray(r[t])||(r[t]=[]);for(let e=0;e<u.length;e++){const i=o.slice(0,t),n=o.slice(t+1),u=i.concat(e).concat(n).join(a),c=s.filter(t=>this.checkPattern({str:t[l],likeStr:u,separator:a})),h=_.map(t=>{const{field:e,disabledFun:r,disabledFieldValue:i}=t,n=c.some(t=>r(t));return{[e]:n?i:!i}}).reduce((t,e)=>Object.assign(Object.assign({},t),e),{});r[t][e]=h}}return r},this.createSingleTon=t=>{let e=null;const r=new Proxy(t,{construct:(t,r)=>e||(e="undefined"!=typeof Reflect&&Reflect.construct?Reflect.construct(t,r):new t(...r),e)});return r.prototype.constructor=r,r},this.downloadLargePDF=(e,...i)=>t(this,[e,...i],void 0,function*(e,i="download.pdf"){var n,o;try{const s=yield fetch(e);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);const _=s.headers.get("content-length"),a=_?parseInt(_,10):0,l=null===(o=null===(n=s.body)||void 0===n?void 0:n.getReader)||void 0===o?void 0:o.call(n);window.showSaveFilePicker?l&&(yield function(e,r,i){return t(this,void 0,void 0,function*(){const t=yield window.showSaveFilePicker({suggestedName:r,types:[{description:"PDF 文件",accept:{"application/pdf":[".pdf"]}}]}),n=yield t.createWritable();let o=0;for(;;){const{done:t,value:r}=yield e.read();if(t)break;yield n.write(r),o+=r.length,i&&(o/i*100).toFixed(1)}return yield n.close(),!0})}(l,i,a)):l&&(yield r(l,i))}catch(t){return Promise.resolve()}}),this.downloadBlob=(e,...r)=>t(this,[e,...r],void 0,function*(t,e="download.pdf"){try{const r=yield fetch(t);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const i=yield r.blob(),n=document.createElement("a");n.href=URL.createObjectURL(i),n.download=e,n.click(),URL.revokeObjectURL(n.href)}catch(t){return Promise.resolve()}})}before_lt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"before_lt_hour"})}before_gt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"before_gt_hour"})}after_lt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"after_lt_hour"})}after_gt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"after_gt_hour"})}is_current_year(t){const e=this.__date2timestamp(t);return(new Date).getFullYear()===new Date(e).getFullYear()}get_time_obj(t){const e=this.__date2timestamp(t),r=new Date(e),i=this.__get_suffix2(r.getMonth()+1),n=this.__get_suffix2(r.getDate()),o=this.__get_suffix2(r.getHours()),s=this.__get_suffix2(r.getMinutes()),_=this.__get_suffix2(r.getSeconds());return{year:String(r.getFullYear()),month:i,day:n,hour:o,minute:s,seconds:_,day_of_week:String(r.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:i="万",show_suffix_always:n=!1}){if(!t)return 0;if(r<=0||e<0)return n?`${t} ${i}`:t;const o=parseFloat(t);if(o<=0)return n?`${o} ${i}`:o;if(o>0&&o<r)return n?`${o} ${i}`:o;const[s,_]=(o/r).toFixed(e).split(".");return _&&0!==parseFloat(_)?`${s}.${_} ${i}`:`${s} ${i}`}format_num2date(t=Date.now()){const e=parseInt(t/1e3/60/60/24%24),r=parseInt(t/1e3/60/60%24),i=parseInt(t/1e3/60%60),n=parseInt(t/1e3%60);return{day:this.__get_suffix2(e),hour:this.__get_suffix2(r),minute:this.__get_suffix2(i),seconds:this.__get_suffix2(n)}}count_down_by_remain_seconds(t=e,r=60){let i;clearTimeout(i);let n=1e3*r,o=this.format_num2date(n),s={remain:n,obj:o};t(s);let _=this;return function t(r=0,a=e,l=1e3,u=0,c=Date.now()){if(r<=0)return clearTimeout(i),_=null,i=null,n=null,o=null,s=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{u+=1,r-=1e3;let e=_.format_num2date(r);a({remain:r,obj:e});let i=1e3-(Date.now()-(c+1e3*u));i<0&&(i=0),t(r,a,i,u,c)},l)}(n,t,1e3),()=>{clearTimeout(i),_=null,i=null,n=null,o=null,s=null}}format_timestamp_to_day_hour_minute_second(t=Date.now()){const e=Math.floor(t/864e5),r=Math.floor(t%864e5/36e5),i=Math.floor(t%36e5/6e4),n=Math.floor(t%6e4/1e3);return{day:this.__get_suffix2(e),hour:this.__get_suffix2(r),minute:this.__get_suffix2(i),seconds:this.__get_suffix2(n)}}count_down(t=Date.now(),r=e){let i;clearTimeout(i);let n=this,o=this.__date2timestamp(t),s=o-Date.now(),_=this.format_timestamp_to_day_hour_minute_second(s),a={remain:s,obj:_};return r(a),function t(r=0,l=e,u=1e3,c=0,h=Date.now()){if(r<=0)return clearTimeout(i),i=null,n=null,o=null,s=null,_=null,a=null,void l({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{c+=1,r-=1e3;let e=n.format_timestamp_to_day_hour_minute_second(r);l({remain:r,obj:e});let i=1e3-(Date.now()-(h+1e3*c));i<0&&(i=0),t(r,l,i,c,h)},u)}(s,r,1e3),()=>{clearTimeout(i),i=null,n=null,o=null,s=null,_=null,a=null}}add(t=1,e=Date.now()){return this.__date2timestamp(e)+60*t*60*1e3}format_thousandth(t,e=2){try{const r=parseFloat(t),i=r.toString().split(".");let n=!1,o="";i[1]&&(o=i[1].replace(/0+$/,""),n=o.length>0);let s=0;n&&(s=void 0!==e?e:o.length);const _=r.toFixed(s).split("."),a=(_[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return _[1]?`${a}.${_[1]}`:a}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const r=(null===(e=t.toString().split(".")[1])||void 0===e?void 0:e.length)||0;let i=t.toString().replace(/\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,function(t){return t+","})});return r&&(i=i.replace(/\d+\.\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+\.)/g,function(t){return t+","})})),i}catch(t){return 0}}is_empty(t){return null==t||("String"===this.__get_type(t)?!t.trim():"Array"===this.__get_type(t)?!t.length:"Object"===this.__get_type(t)&&!Object.keys(t).length)}poll(t,e=1){let r;if(!this.__is_function(t))return()=>{clearTimeout(r),r=void 0};const i=60*e*1e3,n=()=>{t(),r=setTimeout(n,i)};return n(),()=>{clearTimeout(r),r=void 0}}is_equal(t,e,r=!1){const i=this.__is_array(t)||this.__is_object(t),n=this.__is_array(e)||this.__is_object(e);if(!i||!n)return r?t===e:t==e;const o=Object.keys(t),s=Object.keys(e);return 0===o.length&&0===s.length||o.length===s.length&&o.every(i=>{const n=this.__is_array(t[i])||this.__is_object(t[i]),o=this.__is_array(e[i])||this.__is_object(e[i]);return n&&o?this.is_equal(t[i],e[i],r):r?t[i]===e[i]:t[i]==e[i]})}contains(t,e,r=!1){const i=this.__is_array(t)||this.__is_object(t),n=this.__is_array(e)||this.__is_object(e);if(!i||!n)return r?t===e:t==e;const o=Object.keys(t),s=Object.keys(e);return 0===s.length||!(0===o.length||o.length<s.length)&&s.every(i=>{if(o.indexOf(i)<0)return!1;const n=this.__is_array(t[i])||this.__is_object(t[i]),s=this.__is_array(e[i])||this.__is_object(e[i]);return n&&s?this.contains(t[i],e[i],r):r?t[i]===e[i]:t[i]==e[i]})}};exports.default=i,exports.helper=i;
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)}function e(t,e,r,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(t,r):s?s.value=r:e.set(t,r),r}var r,i,s,n,l,a,o,h,u,c,f,d,m;"function"==typeof SuppressedError&&SuppressedError;const _=()=>null;r=new WeakMap,i=new WeakMap,s=new WeakMap,n=new WeakMap,l=new WeakMap,a=new WeakMap,o=new WeakMap,h=new WeakMap,u=new WeakMap,c=new WeakMap,f=new WeakMap,d=new WeakMap,m=new WeakMap;const p=new class{constructor(){r.set(this,1e3),i.set(this,36e5),s.set(this,null),n.set(this,null),l.set(this,t=>Object.prototype.toString.call(t).slice(8,-1)),a.set(this,t=>{if(!t)return Date.now();let e=null;e="string"==typeof t?t.replace(/(\-|\_)/g,"/"):new Date(t);let r=new Date(e);return"Invalid Date"===r.toString()&&(r=new Date(t)),r.getTime()}),o.set(this,e=>"Function"===t(this,l,"f").call(this,e)),h.set(this,e=>"Array"===t(this,l,"f").call(this,e)),u.set(this,e=>"Object"===t(this,l,"f").call(this,e)),c.set(this,t=>String(t).padStart(2,"0")),f.set(this,({date:e,hour:r=1,type:s="before_lt_hour"})=>{let n=t(this,a,"f").call(this,e);const l=new Date(n).getTime(),o=Date.now(),h=l<o,u=l>o;return"before_lt_hour"===s?h&&l+t(this,i,"f")*r>o:"before_gt_hour"===s?h&&l+t(this,i,"f")*r<o:"after_lt_hour"===s?u&&o+t(this,i,"f")*r>l:"after_gt_hour"===s&&(u&&o+t(this,i,"f")*r<l)}),this.offset_time=(e,r="minute")=>{const i=Math.abs(Date.now()-t(this,a,"f").call(this,e)),s=this.format_num2date(i);return"day"===r?t(this,c,"f").call(this,s.day):"hour"===r?t(this,c,"f").call(this,s.hour):"minute"===r?t(this,c,"f").call(this,s.minute):"second"===r?t(this,c,"f").call(this,s.seconds):"The second parameter has an error"},d.set(this,(i=0,s=_,l=t(this,r,"f"),a=0,o=Date.now())=>{if(i<=0)return clearTimeout(t(this,n,"f")),void e(this,n,null,"f");clearTimeout(t(this,n,"f")),e(this,n,setTimeout(()=>{a+=1,i-=t(this,r,"f");let e=this.format_timestamp_to_day_hour_minute_second(i);s({remain:i,obj:e});const n=Date.now()-(o+a*t(this,r,"f"));let l=t(this,r,"f")-n;l<0&&(l=0),t(this,d,"f").call(this,i,s,l,a,o)},l),"f")}),m.set(this,(i=0,n=_,l=t(this,r,"f"),a=0,o=Date.now())=>{if(i<=0)return clearTimeout(t(this,s,"f")),void e(this,s,null,"f");clearTimeout(t(this,s,"f")),e(this,s,setTimeout(()=>{a+=1,i-=t(this,r,"f");let e=this.format_num2date(i);n({remain:i,obj:e});const s=Date.now()-(o+a*t(this,r,"f"));let l=t(this,r,"f")-s;l<0&&(l=0),t(this,m,"f").call(this,i,n,l,a,o)},l),"f")}),this.sleep=t=>new Promise(e=>setTimeout(e,t)),this.roxFormatThousandth=(t,e="万")=>t<1e4?t:(Math.floor(t/1e3)/10).toFixed(1)+e,this.chunk=(t,e,r=!1)=>{if(!Array.isArray(t)||e<=0)return[];const i=[];for(let s=0;s<t.length;s+=e){const n=t.slice(s,s+e);r?n.length===e&&i.push(n):i.push(n)}return i},this.debounce=(t,e=200,r=!1)=>{let i,s=null;return function(...n){const l=this,a=r&&!s;return s&&clearTimeout(s),s=setTimeout(()=>{s=null,r||(i=t.apply(l,n))},e),a&&(i=t.apply(l,n)),i}},this.flatten=(t,e=!1)=>{let r=[];return t.forEach(t=>{e&&Array.isArray(t)?r=r.concat(this.flatten(t,e)):r.push(t)}),r},this.safeRequest=(t,e)=>t&&t.then?t.catch?t.then(t=>[null,t]).catch(t=>(e&&Object.assign(t,e),[t,void 0])):t.then(t=>[null,t]):Promise.resolve([null,t]),this.checkPattern=t=>{const{str:e,likeStr:r,separator:i="-",caseSensitive:s=!1,symbol:n=""}=t,l=(r||"").split(i),a=(e||"").split(i);return l.every((t,e)=>t===n||(s?t===a[e]:a[e]&&t.toLowerCase()===a[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:i=[],skuArrField:s,checkedIndexArr:n=[],combineSkuArr:l=[],disabledArr:a=[],combineSeparator:o="-",combineSkuField:h="id"}=t;for(let t=0;t<i.length;t++){const u=s?(null===(e=i[t])||void 0===e?void 0:e[s])||[]:i[t]||[];Array.isArray(r[t])||(r[t]=[]);for(let e=0;e<u.length;e++){const i=n.slice(0,t),s=n.slice(t+1),u=i.concat(e).concat(s).join(o),c=l.filter(t=>this.checkPattern({str:t[h],likeStr:u,separator:o})),f=a.map(t=>{const{field:e,disabledFun:r,disabledFieldValue:i}=t,s=c.some(t=>r(t));return{[e]:s?i:!i}}).reduce((t,e)=>Object.assign(Object.assign({},t),e),{});r[t][e]=f}}return r}}before_lt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"before_lt_hour"})}before_gt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"before_gt_hour"})}after_lt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"after_lt_hour"})}after_gt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"after_gt_hour"})}is_current_year(e){const r=t(this,a,"f").call(this,e);return(new Date).getFullYear()===new Date(r).getFullYear()}get_time_obj(e){const r=t(this,a,"f").call(this,e),i=new Date(r),s=t(this,c,"f").call(this,i.getMonth()+1),n=t(this,c,"f").call(this,i.getDate()),l=t(this,c,"f").call(this,i.getHours()),o=t(this,c,"f").call(this,i.getMinutes()),h=t(this,c,"f").call(this,i.getSeconds());return{year:String(i.getFullYear()),month:s,day:n,hour:l,minute:o,seconds:h,day_of_week:String(i.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:i="万",show_suffix_always:s=!1}){if(!t)return 0;if(r<=0||e<0)return s?`${t} ${i}`:t;const n=parseFloat(t);if(n<=0)return s?`${n} ${i}`:n;if(n>0&&n<r)return s?`${n} ${i}`:n;const[l,a]=(n/r).toFixed(e).split(".");return a&&0!==parseFloat(a)?`${l}.${a} ${i}`:`${l} ${i}`}format_num2date(e=Date.now()){const r=parseInt(e/1e3/60/60/24%24),i=parseInt(e/1e3/60/60%24),s=parseInt(e/1e3/60%60),n=parseInt(e/1e3%60);return{day:t(this,c,"f").call(this,r),hour:t(this,c,"f").call(this,i),minute:t(this,c,"f").call(this,s),seconds:t(this,c,"f").call(this,n)}}count_down_by_remain_seconds(t=_,e=60){let r;clearTimeout(r);let i=1e3*e,s=this.format_num2date(i),n={remain:i,obj:s};t(n);let l=this;return function t(e=0,a=_,o=1e3,h=0,u=Date.now()){if(e<=0)return clearTimeout(r),l=null,r=null,i=null,s=null,n=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(r),r=setTimeout(()=>{h+=1,e-=1e3;let r=l.format_num2date(e);a({remain:e,obj:r});let i=1e3-(Date.now()-(u+1e3*h));i<0&&(i=0),t(e,a,i,h,u)},o)}(i,t,1e3),()=>{clearTimeout(r),l=null,r=null,i=null,s=null,n=null}}format_timestamp_to_day_hour_minute_second(e=Date.now()){const r=Math.floor(e/864e5),i=Math.floor(e%864e5/36e5),s=Math.floor(e%36e5/6e4),n=Math.floor(e%6e4/1e3);return{day:t(this,c,"f").call(this,r),hour:t(this,c,"f").call(this,i),minute:t(this,c,"f").call(this,s),seconds:t(this,c,"f").call(this,n)}}count_down(e=Date.now(),r=_){let i;clearTimeout(i);let s=this,n=t(this,a,"f").call(this,e),l=n-Date.now(),o=this.format_timestamp_to_day_hour_minute_second(l),h={remain:l,obj:o};return r(h),function t(e=0,r=_,a=1e3,u=0,c=Date.now()){if(e<=0)return clearTimeout(i),i=null,s=null,n=null,l=null,o=null,h=null,void r({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{u+=1,e-=1e3;let i=s.format_timestamp_to_day_hour_minute_second(e);r({remain:e,obj:i});let n=1e3-(Date.now()-(c+1e3*u));n<0&&(n=0),t(e,r,n,u,c)},a)}(l,r,1e3),()=>{clearTimeout(i),i=null,s=null,n=null,l=null,o=null,h=null}}add(e=1,r=Date.now()){return t(this,a,"f").call(this,r)+60*e*60*1e3}format_thousandth(t,e=2){try{const r=parseFloat(t),i=r.toString().split(".");let s=!1,n="";i[1]&&(n=i[1].replace(/0+$/,""),s=n.length>0);let l=0;s&&(l=void 0!==e?e:n.length);const a=r.toFixed(l).split("."),o=(a[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return a[1]?`${o}.${a[1]}`:o}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const r=(null===(e=t.toString().split(".")[1])||void 0===e?void 0:e.length)||0;let i=t.toString().replace(/\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,function(t){return t+","})});return r&&(i=i.replace(/\d+\.\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+\.)/g,function(t){return t+","})})),i}catch(t){return 0}}is_empty(e){return null==e||("String"===t(this,l,"f").call(this,e)?!e.trim():"Array"===t(this,l,"f").call(this,e)?!e.length:"Object"===t(this,l,"f").call(this,e)&&!Object.keys(e).length)}poll(e,r=1){let i;if(!t(this,o,"f").call(this,e))return()=>{clearTimeout(i),i=void 0};const s=60*r*1e3,n=()=>{e(),i=setTimeout(n,s)};return n(),()=>{clearTimeout(i),i=void 0}}is_equal(e,r,i=!1){const s=t(this,h,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,h,"f").call(this,r)||t(this,u,"f").call(this,r);if(!s||!n)return i?e===r:e==r;const l=Object.keys(e),a=Object.keys(r);return 0===l.length&&0===a.length||l.length===a.length&&l.every(s=>{const n=t(this,h,"f").call(this,e[s])||t(this,u,"f").call(this,e[s]),l=t(this,h,"f").call(this,r[s])||t(this,u,"f").call(this,r[s]);return n&&l?this.is_equal(e[s],r[s],i):i?e[s]===r[s]:e[s]==r[s]})}contains(e,r,i=!1){const s=t(this,h,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,h,"f").call(this,r)||t(this,u,"f").call(this,r);if(!s||!n)return i?e===r:e==r;const l=Object.keys(e),a=Object.keys(r);return 0===a.length||!(0===l.length||l.length<a.length)&&a.every(s=>{if(l.indexOf(s)<0)return!1;const n=t(this,h,"f").call(this,e[s])||t(this,u,"f").call(this,e[s]),a=t(this,h,"f").call(this,r[s])||t(this,u,"f").call(this,r[s]);return n&&a?this.contains(e[s],r[s],i):i?e[s]===r[s]:e[s]==r[s]})}};export{p as default,p as helper};
|
|
1
|
+
function t(t,e,r,i){return new(r||(r=Promise))(function(n,o){function s(t){try{a(i.next(t))}catch(t){o(t)}}function _(t){try{a(i.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,_)}a((i=i.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const e=()=>null;function r(e,r,i){return t(this,void 0,void 0,function*(){const t=[];let i=0;const n=10485760;let o=new Uint8Array(n),s=0;for(;;){const{done:r,value:_}=yield e.read();if(_&&(s+_.length>n&&(t.push(o.slice(0,s)),o=new Uint8Array(n),s=0),o.set(_,s),s+=_.length,i+=_.length),r)break}s>0&&t.push(o.slice(0,s));!function(t,e){const r=URL.createObjectURL(t),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),setTimeout(()=>{document.body.removeChild(i),URL.revokeObjectURL(r)},100)}(new Blob(t,{type:"application/pdf"}),r)})}const i=new class{constructor(){this.__interval=1e3,this.__an_hour=36e5,this.__ticker=null,this.__ticker2=null,this.__get_type=t=>Object.prototype.toString.call(t).slice(8,-1),this.__date2timestamp=t=>{if(!t)return Date.now();let e=null;e="string"==typeof t?t.replace(/(\-|\_)/g,"/"):new Date(t);let r=new Date(e);return"Invalid Date"===r.toString()&&(r=new Date(t)),r.getTime()},this.__is_function=t=>"Function"===this.__get_type(t),this.__is_array=t=>"Array"===this.__get_type(t),this.__is_object=t=>"Object"===this.__get_type(t),this.__get_suffix2=t=>String(t).padStart(2,"0"),this.__compare_time=({date:t,hour:e=1,type:r="before_lt_hour"})=>{let i=this.__date2timestamp(t);const n=new Date(i).getTime(),o=Date.now(),s=n<o,_=n>o;return"before_lt_hour"===r?s&&n+this.__an_hour*e>o:"before_gt_hour"===r?s&&n+this.__an_hour*e<o:"after_lt_hour"===r?_&&o+this.__an_hour*e>n:"after_gt_hour"===r&&(_&&o+this.__an_hour*e<n)},this.offset_time=(t,e="minute")=>{const r=Math.abs(Date.now()-this.__date2timestamp(t)),i=this.format_num2date(r);return"day"===e?this.__get_suffix2(i.day):"hour"===e?this.__get_suffix2(i.hour):"minute"===e?this.__get_suffix2(i.minute):"second"===e?this.__get_suffix2(i.seconds):"The second parameter has an error"},this.__loop_time2=(t=0,r=e,i=this.__interval,n=0,o=Date.now())=>{if(t<=0)return clearTimeout(this.__ticker2),void(this.__ticker2=null);clearTimeout(this.__ticker2),this.__ticker2=setTimeout(()=>{n+=1,t-=this.__interval;let e=this.format_timestamp_to_day_hour_minute_second(t);r({remain:t,obj:e});const i=Date.now()-(o+n*this.__interval);let s=this.__interval-i;s<0&&(s=0),this.__loop_time2(t,r,s,n,o)},i)},this.__loop_time=(t=0,r=e,i=this.__interval,n=0,o=Date.now())=>{if(t<=0)return clearTimeout(this.__ticker),void(this.__ticker=null);clearTimeout(this.__ticker),this.__ticker=setTimeout(()=>{n+=1,t-=this.__interval;let e=this.format_num2date(t);r({remain:t,obj:e});const i=Date.now()-(o+n*this.__interval);let s=this.__interval-i;s<0&&(s=0),this.__loop_time(t,r,s,n,o)},i)},this.sleep=t=>new Promise(e=>setTimeout(e,t)),this.roxFormatThousandth=(t,e="万")=>t<1e4?t:(Math.floor(t/1e3)/10).toFixed(1)+e,this.chunk=(t,e,r=!1)=>{if(!Array.isArray(t)||e<=0)return[];const i=[];for(let n=0;n<t.length;n+=e){const o=t.slice(n,n+e);r?o.length===e&&i.push(o):i.push(o)}return i},this.debounce=(t,e=200,r=!1)=>{let i,n=null;return function(...o){const s=this,_=r&&!n;return n&&clearTimeout(n),n=setTimeout(()=>{n=null,r||(i=t.apply(s,o))},e),_&&(i=t.apply(s,o)),i}},this.flatten=(t,e=!1)=>{let r=[];return t.forEach(t=>{e&&Array.isArray(t)?r=r.concat(this.flatten(t,e)):r.push(t)}),r},this.safeRequest=(t,e)=>t&&t.then?t.catch?t.then(t=>[null,t]).catch(t=>(e&&Object.assign(t,e),[t,void 0])):t.then(t=>[null,t]):Promise.resolve([null,t]),this.checkPattern=t=>{const{str:e,likeStr:r,separator:i="-",caseSensitive:n=!1,symbol:o=""}=t,s=(r||"").split(i),_=(e||"").split(i);return s.every((t,e)=>t===o||(n?t===_[e]:_[e]&&t.toLowerCase()===_[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:i=[],skuArrField:n,checkedIndexArr:o=[],combineSkuArr:s=[],disabledArr:_=[],combineSeparator:a="-",combineSkuField:l="id"}=t;for(let t=0;t<i.length;t++){const u=n?(null===(e=i[t])||void 0===e?void 0:e[n])||[]:i[t]||[];Array.isArray(r[t])||(r[t]=[]);for(let e=0;e<u.length;e++){const i=o.slice(0,t),n=o.slice(t+1),u=i.concat(e).concat(n).join(a),c=s.filter(t=>this.checkPattern({str:t[l],likeStr:u,separator:a})),h=_.map(t=>{const{field:e,disabledFun:r,disabledFieldValue:i}=t,n=c.some(t=>r(t));return{[e]:n?i:!i}}).reduce((t,e)=>Object.assign(Object.assign({},t),e),{});r[t][e]=h}}return r},this.createSingleTon=t=>{let e=null;const r=new Proxy(t,{construct:(t,r)=>e||(e="undefined"!=typeof Reflect&&Reflect.construct?Reflect.construct(t,r):new t(...r),e)});return r.prototype.constructor=r,r},this.downloadLargePDF=(e,...i)=>t(this,[e,...i],void 0,function*(e,i="download.pdf"){var n,o;try{const s=yield fetch(e);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);const _=s.headers.get("content-length"),a=_?parseInt(_,10):0,l=null===(o=null===(n=s.body)||void 0===n?void 0:n.getReader)||void 0===o?void 0:o.call(n);window.showSaveFilePicker?l&&(yield function(e,r,i){return t(this,void 0,void 0,function*(){const t=yield window.showSaveFilePicker({suggestedName:r,types:[{description:"PDF 文件",accept:{"application/pdf":[".pdf"]}}]}),n=yield t.createWritable();let o=0;for(;;){const{done:t,value:r}=yield e.read();if(t)break;yield n.write(r),o+=r.length,i&&(o/i*100).toFixed(1)}return yield n.close(),!0})}(l,i,a)):l&&(yield r(l,i))}catch(t){return Promise.resolve()}}),this.downloadBlob=(e,...r)=>t(this,[e,...r],void 0,function*(t,e="download.pdf"){try{const r=yield fetch(t);if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const i=yield r.blob(),n=document.createElement("a");n.href=URL.createObjectURL(i),n.download=e,n.click(),URL.revokeObjectURL(n.href)}catch(t){return Promise.resolve()}})}before_lt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"before_lt_hour"})}before_gt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"before_gt_hour"})}after_lt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"after_lt_hour"})}after_gt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"after_gt_hour"})}is_current_year(t){const e=this.__date2timestamp(t);return(new Date).getFullYear()===new Date(e).getFullYear()}get_time_obj(t){const e=this.__date2timestamp(t),r=new Date(e),i=this.__get_suffix2(r.getMonth()+1),n=this.__get_suffix2(r.getDate()),o=this.__get_suffix2(r.getHours()),s=this.__get_suffix2(r.getMinutes()),_=this.__get_suffix2(r.getSeconds());return{year:String(r.getFullYear()),month:i,day:n,hour:o,minute:s,seconds:_,day_of_week:String(r.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:i="万",show_suffix_always:n=!1}){if(!t)return 0;if(r<=0||e<0)return n?`${t} ${i}`:t;const o=parseFloat(t);if(o<=0)return n?`${o} ${i}`:o;if(o>0&&o<r)return n?`${o} ${i}`:o;const[s,_]=(o/r).toFixed(e).split(".");return _&&0!==parseFloat(_)?`${s}.${_} ${i}`:`${s} ${i}`}format_num2date(t=Date.now()){const e=parseInt(t/1e3/60/60/24%24),r=parseInt(t/1e3/60/60%24),i=parseInt(t/1e3/60%60),n=parseInt(t/1e3%60);return{day:this.__get_suffix2(e),hour:this.__get_suffix2(r),minute:this.__get_suffix2(i),seconds:this.__get_suffix2(n)}}count_down_by_remain_seconds(t=e,r=60){let i;clearTimeout(i);let n=1e3*r,o=this.format_num2date(n),s={remain:n,obj:o};t(s);let _=this;return function t(r=0,a=e,l=1e3,u=0,c=Date.now()){if(r<=0)return clearTimeout(i),_=null,i=null,n=null,o=null,s=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{u+=1,r-=1e3;let e=_.format_num2date(r);a({remain:r,obj:e});let i=1e3-(Date.now()-(c+1e3*u));i<0&&(i=0),t(r,a,i,u,c)},l)}(n,t,1e3),()=>{clearTimeout(i),_=null,i=null,n=null,o=null,s=null}}format_timestamp_to_day_hour_minute_second(t=Date.now()){const e=Math.floor(t/864e5),r=Math.floor(t%864e5/36e5),i=Math.floor(t%36e5/6e4),n=Math.floor(t%6e4/1e3);return{day:this.__get_suffix2(e),hour:this.__get_suffix2(r),minute:this.__get_suffix2(i),seconds:this.__get_suffix2(n)}}count_down(t=Date.now(),r=e){let i;clearTimeout(i);let n=this,o=this.__date2timestamp(t),s=o-Date.now(),_=this.format_timestamp_to_day_hour_minute_second(s),a={remain:s,obj:_};return r(a),function t(r=0,l=e,u=1e3,c=0,h=Date.now()){if(r<=0)return clearTimeout(i),i=null,n=null,o=null,s=null,_=null,a=null,void l({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{c+=1,r-=1e3;let e=n.format_timestamp_to_day_hour_minute_second(r);l({remain:r,obj:e});let i=1e3-(Date.now()-(h+1e3*c));i<0&&(i=0),t(r,l,i,c,h)},u)}(s,r,1e3),()=>{clearTimeout(i),i=null,n=null,o=null,s=null,_=null,a=null}}add(t=1,e=Date.now()){return this.__date2timestamp(e)+60*t*60*1e3}format_thousandth(t,e=2){try{const r=parseFloat(t),i=r.toString().split(".");let n=!1,o="";i[1]&&(o=i[1].replace(/0+$/,""),n=o.length>0);let s=0;n&&(s=void 0!==e?e:o.length);const _=r.toFixed(s).split("."),a=(_[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return _[1]?`${a}.${_[1]}`:a}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const r=(null===(e=t.toString().split(".")[1])||void 0===e?void 0:e.length)||0;let i=t.toString().replace(/\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,function(t){return t+","})});return r&&(i=i.replace(/\d+\.\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+\.)/g,function(t){return t+","})})),i}catch(t){return 0}}is_empty(t){return null==t||("String"===this.__get_type(t)?!t.trim():"Array"===this.__get_type(t)?!t.length:"Object"===this.__get_type(t)&&!Object.keys(t).length)}poll(t,e=1){let r;if(!this.__is_function(t))return()=>{clearTimeout(r),r=void 0};const i=60*e*1e3,n=()=>{t(),r=setTimeout(n,i)};return n(),()=>{clearTimeout(r),r=void 0}}is_equal(t,e,r=!1){const i=this.__is_array(t)||this.__is_object(t),n=this.__is_array(e)||this.__is_object(e);if(!i||!n)return r?t===e:t==e;const o=Object.keys(t),s=Object.keys(e);return 0===o.length&&0===s.length||o.length===s.length&&o.every(i=>{const n=this.__is_array(t[i])||this.__is_object(t[i]),o=this.__is_array(e[i])||this.__is_object(e[i]);return n&&o?this.is_equal(t[i],e[i],r):r?t[i]===e[i]:t[i]==e[i]})}contains(t,e,r=!1){const i=this.__is_array(t)||this.__is_object(t),n=this.__is_array(e)||this.__is_object(e);if(!i||!n)return r?t===e:t==e;const o=Object.keys(t),s=Object.keys(e);return 0===s.length||!(0===o.length||o.length<s.length)&&s.every(i=>{if(o.indexOf(i)<0)return!1;const n=this.__is_array(t[i])||this.__is_object(t[i]),s=this.__is_array(e[i])||this.__is_object(e[i]);return n&&s?this.contains(t[i],e[i],r):r?t[i]===e[i]:t[i]==e[i]})}};export{i as default,i as helper};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
type DateType = number | string | Date;
|
|
2
|
+
type CompareType = "before_lt_hour" | "before_gt_hour" | "after_lt_hour" | "after_gt_hour";
|
|
2
3
|
interface GetTimeObj {
|
|
3
4
|
year: string;
|
|
4
5
|
month: string;
|
|
@@ -15,8 +16,14 @@ interface FormatCount {
|
|
|
15
16
|
suffix?: string;
|
|
16
17
|
show_suffix_always?: boolean;
|
|
17
18
|
}
|
|
19
|
+
interface CompareTime {
|
|
20
|
+
date?: DateType;
|
|
21
|
+
hour?: number;
|
|
22
|
+
type?: CompareType;
|
|
23
|
+
}
|
|
18
24
|
type OffsetTimeReturnType = "day" | "hour" | "minute" | "second";
|
|
19
25
|
type FormatNum2Date = Required<Omit<GetTimeObj, "day_of_week" | "year" | "month">>;
|
|
26
|
+
type TypeString = "Null" | "Undefined" | "Symbol" | "Number" | "String" | "Array" | "Object" | "Boolean" | "Function" | "RegExp" | "Date";
|
|
20
27
|
interface CountDownCallbackParams {
|
|
21
28
|
remain: number;
|
|
22
29
|
obj: FormatNum2Date;
|
|
@@ -43,8 +50,19 @@ interface TransformDisableArgs<T = any> {
|
|
|
43
50
|
disabledArr?: Array<DisabledFunObj<T>>;
|
|
44
51
|
}
|
|
45
52
|
type CountDownCallback = (data: CountDownCallbackParams) => any;
|
|
53
|
+
type Constructor<T = {}> = new (...args: any[]) => T;
|
|
46
54
|
declare class Helper {
|
|
47
|
-
|
|
55
|
+
__interval: number;
|
|
56
|
+
__an_hour: number;
|
|
57
|
+
__ticker: unknown;
|
|
58
|
+
__ticker2: unknown;
|
|
59
|
+
__get_type: (data: any) => TypeString;
|
|
60
|
+
__date2timestamp: (date?: DateType) => number;
|
|
61
|
+
__is_function: (arg?: any) => boolean;
|
|
62
|
+
__is_array: (arg?: any) => boolean;
|
|
63
|
+
__is_object: (arg?: any) => boolean;
|
|
64
|
+
__get_suffix2: (num: number | string) => string;
|
|
65
|
+
__compare_time: ({ date, hour, type }: CompareTime) => boolean;
|
|
48
66
|
offset_time: (date?: DateType, return_type?: OffsetTimeReturnType) => string;
|
|
49
67
|
before_lt_hour(date?: DateType, hour?: number): boolean;
|
|
50
68
|
before_gt_hour(date?: DateType, hour?: number): boolean;
|
|
@@ -57,7 +75,9 @@ declare class Helper {
|
|
|
57
75
|
count_down_by_remain_seconds(fn?: CountDownCallback, seconds?: number): Function;
|
|
58
76
|
format_timestamp_to_day_hour_minute_second(timestamp?: number): FormatNum2Date;
|
|
59
77
|
count_down(date?: DateType, fn?: CountDownCallback): Function;
|
|
78
|
+
__loop_time2: (time?: number, fn?: CountDownCallback, delay?: number, count?: number, start?: number) => void;
|
|
60
79
|
add(hours?: number, start?: DateType): number;
|
|
80
|
+
__loop_time: (time?: number, fn?: CountDownCallback, delay?: number, count?: number, start?: number) => void;
|
|
61
81
|
format_thousandth(num: number | string, decimalPlaces?: number): string | 0;
|
|
62
82
|
format_thousandth_with_same_dotlen(num: number | string): string | 0;
|
|
63
83
|
is_empty(data: any): boolean;
|
|
@@ -81,6 +101,9 @@ declare class Helper {
|
|
|
81
101
|
convertArr2Disable: <T>(arg: TransformDisableArgs<T>) => {
|
|
82
102
|
[key: string]: boolean;
|
|
83
103
|
}[][];
|
|
104
|
+
createSingleTon: <T extends Constructor>(className: T) => T;
|
|
105
|
+
downloadLargePDF: (url: string, filename?: string) => Promise<void>;
|
|
106
|
+
downloadBlob: (url: string, filename?: string) => Promise<void>;
|
|
84
107
|
}
|
|
85
108
|
declare const helper: Helper;
|
|
86
109
|
|