@loickit/shared 0.0.5 → 0.0.8
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 +22 -0
- package/dist/index.d.mts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.mjs +1 -1
- package/dist/typeTool.d.mts +31 -0
- package/dist/typeTool.d.ts +31 -0
- package/dist/typeTool.mjs +1 -0
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -8,3 +8,25 @@ loickit shared lib
|
|
|
8
8
|
|
|
9
9
|
点赞小工具
|
|
10
10
|
|
|
11
|
+
### IntervalFn
|
|
12
|
+
|
|
13
|
+
间隔执行函数, 可以随时修改 delay, 即时生效
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const intervalFn = new IntervalFn(
|
|
17
|
+
(...args: string[]) => {
|
|
18
|
+
console.log('intervalFn', args);
|
|
19
|
+
},
|
|
20
|
+
1000,
|
|
21
|
+
'arg1',
|
|
22
|
+
'arg2'
|
|
23
|
+
);
|
|
24
|
+
intervalFn.run('otherArg1', 'otherArg2');
|
|
25
|
+
intervalFn.pause();
|
|
26
|
+
intervalFn.reset();
|
|
27
|
+
intervalFn.restart('otherArg1', 'otherArg2');
|
|
28
|
+
|
|
29
|
+
console.log(intervalFn.record);
|
|
30
|
+
|
|
31
|
+
intervalFn.maxRecord = 2;
|
|
32
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -23,4 +23,25 @@ declare class IntervalFn {
|
|
|
23
23
|
restart(...otherArgs: any[]): void;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
type DeviceDetectType = 'weixin' | 'mobile' | 'ios' | 'android' | 'iphone' | 'ipad' | null;
|
|
27
|
+
|
|
28
|
+
declare function is(deviceType?: DeviceDetectType): boolean;
|
|
29
|
+
declare function isWeixin(): boolean;
|
|
30
|
+
declare function isMobile(): boolean;
|
|
31
|
+
declare function isIos(): boolean;
|
|
32
|
+
declare function isAndroid(): boolean;
|
|
33
|
+
declare function isIphone(): boolean;
|
|
34
|
+
declare function isIpad(): boolean;
|
|
35
|
+
declare const deviceDetect: {
|
|
36
|
+
is: typeof is;
|
|
37
|
+
isWeixin: typeof isWeixin;
|
|
38
|
+
isMobile: typeof isMobile;
|
|
39
|
+
isIos: typeof isIos;
|
|
40
|
+
isAndroid: typeof isAndroid;
|
|
41
|
+
isIphone: typeof isIphone;
|
|
42
|
+
isIpad: typeof isIpad;
|
|
43
|
+
isWechatMP: () => boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { IntervalFn, Like, deviceDetect };
|
|
47
|
+
export type { DeviceDetectType };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,4 +23,25 @@ declare class IntervalFn {
|
|
|
23
23
|
restart(...otherArgs: any[]): void;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
type DeviceDetectType = 'weixin' | 'mobile' | 'ios' | 'android' | 'iphone' | 'ipad' | null;
|
|
27
|
+
|
|
28
|
+
declare function is(deviceType?: DeviceDetectType): boolean;
|
|
29
|
+
declare function isWeixin(): boolean;
|
|
30
|
+
declare function isMobile(): boolean;
|
|
31
|
+
declare function isIos(): boolean;
|
|
32
|
+
declare function isAndroid(): boolean;
|
|
33
|
+
declare function isIphone(): boolean;
|
|
34
|
+
declare function isIpad(): boolean;
|
|
35
|
+
declare const deviceDetect: {
|
|
36
|
+
is: typeof is;
|
|
37
|
+
isWeixin: typeof isWeixin;
|
|
38
|
+
isMobile: typeof isMobile;
|
|
39
|
+
isIos: typeof isIos;
|
|
40
|
+
isAndroid: typeof isAndroid;
|
|
41
|
+
isIphone: typeof isIphone;
|
|
42
|
+
isIpad: typeof isIpad;
|
|
43
|
+
isWechatMP: () => boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { IntervalFn, Like, deviceDetect };
|
|
47
|
+
export type { DeviceDetectType };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{createElement;width;height;constructor(t,{width:
|
|
1
|
+
class t{createElement;width;height;constructor(t,{width:i,height:e}){this.width=i,this.height=e,this.createElement=t}play(t,i){const e=this.createElement();e.style.position="fixed",e.style.width=this.width+"px",e.style.height=this.height+"px",e.style.left=t-parseInt(e.style.width)/2+"px",e.style.top=i-parseInt(e.style.height)-10+"px";const s=new KeyframeEffect(e,[{transform:"scale(1)",opacity:.5},{transform:`scale(1.5) translateY(-${this.height/2}px)`,opacity:.9},{transform:`scale(1.5) translateY(-${this.height/2+10}px)`,opacity:0}],{duration:600,iterations:1,easing:"linear"});document.body.appendChild(e);const n=new Animation(s,document.timeline);n.onfinish=()=>{e.remove()},n.play()}}class i{timer;fn;delay;args;record;maxRecord;constructor(t,i,...e){this.fn=t,this.delay=i,this.args=e,this.timer=void 0,this.record=0,this.maxRecord=1/0}run(...t){this.fn.apply(this,this.args.concat(t)),this.record++,this.record>=this.maxRecord&&this.pause.call(this),this.timer=setTimeout(this.run.bind(this),this.delay)}pause(){clearTimeout(this.timer),this.timer=void 0}reset(){this.pause.call(this),this.record=0}restart(...t){this.reset.call(this),this.run.apply(this,t)}}const e={weixin:/micromessenger/i,mobile:/AppleWebKit.*Mobile.*/,ios:/\(i[^;]+;( U;)? CPU.+Mac OS X/,android:/Android|Adr/,iphone:/iPhone/,ipad:/iPad/},s=new Map;function n(t=null){if(s.has(t))return s.get(t);if(null===t)return!0;const{userAgent:i}=window.navigator;if(!e[t])return console.warn("deviceType is not support"),!1;const n=e[t].test(i);return s.set(t,n),n}const r={is:n,isWeixin:function(){return n("weixin")},isMobile:function(){return n("mobile")},isIos:function(){return n("ios")},isAndroid:function(){return n("android")},isIphone:function(){return n("iphone")},isIpad:function(){return n("ipad")},isWechatMP:()=>!(!navigator.userAgent.match(/micromessenger/i)||!navigator.userAgent.match(/miniprogram/i))||"miniprogram"===window.__wxjs_environment};export{i as IntervalFn,t as Like,r as deviceDetect};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取函数的参数类型元组
|
|
3
|
+
* @example
|
|
4
|
+
* type Fn = (a: number, b: string) => void
|
|
5
|
+
* type Params = FunctionParams<Fn> // [number, string]
|
|
6
|
+
*/
|
|
7
|
+
type FunctionParams<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
|
|
8
|
+
/**
|
|
9
|
+
* 获取函数指定位置的参数类型
|
|
10
|
+
* @example
|
|
11
|
+
* type Fn = (a: number, b: string) => void
|
|
12
|
+
* type FirstParam = FunctionParam<Fn, 0> // number
|
|
13
|
+
* type SecondParam = FunctionParam<Fn, 1> // string
|
|
14
|
+
*/
|
|
15
|
+
type FunctionParam<T extends (...args: any[]) => any, N extends number> = FunctionParams<T>[N] extends infer P ? P : never;
|
|
16
|
+
/**
|
|
17
|
+
* 获取函数的第一个参数类型
|
|
18
|
+
* @example
|
|
19
|
+
* type Fn = (a: number, b: string) => void
|
|
20
|
+
* type First = FirstFunctionParam<Fn> // number
|
|
21
|
+
*/
|
|
22
|
+
type FunctionFirstParam<T extends (...args: any[]) => any> = FunctionParam<T, 0>;
|
|
23
|
+
/**
|
|
24
|
+
* 获取函数的最后一个参数类型
|
|
25
|
+
* @example
|
|
26
|
+
* type Fn = (a: number, b: string, c: boolean) => void
|
|
27
|
+
* type Last = LastFunctionParam<Fn> // boolean
|
|
28
|
+
*/
|
|
29
|
+
type FunctionLastParam<T extends (...args: any[]) => any> = FunctionParams<T> extends [...infer _, infer Last] ? Last : never;
|
|
30
|
+
|
|
31
|
+
export type { FunctionFirstParam, FunctionLastParam, FunctionParam, FunctionParams };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取函数的参数类型元组
|
|
3
|
+
* @example
|
|
4
|
+
* type Fn = (a: number, b: string) => void
|
|
5
|
+
* type Params = FunctionParams<Fn> // [number, string]
|
|
6
|
+
*/
|
|
7
|
+
type FunctionParams<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
|
|
8
|
+
/**
|
|
9
|
+
* 获取函数指定位置的参数类型
|
|
10
|
+
* @example
|
|
11
|
+
* type Fn = (a: number, b: string) => void
|
|
12
|
+
* type FirstParam = FunctionParam<Fn, 0> // number
|
|
13
|
+
* type SecondParam = FunctionParam<Fn, 1> // string
|
|
14
|
+
*/
|
|
15
|
+
type FunctionParam<T extends (...args: any[]) => any, N extends number> = FunctionParams<T>[N] extends infer P ? P : never;
|
|
16
|
+
/**
|
|
17
|
+
* 获取函数的第一个参数类型
|
|
18
|
+
* @example
|
|
19
|
+
* type Fn = (a: number, b: string) => void
|
|
20
|
+
* type First = FirstFunctionParam<Fn> // number
|
|
21
|
+
*/
|
|
22
|
+
type FunctionFirstParam<T extends (...args: any[]) => any> = FunctionParam<T, 0>;
|
|
23
|
+
/**
|
|
24
|
+
* 获取函数的最后一个参数类型
|
|
25
|
+
* @example
|
|
26
|
+
* type Fn = (a: number, b: string, c: boolean) => void
|
|
27
|
+
* type Last = LastFunctionParam<Fn> // boolean
|
|
28
|
+
*/
|
|
29
|
+
type FunctionLastParam<T extends (...args: any[]) => any> = FunctionParams<T> extends [...infer _, infer Last] ? Last : never;
|
|
30
|
+
|
|
31
|
+
export type { FunctionFirstParam, FunctionLastParam, FunctionParam, FunctionParams };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loickit/shared",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "loickit shared lib",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"import": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./typeTools": {
|
|
12
|
+
"types": "./dist/typeTool.d.ts",
|
|
13
|
+
"import": "./dist/typeTool.d.ts"
|
|
10
14
|
}
|
|
11
15
|
},
|
|
12
16
|
"files": [
|
|
13
17
|
"dist"
|
|
14
18
|
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "loickit-cli build:lib"
|
|
21
|
+
},
|
|
15
22
|
"keywords": [
|
|
16
23
|
"loickit"
|
|
17
24
|
],
|
|
@@ -20,8 +27,5 @@
|
|
|
20
27
|
"access": "public"
|
|
21
28
|
},
|
|
22
29
|
"license": "UNLICENSED",
|
|
23
|
-
"author": "licheung228"
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "loickit-cli build:lib"
|
|
26
|
-
}
|
|
30
|
+
"author": "licheung228"
|
|
27
31
|
}
|