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