fish-helper 0.0.9 → 0.0.11
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 -0
- package/build/helper.cjs.js +1 -1
- package/build/helper.es.js +1 -1
- package/build/types/index.d.ts +3 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ const helper = require('fish-helper')
|
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
> Methods
|
|
10
|
+
>
|
|
11
|
+
> - offset_time(date, type) ------- The time difference (absolute value), returns the corresponding string as the second argument, such as 01,22....
|
|
10
12
|
>
|
|
11
13
|
> - before_lt_hour(date, hour) ------- The <strong>date</strong> is less than <strong>now</strong>, and the date is less than <strong>hour</strong> from <strong>now</strong>
|
|
12
14
|
>
|
|
@@ -29,3 +31,5 @@ const helper = require('fish-helper')
|
|
|
29
31
|
> - count_down_by_remain_seconds(fn, seconds) ------- 60-second countdown. Time can pass by itself
|
|
30
32
|
>
|
|
31
33
|
> - format_thousandth(num) ------- format the data as a string with thousands of bits
|
|
34
|
+
>
|
|
35
|
+
> - is_empty(data) ------- determines whether the data is empty
|
package/build/helper.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(t,e,r,
|
|
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)}var e,r,s,a,i,n,o,h;const l=()=>null;e=new WeakMap,r=new WeakMap,s=new WeakMap,a=new WeakMap,i=new WeakMap,n=new WeakMap,o=new WeakMap,h=new WeakMap;var f=new class{constructor(){e.set(this,1e3),r.set(this,36e5),s.set(this,0),a.set(this,(t=>Object.prototype.toString.call(t).slice(8,-1))),i.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()})),n.set(this,(t=>`0${t}`.slice(-2))),o.set(this,(({date:e,hour:s=1,type:a="before_lt_hour"})=>{let n=t(this,i,"f").call(this,e);const o=new Date(n).getTime(),h=Date.now(),l=o<h,f=o>h;return"before_lt_hour"===a?l&&o+t(this,r,"f")*s>h:"before_gt_hour"===a?l&&o+t(this,r,"f")*s<h:"after_lt_hour"===a?f&&h+t(this,r,"f")*s>o:"after_gt_hour"===a&&(f&&h+t(this,r,"f")*s<o)})),this.offset_time=(e,r="minute")=>{const s=Math.abs(Date.now()-t(this,i,"f").call(this,e)),a=this.format_num2date(s);return"day"===r?t(this,n,"f").call(this,a.day):"hour"===r?t(this,n,"f").call(this,a.hour):"minute"===r?t(this,n,"f").call(this,a.minute):"second"===r?t(this,n,"f").call(this,a.seconds):"The second parameter has an error"},h.set(this,((r=0,a=l,i=t(this,e,"f"),n=0,o=Date.now())=>{r<=0||function(t,e,r,s,a){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===s?a.call(t,r):a?a.value=r:e.set(t,r)}(this,s,setTimeout((()=>{n+=1,r-=t(this,e,"f"),a({remain:r,obj:this.format_num2date(r)});const s=Date.now()-(o+n*t(this,e,"f"));let i=t(this,e,"f")-s;i<0&&(i=0),t(this,h,"f").call(this,r,a,i,n,o)}),i),"f")}))}before_lt_hour(e,r=1){return t(this,o,"f").call(this,{date:e,hour:r,type:"before_lt_hour"})}before_gt_hour(e,r=1){return t(this,o,"f").call(this,{date:e,hour:r,type:"before_gt_hour"})}after_lt_hour(e,r=1){return t(this,o,"f").call(this,{date:e,hour:r,type:"after_lt_hour"})}after_gt_hour(e,r=1){return t(this,o,"f").call(this,{date:e,hour:r,type:"after_gt_hour"})}is_current_year(e){const r=t(this,i,"f").call(this,e);return(new Date).getFullYear()===new Date(r).getFullYear()}get_time_obj(e){const r=t(this,i,"f").call(this,e),s=new Date(r),a=t(this,n,"f").call(this,s.getMonth()+1),o=t(this,n,"f").call(this,s.getDate()),h=t(this,n,"f").call(this,s.getHours()),l=t(this,n,"f").call(this,s.getMinutes()),f=t(this,n,"f").call(this,s.getSeconds());return{year:String(s.getFullYear()),month:a,day:o,hour:h,minute:l,seconds:f,day_of_week:String(s.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:s="万",show_suffix_always:a=!1}){if(!t)return 0;if(r<=0||e<0)return a?`${t} ${s}`:t;const i=parseFloat(t);if(i<=0)return a?`${i} ${s}`:i;if(i>1&&i<r)return a?`${i} ${s}`:i;const[n,o]=(i/r).toFixed(e).split(".");return o&&0!==parseFloat(o)?`${n}.${o} ${s}`:`${n} ${s}`}format_num2date(e=Date.now()){const r=parseInt(e/1e3/60/60/24%24),s=parseInt(e/1e3/60/60%24),a=parseInt(e/1e3/60%60),i=parseInt(e/1e3%60);return{day:t(this,n,"f").call(this,r),hour:t(this,n,"f").call(this,s),minute:t(this,n,"f").call(this,a),seconds:t(this,n,"f").call(this,i)}}count_down_by_remain_seconds(r=l,a=60){const i=a*t(this,e,"f");return r({remain:i,obj:this.format_num2date(i)}),t(this,h,"f").call(this,i,r,t(this,e,"f")),()=>clearTimeout(t(this,s,"f"))}count_down(r=Date.now(),a=l){const n=t(this,i,"f").call(this,r)-Date.now();return a({remain:n,obj:this.format_num2date(n)}),t(this,h,"f").call(this,n,a,t(this,e,"f")),()=>clearTimeout(t(this,s,"f"))}format_thousandth(t){return t.toString().replace(/\d+/,(function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,(function(t){return t+","}))}))}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)}};module.exports=f;
|
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)}var e,r,a,s,i,n,o;const
|
|
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)}var e,r,a,s,i,n,h,o;const l=()=>null;e=new WeakMap,r=new WeakMap,a=new WeakMap,s=new WeakMap,i=new WeakMap,n=new WeakMap,h=new WeakMap,o=new WeakMap;var f=new class{constructor(){e.set(this,1e3),r.set(this,36e5),a.set(this,0),s.set(this,(t=>Object.prototype.toString.call(t).slice(8,-1))),i.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()})),n.set(this,(t=>`0${t}`.slice(-2))),h.set(this,(({date:e,hour:a=1,type:s="before_lt_hour"})=>{let n=t(this,i,"f").call(this,e);const h=new Date(n).getTime(),o=Date.now(),l=h<o,f=h>o;return"before_lt_hour"===s?l&&h+t(this,r,"f")*a>o:"before_gt_hour"===s?l&&h+t(this,r,"f")*a<o:"after_lt_hour"===s?f&&o+t(this,r,"f")*a>h:"after_gt_hour"===s&&(f&&o+t(this,r,"f")*a<h)})),this.offset_time=(e,r="minute")=>{const a=Math.abs(Date.now()-t(this,i,"f").call(this,e)),s=this.format_num2date(a);return"day"===r?t(this,n,"f").call(this,s.day):"hour"===r?t(this,n,"f").call(this,s.hour):"minute"===r?t(this,n,"f").call(this,s.minute):"second"===r?t(this,n,"f").call(this,s.seconds):"The second parameter has an error"},o.set(this,((r=0,s=l,i=t(this,e,"f"),n=0,h=Date.now())=>{r<=0||function(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");"a"===a?s.call(t,r):s?s.value=r:e.set(t,r)}(this,a,setTimeout((()=>{n+=1,r-=t(this,e,"f"),s({remain:r,obj:this.format_num2date(r)});const a=Date.now()-(h+n*t(this,e,"f"));let i=t(this,e,"f")-a;i<0&&(i=0),t(this,o,"f").call(this,r,s,i,n,h)}),i),"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,i,"f").call(this,e);return(new Date).getFullYear()===new Date(r).getFullYear()}get_time_obj(e){const r=t(this,i,"f").call(this,e),a=new Date(r),s=t(this,n,"f").call(this,a.getMonth()+1),h=t(this,n,"f").call(this,a.getDate()),o=t(this,n,"f").call(this,a.getHours()),l=t(this,n,"f").call(this,a.getMinutes()),f=t(this,n,"f").call(this,a.getSeconds());return{year:String(a.getFullYear()),month:s,day:h,hour:o,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,h]=(i/r).toFixed(e).split(".");return h&&0!==parseFloat(h)?`${n}.${h} ${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,n,"f").call(this,r),hour:t(this,n,"f").call(this,a),minute:t(this,n,"f").call(this,s),seconds:t(this,n,"f").call(this,i)}}count_down_by_remain_seconds(r=l,s=60){const i=s*t(this,e,"f");return r({remain:i,obj:this.format_num2date(i)}),t(this,o,"f").call(this,i,r,t(this,e,"f")),()=>clearTimeout(t(this,a,"f"))}count_down(r=Date.now(),s=l){const n=t(this,i,"f").call(this,r)-Date.now();return s({remain:n,obj:this.format_num2date(n)}),t(this,o,"f").call(this,n,s,t(this,e,"f")),()=>clearTimeout(t(this,a,"f"))}format_thousandth(t){return t.toString().replace(/\d+/,(function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,(function(t){return t+","}))}))}is_empty(e){return null==e||("String"===t(this,s,"f").call(this,e)?!e.trim():"Array"===t(this,s,"f").call(this,e)?!e.length:"Object"===t(this,s,"f").call(this,e)&&!Object.keys(e).length)}};export{f as default};
|
package/build/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ interface FormatCount {
|
|
|
15
15
|
suffix?: string;
|
|
16
16
|
show_suffix_always?: boolean;
|
|
17
17
|
}
|
|
18
|
+
type OffsetTimeReturnType = 'day' | 'hour' | 'minute' | 'second';
|
|
18
19
|
type FormatNum2Date = Required<Omit<GetTimeObj, 'day_of_week' | 'year' | 'month'>>;
|
|
19
20
|
interface CountDownCallbackParams {
|
|
20
21
|
remain: number;
|
|
@@ -23,6 +24,7 @@ interface CountDownCallbackParams {
|
|
|
23
24
|
type CountDownCallback = (data: CountDownCallbackParams) => any;
|
|
24
25
|
declare class Helper {
|
|
25
26
|
#private;
|
|
27
|
+
offset_time: (date?: DateType, return_type?: OffsetTimeReturnType) => string;
|
|
26
28
|
before_lt_hour(date?: DateType, hour?: number): boolean;
|
|
27
29
|
before_gt_hour(date?: DateType, hour?: number): boolean;
|
|
28
30
|
after_lt_hour(date?: DateType, hour?: number): boolean;
|
|
@@ -34,6 +36,7 @@ declare class Helper {
|
|
|
34
36
|
count_down_by_remain_seconds(fn?: CountDownCallback, seconds?: number): Function;
|
|
35
37
|
count_down(date?: DateType, fn?: CountDownCallback): Function;
|
|
36
38
|
format_thousandth(num: number | string): string;
|
|
39
|
+
is_empty(data: any): boolean;
|
|
37
40
|
}
|
|
38
41
|
declare const _default: Helper;
|
|
39
42
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fish-helper",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.11",
|
|
5
5
|
"main": "build/helper.cjs.js",
|
|
6
6
|
"module": "build/helper.es.js",
|
|
7
7
|
"types": "build/types/index.d.ts",
|
|
8
8
|
"license": "MIT",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"Time processing tool"
|
|
11
|
+
],
|
|
12
|
+
"description": "a tool to process time",
|
|
9
13
|
"exports": {
|
|
10
14
|
".": {
|
|
11
15
|
"require": "./build/helper.cjs.js",
|