@whitesev/utils 2.3.3 → 2.3.4
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 +55 -43
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +55 -43
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +55 -43
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +55 -43
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +55 -43
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +55 -43
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Log.d.ts +28 -30
- package/dist/types/src/VueObject.d.ts +4 -4
- package/package.json +1 -1
- package/src/Log.ts +72 -60
- package/src/VueObject.ts +4 -4
package/dist/types/src/Log.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/** Utils.Log的初始化配置 */
|
|
2
2
|
declare interface UtilsLogOptions {
|
|
3
|
-
/** 是否输出Tag,false
|
|
3
|
+
/** 是否输出Tag,false的话其它的颜色也不输出 @default true */
|
|
4
4
|
tag: boolean;
|
|
5
|
-
/** log.success
|
|
5
|
+
/** log.success的颜色 @default "#0000FF" */
|
|
6
6
|
successColor: string;
|
|
7
|
-
/** log.warn
|
|
7
|
+
/** log.warn的颜色 @default "0" */
|
|
8
8
|
warnColor: string;
|
|
9
|
-
/** log.error
|
|
9
|
+
/** log.error的颜色 @default "#FF0000" */
|
|
10
10
|
errorColor: string;
|
|
11
|
-
/** log.info
|
|
11
|
+
/** log.info的颜色 @default "0" */
|
|
12
12
|
infoColor: string;
|
|
13
|
-
/** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false
|
|
13
|
+
/** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置 @default false */
|
|
14
14
|
debug: boolean;
|
|
15
|
-
/** 当console输出超过logMaxCount
|
|
15
|
+
/** 当console输出超过logMaxCount数量自动清理控制台 @default false */
|
|
16
16
|
autoClearConsole: boolean;
|
|
17
|
-
/** console输出的最高数量,autoClearConsole
|
|
17
|
+
/** console输出的最高数量,autoClearConsole开启则生效 @default 999 */
|
|
18
18
|
logMaxCount: number;
|
|
19
19
|
}
|
|
20
20
|
declare class Log {
|
|
@@ -22,10 +22,10 @@ declare class Log {
|
|
|
22
22
|
/** 前面的TAG标志 */
|
|
23
23
|
tag: string;
|
|
24
24
|
/**
|
|
25
|
-
* @param
|
|
25
|
+
* @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
|
|
26
26
|
* @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
|
|
27
27
|
*/
|
|
28
|
-
constructor(
|
|
28
|
+
constructor(__GM_info?: {
|
|
29
29
|
script: {
|
|
30
30
|
name: string;
|
|
31
31
|
};
|
|
@@ -48,41 +48,39 @@ declare class Log {
|
|
|
48
48
|
private printContent;
|
|
49
49
|
/**
|
|
50
50
|
* 控制台-普通输出
|
|
51
|
-
* @param
|
|
52
|
-
* @
|
|
53
|
-
*
|
|
51
|
+
* @param args 需要输出的内容
|
|
52
|
+
* @example
|
|
53
|
+
* log.info("输出信息","输出信息2","输出信息3","输出")
|
|
54
54
|
*/
|
|
55
|
-
info(
|
|
55
|
+
info(...args: any[]): void;
|
|
56
56
|
/**
|
|
57
57
|
* 控制台-警告输出
|
|
58
|
-
* @param
|
|
59
|
-
* @
|
|
60
|
-
*
|
|
58
|
+
* @param args 需要输出的内容
|
|
59
|
+
* @example
|
|
60
|
+
* log.warn("输出警告","输出警告2","输出警告3","输出警告4")
|
|
61
61
|
*/
|
|
62
|
-
warn(
|
|
62
|
+
warn(...args: any[]): void;
|
|
63
63
|
/**
|
|
64
64
|
* 控制台-错误输出
|
|
65
|
-
* @param
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
65
|
+
* @param args 需要输出的内容
|
|
66
|
+
* @example
|
|
67
|
+
* log.error("输出错误","输出错误2","输出错误3","输出错误4")
|
|
68
68
|
*/
|
|
69
|
-
error(
|
|
69
|
+
error(...args: any[]): void;
|
|
70
70
|
/**
|
|
71
71
|
* 控制台-成功输出
|
|
72
|
-
* @param
|
|
73
|
-
* @
|
|
74
|
-
*
|
|
72
|
+
* @param args 需要输出的内容
|
|
73
|
+
* @example
|
|
74
|
+
* log.success("输出成功")
|
|
75
75
|
*/
|
|
76
|
-
success(
|
|
76
|
+
success(...args: any[]): void;
|
|
77
77
|
/**
|
|
78
78
|
* 控制台-输出表格
|
|
79
|
-
* @param msg
|
|
80
|
-
* @param color 输出的颜色
|
|
81
|
-
* @param otherStyle 其它CSS
|
|
79
|
+
* @param msg 需要输出的内容
|
|
82
80
|
* @example
|
|
83
81
|
* log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
|
|
84
82
|
*/
|
|
85
|
-
table(msg: any[]
|
|
83
|
+
table(msg: any[]): void;
|
|
86
84
|
/**
|
|
87
85
|
* 配置Log对象的颜色
|
|
88
86
|
* @param paramDetails 配置信息
|
|
@@ -23,7 +23,7 @@ export declare interface Vue2Object {
|
|
|
23
23
|
$data: any;
|
|
24
24
|
$isServer: boolean;
|
|
25
25
|
$props: any;
|
|
26
|
-
$route:
|
|
26
|
+
$route: {
|
|
27
27
|
fullPath: string;
|
|
28
28
|
hash: string;
|
|
29
29
|
matched: any[];
|
|
@@ -33,13 +33,13 @@ export declare interface Vue2Object {
|
|
|
33
33
|
path: string;
|
|
34
34
|
query: any;
|
|
35
35
|
};
|
|
36
|
-
$router:
|
|
36
|
+
$router: {
|
|
37
37
|
afterHooks: Function[];
|
|
38
38
|
app: Vue2Object;
|
|
39
39
|
apps: Vue2Object[];
|
|
40
40
|
beforeHooks: Function[];
|
|
41
41
|
fallback: boolean;
|
|
42
|
-
history:
|
|
42
|
+
history: {
|
|
43
43
|
base: string;
|
|
44
44
|
current: any;
|
|
45
45
|
listeners: any[];
|
|
@@ -66,7 +66,7 @@ export declare interface Vue2Object {
|
|
|
66
66
|
*/
|
|
67
67
|
replace: (to: string, data?: any) => void;
|
|
68
68
|
};
|
|
69
|
-
matcher:
|
|
69
|
+
matcher: {
|
|
70
70
|
addRoute: (...args: any[]) => any;
|
|
71
71
|
addRoutes: (...args: any[]) => any;
|
|
72
72
|
getRoutes: () => any;
|
package/package.json
CHANGED
package/src/Log.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
1
|
/** Utils.Log的初始化配置 */
|
|
3
2
|
declare interface UtilsLogOptions {
|
|
4
|
-
/** 是否输出Tag,false
|
|
3
|
+
/** 是否输出Tag,false的话其它的颜色也不输出 @default true */
|
|
5
4
|
tag: boolean;
|
|
6
|
-
/** log.success
|
|
5
|
+
/** log.success的颜色 @default "#0000FF" */
|
|
7
6
|
successColor: string;
|
|
8
|
-
/** log.warn
|
|
7
|
+
/** log.warn的颜色 @default "0" */
|
|
9
8
|
warnColor: string;
|
|
10
|
-
/** log.error
|
|
9
|
+
/** log.error的颜色 @default "#FF0000" */
|
|
11
10
|
errorColor: string;
|
|
12
|
-
/** log.info
|
|
11
|
+
/** log.info的颜色 @default "0" */
|
|
13
12
|
infoColor: string;
|
|
14
|
-
/** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false
|
|
13
|
+
/** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置 @default false */
|
|
15
14
|
debug: boolean;
|
|
16
|
-
/** 当console输出超过logMaxCount
|
|
15
|
+
/** 当console输出超过logMaxCount数量自动清理控制台 @default false */
|
|
17
16
|
autoClearConsole: boolean;
|
|
18
|
-
/** console输出的最高数量,autoClearConsole
|
|
17
|
+
/** console输出的最高数量,autoClearConsole开启则生效 @default 999 */
|
|
19
18
|
logMaxCount: number;
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -39,6 +38,9 @@ class Log {
|
|
|
39
38
|
autoClearConsole: false,
|
|
40
39
|
logMaxCount: 999,
|
|
41
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* 颜色配置
|
|
43
|
+
*/
|
|
42
44
|
#msgColorDetails = [
|
|
43
45
|
"font-weight: bold; color: cornflowerblue",
|
|
44
46
|
"font-weight: bold; color: cornflowerblue",
|
|
@@ -46,11 +48,11 @@ class Log {
|
|
|
46
48
|
"font-weight: bold; color: cornflowerblue",
|
|
47
49
|
];
|
|
48
50
|
/**
|
|
49
|
-
* @param
|
|
51
|
+
* @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
|
|
50
52
|
* @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
|
|
51
53
|
*/
|
|
52
54
|
constructor(
|
|
53
|
-
|
|
55
|
+
__GM_info?:
|
|
54
56
|
| {
|
|
55
57
|
script: {
|
|
56
58
|
name: string;
|
|
@@ -59,13 +61,13 @@ class Log {
|
|
|
59
61
|
| string,
|
|
60
62
|
console: Console = window.console
|
|
61
63
|
) {
|
|
62
|
-
if (typeof
|
|
63
|
-
this.tag =
|
|
64
|
+
if (typeof __GM_info === "string") {
|
|
65
|
+
this.tag = __GM_info;
|
|
64
66
|
} else if (
|
|
65
|
-
typeof
|
|
66
|
-
typeof
|
|
67
|
+
typeof __GM_info === "object" &&
|
|
68
|
+
typeof __GM_info?.script?.name === "string"
|
|
67
69
|
) {
|
|
68
|
-
this.tag =
|
|
70
|
+
this.tag = __GM_info.script.name;
|
|
69
71
|
}
|
|
70
72
|
this.#console = console;
|
|
71
73
|
}
|
|
@@ -145,7 +147,7 @@ class Log {
|
|
|
145
147
|
* @param color 颜色
|
|
146
148
|
* @param otherStyle 其它CSS
|
|
147
149
|
*/
|
|
148
|
-
private printContent(msg: any, color: string, otherStyle?: string) {
|
|
150
|
+
private printContent(msg: any[], color: string, otherStyle?: string) {
|
|
149
151
|
this.checkClearConsole();
|
|
150
152
|
otherStyle = otherStyle || "";
|
|
151
153
|
let stackSplit = new Error()!.stack!.split("\n");
|
|
@@ -154,36 +156,46 @@ class Log {
|
|
|
154
156
|
this.parseErrorStack(stackSplit);
|
|
155
157
|
let tagName = this.tag;
|
|
156
158
|
let that = this;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
|
|
160
|
+
/** tag的html输出格式 */
|
|
161
|
+
let tagNameHTML = `%c[${tagName}%c`;
|
|
162
|
+
/** 调用的函数名的html输出格式 */
|
|
163
|
+
let callerNameHTML = `%c${callerName}%c]%c`;
|
|
164
|
+
callerName.trim() !== "" && (callerNameHTML = "-" + callerNameHTML);
|
|
165
|
+
/**
|
|
166
|
+
* 输出消息到控制台
|
|
167
|
+
* @param message
|
|
168
|
+
*/
|
|
169
|
+
function consoleMsg(message: any) {
|
|
170
|
+
if (typeof message === "string") {
|
|
159
171
|
that.#console.log(
|
|
160
|
-
|
|
172
|
+
`${tagNameHTML}${callerNameHTML} %s`,
|
|
161
173
|
...that.#msgColorDetails,
|
|
162
174
|
`color: ${color};${otherStyle}`,
|
|
163
|
-
|
|
175
|
+
message
|
|
164
176
|
);
|
|
165
|
-
} else if (typeof
|
|
177
|
+
} else if (typeof message === "number") {
|
|
166
178
|
that.#console.log(
|
|
167
|
-
|
|
179
|
+
`${tagNameHTML}${callerNameHTML} %d`,
|
|
168
180
|
...that.#msgColorDetails,
|
|
169
181
|
`color: ${color};${otherStyle}`,
|
|
170
|
-
|
|
182
|
+
message
|
|
171
183
|
);
|
|
172
|
-
} else if (typeof
|
|
184
|
+
} else if (typeof message === "object") {
|
|
173
185
|
that.#console.log(
|
|
174
|
-
|
|
186
|
+
`${tagNameHTML}${callerNameHTML} %o`,
|
|
175
187
|
...that.#msgColorDetails,
|
|
176
188
|
`color: ${color};${otherStyle}`,
|
|
177
|
-
|
|
189
|
+
message
|
|
178
190
|
);
|
|
179
191
|
} else {
|
|
180
|
-
that.#console.log(
|
|
192
|
+
that.#console.log(message);
|
|
181
193
|
}
|
|
182
194
|
}
|
|
183
195
|
if (Array.isArray(msg)) {
|
|
184
|
-
msg.
|
|
185
|
-
consoleMsg(
|
|
186
|
-
}
|
|
196
|
+
for (let index = 0; index < msg.length; index++) {
|
|
197
|
+
consoleMsg(msg[index]);
|
|
198
|
+
}
|
|
187
199
|
} else {
|
|
188
200
|
consoleMsg(msg);
|
|
189
201
|
}
|
|
@@ -194,69 +206,69 @@ class Log {
|
|
|
194
206
|
}
|
|
195
207
|
/**
|
|
196
208
|
* 控制台-普通输出
|
|
197
|
-
* @param
|
|
198
|
-
* @
|
|
199
|
-
*
|
|
209
|
+
* @param args 需要输出的内容
|
|
210
|
+
* @example
|
|
211
|
+
* log.info("输出信息","输出信息2","输出信息3","输出")
|
|
200
212
|
*/
|
|
201
|
-
info(
|
|
213
|
+
info(...args: any[]) {
|
|
202
214
|
if (this.#disable) return;
|
|
203
|
-
this.printContent
|
|
215
|
+
this.printContent(args, this.#details.infoColor);
|
|
204
216
|
}
|
|
205
217
|
/**
|
|
206
218
|
* 控制台-警告输出
|
|
207
|
-
* @param
|
|
208
|
-
* @
|
|
209
|
-
*
|
|
219
|
+
* @param args 需要输出的内容
|
|
220
|
+
* @example
|
|
221
|
+
* log.warn("输出警告","输出警告2","输出警告3","输出警告4")
|
|
210
222
|
*/
|
|
211
|
-
warn(
|
|
212
|
-
msg: any,
|
|
213
|
-
color = this.#details.warnColor,
|
|
214
|
-
otherStyle = "background: #FEF6D5;padding: 4px 6px 4px 0px;"
|
|
215
|
-
) {
|
|
223
|
+
warn(...args: any[]) {
|
|
216
224
|
if (this.#disable) return;
|
|
217
|
-
this.printContent
|
|
225
|
+
this.printContent(
|
|
226
|
+
args,
|
|
227
|
+
this.#details.warnColor,
|
|
228
|
+
"background: #FEF6D5;padding: 4px 6px 4px 0px;"
|
|
229
|
+
);
|
|
218
230
|
}
|
|
219
231
|
/**
|
|
220
232
|
* 控制台-错误输出
|
|
221
|
-
* @param
|
|
222
|
-
* @
|
|
223
|
-
*
|
|
233
|
+
* @param args 需要输出的内容
|
|
234
|
+
* @example
|
|
235
|
+
* log.error("输出错误","输出错误2","输出错误3","输出错误4")
|
|
224
236
|
*/
|
|
225
|
-
error(
|
|
237
|
+
error(...args: any[]) {
|
|
226
238
|
if (this.#disable) return;
|
|
227
|
-
this.printContent
|
|
239
|
+
this.printContent(args, this.#details.errorColor);
|
|
228
240
|
}
|
|
229
241
|
/**
|
|
230
242
|
* 控制台-成功输出
|
|
231
|
-
* @param
|
|
232
|
-
* @
|
|
233
|
-
*
|
|
243
|
+
* @param args 需要输出的内容
|
|
244
|
+
* @example
|
|
245
|
+
* log.success("输出成功")
|
|
234
246
|
*/
|
|
235
|
-
success(
|
|
247
|
+
success(...args: any[]) {
|
|
236
248
|
if (this.#disable) return;
|
|
237
|
-
this.printContent
|
|
249
|
+
this.printContent(args, this.#details.successColor);
|
|
238
250
|
}
|
|
239
251
|
/**
|
|
240
252
|
* 控制台-输出表格
|
|
241
|
-
* @param msg
|
|
242
|
-
* @param color 输出的颜色
|
|
243
|
-
* @param otherStyle 其它CSS
|
|
253
|
+
* @param msg 需要输出的内容
|
|
244
254
|
* @example
|
|
245
255
|
* log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
|
|
246
256
|
*/
|
|
247
|
-
table(msg: any[]
|
|
257
|
+
table(msg: any[]) {
|
|
248
258
|
if (this.#disable) return;
|
|
249
259
|
this.checkClearConsole();
|
|
250
260
|
let stack = new Error()!.stack!.split("\n");
|
|
251
261
|
stack.splice(0, 1);
|
|
252
262
|
let errorStackParse = this.parseErrorStack(stack);
|
|
263
|
+
/** 堆栈函数名 */
|
|
253
264
|
let stackFunctionName = errorStackParse.name;
|
|
265
|
+
/** 堆栈位置 */
|
|
254
266
|
let stackFunctionNamePosition = errorStackParse.position;
|
|
255
267
|
let callerName = stackFunctionName;
|
|
256
268
|
this.#console.log(
|
|
257
269
|
`%c[${this.tag}%c-%c${callerName}%c]%c`,
|
|
258
270
|
...this.#msgColorDetails,
|
|
259
|
-
`color: ${
|
|
271
|
+
`color: ${this.#details.infoColor};`
|
|
260
272
|
);
|
|
261
273
|
this.#console.table(msg);
|
|
262
274
|
if (this.#details.debug) {
|
package/src/VueObject.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare interface Vue2Object {
|
|
|
25
25
|
$data: any;
|
|
26
26
|
$isServer: boolean;
|
|
27
27
|
$props: any;
|
|
28
|
-
$route:
|
|
28
|
+
$route: {
|
|
29
29
|
fullPath: string;
|
|
30
30
|
hash: string;
|
|
31
31
|
matched: any[];
|
|
@@ -35,13 +35,13 @@ export declare interface Vue2Object {
|
|
|
35
35
|
path: string;
|
|
36
36
|
query: any;
|
|
37
37
|
};
|
|
38
|
-
$router:
|
|
38
|
+
$router: {
|
|
39
39
|
afterHooks: Function[];
|
|
40
40
|
app: Vue2Object;
|
|
41
41
|
apps: Vue2Object[];
|
|
42
42
|
beforeHooks: Function[];
|
|
43
43
|
fallback: boolean;
|
|
44
|
-
history:
|
|
44
|
+
history: {
|
|
45
45
|
base: string;
|
|
46
46
|
current: any;
|
|
47
47
|
listeners: any[];
|
|
@@ -68,7 +68,7 @@ export declare interface Vue2Object {
|
|
|
68
68
|
*/
|
|
69
69
|
replace: (to: string, data?: any) => void;
|
|
70
70
|
};
|
|
71
|
-
matcher:
|
|
71
|
+
matcher: {
|
|
72
72
|
addRoute: (...args: any[]) => any;
|
|
73
73
|
addRoutes: (...args: any[]) => any;
|
|
74
74
|
getRoutes: () => any;
|