@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.
Files changed (60) hide show
  1. package/dist/index.amd.js +5885 -1817
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +5533 -1467
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +5531 -1467
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +5886 -1817
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +5897 -1826
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +5889 -1817
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/src/Dictionary.d.ts +82 -0
  14. package/dist/src/Hooks.d.ts +11 -0
  15. package/dist/src/Httpx.d.ts +1201 -0
  16. package/dist/src/LockFunction.d.ts +31 -0
  17. package/dist/src/Log.d.ts +96 -0
  18. package/dist/src/Progress.d.ts +37 -0
  19. package/dist/src/UtilsGMMenu.d.ts +156 -0
  20. package/dist/src/index.d.ts +20 -27
  21. package/dist/src/indexedDB.d.ts +73 -0
  22. package/dist/src/tryCatch.d.ts +31 -0
  23. package/package.json +36 -37
  24. package/rollup.config.js +0 -3
  25. package/src/Dictionary.ts +152 -0
  26. package/src/{Hooks/Hooks.js → Hooks.ts} +31 -17
  27. package/src/{Httpx/index.d.ts → Httpx.ts} +837 -46
  28. package/src/LockFunction.ts +62 -0
  29. package/src/Log.ts +281 -0
  30. package/src/Progress.ts +143 -0
  31. package/src/UtilsGMMenu.ts +681 -0
  32. package/src/index.ts +17 -29
  33. package/src/indexedDB.ts +421 -0
  34. package/src/tryCatch.ts +107 -0
  35. package/tsconfig.json +1 -1
  36. package/dist/src/Dictionary/Dictionary.d.ts +0 -85
  37. package/dist/src/Hooks/Hooks.d.ts +0 -5
  38. package/dist/src/Httpx/Httpx.d.ts +0 -50
  39. package/dist/src/LockFunction/LockFunction.d.ts +0 -16
  40. package/dist/src/Log/Log.d.ts +0 -66
  41. package/dist/src/Progress/Progress.d.ts +0 -6
  42. package/dist/src/UtilsGMMenu/UtilsGMMenu.d.ts +0 -119
  43. package/dist/src/indexedDB/indexedDB.d.ts +0 -165
  44. package/dist/src/tryCatch/tryCatch.d.ts +0 -31
  45. package/src/Dictionary/Dictionary.js +0 -157
  46. package/src/Dictionary/index.d.ts +0 -52
  47. package/src/Hooks/index.d.ts +0 -16
  48. package/src/Httpx/Httpx.js +0 -747
  49. package/src/LockFunction/LockFunction.js +0 -35
  50. package/src/LockFunction/index.d.ts +0 -47
  51. package/src/Log/Log.js +0 -256
  52. package/src/Log/index.d.ts +0 -91
  53. package/src/Progress/Progress.js +0 -98
  54. package/src/Progress/index.d.ts +0 -30
  55. package/src/UtilsGMMenu/UtilsGMMenu.js +0 -464
  56. package/src/UtilsGMMenu/index.d.ts +0 -224
  57. package/src/indexedDB/index.d.ts +0 -128
  58. package/src/indexedDB/indexedDB.js +0 -355
  59. package/src/tryCatch/index.d.ts +0 -6
  60. package/src/tryCatch/tryCatch.js +0 -100
