fish-helper 0.0.1
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 +29 -0
- package/dist/helper.umd.cjs +1 -0
- package/dist/index.d.ts +37 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
```shell
|
|
2
|
+
npm install fish-helper
|
|
3
|
+
```
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
const helper = require('fish-helper')
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
> Methods
|
|
10
|
+
>
|
|
11
|
+
> - 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
|
+
>
|
|
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
|
+
>
|
|
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>
|
|
18
|
+
>
|
|
19
|
+
> - is_current_year(date) ------- return Boolean
|
|
20
|
+
>
|
|
21
|
+
> - get_time_obj(date) ------- return Object that include keys: year、month、day、hour、minute、seconds、day_of_week
|
|
22
|
+
>
|
|
23
|
+
> - format_count({num, divide, suffix, show_suffix_always}) ------- return <strong>num</strong> or String or 0
|
|
24
|
+
>
|
|
25
|
+
> - format_num2date(timestamp) ------- convert time to Object; return Object that include keys: day、hour、minute、seconds
|
|
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
|
|
28
|
+
>
|
|
29
|
+
> - format_thousandth(num) ------- format the data as a string with thousands of bits
|
|
@@ -0,0 +1 @@
|
|
|
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});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +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;
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fish-helper",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"keywords": ["helper utils"],
|
|
10
|
+
"description": "a utils tool",
|
|
11
|
+
"main": "./dist/helper.umd.cjs",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"author": "a-drowned-fish",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://gitcode.net/weixin_38726348/util.git"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"require": "./dist/helper.umd.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
}
|
|
27
|
+
}
|