fish-helper 0.0.50 → 0.0.52

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
@@ -3,7 +3,7 @@ npm install fish-helper
3
3
  ```
4
4
 
5
5
  ```js
6
- const helper = require('fish-helper')
6
+ const helper = require("fish-helper");
7
7
  ```
8
8
 
9
9
  | Method | Description |
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e,s,l,i,a,r,n,c,h,_,o,u,d=require("tslib");const f=()=>null;t=new WeakMap,e=new WeakMap,s=new WeakMap,l=new WeakMap,i=new WeakMap,a=new WeakMap,r=new WeakMap,n=new WeakMap,c=new WeakMap,h=new WeakMap,_=new WeakMap,o=new WeakMap,u=new WeakMap;const v=new class{constructor(){t.set(this,1e3),e.set(this,36e5),s.set(this,null),l.set(this,null),i.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 s=new Date(e);return"Invalid Date"===s.toString()&&(s=new Date(t)),s.getTime()}),r.set(this,t=>"Function"===d.__classPrivateFieldGet(this,i,"f").call(this,t)),n.set(this,t=>"Array"===d.__classPrivateFieldGet(this,i,"f").call(this,t)),c.set(this,t=>"Object"===d.__classPrivateFieldGet(this,i,"f").call(this,t)),h.set(this,t=>String(t).padStart(2,"0")),_.set(this,({date:t,hour:s=1,type:l="before_lt_hour"})=>{let i=d.__classPrivateFieldGet(this,a,"f").call(this,t);const r=new Date(i).getTime(),n=Date.now(),c=r<n,h=r>n;return"before_lt_hour"===l?c&&r+d.__classPrivateFieldGet(this,e,"f")*s>n:"before_gt_hour"===l?c&&r+d.__classPrivateFieldGet(this,e,"f")*s<n:"after_lt_hour"===l?h&&n+d.__classPrivateFieldGet(this,e,"f")*s>r:"after_gt_hour"===l&&(h&&n+d.__classPrivateFieldGet(this,e,"f")*s<r)}),this.offset_time=(t,e="minute")=>{const s=Math.abs(Date.now()-d.__classPrivateFieldGet(this,a,"f").call(this,t)),l=this.format_num2date(s);return"day"===e?d.__classPrivateFieldGet(this,h,"f").call(this,l.day):"hour"===e?d.__classPrivateFieldGet(this,h,"f").call(this,l.hour):"minute"===e?d.__classPrivateFieldGet(this,h,"f").call(this,l.minute):"second"===e?d.__classPrivateFieldGet(this,h,"f").call(this,l.seconds):"The second parameter has an error"},o.set(this,(e=0,s=f,i=d.__classPrivateFieldGet(this,t,"f"),a=0,r=Date.now())=>{if(e<=0)return clearTimeout(d.__classPrivateFieldGet(this,l,"f")),void d.__classPrivateFieldSet(this,l,null,"f");clearTimeout(d.__classPrivateFieldGet(this,l,"f")),d.__classPrivateFieldSet(this,l,setTimeout(()=>{a+=1,e-=d.__classPrivateFieldGet(this,t,"f");let l=this.format_timestamp_to_day_hour_minute_second(e);s({remain:e,obj:l});const i=Date.now()-(r+a*d.__classPrivateFieldGet(this,t,"f"));let n=d.__classPrivateFieldGet(this,t,"f")-i;n<0&&(n=0),d.__classPrivateFieldGet(this,o,"f").call(this,e,s,n,a,r)},i),"f")}),u.set(this,(e=0,l=f,i=d.__classPrivateFieldGet(this,t,"f"),a=0,r=Date.now())=>{if(e<=0)return clearTimeout(d.__classPrivateFieldGet(this,s,"f")),void d.__classPrivateFieldSet(this,s,null,"f");clearTimeout(d.__classPrivateFieldGet(this,s,"f")),d.__classPrivateFieldSet(this,s,setTimeout(()=>{a+=1,e-=d.__classPrivateFieldGet(this,t,"f");let s=this.format_num2date(e);l({remain:e,obj:s});const i=Date.now()-(r+a*d.__classPrivateFieldGet(this,t,"f"));let n=d.__classPrivateFieldGet(this,t,"f")-i;n<0&&(n=0),d.__classPrivateFieldGet(this,u,"f").call(this,e,l,n,a,r)},i),"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,s=!1)=>{if(!Array.isArray(t)||e<=0)return[];const l=[];for(let i=0;i<t.length;i+=e){const a=t.slice(i,i+e);s?a.length===e&&l.push(a):l.push(a)}return l},this.debounce=(t,e=200,s=!1)=>{let l,i=null;return function(...a){const r=this,n=s&&!i;return i&&clearTimeout(i),i=setTimeout(()=>{i=null,s||(l=t.apply(r,a))},e),n&&(l=t.apply(r,a)),l}},this.flatten=(t,e=!1)=>{let s=[];return t.forEach(t=>{e&&Array.isArray(t)?s=s.concat(this.flatten(t,e)):s.push(t)}),s},this.safeRequest=(t,e)=>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])}before_lt_hour(t=Date.now(),e=1){return d.__classPrivateFieldGet(this,_,"f").call(this,{date:t,hour:e,type:"before_lt_hour"})}before_gt_hour(t=Date.now(),e=1){return d.__classPrivateFieldGet(this,_,"f").call(this,{date:t,hour:e,type:"before_gt_hour"})}after_lt_hour(t=Date.now(),e=1){return d.__classPrivateFieldGet(this,_,"f").call(this,{date:t,hour:e,type:"after_lt_hour"})}after_gt_hour(t=Date.now(),e=1){return d.__classPrivateFieldGet(this,_,"f").call(this,{date:t,hour:e,type:"after_gt_hour"})}is_current_year(t){const e=d.__classPrivateFieldGet(this,a,"f").call(this,t);return(new Date).getFullYear()===new Date(e).getFullYear()}get_time_obj(t){const e=d.__classPrivateFieldGet(this,a,"f").call(this,t),s=new Date(e),l=d.__classPrivateFieldGet(this,h,"f").call(this,s.getMonth()+1),i=d.__classPrivateFieldGet(this,h,"f").call(this,s.getDate()),r=d.__classPrivateFieldGet(this,h,"f").call(this,s.getHours()),n=d.__classPrivateFieldGet(this,h,"f").call(this,s.getMinutes()),c=d.__classPrivateFieldGet(this,h,"f").call(this,s.getSeconds());return{year:String(s.getFullYear()),month:l,day:i,hour:r,minute:n,seconds:c,day_of_week:String(s.getDay())}}format_count({num:t=0,decimal:e=1,divide:s=1e4,suffix:l="万",show_suffix_always:i=!1}){if(!t)return 0;if(s<=0||e<0)return i?`${t} ${l}`:t;const a=parseFloat(t);if(a<=0)return i?`${a} ${l}`:a;if(a>0&&a<s)return i?`${a} ${l}`:a;const[r,n]=(a/s).toFixed(e).split(".");return n&&0!==parseFloat(n)?`${r}.${n} ${l}`:`${r} ${l}`}format_num2date(t=Date.now()){const e=parseInt(t/1e3/60/60/24%24),s=parseInt(t/1e3/60/60%24),l=parseInt(t/1e3/60%60),i=parseInt(t/1e3%60);return{day:d.__classPrivateFieldGet(this,h,"f").call(this,e),hour:d.__classPrivateFieldGet(this,h,"f").call(this,s),minute:d.__classPrivateFieldGet(this,h,"f").call(this,l),seconds:d.__classPrivateFieldGet(this,h,"f").call(this,i)}}count_down_by_remain_seconds(t=f,e=60){let s;clearTimeout(s);let l=1e3*e,i=this.format_num2date(l),a={remain:l,obj:i};t(a);let r=this;return function t(e=0,n=f,c=1e3,h=0,_=Date.now()){if(e<=0)return clearTimeout(s),r=null,s=null,l=null,i=null,a=null,void n({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(s),s=setTimeout(()=>{h+=1,e-=1e3;let s=r.format_num2date(e);n({remain:e,obj:s});let l=1e3-(Date.now()-(_+1e3*h));l<0&&(l=0),t(e,n,l,h,_)},c)}(l,t,1e3),()=>{clearTimeout(s),r=null,s=null,l=null,i=null,a=null}}format_timestamp_to_day_hour_minute_second(t=Date.now()){const e=Math.floor(t/864e5),s=Math.floor(t%864e5/36e5),l=Math.floor(t%36e5/6e4),i=Math.floor(t%6e4/1e3);return{day:d.__classPrivateFieldGet(this,h,"f").call(this,e),hour:d.__classPrivateFieldGet(this,h,"f").call(this,s),minute:d.__classPrivateFieldGet(this,h,"f").call(this,l),seconds:d.__classPrivateFieldGet(this,h,"f").call(this,i)}}count_down(t=Date.now(),e=f){let s;clearTimeout(s);let l=this,i=d.__classPrivateFieldGet(this,a,"f").call(this,t),r=i-Date.now(),n=this.format_timestamp_to_day_hour_minute_second(r),c={remain:r,obj:n};return e(c),function t(e=0,a=f,h=1e3,_=0,o=Date.now()){if(e<=0)return clearTimeout(s),s=null,l=null,i=null,r=null,n=null,c=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(s),s=setTimeout(()=>{_+=1,e-=1e3;let s=l.format_timestamp_to_day_hour_minute_second(e);a({remain:e,obj:s});let i=1e3-(Date.now()-(o+1e3*_));i<0&&(i=0),t(e,a,i,_,o)},h)}(r,e,1e3),()=>{clearTimeout(s),s=null,l=null,i=null,r=null,n=null,c=null}}add(t=1,e=Date.now()){return d.__classPrivateFieldGet(this,a,"f").call(this,e)+60*t*60*1e3}format_thousandth(t,e=2){try{const s=parseFloat(t),l=s.toString().split(".");let i=!1,a="";l[1]&&(a=l[1].replace(/0+$/,""),i=a.length>0);let r=0;i&&(r=void 0!==e?e:a.length);const n=s.toFixed(r).split("."),c=(n[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return n[1]?`${c}.${n[1]}`:c}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const s=(null===(e=t.toString().split(".")[1])||void 0===e?void 0:e.length)||0;let l=t.toString().replace(/\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,function(t){return t+","})});return s&&(l=l.replace(/\d+\.\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+\.)/g,function(t){return t+","})})),l}catch(t){return 0}}is_empty(t){return null==t||("String"===d.__classPrivateFieldGet(this,i,"f").call(this,t)?!t.trim():"Array"===d.__classPrivateFieldGet(this,i,"f").call(this,t)?!t.length:"Object"===d.__classPrivateFieldGet(this,i,"f").call(this,t)&&!Object.keys(t).length)}poll(t,e=1){let s;if(!d.__classPrivateFieldGet(this,r,"f").call(this,t))return()=>{clearTimeout(s),s=void 0};const l=60*e*1e3,i=()=>{t(),s=setTimeout(i,l)};return i(),()=>{clearTimeout(s),s=void 0}}is_equal(t,e,s=!1){const l=d.__classPrivateFieldGet(this,n,"f").call(this,t)||d.__classPrivateFieldGet(this,c,"f").call(this,t),i=d.__classPrivateFieldGet(this,n,"f").call(this,e)||d.__classPrivateFieldGet(this,c,"f").call(this,e);if(!l||!i)return s?t===e:t==e;const a=Object.keys(t),r=Object.keys(e);return 0===a.length&&0===r.length||a.length===r.length&&a.every(l=>{const i=d.__classPrivateFieldGet(this,n,"f").call(this,t[l])||d.__classPrivateFieldGet(this,c,"f").call(this,t[l]),a=d.__classPrivateFieldGet(this,n,"f").call(this,e[l])||d.__classPrivateFieldGet(this,c,"f").call(this,e[l]);return i&&a?this.is_equal(t[l],e[l],s):s?t[l]===e[l]:t[l]==e[l]})}contains(t,e,s=!1){const l=d.__classPrivateFieldGet(this,n,"f").call(this,t)||d.__classPrivateFieldGet(this,c,"f").call(this,t),i=d.__classPrivateFieldGet(this,n,"f").call(this,e)||d.__classPrivateFieldGet(this,c,"f").call(this,e);if(!l||!i)return s?t===e:t==e;const a=Object.keys(t),r=Object.keys(e);return 0===r.length||!(0===a.length||a.length<r.length)&&r.every(l=>{if(a.indexOf(l)<0)return!1;const i=d.__classPrivateFieldGet(this,n,"f").call(this,t[l])||d.__classPrivateFieldGet(this,c,"f").call(this,t[l]),r=d.__classPrivateFieldGet(this,n,"f").call(this,e[l])||d.__classPrivateFieldGet(this,c,"f").call(this,e[l]);return i&&r?this.contains(t[l],e[l],s):s?t[l]===e[l]:t[l]==e[l]})}};exports.default=v,exports.helper=v;
@@ -0,0 +1 @@
1
+ import{__classPrivateFieldGet as t,__classPrivateFieldSet as e}from"tslib";var s,i,l,n,a,r,h,o,u,c,f,m,_;const d=()=>null;s=new WeakMap,i=new WeakMap,l=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,h=new WeakMap,o=new WeakMap,u=new WeakMap,c=new WeakMap,f=new WeakMap,m=new WeakMap,_=new WeakMap;const p=new class{constructor(){s.set(this,1e3),i.set(this,36e5),l.set(this,null),n.set(this,null),a.set(this,t=>Object.prototype.toString.call(t).slice(8,-1)),r.set(this,t=>{if(!t)return Date.now();let e=null;e="string"==typeof t?t.replace(/(\-|\_)/g,"/"):new Date(t);let s=new Date(e);return"Invalid Date"===s.toString()&&(s=new Date(t)),s.getTime()}),h.set(this,e=>"Function"===t(this,a,"f").call(this,e)),o.set(this,e=>"Array"===t(this,a,"f").call(this,e)),u.set(this,e=>"Object"===t(this,a,"f").call(this,e)),c.set(this,t=>String(t).padStart(2,"0")),f.set(this,({date:e,hour:s=1,type:l="before_lt_hour"})=>{let n=t(this,r,"f").call(this,e);const a=new Date(n).getTime(),h=Date.now(),o=a<h,u=a>h;return"before_lt_hour"===l?o&&a+t(this,i,"f")*s>h:"before_gt_hour"===l?o&&a+t(this,i,"f")*s<h:"after_lt_hour"===l?u&&h+t(this,i,"f")*s>a:"after_gt_hour"===l&&(u&&h+t(this,i,"f")*s<a)}),this.offset_time=(e,s="minute")=>{const i=Math.abs(Date.now()-t(this,r,"f").call(this,e)),l=this.format_num2date(i);return"day"===s?t(this,c,"f").call(this,l.day):"hour"===s?t(this,c,"f").call(this,l.hour):"minute"===s?t(this,c,"f").call(this,l.minute):"second"===s?t(this,c,"f").call(this,l.seconds):"The second parameter has an error"},m.set(this,(i=0,l=d,a=t(this,s,"f"),r=0,h=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(()=>{r+=1,i-=t(this,s,"f");let e=this.format_timestamp_to_day_hour_minute_second(i);l({remain:i,obj:e});const n=Date.now()-(h+r*t(this,s,"f"));let a=t(this,s,"f")-n;a<0&&(a=0),t(this,m,"f").call(this,i,l,a,r,h)},a),"f")}),_.set(this,(i=0,n=d,a=t(this,s,"f"),r=0,h=Date.now())=>{if(i<=0)return clearTimeout(t(this,l,"f")),void e(this,l,null,"f");clearTimeout(t(this,l,"f")),e(this,l,setTimeout(()=>{r+=1,i-=t(this,s,"f");let e=this.format_num2date(i);n({remain:i,obj:e});const l=Date.now()-(h+r*t(this,s,"f"));let a=t(this,s,"f")-l;a<0&&(a=0),t(this,_,"f").call(this,i,n,a,r,h)},a),"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,s=!1)=>{if(!Array.isArray(t)||e<=0)return[];const i=[];for(let l=0;l<t.length;l+=e){const n=t.slice(l,l+e);s?n.length===e&&i.push(n):i.push(n)}return i},this.debounce=(t,e=200,s=!1)=>{let i,l=null;return function(...n){const a=this,r=s&&!l;return l&&clearTimeout(l),l=setTimeout(()=>{l=null,s||(i=t.apply(a,n))},e),r&&(i=t.apply(a,n)),i}},this.flatten=(t,e=!1)=>{let s=[];return t.forEach(t=>{e&&Array.isArray(t)?s=s.concat(this.flatten(t,e)):s.push(t)}),s},this.safeRequest=(t,e)=>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])}before_lt_hour(e=Date.now(),s=1){return t(this,f,"f").call(this,{date:e,hour:s,type:"before_lt_hour"})}before_gt_hour(e=Date.now(),s=1){return t(this,f,"f").call(this,{date:e,hour:s,type:"before_gt_hour"})}after_lt_hour(e=Date.now(),s=1){return t(this,f,"f").call(this,{date:e,hour:s,type:"after_lt_hour"})}after_gt_hour(e=Date.now(),s=1){return t(this,f,"f").call(this,{date:e,hour:s,type:"after_gt_hour"})}is_current_year(e){const s=t(this,r,"f").call(this,e);return(new Date).getFullYear()===new Date(s).getFullYear()}get_time_obj(e){const s=t(this,r,"f").call(this,e),i=new Date(s),l=t(this,c,"f").call(this,i.getMonth()+1),n=t(this,c,"f").call(this,i.getDate()),a=t(this,c,"f").call(this,i.getHours()),h=t(this,c,"f").call(this,i.getMinutes()),o=t(this,c,"f").call(this,i.getSeconds());return{year:String(i.getFullYear()),month:l,day:n,hour:a,minute:h,seconds:o,day_of_week:String(i.getDay())}}format_count({num:t=0,decimal:e=1,divide:s=1e4,suffix:i="万",show_suffix_always:l=!1}){if(!t)return 0;if(s<=0||e<0)return l?`${t} ${i}`:t;const n=parseFloat(t);if(n<=0)return l?`${n} ${i}`:n;if(n>0&&n<s)return l?`${n} ${i}`:n;const[a,r]=(n/s).toFixed(e).split(".");return r&&0!==parseFloat(r)?`${a}.${r} ${i}`:`${a} ${i}`}format_num2date(e=Date.now()){const s=parseInt(e/1e3/60/60/24%24),i=parseInt(e/1e3/60/60%24),l=parseInt(e/1e3/60%60),n=parseInt(e/1e3%60);return{day:t(this,c,"f").call(this,s),hour:t(this,c,"f").call(this,i),minute:t(this,c,"f").call(this,l),seconds:t(this,c,"f").call(this,n)}}count_down_by_remain_seconds(t=d,e=60){let s;clearTimeout(s);let i=1e3*e,l=this.format_num2date(i),n={remain:i,obj:l};t(n);let a=this;return function t(e=0,r=d,h=1e3,o=0,u=Date.now()){if(e<=0)return clearTimeout(s),a=null,s=null,i=null,l=null,n=null,void r({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(s),s=setTimeout(()=>{o+=1,e-=1e3;let s=a.format_num2date(e);r({remain:e,obj:s});let i=1e3-(Date.now()-(u+1e3*o));i<0&&(i=0),t(e,r,i,o,u)},h)}(i,t,1e3),()=>{clearTimeout(s),a=null,s=null,i=null,l=null,n=null}}format_timestamp_to_day_hour_minute_second(e=Date.now()){const s=Math.floor(e/864e5),i=Math.floor(e%864e5/36e5),l=Math.floor(e%36e5/6e4),n=Math.floor(e%6e4/1e3);return{day:t(this,c,"f").call(this,s),hour:t(this,c,"f").call(this,i),minute:t(this,c,"f").call(this,l),seconds:t(this,c,"f").call(this,n)}}count_down(e=Date.now(),s=d){let i;clearTimeout(i);let l=this,n=t(this,r,"f").call(this,e),a=n-Date.now(),h=this.format_timestamp_to_day_hour_minute_second(a),o={remain:a,obj:h};return s(o),function t(e=0,s=d,r=1e3,u=0,c=Date.now()){if(e<=0)return clearTimeout(i),i=null,l=null,n=null,a=null,h=null,o=null,void s({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{u+=1,e-=1e3;let i=l.format_timestamp_to_day_hour_minute_second(e);s({remain:e,obj:i});let n=1e3-(Date.now()-(c+1e3*u));n<0&&(n=0),t(e,s,n,u,c)},r)}(a,s,1e3),()=>{clearTimeout(i),i=null,l=null,n=null,a=null,h=null,o=null}}add(e=1,s=Date.now()){return t(this,r,"f").call(this,s)+60*e*60*1e3}format_thousandth(t,e=2){try{const s=parseFloat(t),i=s.toString().split(".");let l=!1,n="";i[1]&&(n=i[1].replace(/0+$/,""),l=n.length>0);let a=0;l&&(a=void 0!==e?e:n.length);const r=s.toFixed(a).split("."),h=(r[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return r[1]?`${h}.${r[1]}`:h}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const s=(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 s&&(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,a,"f").call(this,e)?!e.trim():"Array"===t(this,a,"f").call(this,e)?!e.length:"Object"===t(this,a,"f").call(this,e)&&!Object.keys(e).length)}poll(e,s=1){let i;if(!t(this,h,"f").call(this,e))return()=>{clearTimeout(i),i=void 0};const l=60*s*1e3,n=()=>{e(),i=setTimeout(n,l)};return n(),()=>{clearTimeout(i),i=void 0}}is_equal(e,s,i=!1){const l=t(this,o,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,o,"f").call(this,s)||t(this,u,"f").call(this,s);if(!l||!n)return i?e===s:e==s;const a=Object.keys(e),r=Object.keys(s);return 0===a.length&&0===r.length||a.length===r.length&&a.every(l=>{const n=t(this,o,"f").call(this,e[l])||t(this,u,"f").call(this,e[l]),a=t(this,o,"f").call(this,s[l])||t(this,u,"f").call(this,s[l]);return n&&a?this.is_equal(e[l],s[l],i):i?e[l]===s[l]:e[l]==s[l]})}contains(e,s,i=!1){const l=t(this,o,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,o,"f").call(this,s)||t(this,u,"f").call(this,s);if(!l||!n)return i?e===s:e==s;const a=Object.keys(e),r=Object.keys(s);return 0===r.length||!(0===a.length||a.length<r.length)&&r.every(l=>{if(a.indexOf(l)<0)return!1;const n=t(this,o,"f").call(this,e[l])||t(this,u,"f").call(this,e[l]),r=t(this,o,"f").call(this,s[l])||t(this,u,"f").call(this,s[l]);return n&&r?this.contains(e[l],s[l],i):i?e[l]===s[l]:e[l]==s[l]})}};export{p as default,p as helper};
@@ -1,61 +1,62 @@
1
- type DateType = number | string | Date;
2
- interface GetTimeObj {
3
- year: string;
4
- month: string;
5
- day: string;
6
- hour: string;
7
- minute: string;
8
- seconds: string;
9
- day_of_week: string;
10
- }
11
- interface FormatCount {
12
- num?: number | string;
13
- decimal?: number;
14
- divide?: number;
15
- suffix?: string;
16
- show_suffix_always?: boolean;
17
- }
18
- type OffsetTimeReturnType = 'day' | 'hour' | 'minute' | 'second';
19
- type FormatNum2Date = Required<Omit<GetTimeObj, 'day_of_week' | 'year' | 'month'>>;
20
- interface CountDownCallbackParams {
21
- remain: number;
22
- obj: FormatNum2Date;
23
- }
24
- type CountDownCallback = (data: CountDownCallbackParams) => any;
25
- declare class Helper {
26
- #private;
27
- offset_time: (date?: DateType, return_type?: OffsetTimeReturnType) => string;
28
- before_lt_hour(date?: DateType, hour?: number): boolean;
29
- before_gt_hour(date?: DateType, hour?: number): boolean;
30
- after_lt_hour(date?: DateType, hour?: number): boolean;
31
- after_gt_hour(date?: DateType, hour?: number): boolean;
32
- is_current_year(date?: DateType): boolean;
33
- get_time_obj(date?: DateType): GetTimeObj;
34
- format_count({ num, decimal, divide, suffix, show_suffix_always }: FormatCount): number | string;
35
- format_num2date(timestamp?: number): FormatNum2Date;
36
- count_down_by_remain_seconds(fn?: CountDownCallback, seconds?: number): Function;
37
- format_timestamp_to_day_hour_minute_second(timestamp?: number): FormatNum2Date;
38
- count_down(date?: DateType, fn?: CountDownCallback): Function;
39
- add(hours?: number, start?: DateType): number;
40
- format_thousandth(num: number | string, decimalPlaces?: number): string | 0;
41
- format_thousandth_with_same_dotlen(num: number | string): string | 0;
42
- is_empty(data: any): boolean;
43
- poll(fn: Function, minute?: number): Function;
44
- is_equal(a: any, b: any, exact?: boolean): boolean;
45
- contains(largeRangeData: any, smallRangeData: any, exact?: boolean): boolean;
46
- sleep: (ms: number) => Promise<unknown>;
47
- roxFormatThousandth: (num: number, suffix?: string) => string | number;
48
- chunk: <T>(arr: T[], size: number, exact?: boolean) => T[][];
49
- /**
50
- * 防抖函数,限制函数在指定时间内只执行一次
51
- * @param {Function} func - 需要防抖处理的函数
52
- * @param {number} wait - 防抖时间间隔,单位为毫秒
53
- * @param {boolean} immediate - 是否立即执行一次(触发事件时立即执行,而不是间隔结束后执行)
54
- * @returns {Function} - 返回一个新的防抖处理过的函数
55
- */
56
- debounce: (func: (...args: any[]) => any, wait?: number, immediate?: boolean) => (this: any, ...args: any[]) => any;
57
- flatten: <T>(arr: T[], deep?: boolean) => T[];
58
- safeRequest: <T = any>(promise: Promise<any>, errorInfo: Record<string, any>) => Promise<[any, undefined] | [null, T]>;
59
- }
60
- declare const _default: Helper;
61
- export default _default;
1
+ type DateType = number | string | Date;
2
+ interface GetTimeObj {
3
+ year: string;
4
+ month: string;
5
+ day: string;
6
+ hour: string;
7
+ minute: string;
8
+ seconds: string;
9
+ day_of_week: string;
10
+ }
11
+ interface FormatCount {
12
+ num?: number | string;
13
+ decimal?: number;
14
+ divide?: number;
15
+ suffix?: string;
16
+ show_suffix_always?: boolean;
17
+ }
18
+ type OffsetTimeReturnType = "day" | "hour" | "minute" | "second";
19
+ type FormatNum2Date = Required<Omit<GetTimeObj, "day_of_week" | "year" | "month">>;
20
+ interface CountDownCallbackParams {
21
+ remain: number;
22
+ obj: FormatNum2Date;
23
+ }
24
+ type CountDownCallback = (data: CountDownCallbackParams) => any;
25
+ declare class Helper {
26
+ #private;
27
+ offset_time: (date?: DateType, return_type?: OffsetTimeReturnType) => string;
28
+ before_lt_hour(date?: DateType, hour?: number): boolean;
29
+ before_gt_hour(date?: DateType, hour?: number): boolean;
30
+ after_lt_hour(date?: DateType, hour?: number): boolean;
31
+ after_gt_hour(date?: DateType, hour?: number): boolean;
32
+ is_current_year(date?: DateType): boolean;
33
+ get_time_obj(date?: DateType): GetTimeObj;
34
+ format_count({ num, decimal, divide, suffix, show_suffix_always }: FormatCount): number | string;
35
+ format_num2date(timestamp?: number): FormatNum2Date;
36
+ count_down_by_remain_seconds(fn?: CountDownCallback, seconds?: number): Function;
37
+ format_timestamp_to_day_hour_minute_second(timestamp?: number): FormatNum2Date;
38
+ count_down(date?: DateType, fn?: CountDownCallback): Function;
39
+ add(hours?: number, start?: DateType): number;
40
+ format_thousandth(num: number | string, decimalPlaces?: number): string | 0;
41
+ format_thousandth_with_same_dotlen(num: number | string): string | 0;
42
+ is_empty(data: any): boolean;
43
+ poll(fn: Function, minute?: number): Function;
44
+ is_equal(a: any, b: any, exact?: boolean): boolean;
45
+ contains(largeRangeData: any, smallRangeData: any, exact?: boolean): boolean;
46
+ sleep: (ms: number) => Promise<unknown>;
47
+ roxFormatThousandth: (num: number, suffix?: string) => string | number;
48
+ chunk: <T>(arr: T[], size: number, exact?: boolean) => T[][];
49
+ /**
50
+ * 防抖函数,限制函数在指定时间内只执行一次
51
+ * @param {Function} func - 需要防抖处理的函数
52
+ * @param {number} wait - 防抖时间间隔,单位为毫秒
53
+ * @param {boolean} immediate - 是否立即执行一次(触发事件时立即执行,而不是间隔结束后执行)
54
+ * @returns {Function} - 返回一个新的防抖处理过的函数
55
+ */
56
+ debounce: (func: (...args: any[]) => any, wait?: number, immediate?: boolean) => (this: any, ...args: any[]) => any;
57
+ flatten: <T>(arr: T[], deep?: boolean) => T[];
58
+ safeRequest: <T = any>(promise: Promise<any>, errorInfo?: Record<string, any>) => Promise<[Error | null, T | undefined]>;
59
+ }
60
+ declare const helper: Helper;
61
+
62
+ export { helper as default, helper };
package/package.json CHANGED
@@ -1,34 +1,40 @@
1
1
  {
2
- "name": "fish-helper",
3
- "private": false,
4
- "version": "0.0.50",
5
- "main": "build/helper.cjs.js",
6
- "module": "build/helper.es.js",
7
- "types": "build/types/index.d.ts",
8
- "license": "MIT",
9
- "keywords": [
10
- "js Utils"
11
- ],
12
- "description": "a tool to process time",
13
- "exports": {
14
- ".": {
15
- "require": "./build/helper.cjs.js",
16
- "import": "./build/helper.es.js",
17
- "types": "./build/types/index.d.ts"
18
- },
19
- "./package.json": "./package.json"
20
- },
21
- "files": [
22
- "build"
23
- ],
24
- "scripts": {},
25
- "author": {
26
- "name": "weixin_38726348"
27
- },
28
- "repository": {
29
- "url": "https://gitcode.net/weixin_38726348/util.git"
30
- },
31
- "devDependencies": {
32
- "rollup": "^3.10.0"
2
+ "name": "fish-helper",
3
+ "version": "0.0.52",
4
+ "description": "a tool to process time",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/es/index.js",
7
+ "types": "./dist/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/es/index.js",
11
+ "require": "./dist/cjs/index.js",
12
+ "types": "./dist/types/index.d.ts"
33
13
  }
34
- }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "js utils"
20
+ ],
21
+ "author": "a-drowned-fish",
22
+ "license": "MIT",
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "devDependencies": {
27
+ "tslib": "^2.8.1"
28
+ },
29
+ "peerDependencies": {
30
+ "tslib": "^2.8.1"
31
+ },
32
+ "buildOptions": {
33
+ "name": "helper",
34
+ "formats": [
35
+ "cjs",
36
+ "es"
37
+ ]
38
+ },
39
+ "scripts": {}
40
+ }
@@ -1 +0,0 @@
1
- "use strict";function t(t,e,i,s){if("function"==typeof e||!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(t):s?s.value:e.get(t)}function e(t,e,i,s,l){if("function"==typeof e||!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,i),i}var i,s,l,n,r,a,h,o,u,c,f,m,d;Object.defineProperty(exports,"__esModule",{value:!0});const _=()=>null;i=new WeakMap,s=new WeakMap,l=new WeakMap,n=new WeakMap,r=new WeakMap,a=new WeakMap,h=new WeakMap,o=new WeakMap,u=new WeakMap,c=new WeakMap,f=new WeakMap,m=new WeakMap,d=new WeakMap;var p=new class{constructor(){i.set(this,1e3),s.set(this,36e5),l.set(this,null),n.set(this,null),r.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 i=new Date(e);return"Invalid Date"===i.toString()&&(i=new Date(t)),i.getTime()})),h.set(this,(e=>"Function"===t(this,r,"f").call(this,e))),o.set(this,(e=>"Array"===t(this,r,"f").call(this,e))),u.set(this,(e=>"Object"===t(this,r,"f").call(this,e))),c.set(this,(t=>String(t).padStart(2,"0"))),f.set(this,(({date:e,hour:i=1,type:l="before_lt_hour"})=>{let n=t(this,a,"f").call(this,e);const r=new Date(n).getTime(),h=Date.now(),o=r<h,u=r>h;return"before_lt_hour"===l?o&&r+t(this,s,"f")*i>h:"before_gt_hour"===l?o&&r+t(this,s,"f")*i<h:"after_lt_hour"===l?u&&h+t(this,s,"f")*i>r:"after_gt_hour"===l&&(u&&h+t(this,s,"f")*i<r)})),this.offset_time=(e,i="minute")=>{const s=Math.abs(Date.now()-t(this,a,"f").call(this,e)),l=this.format_num2date(s);return"day"===i?t(this,c,"f").call(this,l.day):"hour"===i?t(this,c,"f").call(this,l.hour):"minute"===i?t(this,c,"f").call(this,l.minute):"second"===i?t(this,c,"f").call(this,l.seconds):"The second parameter has an error"},m.set(this,((s=0,l=_,r=t(this,i,"f"),a=0,h=Date.now())=>{if(s<=0)return clearTimeout(t(this,n,"f")),void e(this,n,null);clearTimeout(t(this,n,"f")),e(this,n,setTimeout((()=>{a+=1,s-=t(this,i,"f");let e=this.format_timestamp_to_day_hour_minute_second(s);l({remain:s,obj:e});const n=Date.now()-(h+a*t(this,i,"f"));let r=t(this,i,"f")-n;r<0&&(r=0),t(this,m,"f").call(this,s,l,r,a,h)}),r))})),d.set(this,((s=0,n=_,r=t(this,i,"f"),a=0,h=Date.now())=>{if(s<=0)return clearTimeout(t(this,l,"f")),void e(this,l,null);clearTimeout(t(this,l,"f")),e(this,l,setTimeout((()=>{a+=1,s-=t(this,i,"f");let e=this.format_num2date(s);n({remain:s,obj:e});const l=Date.now()-(h+a*t(this,i,"f"));let r=t(this,i,"f")-l;r<0&&(r=0),t(this,d,"f").call(this,s,n,r,a,h)}),r))})),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,i=!1)=>{if(!Array.isArray(t)||e<=0)return[];const s=[];for(let l=0;l<t.length;l+=e){const n=t.slice(l,l+e);i?n.length===e&&s.push(n):s.push(n)}return s},this.debounce=(t,e=200,i=!1)=>{let s,l=null;return function(...n){const r=this,a=i&&!l;return l&&clearTimeout(l),l=setTimeout((()=>{l=null,i||(s=t.apply(r,n))}),e),a&&(s=t.apply(r,n)),s}},this.flatten=(t,e=!1)=>{let i=[];return t.forEach((t=>{e&&Array.isArray(t)?i=i.concat(this.flatten(t,e)):i.push(t)})),i},this.safeRequest=(t,e)=>t.then((t=>[null,t])).catch((t=>(e&&Object.assign(t,e),[t,void 0])))}before_lt_hour(e,i=1){return t(this,f,"f").call(this,{date:e,hour:i,type:"before_lt_hour"})}before_gt_hour(e,i=1){return t(this,f,"f").call(this,{date:e,hour:i,type:"before_gt_hour"})}after_lt_hour(e,i=1){return t(this,f,"f").call(this,{date:e,hour:i,type:"after_lt_hour"})}after_gt_hour(e,i=1){return t(this,f,"f").call(this,{date:e,hour:i,type:"after_gt_hour"})}is_current_year(e){const i=t(this,a,"f").call(this,e);return(new Date).getFullYear()===new Date(i).getFullYear()}get_time_obj(e){const i=t(this,a,"f").call(this,e),s=new Date(i),l=t(this,c,"f").call(this,s.getMonth()+1),n=t(this,c,"f").call(this,s.getDate()),r=t(this,c,"f").call(this,s.getHours()),h=t(this,c,"f").call(this,s.getMinutes()),o=t(this,c,"f").call(this,s.getSeconds());return{year:String(s.getFullYear()),month:l,day:n,hour:r,minute:h,seconds:o,day_of_week:String(s.getDay())}}format_count({num:t=0,decimal:e=1,divide:i=1e4,suffix:s="万",show_suffix_always:l=!1}){if(!t)return 0;if(i<=0||e<0)return l?`${t} ${s}`:t;const n=parseFloat(t);if(n<=0)return l?`${n} ${s}`:n;if(n>0&&n<i)return l?`${n} ${s}`:n;const[r,a]=(n/i).toFixed(e).split(".");return a&&0!==parseFloat(a)?`${r}.${a} ${s}`:`${r} ${s}`}format_num2date(e=Date.now()){const i=parseInt(e/1e3/60/60/24%24),s=parseInt(e/1e3/60/60%24),l=parseInt(e/1e3/60%60),n=parseInt(e/1e3%60);return{day:t(this,c,"f").call(this,i),hour:t(this,c,"f").call(this,s),minute:t(this,c,"f").call(this,l),seconds:t(this,c,"f").call(this,n)}}count_down_by_remain_seconds(t=_,e=60){let i;clearTimeout(i);let s=1e3*e,l=this.format_num2date(s),n={remain:s,obj:l};t(n);let r=this;return function t(e=0,a=_,h=1e3,o=0,u=Date.now()){if(e<=0)return clearTimeout(i),r=null,i=null,s=null,l=null,n=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout((()=>{o+=1,e-=1e3;let i=r.format_num2date(e);a({remain:e,obj:i});let s=1e3-(Date.now()-(u+1e3*o));s<0&&(s=0),t(e,a,s,o,u)}),h)}(s,t,1e3),()=>{clearTimeout(i),r=null,i=null,s=null,l=null,n=null}}format_timestamp_to_day_hour_minute_second(e=Date.now()){const i=Math.floor(e/864e5),s=Math.floor(e%864e5/36e5),l=Math.floor(e%36e5/6e4),n=Math.floor(e%6e4/1e3);return{day:t(this,c,"f").call(this,i),hour:t(this,c,"f").call(this,s),minute:t(this,c,"f").call(this,l),seconds:t(this,c,"f").call(this,n)}}count_down(e=Date.now(),i=_){let s;clearTimeout(s);let l=this,n=t(this,a,"f").call(this,e),r=n-Date.now(),h=this.format_timestamp_to_day_hour_minute_second(r),o={remain:r,obj:h};return i(o),function t(e=0,i=_,a=1e3,u=0,c=Date.now()){if(e<=0)return clearTimeout(s),s=null,l=null,n=null,r=null,h=null,o=null,void i({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(s),s=setTimeout((()=>{u+=1,e-=1e3;let s=l.format_timestamp_to_day_hour_minute_second(e);i({remain:e,obj:s});let n=1e3-(Date.now()-(c+1e3*u));n<0&&(n=0),t(e,i,n,u,c)}),a)}(r,i,1e3),()=>{clearTimeout(s),s=null,l=null,n=null,r=null,h=null,o=null}}add(e=1,i=Date.now()){return t(this,a,"f").call(this,i)+60*e*60*1e3}format_thousandth(t,e=2){try{const i=parseFloat(t),s=i.toString().split(".");let l=!1,n="";s[1]&&(n=s[1].replace(/0+$/,""),l=n.length>0);let r=0;l&&(r=void 0!==e?e:n.length);const a=i.toFixed(r).split("."),h=a[0].replace(/(\d)(?=(\d{3})+$)/g,"$1,");return a[1]?`${h}.${a[1]}`:h}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const i=(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 i&&(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,r,"f").call(this,e)?!e.trim():"Array"===t(this,r,"f").call(this,e)?!e.length:"Object"===t(this,r,"f").call(this,e)&&!Object.keys(e).length)}poll(e,i=1){let s;if(!t(this,h,"f").call(this,e))return()=>{clearTimeout(s),s=void 0};const l=60*i*1e3,n=()=>{e(),s=setTimeout(n,l)};return n(),()=>{clearTimeout(s),s=void 0}}is_equal(e,i,s=!1){const l=t(this,o,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,o,"f").call(this,i)||t(this,u,"f").call(this,i);if(!l||!n)return s?e===i:e==i;const r=Object.keys(e),a=Object.keys(i);return 0===r.length&&0===a.length||r.length===a.length&&r.every((l=>{const n=t(this,o,"f").call(this,e[l])||t(this,u,"f").call(this,e[l]),r=t(this,o,"f").call(this,i[l])||t(this,u,"f").call(this,i[l]);return n&&r?this.is_equal(e[l],i[l],s):s?e[l]===i[l]:e[l]==i[l]}))}contains(e,i,s=!1){const l=t(this,o,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,o,"f").call(this,i)||t(this,u,"f").call(this,i);if(!l||!n)return s?e===i:e==i;const r=Object.keys(e),a=Object.keys(i);return 0===a.length||!(0===r.length||r.length<a.length)&&a.every((l=>{if(r.indexOf(l)<0)return!1;const n=t(this,o,"f").call(this,e[l])||t(this,u,"f").call(this,e[l]),a=t(this,o,"f").call(this,i[l])||t(this,u,"f").call(this,i[l]);return n&&a?this.contains(e[l],i[l],s):s?e[l]===i[l]:e[l]==i[l]}))}};exports.default=p;
@@ -1 +0,0 @@
1
- function t(t,e,i,s){if("function"==typeof e||!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(t):s?s.value:e.get(t)}function e(t,e,i,s,l){if("function"==typeof e||!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,i),i}var i,s,l,n,r,a,h,o,u,c,f,m,d;const _=()=>null;i=new WeakMap,s=new WeakMap,l=new WeakMap,n=new WeakMap,r=new WeakMap,a=new WeakMap,h=new WeakMap,o=new WeakMap,u=new WeakMap,c=new WeakMap,f=new WeakMap,m=new WeakMap,d=new WeakMap;var p=new class{constructor(){i.set(this,1e3),s.set(this,36e5),l.set(this,null),n.set(this,null),r.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 i=new Date(e);return"Invalid Date"===i.toString()&&(i=new Date(t)),i.getTime()})),h.set(this,(e=>"Function"===t(this,r,"f").call(this,e))),o.set(this,(e=>"Array"===t(this,r,"f").call(this,e))),u.set(this,(e=>"Object"===t(this,r,"f").call(this,e))),c.set(this,(t=>String(t).padStart(2,"0"))),f.set(this,(({date:e,hour:i=1,type:l="before_lt_hour"})=>{let n=t(this,a,"f").call(this,e);const r=new Date(n).getTime(),h=Date.now(),o=r<h,u=r>h;return"before_lt_hour"===l?o&&r+t(this,s,"f")*i>h:"before_gt_hour"===l?o&&r+t(this,s,"f")*i<h:"after_lt_hour"===l?u&&h+t(this,s,"f")*i>r:"after_gt_hour"===l&&(u&&h+t(this,s,"f")*i<r)})),this.offset_time=(e,i="minute")=>{const s=Math.abs(Date.now()-t(this,a,"f").call(this,e)),l=this.format_num2date(s);return"day"===i?t(this,c,"f").call(this,l.day):"hour"===i?t(this,c,"f").call(this,l.hour):"minute"===i?t(this,c,"f").call(this,l.minute):"second"===i?t(this,c,"f").call(this,l.seconds):"The second parameter has an error"},m.set(this,((s=0,l=_,r=t(this,i,"f"),a=0,h=Date.now())=>{if(s<=0)return clearTimeout(t(this,n,"f")),void e(this,n,null);clearTimeout(t(this,n,"f")),e(this,n,setTimeout((()=>{a+=1,s-=t(this,i,"f");let e=this.format_timestamp_to_day_hour_minute_second(s);l({remain:s,obj:e});const n=Date.now()-(h+a*t(this,i,"f"));let r=t(this,i,"f")-n;r<0&&(r=0),t(this,m,"f").call(this,s,l,r,a,h)}),r))})),d.set(this,((s=0,n=_,r=t(this,i,"f"),a=0,h=Date.now())=>{if(s<=0)return clearTimeout(t(this,l,"f")),void e(this,l,null);clearTimeout(t(this,l,"f")),e(this,l,setTimeout((()=>{a+=1,s-=t(this,i,"f");let e=this.format_num2date(s);n({remain:s,obj:e});const l=Date.now()-(h+a*t(this,i,"f"));let r=t(this,i,"f")-l;r<0&&(r=0),t(this,d,"f").call(this,s,n,r,a,h)}),r))})),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,i=!1)=>{if(!Array.isArray(t)||e<=0)return[];const s=[];for(let l=0;l<t.length;l+=e){const n=t.slice(l,l+e);i?n.length===e&&s.push(n):s.push(n)}return s},this.debounce=(t,e=200,i=!1)=>{let s,l=null;return function(...n){const r=this,a=i&&!l;return l&&clearTimeout(l),l=setTimeout((()=>{l=null,i||(s=t.apply(r,n))}),e),a&&(s=t.apply(r,n)),s}},this.flatten=(t,e=!1)=>{let i=[];return t.forEach((t=>{e&&Array.isArray(t)?i=i.concat(this.flatten(t,e)):i.push(t)})),i},this.safeRequest=(t,e)=>t.then((t=>[null,t])).catch((t=>(e&&Object.assign(t,e),[t,void 0])))}before_lt_hour(e,i=1){return t(this,f,"f").call(this,{date:e,hour:i,type:"before_lt_hour"})}before_gt_hour(e,i=1){return t(this,f,"f").call(this,{date:e,hour:i,type:"before_gt_hour"})}after_lt_hour(e,i=1){return t(this,f,"f").call(this,{date:e,hour:i,type:"after_lt_hour"})}after_gt_hour(e,i=1){return t(this,f,"f").call(this,{date:e,hour:i,type:"after_gt_hour"})}is_current_year(e){const i=t(this,a,"f").call(this,e);return(new Date).getFullYear()===new Date(i).getFullYear()}get_time_obj(e){const i=t(this,a,"f").call(this,e),s=new Date(i),l=t(this,c,"f").call(this,s.getMonth()+1),n=t(this,c,"f").call(this,s.getDate()),r=t(this,c,"f").call(this,s.getHours()),h=t(this,c,"f").call(this,s.getMinutes()),o=t(this,c,"f").call(this,s.getSeconds());return{year:String(s.getFullYear()),month:l,day:n,hour:r,minute:h,seconds:o,day_of_week:String(s.getDay())}}format_count({num:t=0,decimal:e=1,divide:i=1e4,suffix:s="万",show_suffix_always:l=!1}){if(!t)return 0;if(i<=0||e<0)return l?`${t} ${s}`:t;const n=parseFloat(t);if(n<=0)return l?`${n} ${s}`:n;if(n>0&&n<i)return l?`${n} ${s}`:n;const[r,a]=(n/i).toFixed(e).split(".");return a&&0!==parseFloat(a)?`${r}.${a} ${s}`:`${r} ${s}`}format_num2date(e=Date.now()){const i=parseInt(e/1e3/60/60/24%24),s=parseInt(e/1e3/60/60%24),l=parseInt(e/1e3/60%60),n=parseInt(e/1e3%60);return{day:t(this,c,"f").call(this,i),hour:t(this,c,"f").call(this,s),minute:t(this,c,"f").call(this,l),seconds:t(this,c,"f").call(this,n)}}count_down_by_remain_seconds(t=_,e=60){let i;clearTimeout(i);let s=1e3*e,l=this.format_num2date(s),n={remain:s,obj:l};t(n);let r=this;return function t(e=0,a=_,h=1e3,o=0,u=Date.now()){if(e<=0)return clearTimeout(i),r=null,i=null,s=null,l=null,n=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout((()=>{o+=1,e-=1e3;let i=r.format_num2date(e);a({remain:e,obj:i});let s=1e3-(Date.now()-(u+1e3*o));s<0&&(s=0),t(e,a,s,o,u)}),h)}(s,t,1e3),()=>{clearTimeout(i),r=null,i=null,s=null,l=null,n=null}}format_timestamp_to_day_hour_minute_second(e=Date.now()){const i=Math.floor(e/864e5),s=Math.floor(e%864e5/36e5),l=Math.floor(e%36e5/6e4),n=Math.floor(e%6e4/1e3);return{day:t(this,c,"f").call(this,i),hour:t(this,c,"f").call(this,s),minute:t(this,c,"f").call(this,l),seconds:t(this,c,"f").call(this,n)}}count_down(e=Date.now(),i=_){let s;clearTimeout(s);let l=this,n=t(this,a,"f").call(this,e),r=n-Date.now(),h=this.format_timestamp_to_day_hour_minute_second(r),o={remain:r,obj:h};return i(o),function t(e=0,i=_,a=1e3,u=0,c=Date.now()){if(e<=0)return clearTimeout(s),s=null,l=null,n=null,r=null,h=null,o=null,void i({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(s),s=setTimeout((()=>{u+=1,e-=1e3;let s=l.format_timestamp_to_day_hour_minute_second(e);i({remain:e,obj:s});let n=1e3-(Date.now()-(c+1e3*u));n<0&&(n=0),t(e,i,n,u,c)}),a)}(r,i,1e3),()=>{clearTimeout(s),s=null,l=null,n=null,r=null,h=null,o=null}}add(e=1,i=Date.now()){return t(this,a,"f").call(this,i)+60*e*60*1e3}format_thousandth(t,e=2){try{const i=parseFloat(t),s=i.toString().split(".");let l=!1,n="";s[1]&&(n=s[1].replace(/0+$/,""),l=n.length>0);let r=0;l&&(r=void 0!==e?e:n.length);const a=i.toFixed(r).split("."),h=a[0].replace(/(\d)(?=(\d{3})+$)/g,"$1,");return a[1]?`${h}.${a[1]}`:h}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const i=(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 i&&(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,r,"f").call(this,e)?!e.trim():"Array"===t(this,r,"f").call(this,e)?!e.length:"Object"===t(this,r,"f").call(this,e)&&!Object.keys(e).length)}poll(e,i=1){let s;if(!t(this,h,"f").call(this,e))return()=>{clearTimeout(s),s=void 0};const l=60*i*1e3,n=()=>{e(),s=setTimeout(n,l)};return n(),()=>{clearTimeout(s),s=void 0}}is_equal(e,i,s=!1){const l=t(this,o,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,o,"f").call(this,i)||t(this,u,"f").call(this,i);if(!l||!n)return s?e===i:e==i;const r=Object.keys(e),a=Object.keys(i);return 0===r.length&&0===a.length||r.length===a.length&&r.every((l=>{const n=t(this,o,"f").call(this,e[l])||t(this,u,"f").call(this,e[l]),r=t(this,o,"f").call(this,i[l])||t(this,u,"f").call(this,i[l]);return n&&r?this.is_equal(e[l],i[l],s):s?e[l]===i[l]:e[l]==i[l]}))}contains(e,i,s=!1){const l=t(this,o,"f").call(this,e)||t(this,u,"f").call(this,e),n=t(this,o,"f").call(this,i)||t(this,u,"f").call(this,i);if(!l||!n)return s?e===i:e==i;const r=Object.keys(e),a=Object.keys(i);return 0===a.length||!(0===r.length||r.length<a.length)&&a.every((l=>{if(r.indexOf(l)<0)return!1;const n=t(this,o,"f").call(this,e[l])||t(this,u,"f").call(this,e[l]),a=t(this,o,"f").call(this,i[l])||t(this,u,"f").call(this,i[l]);return n&&a?this.contains(e[l],i[l],s):s?e[l]===i[l]:e[l]==i[l]}))}};export{p as default};