fish-helper 0.0.5 → 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 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
- > - 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>
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({date, interval}, fn) ------- fn is a callback function that takes a remaining time argument; return a function to stop the timer
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
@@ -0,0 +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,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;
@@ -0,0 +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,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};
@@ -1,37 +1,34 @@
1
- declare 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
- interface CountDown {
19
- date?: DateType;
20
- interval?: number;
21
- }
22
- declare type CountDownCallback = (num: number) => any;
23
- declare class Helper {
24
- #private;
25
- before_lt_hour(date?: DateType, hour?: number): boolean;
26
- before_gt_hour(date?: DateType, hour?: number): boolean;
27
- after_lt_hour(date?: DateType, hour?: number): boolean;
28
- after_gt_hour(date?: DateType, hour?: number): boolean;
29
- is_current_year(date?: DateType): boolean;
30
- get_time_obj(date?: DateType): GetTimeObj;
31
- format_count({ num, decimal, divide, suffix, show_suffix_always }: FormatCount): number | string;
32
- format_num2date(timestamp?: number): Required<Omit<GetTimeObj, 'day_of_week' | 'year' | 'month'>>;
33
- count_down({ date, interval }: CountDown, fn?: CountDownCallback): Function;
34
- format_thousandth(num: number | string): string;
35
- }
36
- declare const _default: Helper;
37
- 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 CountDownCallback = (num: number) => any;
19
+ declare class Helper {
20
+ #private;
21
+ before_lt_hour(date?: DateType, hour?: number): boolean;
22
+ before_gt_hour(date?: DateType, hour?: number): boolean;
23
+ after_lt_hour(date?: DateType, hour?: number): boolean;
24
+ after_gt_hour(date?: DateType, hour?: number): boolean;
25
+ is_current_year(date?: DateType): boolean;
26
+ get_time_obj(date?: DateType): GetTimeObj;
27
+ format_count({ num, decimal, divide, suffix, show_suffix_always }: FormatCount): number | string;
28
+ format_num2date(timestamp?: number): Required<Omit<GetTimeObj, 'day_of_week' | 'year' | 'month'>>;
29
+ count_down(date?: DateType, fn?: CountDownCallback): Function;
30
+ count_down_by_remain_seconds(fn?: CountDownCallback, seconds?: number): Function;
31
+ format_thousandth(num: number | string): string;
32
+ }
33
+ declare const _default: Helper;
34
+ export default _default;
package/package.json CHANGED
@@ -1,33 +1,35 @@
1
1
  {
2
2
  "name": "fish-helper",
3
3
  "private": false,
4
- "version": "0.0.5",
5
- "type": "commonjs",
6
- "main": "dist/helper.umd.js",
4
+ "version": "0.0.7",
5
+ "main": "build/helper.cjs.js",
6
+ "module": "build/helper.es.js",
7
+ "types": "build/types/index.d.ts",
8
+ "license": "MIT",
7
9
  "description": "utils",
8
10
  "keywords": [
9
11
  "helper",
10
12
  "utils"
11
13
  ],
14
+ "exports": {
15
+ ".": {
16
+ "require": "./build/helper.cjs.js",
17
+ "import": "./build/helper.es.js"
18
+ }
19
+ },
12
20
  "files": [
13
- "dist"
21
+ "build"
14
22
  ],
23
+ "scripts": {
24
+ "dev": "rollup -w -c rolluo.config.js"
25
+ },
15
26
  "author": {
16
27
  "name": "weixin_38726348"
17
28
  },
18
29
  "repository": {
19
30
  "url": "https://gitcode.net/weixin_38726348/util.git"
20
31
  },
21
- "scripts": {
22
- "build": "tsc && vite build"
23
- },
24
32
  "devDependencies": {
25
- "typescript": "^4.9.3",
26
- "vite": "^4.0.0"
27
- },
28
- "exports": {
29
- ".": {
30
- "require": "./dist/helper.umd.js"
31
- }
33
+ "rollup": "^3.10.0"
32
34
  }
33
35
  }
