@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/index.esm.js
CHANGED
|
@@ -3114,6 +3114,9 @@ class Log {
|
|
|
3114
3114
|
autoClearConsole: false,
|
|
3115
3115
|
logMaxCount: 999,
|
|
3116
3116
|
};
|
|
3117
|
+
/**
|
|
3118
|
+
* 颜色配置
|
|
3119
|
+
*/
|
|
3117
3120
|
#msgColorDetails = [
|
|
3118
3121
|
"font-weight: bold; color: cornflowerblue",
|
|
3119
3122
|
"font-weight: bold; color: cornflowerblue",
|
|
@@ -3121,16 +3124,16 @@ class Log {
|
|
|
3121
3124
|
"font-weight: bold; color: cornflowerblue",
|
|
3122
3125
|
];
|
|
3123
3126
|
/**
|
|
3124
|
-
* @param
|
|
3127
|
+
* @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
|
|
3125
3128
|
* @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
|
|
3126
3129
|
*/
|
|
3127
|
-
constructor(
|
|
3128
|
-
if (typeof
|
|
3129
|
-
this.tag =
|
|
3130
|
+
constructor(__GM_info, console = window.console) {
|
|
3131
|
+
if (typeof __GM_info === "string") {
|
|
3132
|
+
this.tag = __GM_info;
|
|
3130
3133
|
}
|
|
3131
|
-
else if (typeof
|
|
3132
|
-
typeof
|
|
3133
|
-
this.tag =
|
|
3134
|
+
else if (typeof __GM_info === "object" &&
|
|
3135
|
+
typeof __GM_info?.script?.name === "string") {
|
|
3136
|
+
this.tag = __GM_info.script.name;
|
|
3134
3137
|
}
|
|
3135
3138
|
this.#console = console;
|
|
3136
3139
|
}
|
|
@@ -3205,24 +3208,33 @@ class Log {
|
|
|
3205
3208
|
let { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
|
|
3206
3209
|
let tagName = this.tag;
|
|
3207
3210
|
let that = this;
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
+
/** tag的html输出格式 */
|
|
3212
|
+
let tagNameHTML = `%c[${tagName}%c`;
|
|
3213
|
+
/** 调用的函数名的html输出格式 */
|
|
3214
|
+
let callerNameHTML = `%c${callerName}%c]%c`;
|
|
3215
|
+
callerName.trim() !== "" && (callerNameHTML = "-" + callerNameHTML);
|
|
3216
|
+
/**
|
|
3217
|
+
* 输出消息到控制台
|
|
3218
|
+
* @param message
|
|
3219
|
+
*/
|
|
3220
|
+
function consoleMsg(message) {
|
|
3221
|
+
if (typeof message === "string") {
|
|
3222
|
+
that.#console.log(`${tagNameHTML}${callerNameHTML} %s`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
|
|
3211
3223
|
}
|
|
3212
|
-
else if (typeof
|
|
3213
|
-
that.#console.log(
|
|
3224
|
+
else if (typeof message === "number") {
|
|
3225
|
+
that.#console.log(`${tagNameHTML}${callerNameHTML} %d`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
|
|
3214
3226
|
}
|
|
3215
|
-
else if (typeof
|
|
3216
|
-
that.#console.log(
|
|
3227
|
+
else if (typeof message === "object") {
|
|
3228
|
+
that.#console.log(`${tagNameHTML}${callerNameHTML} %o`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
|
|
3217
3229
|
}
|
|
3218
3230
|
else {
|
|
3219
|
-
that.#console.log(
|
|
3231
|
+
that.#console.log(message);
|
|
3220
3232
|
}
|
|
3221
3233
|
}
|
|
3222
3234
|
if (Array.isArray(msg)) {
|
|
3223
|
-
msg.
|
|
3224
|
-
consoleMsg(
|
|
3225
|
-
}
|
|
3235
|
+
for (let index = 0; index < msg.length; index++) {
|
|
3236
|
+
consoleMsg(msg[index]);
|
|
3237
|
+
}
|
|
3226
3238
|
}
|
|
3227
3239
|
else {
|
|
3228
3240
|
consoleMsg(msg);
|
|
@@ -3234,67 +3246,67 @@ class Log {
|
|
|
3234
3246
|
}
|
|
3235
3247
|
/**
|
|
3236
3248
|
* 控制台-普通输出
|
|
3237
|
-
* @param
|
|
3238
|
-
* @
|
|
3239
|
-
*
|
|
3249
|
+
* @param args 需要输出的内容
|
|
3250
|
+
* @example
|
|
3251
|
+
* log.info("输出信息","输出信息2","输出信息3","输出")
|
|
3240
3252
|
*/
|
|
3241
|
-
info(
|
|
3253
|
+
info(...args) {
|
|
3242
3254
|
if (this.#disable)
|
|
3243
3255
|
return;
|
|
3244
|
-
this.printContent
|
|
3256
|
+
this.printContent(args, this.#details.infoColor);
|
|
3245
3257
|
}
|
|
3246
3258
|
/**
|
|
3247
3259
|
* 控制台-警告输出
|
|
3248
|
-
* @param
|
|
3249
|
-
* @
|
|
3250
|
-
*
|
|
3260
|
+
* @param args 需要输出的内容
|
|
3261
|
+
* @example
|
|
3262
|
+
* log.warn("输出警告","输出警告2","输出警告3","输出警告4")
|
|
3251
3263
|
*/
|
|
3252
|
-
warn(
|
|
3264
|
+
warn(...args) {
|
|
3253
3265
|
if (this.#disable)
|
|
3254
3266
|
return;
|
|
3255
|
-
this.printContent
|
|
3267
|
+
this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
|
|
3256
3268
|
}
|
|
3257
3269
|
/**
|
|
3258
3270
|
* 控制台-错误输出
|
|
3259
|
-
* @param
|
|
3260
|
-
* @
|
|
3261
|
-
*
|
|
3271
|
+
* @param args 需要输出的内容
|
|
3272
|
+
* @example
|
|
3273
|
+
* log.error("输出错误","输出错误2","输出错误3","输出错误4")
|
|
3262
3274
|
*/
|
|
3263
|
-
error(
|
|
3275
|
+
error(...args) {
|
|
3264
3276
|
if (this.#disable)
|
|
3265
3277
|
return;
|
|
3266
|
-
this.printContent
|
|
3278
|
+
this.printContent(args, this.#details.errorColor);
|
|
3267
3279
|
}
|
|
3268
3280
|
/**
|
|
3269
3281
|
* 控制台-成功输出
|
|
3270
|
-
* @param
|
|
3271
|
-
* @
|
|
3272
|
-
*
|
|
3282
|
+
* @param args 需要输出的内容
|
|
3283
|
+
* @example
|
|
3284
|
+
* log.success("输出成功")
|
|
3273
3285
|
*/
|
|
3274
|
-
success(
|
|
3286
|
+
success(...args) {
|
|
3275
3287
|
if (this.#disable)
|
|
3276
3288
|
return;
|
|
3277
|
-
this.printContent
|
|
3289
|
+
this.printContent(args, this.#details.successColor);
|
|
3278
3290
|
}
|
|
3279
3291
|
/**
|
|
3280
3292
|
* 控制台-输出表格
|
|
3281
|
-
* @param msg
|
|
3282
|
-
* @param color 输出的颜色
|
|
3283
|
-
* @param otherStyle 其它CSS
|
|
3293
|
+
* @param msg 需要输出的内容
|
|
3284
3294
|
* @example
|
|
3285
3295
|
* log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
|
|
3286
3296
|
*/
|
|
3287
|
-
table(msg
|
|
3297
|
+
table(msg) {
|
|
3288
3298
|
if (this.#disable)
|
|
3289
3299
|
return;
|
|
3290
3300
|
this.checkClearConsole();
|
|
3291
3301
|
let stack = new Error().stack.split("\n");
|
|
3292
3302
|
stack.splice(0, 1);
|
|
3293
3303
|
let errorStackParse = this.parseErrorStack(stack);
|
|
3304
|
+
/** 堆栈函数名 */
|
|
3294
3305
|
let stackFunctionName = errorStackParse.name;
|
|
3306
|
+
/** 堆栈位置 */
|
|
3295
3307
|
let stackFunctionNamePosition = errorStackParse.position;
|
|
3296
3308
|
let callerName = stackFunctionName;
|
|
3297
|
-
this.#console.log(`%c[${this.tag}%c-%c${callerName}%c]%c`, ...this.#msgColorDetails, `color: ${
|
|
3309
|
+
this.#console.log(`%c[${this.tag}%c-%c${callerName}%c]%c`, ...this.#msgColorDetails, `color: ${this.#details.infoColor};`);
|
|
3298
3310
|
this.#console.table(msg);
|
|
3299
3311
|
if (this.#details.debug) {
|
|
3300
3312
|
this.#console.log(stackFunctionNamePosition);
|