fish-helper 0.0.56 → 0.0.57
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 +22 -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";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=()=>null;const e=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 _=new Date(i).getTime(),n=Date.now(),s=_<n,o=_>n;return"before_lt_hour"===r?s&&_+this.__an_hour*e>n:"before_gt_hour"===r?s&&_+this.__an_hour*e<n:"after_lt_hour"===r?o&&n+this.__an_hour*e>_:"after_gt_hour"===r&&(o&&n+this.__an_hour*e<_)},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=(e=0,r=t,i=this.__interval,_=0,n=Date.now())=>{if(e<=0)return clearTimeout(this.__ticker2),void(this.__ticker2=null);clearTimeout(this.__ticker2),this.__ticker2=setTimeout(()=>{_+=1,e-=this.__interval;let t=this.format_timestamp_to_day_hour_minute_second(e);r({remain:e,obj:t});const i=Date.now()-(n+_*this.__interval);let s=this.__interval-i;s<0&&(s=0),this.__loop_time2(e,r,s,_,n)},i)},this.__loop_time=(e=0,r=t,i=this.__interval,_=0,n=Date.now())=>{if(e<=0)return clearTimeout(this.__ticker),void(this.__ticker=null);clearTimeout(this.__ticker),this.__ticker=setTimeout(()=>{_+=1,e-=this.__interval;let t=this.format_num2date(e);r({remain:e,obj:t});const i=Date.now()-(n+_*this.__interval);let s=this.__interval-i;s<0&&(s=0),this.__loop_time(e,r,s,_,n)},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 _=0;_<t.length;_+=e){const n=t.slice(_,_+e);r?n.length===e&&i.push(n):i.push(n)}return i},this.debounce=(t,e=200,r=!1)=>{let i,_=null;return function(...n){const s=this,o=r&&!_;return _&&clearTimeout(_),_=setTimeout(()=>{_=null,r||(i=t.apply(s,n))},e),o&&(i=t.apply(s,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:_=!1,symbol:n=""}=t,s=(r||"").split(i),o=(e||"").split(i);return s.every((t,e)=>t===n||(_?t===o[e]:o[e]&&t.toLowerCase()===o[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:i=[],skuArrField:_,checkedIndexArr:n=[],combineSkuArr:s=[],disabledArr:o=[],combineSeparator:a="-",combineSkuField:u="id"}=t;for(let t=0;t<i.length;t++){const l=_?(null===(e=i[t])||void 0===e?void 0:e[_])||[]:i[t]||[];Array.isArray(r[t])||(r[t]=[]);for(let e=0;e<l.length;e++){const i=n.slice(0,t),_=n.slice(t+1),l=i.concat(e).concat(_).join(a),h=s.filter(t=>this.checkPattern({str:t[u],likeStr:l,separator:a})),c=o.map(t=>{const{field:e,disabledFun:r,disabledFieldValue:i}=t,_=h.some(t=>r(t));return{[e]:_?i:!i}}).reduce((t,e)=>Object.assign(Object.assign({},t),e),{});r[t][e]=c}}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}}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),_=this.__get_suffix2(r.getDate()),n=this.__get_suffix2(r.getHours()),s=this.__get_suffix2(r.getMinutes()),o=this.__get_suffix2(r.getSeconds());return{year:String(r.getFullYear()),month:i,day:_,hour:n,minute:s,seconds:o,day_of_week:String(r.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:i="万",show_suffix_always:_=!1}){if(!t)return 0;if(r<=0||e<0)return _?`${t} ${i}`:t;const n=parseFloat(t);if(n<=0)return _?`${n} ${i}`:n;if(n>0&&n<r)return _?`${n} ${i}`:n;const[s,o]=(n/r).toFixed(e).split(".");return o&&0!==parseFloat(o)?`${s}.${o} ${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),_=parseInt(t/1e3%60);return{day:this.__get_suffix2(e),hour:this.__get_suffix2(r),minute:this.__get_suffix2(i),seconds:this.__get_suffix2(_)}}count_down_by_remain_seconds(e=t,r=60){let i;clearTimeout(i);let _=1e3*r,n=this.format_num2date(_),s={remain:_,obj:n};e(s);let o=this;return function e(r=0,a=t,u=1e3,l=0,h=Date.now()){if(r<=0)return clearTimeout(i),o=null,i=null,_=null,n=null,s=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{l+=1,r-=1e3;let t=o.format_num2date(r);a({remain:r,obj:t});let i=1e3-(Date.now()-(h+1e3*l));i<0&&(i=0),e(r,a,i,l,h)},u)}(_,e,1e3),()=>{clearTimeout(i),o=null,i=null,_=null,n=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),_=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(_)}}count_down(e=Date.now(),r=t){let i;clearTimeout(i);let _=this,n=this.__date2timestamp(e),s=n-Date.now(),o=this.format_timestamp_to_day_hour_minute_second(s),a={remain:s,obj:o};return r(a),function e(r=0,u=t,l=1e3,h=0,c=Date.now()){if(r<=0)return clearTimeout(i),i=null,_=null,n=null,s=null,o=null,a=null,void u({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{h+=1,r-=1e3;let t=_.format_timestamp_to_day_hour_minute_second(r);u({remain:r,obj:t});let i=1e3-(Date.now()-(c+1e3*h));i<0&&(i=0),e(r,u,i,h,c)},l)}(s,r,1e3),()=>{clearTimeout(i),i=null,_=null,n=null,s=null,o=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 _=!1,n="";i[1]&&(n=i[1].replace(/0+$/,""),_=n.length>0);let s=0;_&&(s=void 0!==e?e:n.length);const o=r.toFixed(s).split("."),a=(o[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return o[1]?`${a}.${o[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,_=()=>{t(),r=setTimeout(_,i)};return _(),()=>{clearTimeout(r),r=void 0}}is_equal(t,e,r=!1){const i=this.__is_array(t)||this.__is_object(t),_=this.__is_array(e)||this.__is_object(e);if(!i||!_)return r?t===e:t==e;const n=Object.keys(t),s=Object.keys(e);return 0===n.length&&0===s.length||n.length===s.length&&n.every(i=>{const _=this.__is_array(t[i])||this.__is_object(t[i]),n=this.__is_array(e[i])||this.__is_object(e[i]);return _&&n?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),_=this.__is_array(e)||this.__is_object(e);if(!i||!_)return r?t===e:t==e;const n=Object.keys(t),s=Object.keys(e);return 0===s.length||!(0===n.length||n.length<s.length)&&s.every(i=>{if(n.indexOf(i)<0)return!1;const _=this.__is_array(t[i])||this.__is_object(t[i]),s=this.__is_array(e[i])||this.__is_object(e[i]);return _&&s?this.contains(t[i],e[i],r):r?t[i]===e[i]:t[i]==e[i]})}};exports.default=e,exports.helper=e;
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const t=()=>null;const e=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(),_=Date.now(),s=n<_,o=n>_;return"before_lt_hour"===r?s&&n+this.__an_hour*e>_:"before_gt_hour"===r?s&&n+this.__an_hour*e<_:"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=(e=0,r=t,i=this.__interval,n=0,_=Date.now())=>{if(e<=0)return clearTimeout(this.__ticker2),void(this.__ticker2=null);clearTimeout(this.__ticker2),this.__ticker2=setTimeout(()=>{n+=1,e-=this.__interval;let t=this.format_timestamp_to_day_hour_minute_second(e);r({remain:e,obj:t});const i=Date.now()-(_+n*this.__interval);let s=this.__interval-i;s<0&&(s=0),this.__loop_time2(e,r,s,n,_)},i)},this.__loop_time=(e=0,r=t,i=this.__interval,n=0,_=Date.now())=>{if(e<=0)return clearTimeout(this.__ticker),void(this.__ticker=null);clearTimeout(this.__ticker),this.__ticker=setTimeout(()=>{n+=1,e-=this.__interval;let t=this.format_num2date(e);r({remain:e,obj:t});const i=Date.now()-(_+n*this.__interval);let s=this.__interval-i;s<0&&(s=0),this.__loop_time(e,r,s,n,_)},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 _=t.slice(n,n+e);r?_.length===e&&i.push(_):i.push(_)}return i},this.debounce=(t,e=200,r=!1)=>{let i,n=null;return function(..._){const s=this,o=r&&!n;return n&&clearTimeout(n),n=setTimeout(()=>{n=null,r||(i=t.apply(s,_))},e),o&&(i=t.apply(s,_)),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:_=""}=t,s=(r||"").split(i),o=(e||"").split(i);return s.every((t,e)=>t===_||(n?t===o[e]:o[e]&&t.toLowerCase()===o[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:i=[],skuArrField:n,checkedIndexArr:_=[],combineSkuArr:s=[],disabledArr:o=[],combineSeparator:a="-",combineSkuField:u="id"}=t;for(let t=0;t<i.length;t++){const l=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<l.length;e++){const i=_.slice(0,t),n=_.slice(t+1),l=i.concat(e).concat(n).join(a),h=s.filter(t=>this.checkPattern({str:t[u],likeStr:l,separator:a})),c=o.map(t=>{const{field:e,disabledFun:r,disabledFieldValue:i}=t,n=h.some(t=>r(t));return{[e]:n?i:!i}}).reduce((t,e)=>Object.assign(Object.assign({},t),e),{});r[t][e]=c}}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}}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()),_=this.__get_suffix2(r.getHours()),s=this.__get_suffix2(r.getMinutes()),o=this.__get_suffix2(r.getSeconds());return{year:String(r.getFullYear()),month:i,day:n,hour:_,minute:s,seconds:o,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 _=parseFloat(t);if(_<=0)return n?`${_} ${i}`:_;if(_>0&&_<r)return n?`${_} ${i}`:_;const[s,o]=(_/r).toFixed(e).split(".");return o&&0!==parseFloat(o)?`${s}.${o} ${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(e=t,r=60){let i;clearTimeout(i);let n=1e3*r,_=this.format_num2date(n),s={remain:n,obj:_};e(s);let o=this;return function e(r=0,a=t,u=1e3,l=0,h=Date.now()){if(r<=0)return clearTimeout(i),o=null,i=null,n=null,_=null,s=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{l+=1,r-=1e3;let t=o.format_num2date(r);a({remain:r,obj:t});let i=1e3-(Date.now()-(h+1e3*l));i<0&&(i=0),e(r,a,i,l,h)},u)}(n,e,1e3),()=>{clearTimeout(i),o=null,i=null,n=null,_=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(e=Date.now(),r=t){let i;clearTimeout(i);let n=this,_=this.__date2timestamp(e),s=_-Date.now(),o=this.format_timestamp_to_day_hour_minute_second(s),a={remain:s,obj:o};return r(a),function e(r=0,u=t,l=1e3,h=0,c=Date.now()){if(r<=0)return clearTimeout(i),i=null,n=null,_=null,s=null,o=null,a=null,void u({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{h+=1,r-=1e3;let t=n.format_timestamp_to_day_hour_minute_second(r);u({remain:r,obj:t});let i=1e3-(Date.now()-(c+1e3*h));i<0&&(i=0),e(r,u,i,h,c)},l)}(s,r,1e3),()=>{clearTimeout(i),i=null,n=null,_=null,s=null,o=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,_="";i[1]&&(_=i[1].replace(/0+$/,""),n=_.length>0);let s=0;n&&(s=void 0!==e?e:_.length);const o=r.toFixed(s).split("."),a=(o[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return o[1]?`${a}.${o[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 _=Object.keys(t),s=Object.keys(e);return 0===_.length&&0===s.length||_.length===s.length&&_.every(i=>{const n=this.__is_array(t[i])||this.__is_object(t[i]),_=this.__is_array(e[i])||this.__is_object(e[i]);return n&&_?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 _=Object.keys(t),s=Object.keys(e);return 0===s.length||!(0===_.length||_.length<s.length)&&s.every(i=>{if(_.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{e as default,e 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,7 @@ 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;
|
|
84
105
|
}
|
|
85
106
|
declare const helper: Helper;
|
|
86
107
|
|