@whitesev/utils 2.9.12 → 2.10.0

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 (73) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +206 -117
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +1 -1
  5. package/dist/index.amd.min.js.map +1 -1
  6. package/dist/index.cjs.js +206 -117
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +1 -1
  9. package/dist/index.cjs.min.js.map +1 -1
  10. package/dist/index.esm.js +206 -117
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +1 -1
  13. package/dist/index.esm.min.js.map +1 -1
  14. package/dist/index.iife.js +206 -117
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +1 -1
  17. package/dist/index.iife.min.js.map +1 -1
  18. package/dist/index.system.js +206 -117
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +1 -1
  21. package/dist/index.system.min.js.map +1 -1
  22. package/dist/index.umd.js +206 -117
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +1 -1
  25. package/dist/index.umd.min.js.map +1 -1
  26. package/dist/types/src/Dictionary.d.ts +2 -0
  27. package/dist/types/src/Utils.d.ts +9 -2
  28. package/dist/types/src/types/Httpx.d.ts +1344 -1344
  29. package/dist/types/src/types/Log.d.ts +19 -19
  30. package/dist/types/src/types/Progress.d.ts +20 -20
  31. package/dist/types/src/types/React.d.ts +119 -119
  32. package/dist/types/src/types/TryCatch.d.ts +9 -9
  33. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  34. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  35. package/dist/types/src/types/Vue2.d.ts +166 -166
  36. package/dist/types/src/types/WindowApi.d.ts +14 -14
  37. package/dist/types/src/types/ajaxHooker.d.ts +155 -155
  38. package/dist/types/src/types/env.d.ts +7 -7
  39. package/dist/types/src/types/global.d.ts +31 -31
  40. package/package.json +26 -24
  41. package/src/ColorConversion.ts +118 -118
  42. package/src/CommonUtil.ts +301 -301
  43. package/src/DOMUtils.ts +251 -251
  44. package/src/Dictionary.ts +205 -199
  45. package/src/GBKEncoder.ts +108 -108
  46. package/src/Hooks.ts +73 -73
  47. package/src/Httpx.ts +1457 -1457
  48. package/src/LockFunction.ts +65 -62
  49. package/src/Log.ts +233 -233
  50. package/src/ModuleRaid.js +378 -360
  51. package/src/Progress.ts +108 -108
  52. package/src/TryCatch.ts +86 -86
  53. package/src/Utils.ts +3907 -3852
  54. package/src/UtilsCommon.ts +14 -14
  55. package/src/UtilsGMCookie.ts +273 -273
  56. package/src/UtilsGMMenu.ts +460 -460
  57. package/src/Vue.ts +233 -233
  58. package/src/WindowApi.ts +59 -59
  59. package/src/ajaxHooker/ajaxHooker.js +606 -538
  60. package/src/ajaxHooker/ajaxHooker1.2.4.js +440 -438
  61. package/src/indexedDB.ts +497 -497
  62. package/src/types/Httpx.d.ts +1344 -1344
  63. package/src/types/Log.d.ts +19 -19
  64. package/src/types/Progress.d.ts +20 -20
  65. package/src/types/React.d.ts +119 -119
  66. package/src/types/TryCatch.d.ts +9 -9
  67. package/src/types/UtilsGMCookie.d.ts +93 -93
  68. package/src/types/UtilsGMMenu.d.ts +77 -77
  69. package/src/types/Vue2.d.ts +166 -166
  70. package/src/types/WindowApi.d.ts +14 -14
  71. package/src/types/ajaxHooker.d.ts +155 -155
  72. package/src/types/env.d.ts +7 -7
  73. package/src/types/global.d.ts +31 -31