@@ -1,35 +0,0 @@
1
- const LockFunction = function (callback, context, delayTime = 0) {
2
- let flag = false;
3
- let that = this;
4
- context = context || this;
5
- /**
6
- * 锁
7
- */
8
- this.lock = function () {
9
- flag = true;
10
- };
11
- /**
12
- * 解锁
13
- */
14
- this.unlock = function () {
15
- setTimeout(() => {
16
- flag = false;
17
- }, delayTime);
18
- };
19
- /**
20
- * 执行
21
- */
22
- this.run = async function (...args) {
23
- if (flag) {
24
- return;
25
- }
26
- that.lock();
27
- await callback.apply(context, args);
28
- that.unlock();
29
- };
30
- };
31
-
32
-
33
- export {
34
- LockFunction
35
- }
@@ -1,47 +0,0 @@
1
- /** Utils.LockFunction */
2
- declare interface UtilsLockFunction {
3
- /**
4
- * @param callback 需要执行的函数
5
- * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
6
- */
7
- new <K extends (...args: any[]) => any | Promise<any> | void>(
8
- callback: K,
9
- delayTime?: number
10
- ): {
11
- /**
12
- * 上锁
13
- */
14
- lock: () => void;
15
- /**
16
- * 解锁
17
- */
18
- unlock: () => void;
19
- /**
20
- * 执行函数
21
- */
22
- run: () => ReturnType<K>;
23
- };
24
- /**
25
- * @param callback 需要执行的函数
26
- * @param context (可选)函数作用域,默认:this(Utils)
27
- * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
28
- */
29
- new <K extends (...args: any[]) => any | Promise<any>>(
30
- callback: K,
31
- context?: UtilsNestedObjectWithToString,
32
- delayTime?: number
33
- ): {
34
- /**
35
- * 上锁
36
- */
37
- lock: () => void;
38
- /**
39
- * 解锁
40
- */
41
- unlock: () => void;
42
- /**
43
- * 执行函数
44
- */
45
- run: () => ReturnType<K>;
46
- };
47
- }
package/src/Log/Log.js DELETED
@@ -1,256 +0,0 @@
1
- const Log = function (
2
- _GM_info_ = {
3
- script: {
4
- name: "Utils.Log",
5
- },
6
- },
7
- console = globalThis.console
8
- ) {
9
- let msgColorDetails = [
10
- "font-weight: bold; color: cornflowerblue",
11
- "font-weight: bold; color: cornflowerblue",
12
- "font-weight: bold; color: darkorange",
13
- "font-weight: bold; color: cornflowerblue",
14
- ];
15
- /**
16
- * @type {UtilsLogOptions}
17
- */
18
- let details = {
19
- tag: true,
20
- successColor: "#0000FF",
21
- errorColor: "#FF0000",
22
- infoColor: "0",
23
- warnColor: "0",
24
- debug: false,
25
- autoClearConsole: false,
26
- logMaxCount: 999,
27
- };
28
- let logCount = 0;
29
- /**
30
- * 解析Error的堆栈获取实际调用者的函数名及函数所在的位置
31
- * @param {string[]} stack
32
- * @returns {{
33
- * name: string,
34
- * position: string,
35
- * }}
36
- */
37
- let parseErrorStack = function (stack) {
38
- let result = {
39
- name: "",
40
- position: "",
41
- };
42
- for (let stackString of stack) {
43
- stackString = stackString.trim();
44
- let stackFunctionName = stackString.match(/^at[\s]+(.+?)[\s]+/i);
45
- let stackFunctionNamePosition = stackString.match(
46
- /^at[\s]+.+[\s]+\((.+?)\)/i
47
- );
48
- if (stackFunctionName == null) {
49
- continue;
50
- }
51
- stackFunctionName = stackFunctionName[stackFunctionName.length - 1];
52
- stackFunctionNamePosition =
53
- stackFunctionNamePosition[stackFunctionNamePosition.length - 1];
54
- if (
55
- stackFunctionName === "" ||
56
- stackFunctionName.match(
57
- new RegExp(
58
- "(^Utils.Log.|.<anonymous>$|^Function.each|^NodeList.forEach|^k.fn.init.each)",
59
- "g"
60
- )
61
- )
62
- ) {
63
- continue;
64
- } else {
65
- result.name = stackFunctionName;
66
- result.position = stackFunctionNamePosition;
67
- break;
68
- }
69
- }
70
- if (result.position === "") {
71
- let lastStackString = stack[stack.length - 1].trim();
72
- if (lastStackString.startsWith("at chrome-extension://")) {
73
- let lastStackMatch = lastStackString.match(/^at[\s]+(.+)/);
74
- if (lastStackMatch) {
75
- result.position = lastStackMatch[lastStackMatch.length - 1];
76
- }
77
- }
78
- }
79
- if (result.position === "") {
80
- result.position = stack[stack.length - 1].trim().replace(/^at[\s]*/g, "");
81
- }
82
- return result;
83
- };
84
- /**
85
- * 待恢复的函数或对象
86
- */
87
- let recoveryList = [];
88
- /**
89
- * 检测清理控制台
90
- * @this {Utils.Log}
91
- */
92
- let checkClearConsole = function () {
93
- logCount++;
94
- if (details.autoClearConsole && logCount > details.logMaxCount) {
95
- console.clear();
96
- logCount = 0;
97
- }
98
- };
99
- /**
100
- * 输出内容
101
- * @param {any} msg 需要输出的内容
102
- * @param {string} color 颜色
103
- * @param {string|undefined} otherStyle 其它CSS
104
- * @this {Utils.Log}
105
- */
106
- let printContent = function (msg, color, otherStyle) {
107
- checkClearConsole.apply(this);
108
- otherStyle = otherStyle || "";
109
- let stackSplit = new Error().stack.split("\n");
110
- stackSplit.splice(0, 2);
111
- let { name: callerName, position: callerPosition } =
112
- parseErrorStack(stackSplit);
113
- let tagName = this.tag;
114
- function consoleMsg(_msg_) {
115
- if (typeof _msg_ === "string") {
116
- console.log(
117
- `%c[${tagName}%c-%c${callerName}%c]%c %s`,
118
- ...msgColorDetails,
119
- `color: ${color};${otherStyle}`,
120
- _msg_
121
- );
122
- } else if (typeof _msg_ === "number") {
123
- console.log(
124
- `%c[${tagName}%c-%c${callerName}%c]%c %d`,
125
- ...msgColorDetails,
126
- `color: ${color};${otherStyle}`,
127
- _msg_
128
- );
129
- } else if (typeof _msg_ === "object") {
130
- console.log(
131
- `%c[${tagName}%c-%c${callerName}%c]%c %o`,
132
- ...msgColorDetails,
133
- `color: ${color};${otherStyle}`,
134
- _msg_
135
- );
136
- } else {
137
- console.log(_msg_);
138
- }
139
- }
140
- if (Array.isArray(msg)) {
141
- msg.forEach((item) => {
142
- consoleMsg(item);
143
- });
144
- } else {
145
- consoleMsg(msg);
146
- }
147
- if (details.debug) {
148
- /* 如果开启调试模式,输出堆栈位置 */
149
- console.log(callerPosition);
150
- }
151
- };
152
- /**
153
- * 前面的TAG标志
154
- */
155
- this.tag = _GM_info_?.script?.name || "Utils.Log";
156
- /**
157
- * 控制台-普通输出
158
- * @param {any} msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
159
- * @param {string|undefined} color 输出的颜色
160
- * @param {string|undefined} otherStyle 其它CSS
161
- */
162
- this.info = function (msg, color = details.infoColor, otherStyle) {
163
- printContent.call(this, msg, color, otherStyle);
164
- };
165
- /**
166
- * 控制台-警告输出
167
- * @param {any} msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
168
- * @param {string|undefined} color 输出的颜色
169
- * @param {string|undefined} otherStyle 其它CSS
170
- */
171
- this.warn = function (
172
- msg,
173
- color = details.warnColor,
174
- otherStyle = "background: #FEF6D5;padding: 4px 6px 4px 0px;"
175
- ) {
176
- printContent.call(this, msg, color, otherStyle);
177
- };
178
- /**
179
- * 控制台-错误输出
180
- * @param {any} msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
181
- * @param {string|undefined} color 输出的颜色
182
- * @param {string|undefined} otherStyle 其它CSS
183
- */
184
- this.error = function (msg, color = details.errorColor, otherStyle) {
185
- printContent.call(this, msg, color, otherStyle);
186
- };
187
- /**
188
- * 控制台-成功输出
189
- * @param {any} msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
190
- * @param {string|undefined} color 输出的颜色
191
- * @param {string|undefined} otherStyle 其它CSS
192
- */
193
- this.success = function (msg, color = details.successColor, otherStyle) {
194
- printContent.call(this, msg, color, otherStyle);
195
- };
196
- /**
197
- * 控制台-输出表格
198
- * @param {object[]} msg
199
- * @param {string|undefined} color 输出的颜色
200
- * @param {string|undefined} otherStyle 其它CSS
201
- * @example
202
- * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
203
- */
204
- this.table = function (msg, color = details.infoColor, otherStyle = "") {
205
- checkClearConsole.apply(this);
206
- let stack = new Error().stack.split("\n");
207
- stack.splice(0, 1);
208
- let errorStackParse = parseErrorStack(stack);
209
- let stackFunctionName = errorStackParse.name;
210
- let stackFunctionNamePosition = errorStackParse.position;
211
- let callerName = stackFunctionName;
212
- console.log(
213
- `%c[${this.tag}%c-%c${callerName}%c]%c`,
214
- ...msgColorDetails,
215
- `color: ${color};${otherStyle}`
216
- );
217
- console.table(msg);
218
- if (details.debug) {
219
- console.log(stackFunctionNamePosition);
220
- }
221
- };
222
- /**
223
- * 配置Log对象的颜色
224
- * @param {UtilsLogOptions} paramDetails 配置信息
225
- */
226
- this.config = function (paramDetails) {
227
- details = Object.assign(details, paramDetails);
228
- };
229
- /**
230
- * 禁用输出
231
- */
232
- this.disable = function () {
233
- let that = this;
234
- Object.keys(this)
235
- .filter((keyName) => Boolean(keyName.match(/info|error|success|table/)))
236
- .forEach((keyName) => {
237
- let value = {};
238
- value[keyName] = that[keyName];
239
- recoveryList = [...recoveryList, value];
240
- that[keyName] = () => {};
241
- });
242
- };
243
- /**
244
- * 恢复输出
245
- */
246
- this.recovery = function () {
247
- let that = this;
248
- recoveryList.forEach((item) => {
249
- let keyName = Object.keys(item);
250
- that[keyName] = item[keyName];
251
- });
252
- recoveryList = [];
253
- };
254
- };
255
-
256
- export { Log };
@@ -1,91 +0,0 @@
1
- /** Utils.Log的初始化配置 */
2
- declare interface UtilsLogOptions {
3
- /** 是否输出Tag,false的话其它的颜色也不输出,默认为true */
4
- tag?: boolean;
5
- /** log.success的颜色,默认#0000FF */
6
- successColor?: string;
7
- /** log.warn的颜色,默认0 */
8
- warnColor?: string;
9
- /** log.error的颜色,默认#FF0000 */
10
- errorColor?: string;
11
- /** log.info的颜色,默认0 */
12
- infoColor?: string;
13
- /** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置,默认false */
14
- debug?: boolean;
15
- /** 当console输出超过logMaxCount数量自动清理控制台,默认false */
16
- autoClearConsole?: boolean;
17
- /** console输出的最高数量,autoClearConsole开启则生效,默认999 */
18
- logMaxCount?: number;
19
- }
20
-
21
- /** Utils.Log */
22
- declare interface UtilsLogConstructor {
23
- /** 前面的TAG标志 */
24
- tag: string;
25
- /**
26
- * 控制台-普通输出
27
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
28
- * @param color 输出的颜色
29
- * @param otherStyle 其它CSS
30
- */
31
- info(msg: any, color?: string, otherStyle?: string): void;
32
- /**
33
- * 控制台-警告输出
34
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
35
- * @param color 输出的颜色
36
- * @param otherStyle 其它CSS
37
- */
38
- warn(msg: any, color?: string, otherStyle?: string): void;
39
- /**
40
- * 控制台-错误输出
41
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
42
- * @param color 输出的颜色
43
- * @param otherStyle 其它CSS
44
- */
45
- error(msg: any, color?: string, otherStyle?: string): void;
46
- /**
47
- * 控制台-成功输出
48
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
49
- * @param color 输出的颜色
50
- * @param otherStyle 其它CSS
51
- */
52
- success(msg: any, color?: string, otherStyle?: string): void;
53
- /**
54
- * 控制台-输出表格
55
- * @param msg
56
- * @param color 输出的颜色
57
- * @param otherStyle 其它CSS
58
- * @example
59
- * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
60
- */
61
- table(
62
- msg: UtilsNestedObjectWithToString[],
63
- color?: string,
64
- otherStyle?: string
65
- ): void;
66
- /**
67
- * 配置Log对象的颜色
68
- * @param paramDetails 配置信息
69
- */
70
- config(paramDetails: UtilsLogOptions): void;
71
- /** 禁用输出 */
72
- disable(): void;
73
- /** 恢复输出 */
74
- recovery(): void;
75
- }
76
-
77
- /** Utils.Log */
78
- declare interface UtilsLog {
79
- /**
80
- * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}}
81
- * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
82
- */
83
- new (
84
- _GM_info_: {
85
- script: {
86
- name: string;
87
- };
88
- },
89
- console: Console
90
- ): UtilsLogConstructor;
91
- }
@@ -1,98 +0,0 @@
1
- const Progress = function (paramConfig) {
2
- this.config = {
3
- /**
4
- * canvas元素节点
5
- * @type {HTMLCanvasElement}
6
- */
7
- canvasNode: null,
8
- /**
9
- * 绘制角度
10
- */
11
- deg: 95,
12
- /**
13
- * 进度
14
- */
15
- progress: 0,
16
- /**
17
- * 绘制的线宽度
18
- */
19
- lineWidth: 10,
20
- /**
21
- * 绘制的背景颜色
22
- */
23
- lineBgColor: "#1e637c",
24
- /**
25
- * 绘制的线的颜色
26
- */
27
- lineColor: "#25deff",
28
- /**
29
- * 绘制的字体颜色
30
- */
31
- textColor: "#000000",
32
- /**
33
- * 绘制的字体大小(px)
34
- */
35
- fontSize: 22,
36
- /**
37
- * 绘制的圆的半径
38
- */
39
- circleRadius: 50,
40
- /**
41
- * 控制绘制的函数
42
- */
43
- draw: () => {},
44
- };
45
- this.config = Utils.assign(this.config, paramConfig);
46
- if (!(this.config.canvasNode instanceof HTMLCanvasElement)) {
47
- throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
48
- }
49
- /* 获取画笔 */
50
- let ctx = this.config.canvasNode.getContext("2d");
51
- /* 元素宽度 */
52
- let width = this.config.canvasNode.width;
53
- /* 元素高度 */
54
- let height = this.config.canvasNode.height;
55
-
56
- /* 清除锯齿 */
57
- if (window.devicePixelRatio) {
58
- this.config.canvasNode.style.width = width + "px";
59
- this.config.canvasNode.style.height = height + "px";
60
- this.config.canvasNode.height = height * window.devicePixelRatio;
61
- this.config.canvasNode.width = width * window.devicePixelRatio;
62
- ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
63
- }
64
- /* 设置线宽 */
65
- ctx.lineWidth = this.config.lineWidth;
66
- /* 绘制 */
67
- this.draw = function () {
68
- let degActive = (this.config.progress * 360) / 100;
69
- /* 清除画布 */
70
- ctx.clearRect(0, 0, width, height);
71
- /* 开始绘制底圆 */
72
- ctx.beginPath();
73
- ctx.arc(width / 2, height / 2, this.config.circleRadius, 1, 8);
74
- ctx.strokeStyle = this.config.lineBgColor;
75
- ctx.stroke();
76
- /* 开始绘制动态圆 */
77
- ctx.beginPath();
78
- ctx.arc(
79
- width / 2,
80
- height / 2,
81
- this.config.circleRadius,
82
- -Math.PI / 2,
83
- (degActive * Math.PI) / 180 - Math.PI / 2
84
- );
85
- ctx.strokeStyle = this.config.lineColor;
86
- ctx.stroke();
87
- /* 获取百分比 */
88
- let txt = parseInt(this.config.progress) + "%";
89
- ctx.font = this.config.fontSize + "px SimHei";
90
- /* 获取文本宽度 */
91
- let w = ctx.measureText(txt).width;
92
- let h = this.config.fontSize / 2;
93
- ctx.fillStyle = this.config.textColor;
94
- ctx.fillText(txt, width / 2 - w / 2, height / 2 + h / 2);
95
- }.bind(this);
96
- };
97
-
98
- export { Progress };
@@ -1,30 +0,0 @@
1
- /** Progress */
2
- declare interface UtilsProgressConstructor {}
3
- /** Progress */
4
- declare interface UtilsProgress {
5
- /**
6
- * @param paramConfig 配置信息
7
- */
8
- new (paramConfig: {
9
- /** canvas元素节点 */
10
- canvasNode?: HTMLCanvasElement;
11
- /** 绘制角度,默认:95 */
12
- deg: number;
13
- /** 进度,默认:0 */
14
- progress: number;
15
- /** 绘制的线宽度,默认:10 */
16
- lineWidth: number;
17
- /** 绘制的背景颜色,默认:#1e637c */
18
- lineBgColor: string;
19
- /** 绘制的线的颜色,默认:#25deff */
20
- lineColor: string;
21
- /** 绘制的字体颜色,默认:#000000 */
22
- textColor: string;
23
- /** 绘制的字体大小(px),默认:22px */
24
- fontSize: string;
25
- /** 绘制的圆的半径,默认:50 */
26
- circleRadius: string;
27
- /** 控制绘制的函数 */
28
- draw?: () => void;
29
- }): UtilsProgressConstructor;
30
- }