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