@whitesev/utils 1.0.4 → 1.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/dist/index.amd.js +5885 -1817
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +5533 -1467
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +5531 -1467
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +5886 -1817
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +5897 -1826
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +5889 -1817
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Dictionary.d.ts +82 -0
- package/dist/src/Hooks.d.ts +11 -0
- package/dist/src/Httpx.d.ts +1201 -0
- package/dist/src/LockFunction.d.ts +31 -0
- package/dist/src/Log.d.ts +96 -0
- package/dist/src/Progress.d.ts +37 -0
- package/dist/src/UtilsGMMenu.d.ts +156 -0
- package/dist/src/index.d.ts +20 -27
- package/dist/src/indexedDB.d.ts +73 -0
- package/dist/src/tryCatch.d.ts +31 -0
- package/package.json +36 -37
- package/rollup.config.js +0 -3
- package/src/Dictionary.ts +152 -0
- package/src/{Hooks/Hooks.js → Hooks.ts} +31 -17
- package/src/{Httpx/index.d.ts → Httpx.ts} +837 -46
- package/src/LockFunction.ts +62 -0
- package/src/Log.ts +281 -0
- package/src/Progress.ts +143 -0
- package/src/UtilsGMMenu.ts +681 -0
- package/src/index.ts +17 -29
- package/src/indexedDB.ts +421 -0
- package/src/tryCatch.ts +107 -0
- package/tsconfig.json +1 -1
- package/dist/src/Dictionary/Dictionary.d.ts +0 -85
- package/dist/src/Hooks/Hooks.d.ts +0 -5
- package/dist/src/Httpx/Httpx.d.ts +0 -50
- package/dist/src/LockFunction/LockFunction.d.ts +0 -16
- package/dist/src/Log/Log.d.ts +0 -66
- package/dist/src/Progress/Progress.d.ts +0 -6
- package/dist/src/UtilsGMMenu/UtilsGMMenu.d.ts +0 -119
- package/dist/src/indexedDB/indexedDB.d.ts +0 -165
- package/dist/src/tryCatch/tryCatch.d.ts +0 -31
- package/src/Dictionary/Dictionary.js +0 -157
- package/src/Dictionary/index.d.ts +0 -52
- package/src/Hooks/index.d.ts +0 -16
- package/src/Httpx/Httpx.js +0 -747
- package/src/LockFunction/LockFunction.js +0 -35
- package/src/LockFunction/index.d.ts +0 -47
- package/src/Log/Log.js +0 -256
- package/src/Log/index.d.ts +0 -91
- package/src/Progress/Progress.js +0 -98
- package/src/Progress/index.d.ts +0 -30
- package/src/UtilsGMMenu/UtilsGMMenu.js +0 -464
- package/src/UtilsGMMenu/index.d.ts +0 -224
- package/src/indexedDB/index.d.ts +0 -128
- package/src/indexedDB/indexedDB.js +0 -355
- package/src/tryCatch/index.d.ts +0 -6
- package/src/tryCatch/tryCatch.js +0 -100
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
|
|
2
|
+
#private;
|
|
3
|
+
/**
|
|
4
|
+
* @param callback 需要执行的函数
|
|
5
|
+
* @param delayTime (可选)延迟xx毫秒后解锁,默认:0
|
|
6
|
+
*/
|
|
7
|
+
constructor(callback: K, delayTime?: number);
|
|
8
|
+
/**
|
|
9
|
+
* @param callback 需要执行的函数
|
|
10
|
+
* @param context (可选)函数作用域,默认:this(Utils)
|
|
11
|
+
* @param delayTime (可选)延迟xx毫秒后解锁,默认:0
|
|
12
|
+
*/
|
|
13
|
+
constructor(callback: K, context?: any, delayTime?: number);
|
|
14
|
+
/**
|
|
15
|
+
* 判断是否被锁
|
|
16
|
+
*/
|
|
17
|
+
isLock(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 锁
|
|
20
|
+
*/
|
|
21
|
+
lock(): void;
|
|
22
|
+
/**
|
|
23
|
+
* 解锁
|
|
24
|
+
*/
|
|
25
|
+
unlock(): void;
|
|
26
|
+
/**
|
|
27
|
+
* 执行
|
|
28
|
+
*/
|
|
29
|
+
run(...args: any[]): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export { LockFunction };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { AnyObject } from ".";
|
|
2
|
+
/** Utils.Log的初始化配置 */
|
|
3
|
+
declare interface UtilsLogOptions {
|
|
4
|
+
/** 是否输出Tag,false的话其它的颜色也不输出,默认为true */
|
|
5
|
+
tag: boolean;
|
|
6
|
+
/** log.success的颜色,默认#0000FF */
|
|
7
|
+
successColor: string;
|
|
8
|
+
/** log.warn的颜色,默认0 */
|
|
9
|
+
warnColor: string;
|
|
10
|
+
/** log.error的颜色,默认#FF0000 */
|
|
11
|
+
errorColor: string;
|
|
12
|
+
/** log.info的颜色,默认0 */
|
|
13
|
+
infoColor: string;
|
|
14
|
+
/** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置,默认false */
|
|
15
|
+
debug: boolean;
|
|
16
|
+
/** 当console输出超过logMaxCount数量自动清理控制台,默认false */
|
|
17
|
+
autoClearConsole: boolean;
|
|
18
|
+
/** console输出的最高数量,autoClearConsole开启则生效,默认999 */
|
|
19
|
+
logMaxCount: number;
|
|
20
|
+
}
|
|
21
|
+
declare class Log {
|
|
22
|
+
#private;
|
|
23
|
+
tag: string;
|
|
24
|
+
/**
|
|
25
|
+
* @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}}
|
|
26
|
+
* @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
|
|
27
|
+
*/
|
|
28
|
+
constructor(_GM_info_?: {
|
|
29
|
+
script: {
|
|
30
|
+
name: string;
|
|
31
|
+
};
|
|
32
|
+
}, console?: Console);
|
|
33
|
+
/**
|
|
34
|
+
* 解析Error的堆栈获取实际调用者的函数名及函数所在的位置
|
|
35
|
+
* @param stack
|
|
36
|
+
*/
|
|
37
|
+
private parseErrorStack;
|
|
38
|
+
/**
|
|
39
|
+
* 检测清理控制台
|
|
40
|
+
*/
|
|
41
|
+
private checkClearConsole;
|
|
42
|
+
/**
|
|
43
|
+
* 输出内容
|
|
44
|
+
* @param msg 需要输出的内容
|
|
45
|
+
* @param color 颜色
|
|
46
|
+
* @param otherStyle 其它CSS
|
|
47
|
+
*/
|
|
48
|
+
private printContent;
|
|
49
|
+
/**
|
|
50
|
+
* 控制台-普通输出
|
|
51
|
+
* @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
|
|
52
|
+
* @param color 输出的颜色
|
|
53
|
+
* @param otherStyle 其它CSS
|
|
54
|
+
*/
|
|
55
|
+
info(msg: any, color?: string, otherStyle?: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* 控制台-警告输出
|
|
58
|
+
* @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
|
|
59
|
+
* @param color 输出的颜色
|
|
60
|
+
* @param otherStyle 其它CSS
|
|
61
|
+
*/
|
|
62
|
+
warn(msg: any, color?: string, otherStyle?: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* 控制台-错误输出
|
|
65
|
+
* @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
|
|
66
|
+
* @param color 输出的颜色
|
|
67
|
+
* @param otherStyle 其它CSS
|
|
68
|
+
*/
|
|
69
|
+
error(msg: any, color?: string, otherStyle?: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* 控制台-成功输出
|
|
72
|
+
* @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
|
|
73
|
+
* @param color 输出的颜色
|
|
74
|
+
* @param otherStyle 其它CSS
|
|
75
|
+
*/
|
|
76
|
+
success(msg: any, color?: string, otherStyle?: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* 控制台-输出表格
|
|
79
|
+
* @param msg
|
|
80
|
+
* @param color 输出的颜色
|
|
81
|
+
* @param otherStyle 其它CSS
|
|
82
|
+
* @example
|
|
83
|
+
* log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
|
|
84
|
+
*/
|
|
85
|
+
table(msg: AnyObject[], color?: string, otherStyle?: string): void;
|
|
86
|
+
/**
|
|
87
|
+
* 配置Log对象的颜色
|
|
88
|
+
* @param paramDetails 配置信息
|
|
89
|
+
*/
|
|
90
|
+
config(paramDetails: Partial<UtilsLogOptions>): void;
|
|
91
|
+
/** 禁用输出 */
|
|
92
|
+
disable(): void;
|
|
93
|
+
/** 恢复输出 */
|
|
94
|
+
recovery(): void;
|
|
95
|
+
}
|
|
96
|
+
export { Log };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
declare interface ProgressParamConfig {
|
|
2
|
+
/** canvas元素节点 */
|
|
3
|
+
canvasNode: HTMLCanvasElement;
|
|
4
|
+
/** 绘制角度,默认:95 */
|
|
5
|
+
deg: number;
|
|
6
|
+
/** 进度,默认:0 */
|
|
7
|
+
progress: number;
|
|
8
|
+
/** 绘制的线宽度,默认:10 */
|
|
9
|
+
lineWidth: number;
|
|
10
|
+
/** 绘制的背景颜色,默认:#1e637c */
|
|
11
|
+
lineBgColor: string;
|
|
12
|
+
/** 绘制的线的颜色,默认:#25deff */
|
|
13
|
+
lineColor: string;
|
|
14
|
+
/** 绘制的字体颜色,默认:#000000 */
|
|
15
|
+
textColor: string;
|
|
16
|
+
/** 绘制的字体大小(px),默认:22px */
|
|
17
|
+
fontSize: number;
|
|
18
|
+
/** 绘制的圆的半径,默认:50 */
|
|
19
|
+
circleRadius: number;
|
|
20
|
+
}
|
|
21
|
+
declare class Progress {
|
|
22
|
+
#private;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param paramConfig 配置信息
|
|
26
|
+
*/
|
|
27
|
+
constructor(paramConfig: ProgressParamConfig);
|
|
28
|
+
/**
|
|
29
|
+
* 初始化
|
|
30
|
+
*/
|
|
31
|
+
private init;
|
|
32
|
+
/**
|
|
33
|
+
* 绘制
|
|
34
|
+
*/
|
|
35
|
+
draw(): void;
|
|
36
|
+
}
|
|
37
|
+
export { Progress };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
declare interface UtilsGMMenuClickCallBackData {
|
|
2
|
+
/** 菜单键名 */
|
|
3
|
+
key: string;
|
|
4
|
+
/** 是否启用 */
|
|
5
|
+
enable: boolean;
|
|
6
|
+
/** 点击前的enable值 */
|
|
7
|
+
oldEnable: boolean;
|
|
8
|
+
/** 触发的事件 */
|
|
9
|
+
event: MouseEvent | KeyboardEvent;
|
|
10
|
+
/** 将enable值写入本地的回调,设置参数false就不保存到本地 */
|
|
11
|
+
storeValue(enable: boolean): void;
|
|
12
|
+
}
|
|
13
|
+
declare interface UtilsGMMenuOption {
|
|
14
|
+
/** 菜单的本地键key,不可重复,会覆盖 */
|
|
15
|
+
key: string;
|
|
16
|
+
/** 菜单的文本 */
|
|
17
|
+
text: string;
|
|
18
|
+
/** (可选)菜单的开启状态,默认为false */
|
|
19
|
+
enable?: boolean;
|
|
20
|
+
/** (可选)使用条件:TamperMonkey版本>5.0,如果id和已注册的菜单id相同,可修改当前已注册菜单的options */
|
|
21
|
+
id?: number;
|
|
22
|
+
/** (可选)An optional access key. Please see the description below. Either options or accessKey can be specified. */
|
|
23
|
+
accessKey?: string;
|
|
24
|
+
/** (可选)自动关闭菜单,可不设置 */
|
|
25
|
+
autoClose?: boolean;
|
|
26
|
+
/** 使用条件:TamperMonkey版本>5.0,使用菜单项的鼠标悬浮上的工具提示*/
|
|
27
|
+
title?: string;
|
|
28
|
+
/** (可选)点击菜单后自动刷新网页,默认为true */
|
|
29
|
+
autoReload?: boolean;
|
|
30
|
+
/** 菜单的显示文本,未设置的话则自动根据enable在前面加上图标 */
|
|
31
|
+
showText(text: string, enable: boolean): string;
|
|
32
|
+
/** 点击菜单的回调 */
|
|
33
|
+
callback(data: UtilsGMMenuClickCallBackData): void;
|
|
34
|
+
/** 是否允许菜单进行存储值,默认true允许 */
|
|
35
|
+
isStoreValue?: boolean;
|
|
36
|
+
}
|
|
37
|
+
declare interface UtilsGMMenuConstructorOptions {
|
|
38
|
+
/** (可选)配置*/
|
|
39
|
+
data?: UtilsGMMenuOption[];
|
|
40
|
+
/** (可选)全局菜单点击菜单后自动刷新网页,默认为true */
|
|
41
|
+
autoReload?: boolean;
|
|
42
|
+
/** 油猴函数 @grant GM_getValue */
|
|
43
|
+
GM_getValue<T extends any>(name: string, defaultValue?: T): T;
|
|
44
|
+
/** 油猴函数 @grant GM_setValue */
|
|
45
|
+
GM_setValue(name: string, value: any): Promise<undefined> | undefined;
|
|
46
|
+
/** 油猴函数 @grant GM_registerMenuCommand */
|
|
47
|
+
GM_registerMenuCommand(name: string, listener: (event: PointerEvent | MouseEvent) => void, accessKey?: string): number;
|
|
48
|
+
/** 油猴函数 @grant GM_unregisterMenuCommand */
|
|
49
|
+
GM_unregisterMenuCommand(id: number): void;
|
|
50
|
+
}
|
|
51
|
+
declare class GMMenu {
|
|
52
|
+
private GM_Api;
|
|
53
|
+
private MenuHandle;
|
|
54
|
+
constructor(details: UtilsGMMenuConstructorOptions);
|
|
55
|
+
/**
|
|
56
|
+
* 新增菜单数据
|
|
57
|
+
* @param paramData
|
|
58
|
+
*/
|
|
59
|
+
add(paramData: UtilsGMMenuOption[] | UtilsGMMenuOption): void;
|
|
60
|
+
/**
|
|
61
|
+
* 更新菜单数据
|
|
62
|
+
* @param options 数据
|
|
63
|
+
*/
|
|
64
|
+
update(options?: UtilsGMMenuOption[] | UtilsGMMenuOption): void;
|
|
65
|
+
/**
|
|
66
|
+
* 卸载菜单
|
|
67
|
+
* @param menuId 已注册的菜单id
|
|
68
|
+
*/
|
|
69
|
+
delete(menuId: number): void;
|
|
70
|
+
/**
|
|
71
|
+
* 根据键值获取enable值
|
|
72
|
+
* @param menuKey 菜单-键key
|
|
73
|
+
*/
|
|
74
|
+
get(menuKey: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* 根据键值获取enable值
|
|
77
|
+
* @param menuKey 菜单-键key
|
|
78
|
+
*/
|
|
79
|
+
getEnable(menuKey: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* 根据键值获取text值
|
|
82
|
+
* @param menuKey 菜单-键key
|
|
83
|
+
*/
|
|
84
|
+
getText(menuKey: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* 根据键值获取showText函数的值
|
|
87
|
+
* @param menuKey 菜单-键key
|
|
88
|
+
*/
|
|
89
|
+
getShowTextValue(menuKey: string): string;
|
|
90
|
+
/**
|
|
91
|
+
* 获取当前已注册菜单的id
|
|
92
|
+
* @param menuKey
|
|
93
|
+
*/
|
|
94
|
+
getMenuId(menuKey: string): number | undefined | null;
|
|
95
|
+
/**
|
|
96
|
+
* 根据键值获取accessKey值
|
|
97
|
+
* @param menuKey 菜单-键key
|
|
98
|
+
*/
|
|
99
|
+
getAccessKey(menuKey: string): string | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* 根据键值获取autoClose值
|
|
102
|
+
* @param menuKey 菜单-键key
|
|
103
|
+
*/
|
|
104
|
+
getAutoClose(menuKey: string): boolean | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* 根据键值获取autoReload值
|
|
107
|
+
* @param menuKey 菜单-键key
|
|
108
|
+
*/
|
|
109
|
+
getAutoReload(menuKey: string): boolean | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* 根据键值获取callback函数
|
|
112
|
+
* @param menuKey 菜单-键key
|
|
113
|
+
*/
|
|
114
|
+
getCallBack(menuKey: string): Function | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* 获取当enable为true时默认显示在菜单中前面的emoji图标
|
|
117
|
+
*/
|
|
118
|
+
getEnableTrueEmoji(): string;
|
|
119
|
+
/**
|
|
120
|
+
* 获取当enable为false时默认显示在菜单中前面的emoji图标
|
|
121
|
+
*/
|
|
122
|
+
getEnableFalseEmoji(): string;
|
|
123
|
+
/**
|
|
124
|
+
* 获取本地存储的菜单外部的键名
|
|
125
|
+
* @param keyName
|
|
126
|
+
*/
|
|
127
|
+
getLocalStorageKeyName(): string;
|
|
128
|
+
/**
|
|
129
|
+
* 设置菜单的值
|
|
130
|
+
* @param menuKey 菜单-键key
|
|
131
|
+
* @param value 需要设置的值
|
|
132
|
+
*/
|
|
133
|
+
setValue(menuKey: string, value: any): void;
|
|
134
|
+
/**
|
|
135
|
+
* 设置菜单的值
|
|
136
|
+
* @param menuKey 菜单-键key
|
|
137
|
+
* @param value 需要设置的值
|
|
138
|
+
*/
|
|
139
|
+
setEnable(menuKey: string, value: boolean): void;
|
|
140
|
+
/**
|
|
141
|
+
* 设置当enable为true时默认显示在菜单中前面的emoji图标
|
|
142
|
+
* @param emojiString
|
|
143
|
+
*/
|
|
144
|
+
setEnableTrueEmoji(emojiString: string): void;
|
|
145
|
+
/**
|
|
146
|
+
* 设置当enable为false时默认显示在菜单中前面的emoji图标
|
|
147
|
+
* @param emojiString
|
|
148
|
+
*/
|
|
149
|
+
setEnableFalseEmoji(emojiString: string): void;
|
|
150
|
+
/**
|
|
151
|
+
* 设置本地存储的菜单外部的键名
|
|
152
|
+
* @param keyName
|
|
153
|
+
*/
|
|
154
|
+
setLocalStorageKeyName(keyName: string): void;
|
|
155
|
+
}
|
|
156
|
+
export { GMMenu };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/// <reference path="../../src/ajaxHooker/index.d.ts" />
|
|
2
|
-
/// <reference path="../../src/Dictionary/index.d.ts" />
|
|
3
|
-
/// <reference path="../../src/Hooks/index.d.ts" />
|
|
4
|
-
/// <reference path="../../src/Httpx/index.d.ts" />
|
|
5
|
-
/// <reference path="../../src/indexedDB/index.d.ts" />
|
|
6
|
-
/// <reference path="../../src/LockFunction/index.d.ts" />
|
|
7
|
-
/// <reference path="../../src/Log/index.d.ts" />
|
|
8
|
-
/// <reference path="../../src/Progress/index.d.ts" />
|
|
9
|
-
/// <reference path="../../src/tryCatch/index.d.ts" />
|
|
10
|
-
/// <reference path="../../src/UtilsGMMenu/index.d.ts" />
|
|
11
2
|
import { ColorConversion } from "./ColorConversion";
|
|
12
3
|
import { GBKEncoder } from "./GBKEncoder";
|
|
13
4
|
import { UtilsGMCookie } from "./UtilsGMCookie";
|
|
5
|
+
import { GMMenu } from "./UtilsGMMenu";
|
|
6
|
+
import { Hooks } from "./Hooks";
|
|
7
|
+
import { Httpx } from "./Httpx";
|
|
8
|
+
import { indexedDB } from "./indexedDB";
|
|
9
|
+
import { LockFunction } from "./LockFunction";
|
|
10
|
+
import { Log } from "./Log";
|
|
11
|
+
import { Progress } from "./Progress";
|
|
12
|
+
import { UtilsDictionary } from "./Dictionary";
|
|
14
13
|
export declare var unsafeWindow: Window & typeof globalThis;
|
|
15
14
|
export type JSTypeMap = {
|
|
16
15
|
string: string;
|
|
@@ -339,9 +338,7 @@ declare class Utils {
|
|
|
339
338
|
* > true
|
|
340
339
|
* dictionary.concat(dictionary2);
|
|
341
340
|
**/
|
|
342
|
-
Dictionary:
|
|
343
|
-
new <K, V>(): UtilsDictionaryConstructor<K, V>;
|
|
344
|
-
};
|
|
341
|
+
Dictionary: typeof UtilsDictionary;
|
|
345
342
|
/**
|
|
346
343
|
* 主动触发事件
|
|
347
344
|
* @param element 元素
|
|
@@ -832,7 +829,7 @@ declare class Utils {
|
|
|
832
829
|
// 删除键为menu_key的菜单
|
|
833
830
|
GM_Menu.delete("menu_key");
|
|
834
831
|
**/
|
|
835
|
-
GM_Menu:
|
|
832
|
+
GM_Menu: typeof GMMenu;
|
|
836
833
|
/**
|
|
837
834
|
* 基于Function prototype,能够勾住和释放任何函数
|
|
838
835
|
*
|
|
@@ -857,7 +854,7 @@ declare class Utils {
|
|
|
857
854
|
}
|
|
858
855
|
testFunction.hook(testFunction,myFunction,window);
|
|
859
856
|
**/
|
|
860
|
-
Hooks:
|
|
857
|
+
Hooks: typeof Hooks;
|
|
861
858
|
/**
|
|
862
859
|
* 为减少代码量和回调,把GM_xmlhttpRequest封装
|
|
863
860
|
* 文档地址: https://www.tampermonkey.net/documentation.php?ext=iikm
|
|
@@ -896,7 +893,7 @@ declare class Utils {
|
|
|
896
893
|
})
|
|
897
894
|
// 优先级为 默认details < 全局details < 单独的details
|
|
898
895
|
*/
|
|
899
|
-
Httpx:
|
|
896
|
+
Httpx: typeof Httpx;
|
|
900
897
|
/**
|
|
901
898
|
* 浏览器端的indexedDB操作封装
|
|
902
899
|
* @example
|
|
@@ -922,7 +919,7 @@ declare class Utils {
|
|
|
922
919
|
console.log(resolve,'清除数据库---->>>>>>name')
|
|
923
920
|
})
|
|
924
921
|
**/
|
|
925
|
-
indexedDB:
|
|
922
|
+
indexedDB: typeof indexedDB;
|
|
926
923
|
/**
|
|
927
924
|
* 判断目标函数是否是Native Code
|
|
928
925
|
* @param target
|
|
@@ -1164,7 +1161,7 @@ declare class Utils {
|
|
|
1164
1161
|
await lock.run();
|
|
1165
1162
|
> 1
|
|
1166
1163
|
**/
|
|
1167
|
-
LockFunction:
|
|
1164
|
+
LockFunction: typeof LockFunction;
|
|
1168
1165
|
/**
|
|
1169
1166
|
* 日志对象
|
|
1170
1167
|
* @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}}
|
|
@@ -1194,7 +1191,7 @@ declare class Utils {
|
|
|
1194
1191
|
log.success("颜色为#31dc02");
|
|
1195
1192
|
> 颜色为#31dc02
|
|
1196
1193
|
*/
|
|
1197
|
-
Log:
|
|
1194
|
+
Log: typeof Log;
|
|
1198
1195
|
/**
|
|
1199
1196
|
* 合并数组内的JSON的值字符串
|
|
1200
1197
|
* @param data 需要合并的数组
|
|
@@ -1386,7 +1383,7 @@ declare class Utils {
|
|
|
1386
1383
|
let progress = new Utils.Process({canvasNode:document.querySelector("canvas")});
|
|
1387
1384
|
progress.draw();
|
|
1388
1385
|
* **/
|
|
1389
|
-
Progress:
|
|
1386
|
+
Progress: typeof Progress;
|
|
1390
1387
|
/**
|
|
1391
1388
|
* 劫持Event的isTrust为true,注入时刻,ducument-start
|
|
1392
1389
|
* @param isTrustValue (可选)让isTrusted为true
|
|
@@ -1539,7 +1536,6 @@ declare class Utils {
|
|
|
1539
1536
|
toSearchParamsStr(obj: object | object[]): string;
|
|
1540
1537
|
/**
|
|
1541
1538
|
* 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
1542
|
-
* @returns 返回一个对象,其中包含 error 和 run 两个方法。
|
|
1543
1539
|
* @example
|
|
1544
1540
|
* Utils.tryCatch().error().run(()=>{console.log(1)});
|
|
1545
1541
|
* > 1
|
|
@@ -1547,13 +1543,10 @@ declare class Utils {
|
|
|
1547
1543
|
* Utils.tryCatch().config({log:true}).error((error)=>{console.log(error)}).run(()=>{throw new Error('测试错误')});
|
|
1548
1544
|
* > ()=>{throw new Error('测试错误')}出现错误
|
|
1549
1545
|
*/
|
|
1550
|
-
tryCatch: (...args: any
|
|
1551
|
-
():
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
}): any;
|
|
1555
|
-
error(handler: string | Function): any;
|
|
1556
|
-
run(callback: string | Function, __context__?: object | null | undefined): any;
|
|
1546
|
+
tryCatch: (...args: any) => {
|
|
1547
|
+
config(paramDetails: import("./tryCatch").UtilsTryCatchConfig): any;
|
|
1548
|
+
error(handler: string | Function | ((...args: any[]) => any)): any;
|
|
1549
|
+
run<A extends any[], R>(callback: string | Function | ((...args: A) => R), __context__?: any): import("./tryCatch").UtilsTryCatchType;
|
|
1557
1550
|
};
|
|
1558
1551
|
/**
|
|
1559
1552
|
* 数组去重,去除重复的值
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
declare class indexedDB {
|
|
2
|
+
#private;
|
|
3
|
+
/**
|
|
4
|
+
* @param dbName 数据存储名,默认为:default_db
|
|
5
|
+
* @param storeName 表名,默认为:default_form
|
|
6
|
+
* @param dbVersion indexDB的版本号,默认为:1
|
|
7
|
+
*/
|
|
8
|
+
constructor(dbName?: string, storeName?: string, dbVersion?: number);
|
|
9
|
+
/**
|
|
10
|
+
* 创建 “表”
|
|
11
|
+
* @param dbName 表名
|
|
12
|
+
*/
|
|
13
|
+
createStore(dbName: string): IDBObjectStore;
|
|
14
|
+
/**
|
|
15
|
+
* 打开数据库
|
|
16
|
+
* @param callback 回调
|
|
17
|
+
* @param dbName 数据库名
|
|
18
|
+
*/
|
|
19
|
+
private open;
|
|
20
|
+
/**
|
|
21
|
+
* 保存数据到数据库
|
|
22
|
+
* @param key 数据key
|
|
23
|
+
* @param value 数据值
|
|
24
|
+
*/
|
|
25
|
+
save(key: string, value: any): Promise<{
|
|
26
|
+
success: boolean;
|
|
27
|
+
code: number;
|
|
28
|
+
msg: string;
|
|
29
|
+
event?: Event;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* 根据key获取值
|
|
33
|
+
* @param key 数据key
|
|
34
|
+
*/
|
|
35
|
+
get<T extends any>(key: string): Promise<{
|
|
36
|
+
success: boolean;
|
|
37
|
+
code: number;
|
|
38
|
+
msg: string;
|
|
39
|
+
data: T;
|
|
40
|
+
event?: Event;
|
|
41
|
+
result?: any;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* 正则获取数据
|
|
45
|
+
* @param key 数据键
|
|
46
|
+
*/
|
|
47
|
+
regexpGet<T extends any>(key: string): Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
code: number;
|
|
50
|
+
msg: string;
|
|
51
|
+
data: T[];
|
|
52
|
+
event?: Event;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* 删除数据
|
|
56
|
+
* @param {string} key 数据键
|
|
57
|
+
*/
|
|
58
|
+
delete(key: string): Promise<{
|
|
59
|
+
success: boolean;
|
|
60
|
+
code: number;
|
|
61
|
+
msg: string;
|
|
62
|
+
event?: Event;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* 删除所有数据
|
|
66
|
+
*/
|
|
67
|
+
deleteAll(): Promise<{
|
|
68
|
+
success: boolean;
|
|
69
|
+
code: number;
|
|
70
|
+
msg: string;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
export { indexedDB };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare interface UtilsTryCatchConfig {
|
|
2
|
+
log: boolean;
|
|
3
|
+
}
|
|
4
|
+
/** tryCatch */
|
|
5
|
+
export declare interface UtilsTryCatchType {
|
|
6
|
+
run: UtilsTryCatchType;
|
|
7
|
+
config: UtilsTryCatchType;
|
|
8
|
+
error: UtilsTryCatchType;
|
|
9
|
+
}
|
|
10
|
+
declare const TryCatch: (...args: any) => {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param paramDetails 配置
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
config(paramDetails: UtilsTryCatchConfig): any;
|
|
17
|
+
/**
|
|
18
|
+
* 处理错误
|
|
19
|
+
* @param handler
|
|
20
|
+
*/
|
|
21
|
+
error(handler: ((...args: any[]) => any) | string | Function): any;
|
|
22
|
+
/**
|
|
23
|
+
* 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
24
|
+
* @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
25
|
+
* @param __context__ 待执行函数的作用域,用于apply指定
|
|
26
|
+
* @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
|
|
27
|
+
* @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
|
|
28
|
+
*/
|
|
29
|
+
run<A extends any[], R>(callback: ((...args: A) => R) | string | Function, __context__?: any): UtilsTryCatchType;
|
|
30
|
+
};
|
|
31
|
+
export { TryCatch };
|
package/package.json
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@whitesev/utils",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "一个常用的工具库",
|
|
5
|
-
"main": "dist/index.cjs.js",
|
|
6
|
-
"module": "dist/node/index.esm.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"jsdelivr": "dist/index.umd.js",
|
|
9
|
-
"exports": {
|
|
10
|
-
"./package.json": "./package.json",
|
|
11
|
-
".": {
|
|
12
|
-
"import": "./dist/index.esm.js",
|
|
13
|
-
"require": "./dist/index.cjs.js",
|
|
14
|
-
"types": "./dist/index.d.ts"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "rollup --config"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [
|
|
21
|
-
"typescript"
|
|
22
|
-
],
|
|
23
|
-
"author": "WhiteSev",
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@rollup/plugin-babel": "^6.0.4",
|
|
27
|
-
"@rollup/plugin-commonjs": "^25.0.8",
|
|
28
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
29
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
30
|
-
"rollup-plugin-clear": "^2.0.7",
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@whitesev/utils",
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "一个常用的工具库",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/node/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"jsdelivr": "dist/index.umd.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.esm.js",
|
|
13
|
+
"require": "./dist/index.cjs.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "rollup --config"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"author": "WhiteSev",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
27
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
28
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
29
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
30
|
+
"rollup-plugin-clear": "^2.0.7",
|
|
31
|
+
"tslib": "^2.6.2"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"typescript": "^5.4.5"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/rollup.config.js
CHANGED
|
@@ -6,8 +6,6 @@ const { nodeResolve } = require("@rollup/plugin-node-resolve");
|
|
|
6
6
|
const typescript = require("@rollup/plugin-typescript");
|
|
7
7
|
// 清空 dist
|
|
8
8
|
const cleaner = require("rollup-plugin-clear");
|
|
9
|
-
// 处理 .d.ts 声明文件
|
|
10
|
-
const { dts } = require("rollup-plugin-dts");
|
|
11
9
|
|
|
12
10
|
// 模块名
|
|
13
11
|
const moduleName = "Utils";
|
|
@@ -16,7 +14,6 @@ module.exports = {
|
|
|
16
14
|
cleaner({
|
|
17
15
|
targets: ["./dist"],
|
|
18
16
|
}),
|
|
19
|
-
dts(),
|
|
20
17
|
nodeResolve(),
|
|
21
18
|
commonjs(),
|
|
22
19
|
typescript(),
|