@@ -1 +0,0 @@
1
- var I=(n,o,c)=>{if(!o.has(n))throw TypeError("Cannot "+c)};var h=(n,o,c)=>(I(n,o,"read from private field"),c?c.call(n):o.get(n)),g=(n,o,c)=>{if(o.has(n))throw TypeError("Cannot add the same private member more than once");o instanceof WeakSet?o.add(n):o.set(n,c)},m=(n,o,c,l)=>(I(n,o,"write to private field"),l?l.call(n,c):o.set(n,c),c);var a=(n,o,c)=>(I(n,o,"access private method"),c);(function(n,o){typeof exports=="object"&&typeof module<"u"?module.exports=o():typeof define=="function"&&define.amd?define(o):(n=typeof globalThis<"u"?globalThis:n||self,n.helper=o())})(this,function(){var l,p,D,w,d,y,$,T,b,F;"use strict";const n=()=>null;class o{constructor(){g(this,d);g(this,$);g(this,b);g(this,l,60*60*1e3);g(this,p,0);g(this,D,0);g(this,w,0)}before_lt_hour(e,t=1){return a(this,$,T).call(this,{date:e,hour:t,type:"before_lt_hour"})}before_gt_hour(e,t=1){return a(this,$,T).call(this,{date:e,hour:t,type:"before_gt_hour"})}after_lt_hour(e,t=1){return a(this,$,T).call(this,{date:e,hour:t,type:"after_lt_hour"})}after_gt_hour(e,t=1){return a(this,$,T).call(this,{date:e,hour:t,type:"after_gt_hour"})}is_current_year(e){const t=a(this,d,y).call(this,e);return new Date().getFullYear()===new Date(t).getFullYear()}get_time_obj(e){const t=a(this,d,y).call(this,e),r=new Date(t),i=`0${r.getMonth()+1}`.slice(-2),u=`0${r.getDate()}`.slice(-2),s=`0${r.getHours()}`.slice(-2),f=`0${r.getMinutes()}`.slice(-2),_=`0${r.getSeconds()}`.slice(-2);return{year:String(r.getFullYear()),month:i,day:u,hour:s,minute:f,seconds:_,day_of_week:String(r.getDay())}}format_count({num:e=0,decimal:t=1,divide:r=1e4,suffix:i="万",show_suffix_always:u=!1}){if(!e)return 0;if(r<=0||t<0)return u?`${e} ${i}`:e;const s=parseFloat(e);if(s<=0)return u?`${s} ${i}`:s;if(s>1&&s<=r)return u?`${s} ${i}`:s;const[f,_]=(s/r).toFixed(t).split(".");return!_||parseFloat(_)===0?`${f} ${i}`:`${f}.${_} ${i}`}format_num2date(e=Date.now()){const t=parseInt(e/1e3/60/60/24%24),r=parseInt(e/1e3/60/60%24),i=parseInt(e/1e3/60%60),u=parseInt(e/1e3%60),s=`0${t}`.slice(-2),f=`0${r}`.slice(-2),_=`0${i}`.slice(-2),S=`0${u}`.slice(-2);return{day:s,hour:f,minute:_,seconds:S}}count_down({date:e=Date.now(),interval:t=1e3},r=n){const i=a(this,d,y).call(this,e);return m(this,p,0),m(this,D,Date.now()),a(this,b,F).call(this,i,t,r),()=>clearTimeout(h(this,w))}format_thousandth(e){return e.toString().replace(/\d+/,function(r){return r.replace(/(\d)(?=(\d{3})+$)/g,function(i){return i+","})})}}return l=new WeakMap,p=new WeakMap,D=new WeakMap,w=new WeakMap,d=new WeakSet,y=function(e){if(!e)return Date.now();let t=null;return typeof e=="string"?t=e.replaceAll("/","-").replaceAll(".","-").replaceAll("_","-"):t=new Date(e),new Date(t).getTime()},$=new WeakSet,T=function({date:e,hour:t=1,type:r="before_lt_hour"}){let i=a(this,d,y).call(this,e);const u=new Date(i).getTime(),s=Date.now(),f=u<s,_=u>s;return r==="before_lt_hour"?f&&u+h(this,l)*t>s:r==="before_gt_hour"?f&&u+h(this,l)*t<s:r==="after_lt_hour"?_&&s+h(this,l)*t>u:r==="after_gt_hour"?_&&s+h(this,l)*t<u:!1},b=new WeakSet,F=function(e=Date.now(),t=1e3,r=n){if(e<=Date.now()||t<0)return r(0),clearTimeout(h(this,w));m(this,w,setTimeout(()=>{m(this,p,h(this,p)+1),r(e-Date.now());const i=Date.now()-(h(this,D)+h(this,p)*t);t<=i?(m(this,p,0),m(this,D,Date.now()),a(this,b,F).call(this,e,0,r)):a(this,b,F).call(this,e,t,r)},t))},new o});