fish-helper 0.0.6 → 0.0.7
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 +4 -2
- package/build/helper.cjs.js +1 -1
- package/build/helper.es.js +1 -1
- package/build/types/index.d.ts +2 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ const helper = require('fish-helper')
|
|
|
14
14
|
>
|
|
15
15
|
> - after_lt_hour(date, hour) ------- The <strong>date</strong> is greater than <strong>now</strong>, and the date is less than <strong>hour</strong> from <strong>now</strong>
|
|
16
16
|
>
|
|
17
|
-
>
|
|
17
|
+
> - after_gt_hour(date, hour) ------- The <strong>date</strong> is greater than <strong>now</strong>, and the date is greater than <strong>hour</strong> from <strong>now</strong>
|
|
18
18
|
>
|
|
19
19
|
> - is_current_year(date) ------- return Boolean
|
|
20
20
|
>
|
|
@@ -24,6 +24,8 @@ const helper = require('fish-helper')
|
|
|
24
24
|
>
|
|
25
25
|
> - format_num2date(timestamp) ------- convert time to Object; return Object that include keys: day、hour、minute、seconds
|
|
26
26
|
>
|
|
27
|
-
> - count_down(
|
|
27
|
+
> - 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
|
|
28
28
|
>
|
|
29
|
+
> - count_down_by_remain_seconds(fn, seconds) ------- 60-second countdown. Time can pass by itself
|
|
30
|
+
>
|
|
29
31
|
> - format_thousandth(num) ------- format the data as a string with thousands of bits
|
package/build/helper.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(t,e,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(t):a?a.value:e.get(t)}function e(t,e,r,a,
|
|
1
|
+
"use strict";function t(t,e,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(t):a?a.value:e.get(t)}function e(t,e,r,a,s){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!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"===a?s.call(t,r):s?s.value=r:e.set(t,r),r}var r,a,s,i,n,o,h,l;const f=()=>null,u=1e3;r=new WeakMap,a=new WeakMap,s=new WeakMap,i=new WeakMap,n=new WeakMap,o=new WeakMap,h=new WeakMap,l=new WeakMap;var c=new class{constructor(){r.set(this,36e5),a.set(this,0),s.set(this,0),i.set(this,0),n.set(this,(t=>{if(!t)return Date.now();let e=null;return e="string"==typeof t?t.replace(/(\/|\.|_)/g,"-"):new Date(t),new Date(e).getTime()})),o.set(this,(t=>`0${t}`.slice(-2))),h.set(this,(({date:e,hour:a=1,type:s="before_lt_hour"})=>{let i=t(this,n,"f").call(this,e);const o=new Date(i).getTime(),h=Date.now(),l=o<h,f=o>h;return"before_lt_hour"===s?l&&o+t(this,r,"f")*a>h:"before_gt_hour"===s?l&&o+t(this,r,"f")*a<h:"after_lt_hour"===s?f&&h+t(this,r,"f")*a>o:"after_gt_hour"===s&&(f&&h+t(this,r,"f")*a<o)})),l.set(this,((r=Date.now(),n=f,o=1e3)=>{r<=Date.now()?clearTimeout(t(this,i,"f")):e(this,i,setTimeout((()=>{if(r<=Date.now())return;e(this,a,t(this,a,"f")+1,"f"),n(r-Date.now());const i=Math.abs(Date.now()-(t(this,s,"f")+t(this,a,"f")*u));u<=i?(e(this,a,0,"f"),e(this,s,Date.now(),"f"),t(this,l,"f").call(this,r,n,0)):t(this,l,"f").call(this,r,n)}),o),"f")}))}before_lt_hour(e,r=1){return t(this,h,"f").call(this,{date:e,hour:r,type:"before_lt_hour"})}before_gt_hour(e,r=1){return t(this,h,"f").call(this,{date:e,hour:r,type:"before_gt_hour"})}after_lt_hour(e,r=1){return t(this,h,"f").call(this,{date:e,hour:r,type:"after_lt_hour"})}after_gt_hour(e,r=1){return t(this,h,"f").call(this,{date:e,hour:r,type:"after_gt_hour"})}is_current_year(e){const r=t(this,n,"f").call(this,e);return(new Date).getFullYear()===new Date(r).getFullYear()}get_time_obj(e){const r=t(this,n,"f").call(this,e),a=new Date(r),s=t(this,o,"f").call(this,a.getMonth()+1),i=t(this,o,"f").call(this,a.getDate()),h=t(this,o,"f").call(this,a.getHours()),l=t(this,o,"f").call(this,a.getMinutes()),f=t(this,o,"f").call(this,a.getSeconds());return{year:String(a.getFullYear()),month:s,day:i,hour:h,minute:l,seconds:f,day_of_week:String(a.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:a="万",show_suffix_always:s=!1}){if(!t)return 0;if(r<=0||e<0)return s?`${t} ${a}`:t;const i=parseFloat(t);if(i<=0)return s?`${i} ${a}`:i;if(i>1&&i<=r)return s?`${i} ${a}`:i;const[n,o]=(i/r).toFixed(e).split(".");return o&&0!==parseFloat(o)?`${n}.${o} ${a}`:`${n} ${a}`}format_num2date(e=Date.now()){const r=parseInt(e/1e3/60/60/24%24),a=parseInt(e/1e3/60/60%24),s=parseInt(e/1e3/60%60),i=parseInt(e/1e3%60);return{day:t(this,o,"f").call(this,r),hour:t(this,o,"f").call(this,a),minute:t(this,o,"f").call(this,s),seconds:t(this,o,"f").call(this,i)}}count_down(r=Date.now(),o=f){const h=t(this,n,"f").call(this,r);return e(this,a,0,"f"),e(this,s,Date.now(),"f"),t(this,l,"f").call(this,h,o),()=>clearTimeout(t(this,i,"f"))}count_down_by_remain_seconds(t=f,e=60){const r=Date.now()+1e3*e;return this.count_down(r,t)}format_thousandth(t){return t.toString().replace(/\d+/,(function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,(function(t){return t+","}))}))}};module.exports=c;
|
package/build/helper.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,e,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(t):a?a.value:e.get(t)}function e(t,e,r,a,
|
|
1
|
+
function t(t,e,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(t):a?a.value:e.get(t)}function e(t,e,r,a,s){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!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"===a?s.call(t,r):s?s.value=r:e.set(t,r),r}var r,a,s,i,n,o,h,l;const f=()=>null,u=1e3;r=new WeakMap,a=new WeakMap,s=new WeakMap,i=new WeakMap,n=new WeakMap,o=new WeakMap,h=new WeakMap,l=new WeakMap;var c=new class{constructor(){r.set(this,36e5),a.set(this,0),s.set(this,0),i.set(this,0),n.set(this,(t=>{if(!t)return Date.now();let e=null;return e="string"==typeof t?t.replace(/(\/|\.|_)/g,"-"):new Date(t),new Date(e).getTime()})),o.set(this,(t=>`0${t}`.slice(-2))),h.set(this,(({date:e,hour:a=1,type:s="before_lt_hour"})=>{let i=t(this,n,"f").call(this,e);const o=new Date(i).getTime(),h=Date.now(),l=o<h,f=o>h;return"before_lt_hour"===s?l&&o+t(this,r,"f")*a>h:"before_gt_hour"===s?l&&o+t(this,r,"f")*a<h:"after_lt_hour"===s?f&&h+t(this,r,"f")*a>o:"after_gt_hour"===s&&(f&&h+t(this,r,"f")*a<o)})),l.set(this,((r=Date.now(),n=f,o=1e3)=>{r<=Date.now()?clearTimeout(t(this,i,"f")):e(this,i,setTimeout((()=>{if(r<=Date.now())return;e(this,a,t(this,a,"f")+1,"f"),n(r-Date.now());const i=Math.abs(Date.now()-(t(this,s,"f")+t(this,a,"f")*u));u<=i?(e(this,a,0,"f"),e(this,s,Date.now(),"f"),t(this,l,"f").call(this,r,n,0)):t(this,l,"f").call(this,r,n)}),o),"f")}))}before_lt_hour(e,r=1){return t(this,h,"f").call(this,{date:e,hour:r,type:"before_lt_hour"})}before_gt_hour(e,r=1){return t(this,h,"f").call(this,{date:e,hour:r,type:"before_gt_hour"})}after_lt_hour(e,r=1){return t(this,h,"f").call(this,{date:e,hour:r,type:"after_lt_hour"})}after_gt_hour(e,r=1){return t(this,h,"f").call(this,{date:e,hour:r,type:"after_gt_hour"})}is_current_year(e){const r=t(this,n,"f").call(this,e);return(new Date).getFullYear()===new Date(r).getFullYear()}get_time_obj(e){const r=t(this,n,"f").call(this,e),a=new Date(r),s=t(this,o,"f").call(this,a.getMonth()+1),i=t(this,o,"f").call(this,a.getDate()),h=t(this,o,"f").call(this,a.getHours()),l=t(this,o,"f").call(this,a.getMinutes()),f=t(this,o,"f").call(this,a.getSeconds());return{year:String(a.getFullYear()),month:s,day:i,hour:h,minute:l,seconds:f,day_of_week:String(a.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:a="万",show_suffix_always:s=!1}){if(!t)return 0;if(r<=0||e<0)return s?`${t} ${a}`:t;const i=parseFloat(t);if(i<=0)return s?`${i} ${a}`:i;if(i>1&&i<=r)return s?`${i} ${a}`:i;const[n,o]=(i/r).toFixed(e).split(".");return o&&0!==parseFloat(o)?`${n}.${o} ${a}`:`${n} ${a}`}format_num2date(e=Date.now()){const r=parseInt(e/1e3/60/60/24%24),a=parseInt(e/1e3/60/60%24),s=parseInt(e/1e3/60%60),i=parseInt(e/1e3%60);return{day:t(this,o,"f").call(this,r),hour:t(this,o,"f").call(this,a),minute:t(this,o,"f").call(this,s),seconds:t(this,o,"f").call(this,i)}}count_down(r=Date.now(),o=f){const h=t(this,n,"f").call(this,r);return e(this,a,0,"f"),e(this,s,Date.now(),"f"),t(this,l,"f").call(this,h,o),()=>clearTimeout(t(this,i,"f"))}count_down_by_remain_seconds(t=f,e=60){const r=Date.now()+1e3*e;return this.count_down(r,t)}format_thousandth(t){return t.toString().replace(/\d+/,(function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,(function(t){return t+","}))}))}};export{c as default};
|
package/build/types/index.d.ts
CHANGED
|
@@ -15,10 +15,6 @@ interface FormatCount {
|
|
|
15
15
|
suffix?: string;
|
|
16
16
|
show_suffix_always?: boolean;
|
|
17
17
|
}
|
|
18
|
-
interface CountDown {
|
|
19
|
-
date?: DateType;
|
|
20
|
-
interval?: number;
|
|
21
|
-
}
|
|
22
18
|
type CountDownCallback = (num: number) => any;
|
|
23
19
|
declare class Helper {
|
|
24
20
|
#private;
|
|
@@ -30,7 +26,8 @@ declare class Helper {
|
|
|
30
26
|
get_time_obj(date?: DateType): GetTimeObj;
|
|
31
27
|
format_count({ num, decimal, divide, suffix, show_suffix_always }: FormatCount): number | string;
|
|
32
28
|
format_num2date(timestamp?: number): Required<Omit<GetTimeObj, 'day_of_week' | 'year' | 'month'>>;
|
|
33
|
-
count_down(
|
|
29
|
+
count_down(date?: DateType, fn?: CountDownCallback): Function;
|
|
30
|
+
count_down_by_remain_seconds(fn?: CountDownCallback, seconds?: number): Function;
|
|
34
31
|
format_thousandth(num: number | string): string;
|
|
35
32
|
}
|
|
36
33
|
declare const _default: Helper;
|