fish-helper 0.0.4 → 0.0.6

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
@@ -13,8 +13,8 @@ const helper = require('fish-helper')
13
13
  > - before_gt_hour(date, hour) ------- The <strong>date</strong> is less than <strong>now</strong>, and the date is greater than <strong>hour</strong> from <strong>now</strong>
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
- >
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>
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>
18
18
  >
19
19
  > - is_current_year(date) ------- return Boolean
20
20
  >
@@ -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,i){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?i.call(t,r):i?i.value=r:e.set(t,r),r}var r,a,i,s,n,o,h,l,u;const c=()=>null;a=new WeakMap,i=new WeakMap,s=new WeakMap,n=new WeakMap,r=new WeakSet,o=function(t){if(!t)return Date.now();let e=null;return e="string"==typeof t?t.replace(/(\/|\.|_)/g,"-"):new Date(t),new Date(e).getTime()},h=function(t){return`0${t}`.slice(-2)},l=function({date:e,hour:i=1,type:s="before_lt_hour"}){let n=t(this,r,"m",o).call(this,e);const h=new Date(n).getTime(),l=Date.now(),u=h<l,c=h>l;return"before_lt_hour"===s?u&&h+t(this,a,"f")*i>l:"before_gt_hour"===s?u&&h+t(this,a,"f")*i<l:"after_lt_hour"===s?c&&l+t(this,a,"f")*i>h:"after_gt_hour"===s&&(c&&l+t(this,a,"f")*i<h)},u=function a(o=Date.now(),h=1e3,l=c){if(o<=Date.now()||h<0)return l(0),clearTimeout(t(this,n,"f"));e(this,n,setTimeout((()=>{e(this,i,t(this,i,"f")+1,"f"),l(o-Date.now());const n=Date.now()-(t(this,s,"f")+t(this,i,"f")*h);h<=n?(e(this,i,0,"f"),e(this,s,Date.now(),"f"),t(this,r,"m",a).call(this,o,0,l)):t(this,r,"m",a).call(this,o,h,l)}),h),"f")};var f=new class{constructor(){r.add(this),a.set(this,36e5),i.set(this,0),s.set(this,0),n.set(this,0)}before_lt_hour(e,a=1){return t(this,r,"m",l).call(this,{date:e,hour:a,type:"before_lt_hour"})}before_gt_hour(e,a=1){return t(this,r,"m",l).call(this,{date:e,hour:a,type:"before_gt_hour"})}after_lt_hour(e,a=1){return t(this,r,"m",l).call(this,{date:e,hour:a,type:"after_lt_hour"})}after_gt_hour(e,a=1){return t(this,r,"m",l).call(this,{date:e,hour:a,type:"after_gt_hour"})}is_current_year(e){const a=t(this,r,"m",o).call(this,e);return(new Date).getFullYear()===new Date(a).getFullYear()}get_time_obj(e){const a=t(this,r,"m",o).call(this,e),i=new Date(a),s=t(this,r,"m",h).call(this,i.getMonth()+1),n=t(this,r,"m",h).call(this,i.getDate()),l=t(this,r,"m",h).call(this,i.getHours()),u=t(this,r,"m",h).call(this,i.getMinutes()),c=t(this,r,"m",h).call(this,i.getSeconds());return{year:String(i.getFullYear()),month:s,day:n,hour:l,minute:u,seconds:c,day_of_week:String(i.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:a="万",show_suffix_always:i=!1}){if(!t)return 0;if(r<=0||e<0)return i?`${t} ${a}`:t;const s=parseFloat(t);if(s<=0)return i?`${s} ${a}`:s;if(s>1&&s<=r)return i?`${s} ${a}`:s;const[n,o]=(s/r).toFixed(e).split(".");return o&&0!==parseFloat(o)?`${n}.${o} ${a}`:`${n} ${a}`}format_num2date(e=Date.now()){const a=parseInt(e/1e3/60/60/24%24),i=parseInt(e/1e3/60/60%24),s=parseInt(e/1e3/60%60),n=parseInt(e/1e3%60);return{day:t(this,r,"m",h).call(this,a),hour:t(this,r,"m",h).call(this,i),minute:t(this,r,"m",h).call(this,s),seconds:t(this,r,"m",h).call(this,n)}}count_down({date:a=Date.now(),interval:h=1e3},l=c){const f=t(this,r,"m",o).call(this,a);return e(this,i,0,"f"),e(this,s,Date.now(),"f"),t(this,r,"m",u).call(this,f,h,l),()=>clearTimeout(t(this,n,"f"))}format_thousandth(t){return t.toString().replace(/\d+/,(function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,(function(t){return t+","}))}))}};module.exports=f;
@@ -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,i){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?i.call(t,r):i?i.value=r:e.set(t,r),r}var r,a,i,n,s,o,h,l,u;const c=()=>null;a=new WeakMap,i=new WeakMap,n=new WeakMap,s=new WeakMap,r=new WeakSet,o=function(t){if(!t)return Date.now();let e=null;return e="string"==typeof t?t.replace(/(\/|\.|_)/g,"-"):new Date(t),new Date(e).getTime()},h=function(t){return`0${t}`.slice(-2)},l=function({date:e,hour:i=1,type:n="before_lt_hour"}){let s=t(this,r,"m",o).call(this,e);const h=new Date(s).getTime(),l=Date.now(),u=h<l,c=h>l;return"before_lt_hour"===n?u&&h+t(this,a,"f")*i>l:"before_gt_hour"===n?u&&h+t(this,a,"f")*i<l:"after_lt_hour"===n?c&&l+t(this,a,"f")*i>h:"after_gt_hour"===n&&(c&&l+t(this,a,"f")*i<h)},u=function a(o=Date.now(),h=1e3,l=c){if(o<=Date.now()||h<0)return l(0),clearTimeout(t(this,s,"f"));e(this,s,setTimeout((()=>{e(this,i,t(this,i,"f")+1,"f"),l(o-Date.now());const s=Date.now()-(t(this,n,"f")+t(this,i,"f")*h);h<=s?(e(this,i,0,"f"),e(this,n,Date.now(),"f"),t(this,r,"m",a).call(this,o,0,l)):t(this,r,"m",a).call(this,o,h,l)}),h),"f")};var f=new class{constructor(){r.add(this),a.set(this,36e5),i.set(this,0),n.set(this,0),s.set(this,0)}before_lt_hour(e,a=1){return t(this,r,"m",l).call(this,{date:e,hour:a,type:"before_lt_hour"})}before_gt_hour(e,a=1){return t(this,r,"m",l).call(this,{date:e,hour:a,type:"before_gt_hour"})}after_lt_hour(e,a=1){return t(this,r,"m",l).call(this,{date:e,hour:a,type:"after_lt_hour"})}after_gt_hour(e,a=1){return t(this,r,"m",l).call(this,{date:e,hour:a,type:"after_gt_hour"})}is_current_year(e){const a=t(this,r,"m",o).call(this,e);return(new Date).getFullYear()===new Date(a).getFullYear()}get_time_obj(e){const a=t(this,r,"m",o).call(this,e),i=new Date(a),n=t(this,r,"m",h).call(this,i.getMonth()+1),s=t(this,r,"m",h).call(this,i.getDate()),l=t(this,r,"m",h).call(this,i.getHours()),u=t(this,r,"m",h).call(this,i.getMinutes()),c=t(this,r,"m",h).call(this,i.getSeconds());return{year:String(i.getFullYear()),month:n,day:s,hour:l,minute:u,seconds:c,day_of_week:String(i.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:a="万",show_suffix_always:i=!1}){if(!t)return 0;if(r<=0||e<0)return i?`${t} ${a}`:t;const n=parseFloat(t);if(n<=0)return i?`${n} ${a}`:n;if(n>1&&n<=r)return i?`${n} ${a}`:n;const[s,o]=(n/r).toFixed(e).split(".");return o&&0!==parseFloat(o)?`${s}.${o} ${a}`:`${s} ${a}`}format_num2date(e=Date.now()){const a=parseInt(e/1e3/60/60/24%24),i=parseInt(e/1e3/60/60%24),n=parseInt(e/1e3/60%60),s=parseInt(e/1e3%60);return{day:t(this,r,"m",h).call(this,a),hour:t(this,r,"m",h).call(this,i),minute:t(this,r,"m",h).call(this,n),seconds:t(this,r,"m",h).call(this,s)}}count_down({date:a=Date.now(),interval:h=1e3},l=c){const f=t(this,r,"m",o).call(this,a);return e(this,i,0,"f"),e(this,n,Date.now(),"f"),t(this,r,"m",u).call(this,f,h,l),()=>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+","}))}))}};export{f as default};
@@ -1,37 +1,37 @@
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
+ interface CountDown {
19
+ date?: DateType;
20
+ interval?: number;
21
+ }
22
+ 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;
package/package.json CHANGED
@@ -1,33 +1,35 @@
1
1
  {
2
2
  "name": "fish-helper",
3
3
  "private": false,
4
- "version": "0.0.4",
5
- "type": "commonjs",
6
- "main": "dist/helper.umd.js",
4
+ "version": "0.0.6",
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});