@@ -1,62 +1,65 @@
1
- export class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
2
- #flag: boolean = false;
3
- #delayTime: number = 0;
4
- #callback: K;
5
- #timeId: number | undefined = void 0;
6
- lock: () => void;
7
- unlock: () => void;
8
- run: (...args: any[]) => Promise<void>;
9
- isLock: () => boolean;
10
- /**
11
- * @param callback 需要执行的函数
12
- * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
13
- */
14
- constructor(callback: K, delayTime?: number);
15
- /**
16
- * @param callback 需要执行的函数
17
- * @param context (可选)函数作用域,默认:this(Utils)
18
- * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
19
- */
20
- constructor(callback: K, context?: any, delayTime?: number);
21
- constructor(callback: K, context?: any, delayTime?: number) {
22
- const that = this;
23
- this.#callback = callback;
24
- if (typeof context === "number") {
25
- this.#delayTime = context;
26
- } else {
27
- this.#delayTime = delayTime as number;
28
- }
29
- /**
30
- * 锁
31
- */
32
- this.lock = function () {
33
- that.#flag = true;
34
- clearTimeout(that.#timeId);
35
- };
36
- /**
37
- * 解锁
38
- */
39
- this.unlock = function () {
40
- that.#timeId = setTimeout(() => {
41
- that.#flag = false;
42
- }, that.#delayTime);
43
- };
44
- /**
45
- * 判断是否被锁
46
- */
47
- this.isLock = function () {
48
- return that.#flag;
49
- };
50
- /**
51
- * 执行
52
- */
53
- this.run = async function (...args: any[]) {
54
- if (that.isLock()) {
55
- return;
56
- }
57
- that.lock();
58
- await that.#callback.apply(this, args);
59
- that.unlock();
60
- };
61
- }
62
- }
1
+ export class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
2
+ #flag: boolean = false;
3
+ #delayTime: number = 0;
4
+ #callback: K;
5
+ #timeId: number | undefined = void 0;
6
+ lock: () => void;
7
+ unlock: () => void;
8
+ run: (...args: any[]) => Promise<void>;
9
+ isLock: () => boolean;
10
+ /**
11
+ * @param callback 需要执行的函数
12
+ * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
13
+ */
14
+ constructor(callback: K, delayTime?: number);
15
+ /**
16
+ * @param callback 需要执行的函数
17
+ * @param context (可选)函数作用域,默认:this(Utils)
18
+ * @param delayTime (可选)延迟xx毫秒后解锁,默认:0
19
+ */
20
+ constructor(callback: K, context?: any, delayTime?: number);
21
+ constructor(callback: K, context?: any, delayTime?: number) {
22
+ const that = this;
23
+ this.#callback = callback;
24
+ if (typeof context === "number") {
25
+ this.#delayTime = context;
26
+ } else {
27
+ this.#delayTime = delayTime as number;
28
+ }
29
+ /**
30
+ * 锁
31
+ */
32
+ this.lock = function () {
33
+ that.#flag = true;
34
+ clearTimeout(that.#timeId);
35
+ };
36
+ /**
37
+ * 解锁
38
+ */
39
+ this.unlock = function () {
40
+ that.#timeId = setTimeout(
41
+ () => {
42
+ that.#flag = false;
43
+ },
44
+ that.#delayTime
45
+ );
46
+ };
47
+ /**
48
+ * 判断是否被锁
49
+ */
50
+ this.isLock = function () {
51
+ return that.#flag;
52
+ };
53
+ /**
54
+ * 执行
55
+ */
56
+ this.run = async function (...args: any[]) {
57
+ if (that.isLock()) {
58
+ return;
59
+ }
60
+ that.lock();
61
+ await that.#callback.apply(this, args);
62
+ that.unlock();
63
+ };
64
+ }
65
+ }
package/src/Log.ts CHANGED
@@ -1,233 +1,233 @@
1
- import type { UtilsLogOptions } from "./types/Log";
2
-
3
- export class Log {
4
- /** 是否禁用输出的flag */
5
- #disable: boolean = false;
6
- /** 前面的TAG标志 */
7
- tag: string = "Utils.Log";
8
- /* 使用的console函数 */
9
- #console: Console = null as any;
10
- /* 当前输出的数量 */
11
- #logCount = 0;
12
- /* 配置 */
13
- #details: UtilsLogOptions = {
14
- tag: true,
15
- successColor: "background: #0eac0eff;",
16
- errorColor: "background: #FF0000;",
17
- infoColor: "background: #6495ed;",
18
- warnColor: "background: #ff8c00;",
19
- debug: false,
20
- autoClearConsole: false,
21
- logMaxCount: 999,
22
- };
23
- /**
24
- * 通用样式配置
25
- */
26
- #commonStyleConfig = {
27
- commonStyle: "color: #ffffff; padding: 3px; border-radius: 3px;line-height: 1;margin-right: 6px;",
28
- tagStyle: "background: #6495ed;",
29
- callerNameStyle: "background: #78909C;",
30
- };
31
- /**
32
- * @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
33
- * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
34
- */
35
- constructor(
36
- __GM_info?:
37
- | {
38
- script: {
39
- name: string;
40
- };
41
- }
42
- | string,
43
- console: Console = window.console
44
- ) {
45
- if (typeof __GM_info === "string") {
46
- this.tag = __GM_info;
47
- } else if (typeof __GM_info === "object" && typeof __GM_info?.script?.name === "string") {
48
- this.tag = __GM_info.script.name;
49
- }
50
- this.#console = console;
51
- }
52
-
53
- /**
54
- * 解析Error的堆栈获取实际调用者的函数名及函数所在的位置
55
- * @param stack
56
- */
57
- private parseErrorStack(stack: string[]) {
58
- const result = {
59
- name: "",
60
- position: "",
61
- };
62
- for (let stackString of stack) {
63
- stackString = stackString.trim();
64
- const stackFunctionNameMatch = stackString.match(/^at[\s]+(.+?)[\s]+/i);
65
- const stackFunctionNamePositionMatch = stackString.match(/^at[\s]+.+[\s]+\((.+?)\)/i);
66
- if (stackFunctionNameMatch == null) {
67
- continue;
68
- }
69
- if (stackFunctionNamePositionMatch == null) {
70
- continue;
71
- }
72
- /* 获取最后一个,因为第一个是包含了at */
73
- const stackFunctionName = stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
74
- const stackFunctionNamePosition = stackFunctionNamePositionMatch[stackFunctionNamePositionMatch.length - 1];
75
- if (
76
- stackFunctionName === "" ||
77
- stackFunctionName.match(/^(Utils\.|)Log(\.|)|.<anonymous>$|^Function.each|^NodeList.forEach|^k.fn.init.each/g)
78
- ) {
79
- continue;
80
- } else {
81
- result.name = stackFunctionName;
82
- result.position = stackFunctionNamePosition;
83
- break;
84
- }
85
- }
86
- if (result.position === "") {
87
- const lastStackString = stack[stack.length - 1].trim();
88
- if (lastStackString.startsWith("at chrome-extension://")) {
89
- const lastStackMatch = lastStackString.match(/^at[\s]+(.+)/);
90
- if (lastStackMatch) {
91
- result.position = lastStackMatch[lastStackMatch.length - 1];
92
- }
93
- }
94
- }
95
- if (result.position === "") {
96
- result.position = stack[stack.length - 1].trim().replace(/^at[\s]*/g, "");
97
- }
98
- return result;
99
- }
100
- /**
101
- * 检测清理控制台
102
- */
103
- private checkClearConsole() {
104
- this.#logCount++;
105
- if (this.#details.autoClearConsole && this.#logCount > this.#details.logMaxCount) {
106
- this.#console.clear();
107
- this.#logCount = 0;
108
- }
109
- }
110
-
111
- /**
112
- * 输出内容
113
- * @param msg 需要输出的内容
114
- * @param tagColor tag颜色
115
- */
116
- private printContent(msg: any[], tagColor?: string) {
117
- this.checkClearConsole();
118
- const stackSplit = new Error()!.stack!.split("\n");
119
- stackSplit.splice(0, 2);
120
- const { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
121
- const tagName = this.tag;
122
- const that = this;
123
-
124
- const msgColorDetails: string[] = [];
125
- // 控制台输出的tag的html格式
126
- let consoleHTML = `%c${tagName}`;
127
- /** tag的html输出格式 */
128
- if (typeof tagColor === "string" && tagColor.trim() !== "") {
129
- msgColorDetails.push(that.#commonStyleConfig.commonStyle + tagColor);
130
- } else {
131
- msgColorDetails.push(that.#commonStyleConfig.commonStyle + that.#commonStyleConfig.tagStyle);
132
- }
133
- // 调用的函数名的html输出格式
134
- if (callerName.trim() == "") {
135
- // 无调用函数名
136
- } else {
137
- consoleHTML = `${consoleHTML}%c${callerName}`;
138
- msgColorDetails.push(that.#commonStyleConfig.commonStyle + that.#commonStyleConfig.callerNameStyle);
139
- }
140
- if (Array.isArray(msg)) {
141
- that.#console.log(`${consoleHTML}`, ...msgColorDetails, ...msg);
142
- } else {
143
- that.#console.log(`${consoleHTML}`, ...msgColorDetails, msg);
144
- }
145
- if (this.#details.debug) {
146
- /* 如果开启调试模式,输出堆栈位置 */
147
- this.#console.log(callerPosition);
148
- }
149
- }
150
- /**
151
- * 控制台-普通输出
152
- * @param args 需要输出的内容
153
- * @example
154
- * log.info("输出信息","输出信息2","输出信息3","输出")
155
- */
156
- info(...args: any[]) {
157
- if (this.#disable) return;
158
- this.printContent(args, this.#details.infoColor);
159
- }
160
- /**
161
- * 控制台-警告输出
162
- * @param args 需要输出的内容
163
- * @example
164
- * log.warn("输出警告","输出警告2","输出警告3","输出警告4")
165
- */
166
- warn(...args: any[]) {
167
- if (this.#disable) return;
168
- // , "background: #FEF6D5;padding: 4px 6px 4px 0px;"
169
- this.printContent(args, this.#details.warnColor);
170
- }
171
- /**
172
- * 控制台-错误输出
173
- * @param args 需要输出的内容
174
- * @example
175
- * log.error("输出错误","输出错误2","输出错误3","输出错误4")
176
- */
177
- error(...args: any[]) {
178
- if (this.#disable) return;
179
- this.printContent(args, this.#details.errorColor);
180
- }
181
- /**
182
- * 控制台-成功输出
183
- * @param args 需要输出的内容
184
- * @example
185
- * log.success("输出成功")
186
- */
187
- success(...args: any[]) {
188
- if (this.#disable) return;
189
- this.printContent(args, this.#details.successColor);
190
- }
191
- /**
192
- * 控制台-输出表格
193
- * @param msg 需要输出的内容
194
- * @example
195
- * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
196
- */
197
- table(msg: any[]) {
198
- if (this.#disable) return;
199
- this.checkClearConsole();
200
- const stack = new Error()!.stack!.split("\n");
201
- stack.splice(0, 1);
202
- const errorStackParse = this.parseErrorStack(stack);
203
- /** 堆栈函数名 */
204
- const stackFunctionName = errorStackParse.name;
205
- /** 堆栈位置 */
206
- const stackFunctionNamePosition = errorStackParse.position;
207
- const callerName = stackFunctionName;
208
- const msgColorDetails: string[] = [
209
- `${this.#commonStyleConfig.commonStyle + this.#details.infoColor}`,
210
- `${this.#commonStyleConfig.commonStyle + this.#commonStyleConfig.callerNameStyle}`,
211
- ];
212
- this.#console.log(`%c${this.tag}%c${callerName}%c`, msgColorDetails);
213
- this.#console.table(msg);
214
- if (this.#details.debug) {
215
- this.#console.log(stackFunctionNamePosition);
216
- }
217
- }
218
- /**
219
- * 配置Log对象的颜色
220
- * @param paramDetails 配置信息
221
- */
222
- config(paramDetails: Partial<UtilsLogOptions>) {
223
- this.#details = Object.assign(this.#details, paramDetails);
224
- }
225
- /** 禁用输出 */
226
- disable() {
227
- this.#disable = true;
228
- }
229
- /** 恢复输出 */
230
- recovery() {
231
- this.#disable = false;
232
- }
233
- }
1
+ import type { UtilsLogOptions } from "./types/Log";
2
+
3
+ export class Log {
4
+ /** 是否禁用输出的flag */
5
+ #disable: boolean = false;
6
+ /** 前面的TAG标志 */
7
+ tag: string = "Utils.Log";
8
+ /* 使用的console函数 */
9
+ #console: Console = null as any;
10
+ /* 当前输出的数量 */
11
+ #logCount = 0;
12
+ /* 配置 */
13
+ #details: UtilsLogOptions = {
14
+ tag: true,
15
+ successColor: "background: #0eac0eff;",
16
+ errorColor: "background: #FF0000;",
17
+ infoColor: "background: #6495ed;",
18
+ warnColor: "background: #ff8c00;",
19
+ debug: false,
20
+ autoClearConsole: false,
21
+ logMaxCount: 999,
22
+ };
23
+ /**
24
+ * 通用样式配置
25
+ */
26
+ #commonStyleConfig = {
27
+ commonStyle: "color: #ffffff; padding: 3px; border-radius: 3px;line-height: 1;margin-right: 6px;",
28
+ tagStyle: "background: #6495ed;",
29
+ callerNameStyle: "background: #78909C;",
30
+ };
31
+ /**
32
+ * @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
33
+ * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
34
+ */
35
+ constructor(
36
+ __GM_info?:
37
+ | {
38
+ script: {
39
+ name: string;
40
+ };
41
+ }
42
+ | string,
43
+ console: Console = window.console
44
+ ) {
45
+ if (typeof __GM_info === "string") {
46
+ this.tag = __GM_info;
47
+ } else if (typeof __GM_info === "object" && typeof __GM_info?.script?.name === "string") {
48
+ this.tag = __GM_info.script.name;
49
+ }
50
+ this.#console = console;
51
+ }
52
+
53
+ /**
54
+ * 解析Error的堆栈获取实际调用者的函数名及函数所在的位置
55
+ * @param stack
56
+ */
57
+ private parseErrorStack(stack: string[]) {
58
+ const result = {
59
+ name: "",
60
+ position: "",
61
+ };
62
+ for (let stackString of stack) {
63
+ stackString = stackString.trim();
64
+ const stackFunctionNameMatch = stackString.match(/^at[\s]+(.+?)[\s]+/i);
65
+ const stackFunctionNamePositionMatch = stackString.match(/^at[\s]+.+[\s]+\((.+?)\)/i);
66
+ if (stackFunctionNameMatch == null) {
67
+ continue;
68
+ }
69
+ if (stackFunctionNamePositionMatch == null) {
70
+ continue;
71
+ }
72
+ /* 获取最后一个,因为第一个是包含了at */
73
+ const stackFunctionName = stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
74
+ const stackFunctionNamePosition = stackFunctionNamePositionMatch[stackFunctionNamePositionMatch.length - 1];
75
+ if (
76
+ stackFunctionName === "" ||
77
+ stackFunctionName.match(/^(Utils\.|)Log(\.|)|.<anonymous>$|^Function.each|^NodeList.forEach|^k.fn.init.each/g)
78
+ ) {
79
+ continue;
80
+ } else {
81
+ result.name = stackFunctionName;
82
+ result.position = stackFunctionNamePosition;
83
+ break;
84
+ }
85
+ }
86
+ if (result.position === "") {
87
+ const lastStackString = stack[stack.length - 1].trim();
88
+ if (lastStackString.startsWith("at chrome-extension://")) {
89
+ const lastStackMatch = lastStackString.match(/^at[\s]+(.+)/);
90
+ if (lastStackMatch) {
91
+ result.position = lastStackMatch[lastStackMatch.length - 1];
92
+ }
93
+ }
94
+ }
95
+ if (result.position === "") {
96
+ result.position = stack[stack.length - 1].trim().replace(/^at[\s]*/g, "");
97
+ }
98
+ return result;
99
+ }
100
+ /**
101
+ * 检测清理控制台
102
+ */
103
+ private checkClearConsole() {
104
+ this.#logCount++;
105
+ if (this.#details.autoClearConsole && this.#logCount > this.#details.logMaxCount) {
106
+ this.#console.clear();
107
+ this.#logCount = 0;
108
+ }
109
+ }
110
+
111
+ /**
112
+ * 输出内容
113
+ * @param msg 需要输出的内容
114
+ * @param tagColor tag颜色
115
+ */
116
+ private printContent(msg: any[], tagColor?: string) {
117
+ this.checkClearConsole();
118
+ const stackSplit = new Error()!.stack!.split("\n");
119
+ stackSplit.splice(0, 2);
120
+ const { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
121
+ const tagName = this.tag;
122
+ const that = this;
123
+
124
+ const msgColorDetails: string[] = [];
125
+ // 控制台输出的tag的html格式
126
+ let consoleHTML = `%c${tagName}`;
127
+ /** tag的html输出格式 */
128
+ if (typeof tagColor === "string" && tagColor.trim() !== "") {
129
+ msgColorDetails.push(that.#commonStyleConfig.commonStyle + tagColor);
130
+ } else {
131
+ msgColorDetails.push(that.#commonStyleConfig.commonStyle + that.#commonStyleConfig.tagStyle);
132
+ }
133
+ // 调用的函数名的html输出格式
134
+ if (callerName.trim() == "") {
135
+ // 无调用函数名
136
+ } else {
137
+ consoleHTML = `${consoleHTML}%c${callerName}`;
138
+ msgColorDetails.push(that.#commonStyleConfig.commonStyle + that.#commonStyleConfig.callerNameStyle);
139
+ }
140
+ if (Array.isArray(msg)) {
141
+ that.#console.log(`${consoleHTML}`, ...msgColorDetails, ...msg);
142
+ } else {
143
+ that.#console.log(`${consoleHTML}`, ...msgColorDetails, msg);
144
+ }
145
+ if (this.#details.debug) {
146
+ /* 如果开启调试模式,输出堆栈位置 */
147
+ this.#console.log(callerPosition);
148
+ }
149
+ }
150
+ /**
151
+ * 控制台-普通输出
152
+ * @param args 需要输出的内容
153
+ * @example
154
+ * log.info("输出信息","输出信息2","输出信息3","输出")
155
+ */
156
+ info(...args: any[]) {
157
+ if (this.#disable) return;
158
+ this.printContent(args, this.#details.infoColor);
159
+ }
160
+ /**
161
+ * 控制台-警告输出
162
+ * @param args 需要输出的内容
163
+ * @example
164
+ * log.warn("输出警告","输出警告2","输出警告3","输出警告4")
165
+ */
166
+ warn(...args: any[]) {
167
+ if (this.#disable) return;
168
+ // , "background: #FEF6D5;padding: 4px 6px 4px 0px;"
169
+ this.printContent(args, this.#details.warnColor);
170
+ }
171
+ /**
172
+ * 控制台-错误输出
173
+ * @param args 需要输出的内容
174
+ * @example
175
+ * log.error("输出错误","输出错误2","输出错误3","输出错误4")
176
+ */
177
+ error(...args: any[]) {
178
+ if (this.#disable) return;
179
+ this.printContent(args, this.#details.errorColor);
180
+ }
181
+ /**
182
+ * 控制台-成功输出
183
+ * @param args 需要输出的内容
184
+ * @example
185
+ * log.success("输出成功")
186
+ */
187
+ success(...args: any[]) {
188
+ if (this.#disable) return;
189
+ this.printContent(args, this.#details.successColor);
190
+ }
191
+ /**
192
+ * 控制台-输出表格
193
+ * @param msg 需要输出的内容
194
+ * @example
195
+ * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
196
+ */
197
+ table(msg: any[]) {
198
+ if (this.#disable) return;
199
+ this.checkClearConsole();
200
+ const stack = new Error()!.stack!.split("\n");
201
+ stack.splice(0, 1);
202
+ const errorStackParse = this.parseErrorStack(stack);
203
+ /** 堆栈函数名 */
204
+ const stackFunctionName = errorStackParse.name;
205
+ /** 堆栈位置 */
206
+ const stackFunctionNamePosition = errorStackParse.position;
207
+ const callerName = stackFunctionName;
208
+ const msgColorDetails: string[] = [
209
+ `${this.#commonStyleConfig.commonStyle + this.#details.infoColor}`,
210
+ `${this.#commonStyleConfig.commonStyle + this.#commonStyleConfig.callerNameStyle}`,
211
+ ];
212
+ this.#console.log(`%c${this.tag}%c${callerName}%c`, msgColorDetails);
213
+ this.#console.table(msg);
214
+ if (this.#details.debug) {
215
+ this.#console.log(stackFunctionNamePosition);
216
+ }
217
+ }
218
+ /**
219
+ * 配置Log对象的颜色
220
+ * @param paramDetails 配置信息
221
+ */
222
+ config(paramDetails: Partial<UtilsLogOptions>) {
223
+ this.#details = Object.assign(this.#details, paramDetails);
224
+ }
225
+ /** 禁用输出 */
226
+ disable() {
227
+ this.#disable = true;
228
+ }
229
+ /** 恢复输出 */
230
+ recovery() {
231
+ this.#disable = false;
232
+ }
233
+ }