@whitesev/utils 2.3.3 → 2.3.5

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.
@@ -1,20 +1,20 @@
1
1
  /** Utils.Log的初始化配置 */
2
2
  declare interface UtilsLogOptions {
3
- /** 是否输出Tag,false的话其它的颜色也不输出,默认为true */
3
+ /** 是否输出Tag,false的话其它的颜色也不输出 @default true */
4
4
  tag: boolean;
5
- /** log.success的颜色,默认#0000FF */
5
+ /** log.success的颜色 @default "#0000FF" */
6
6
  successColor: string;
7
- /** log.warn的颜色,默认0 */
7
+ /** log.warn的颜色 @default "0" */
8
8
  warnColor: string;
9
- /** log.error的颜色,默认#FF0000 */
9
+ /** log.error的颜色 @default "#FF0000" */
10
10
  errorColor: string;
11
- /** log.info的颜色,默认0 */
11
+ /** log.info的颜色 @default "0" */
12
12
  infoColor: string;
13
- /** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置,默认false */
13
+ /** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置 @default false */
14
14
  debug: boolean;
15
- /** 当console输出超过logMaxCount数量自动清理控制台,默认false */
15
+ /** 当console输出超过logMaxCount数量自动清理控制台 @default false */
16
16
  autoClearConsole: boolean;
17
- /** console输出的最高数量,autoClearConsole开启则生效,默认999 */
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 _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
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(_GM_info_?: {
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 msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
52
- * @param color 输出的颜色
53
- * @param otherStyle 其它CSS
51
+ * @param args 需要输出的内容
52
+ * @example
53
+ * log.info("输出信息","输出信息2","输出信息3","输出")
54
54
  */
55
- info(msg: any, color?: string, otherStyle?: string): void;
55
+ info(...args: any[]): void;
56
56
  /**
57
57
  * 控制台-警告输出
58
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
59
- * @param color 输出的颜色
60
- * @param otherStyle 其它CSS
58
+ * @param args 需要输出的内容
59
+ * @example
60
+ * log.warn("输出警告","输出警告2","输出警告3","输出警告4")
61
61
  */
62
- warn(msg: any, color?: string, otherStyle?: string): void;
62
+ warn(...args: any[]): void;
63
63
  /**
64
64
  * 控制台-错误输出
65
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
66
- * @param color 输出的颜色
67
- * @param otherStyle 其它CSS
65
+ * @param args 需要输出的内容
66
+ * @example
67
+ * log.error("输出错误","输出错误2","输出错误3","输出错误4")
68
68
  */
69
- error(msg: any, color?: string, otherStyle?: string): void;
69
+ error(...args: any[]): void;
70
70
  /**
71
71
  * 控制台-成功输出
72
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
73
- * @param color 输出的颜色
74
- * @param otherStyle 其它CSS
72
+ * @param args 需要输出的内容
73
+ * @example
74
+ * log.success("输出成功")
75
75
  */
76
- success(msg: any, color?: string, otherStyle?: string): void;
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[], color?: string, otherStyle?: string): void;
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: any & {
26
+ $route: {
27
27
  fullPath: string;
28
28
  hash: string;
29
29
  matched: any[];
@@ -32,49 +32,55 @@ export declare interface Vue2Object {
32
32
  params: any;
33
33
  path: string;
34
34
  query: any;
35
+ [key: string]: any;
35
36
  };
36
- $router: any & {
37
+ $router: {
37
38
  afterHooks: Function[];
38
39
  app: Vue2Object;
39
40
  apps: Vue2Object[];
40
41
  beforeHooks: Function[];
41
42
  fallback: boolean;
42
- history: any & {
43
+ history: {
43
44
  base: string;
44
- current: any;
45
+ current: Vue2Object["$route"];
45
46
  listeners: any[];
46
47
  router: Vue2Object["$router"];
47
48
  /**
48
49
  *
49
50
  * @param delta 访问的距离。如果 delta < 0 则后退相应数量的记录,如果 > 0 则前进。
50
51
  * @param triggerListeners 是否应该触发连接到该历史的监听器
51
- * @returns
52
52
  */
53
53
  go: (delta: number, triggerListeners?: boolean) => void;
54
54
  /**
55
55
  *
56
56
  * @param to 要设置的地址
57
57
  * @param data 可选的 HistoryState 以关联该导航记录
58
- * @returns
59
58
  */
60
59
  push: (to: string, data?: any) => void;
61
60
  /**
62
61
  *
63
62
  * @param to 要设置的地址
64
63
  * @param data 可选的 HistoryState 以关联该导航记录
65
- * @returns
66
64
  */
67
65
  replace: (to: string, data?: any) => void;
66
+ [key: string]: any;
68
67
  };
69
- matcher: any & {
68
+ matcher: {
70
69
  addRoute: (...args: any[]) => any;
71
70
  addRoutes: (...args: any[]) => any;
72
71
  getRoutes: () => any;
73
72
  match: (...args: any[]) => any;
73
+ [key: string]: any;
74
74
  };
75
75
  mode: string;
76
+ options: {
77
+ mode: string;
78
+ routes: any[];
79
+ scrollBehavior: (...args: any[]) => any;
80
+ [key: string]: any;
81
+ };
76
82
  resolveHooks: ((...args: any[]) => any)[];
77
- currentRoute: any;
83
+ currentRoute: Vue2Object["$route"];
78
84
  beforeEach: (callback: ((
79
85
  /** 即将要进入的目标 路由对象 */
80
86
  to: Vue2Object["$route"],
@@ -97,6 +103,13 @@ export declare interface Vue2Object {
97
103
  from: Vue2Object["$route"]) => void)
98
104
  /** 移除上一个添加的监听 */
99
105
  | (() => void)) => void;
106
+ push: (...args: any[]) => void;
107
+ back: () => void;
108
+ go: (...args: any[]) => void;
109
+ replace: (...args: any[]) => void;
110
+ addRoute: (...args: any[]) => void;
111
+ addRoutes: (...args: any[]) => void;
112
+ [key: string]: any;
100
113
  };
101
114
  $ssrContext: any;
102
115
  $watch: (key: string | string[] | (() => any), handler: (this: any, newVal: any, oldVal: any) => void, options?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Log.ts CHANGED
@@ -1,21 +1,20 @@
1
-
2
1
  /** Utils.Log的初始化配置 */
3
2
  declare interface UtilsLogOptions {
4
- /** 是否输出Tag,false的话其它的颜色也不输出,默认为true */
3
+ /** 是否输出Tag,false的话其它的颜色也不输出 @default true */
5
4
  tag: boolean;
6
- /** log.success的颜色,默认#0000FF */
5
+ /** log.success的颜色 @default "#0000FF" */
7
6
  successColor: string;
8
- /** log.warn的颜色,默认0 */
7
+ /** log.warn的颜色 @default "0" */
9
8
  warnColor: string;
10
- /** log.error的颜色,默认#FF0000 */
9
+ /** log.error的颜色 @default "#FF0000" */
11
10
  errorColor: string;
12
- /** log.info的颜色,默认0 */
11
+ /** log.info的颜色 @default "0" */
13
12
  infoColor: string;
14
- /** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置,默认false */
13
+ /** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置 @default false */
15
14
  debug: boolean;
16
- /** 当console输出超过logMaxCount数量自动清理控制台,默认false */
15
+ /** 当console输出超过logMaxCount数量自动清理控制台 @default false */
17
16
  autoClearConsole: boolean;
18
- /** console输出的最高数量,autoClearConsole开启则生效,默认999 */
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 _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
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
- _GM_info_?:
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 _GM_info_ === "string") {
63
- this.tag = _GM_info_;
64
+ if (typeof __GM_info === "string") {
65
+ this.tag = __GM_info;
64
66
  } else if (
65
- typeof _GM_info_ === "object" &&
66
- typeof _GM_info_?.script?.name === "string"
67
+ typeof __GM_info === "object" &&
68
+ typeof __GM_info?.script?.name === "string"
67
69
  ) {
68
- this.tag = _GM_info_.script.name;
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
- function consoleMsg(_msg_: any) {
158
- if (typeof _msg_ === "string") {
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
- `%c[${tagName}%c-%c${callerName}%c]%c %s`,
172
+ `${tagNameHTML}${callerNameHTML} %s`,
161
173
  ...that.#msgColorDetails,
162
174
  `color: ${color};${otherStyle}`,
163
- _msg_
175
+ message
164
176
  );
165
- } else if (typeof _msg_ === "number") {
177
+ } else if (typeof message === "number") {
166
178
  that.#console.log(
167
- `%c[${tagName}%c-%c${callerName}%c]%c %d`,
179
+ `${tagNameHTML}${callerNameHTML} %d`,
168
180
  ...that.#msgColorDetails,
169
181
  `color: ${color};${otherStyle}`,
170
- _msg_
182
+ message
171
183
  );
172
- } else if (typeof _msg_ === "object") {
184
+ } else if (typeof message === "object") {
173
185
  that.#console.log(
174
- `%c[${tagName}%c-%c${callerName}%c]%c %o`,
186
+ `${tagNameHTML}${callerNameHTML} %o`,
175
187
  ...that.#msgColorDetails,
176
188
  `color: ${color};${otherStyle}`,
177
- _msg_
189
+ message
178
190
  );
179
191
  } else {
180
- that.#console.log(_msg_);
192
+ that.#console.log(message);
181
193
  }
182
194
  }
183
195
  if (Array.isArray(msg)) {
184
- msg.forEach((item) => {
185
- consoleMsg(item);
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 msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
198
- * @param color 输出的颜色
199
- * @param otherStyle 其它CSS
209
+ * @param args 需要输出的内容
210
+ * @example
211
+ * log.info("输出信息","输出信息2","输出信息3","输出")
200
212
  */
201
- info(msg: any, color: string = this.#details.infoColor, otherStyle?: string) {
213
+ info(...args: any[]) {
202
214
  if (this.#disable) return;
203
- this.printContent.call(this, msg, color, otherStyle);
215
+ this.printContent(args, this.#details.infoColor);
204
216
  }
205
217
  /**
206
218
  * 控制台-警告输出
207
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
208
- * @param color 输出的颜色
209
- * @param otherStyle 其它CSS
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.call(this, msg, color, otherStyle);
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 msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
222
- * @param color 输出的颜色
223
- * @param otherStyle 其它CSS
233
+ * @param args 需要输出的内容
234
+ * @example
235
+ * log.error("输出错误","输出错误2","输出错误3","输出错误4")
224
236
  */
225
- error(msg: any, color = this.#details.errorColor, otherStyle?: string) {
237
+ error(...args: any[]) {
226
238
  if (this.#disable) return;
227
- this.printContent.call(this, msg, color, otherStyle);
239
+ this.printContent(args, this.#details.errorColor);
228
240
  }
229
241
  /**
230
242
  * 控制台-成功输出
231
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
232
- * @param color 输出的颜色
233
- * @param otherStyle 其它CSS
243
+ * @param args 需要输出的内容
244
+ * @example
245
+ * log.success("输出成功")
234
246
  */
235
- success(msg: any, color = this.#details.successColor, otherStyle?: string) {
247
+ success(...args: any[]) {
236
248
  if (this.#disable) return;
237
- this.printContent.call(this, msg, color, otherStyle);
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[], color = this.#details.infoColor, otherStyle = "") {
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: ${color};${otherStyle}`
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: any & {
28
+ $route: {
29
29
  fullPath: string;
30
30
  hash: string;
31
31
  matched: any[];
@@ -34,49 +34,55 @@ export declare interface Vue2Object {
34
34
  params: any;
35
35
  path: string;
36
36
  query: any;
37
+ [key: string]: any;
37
38
  };
38
- $router: any & {
39
+ $router: {
39
40
  afterHooks: Function[];
40
41
  app: Vue2Object;
41
42
  apps: Vue2Object[];
42
43
  beforeHooks: Function[];
43
44
  fallback: boolean;
44
- history: any & {
45
+ history: {
45
46
  base: string;
46
- current: any;
47
+ current: Vue2Object["$route"];
47
48
  listeners: any[];
48
49
  router: Vue2Object["$router"];
49
50
  /**
50
51
  *
51
52
  * @param delta 访问的距离。如果 delta < 0 则后退相应数量的记录,如果 > 0 则前进。
52
53
  * @param triggerListeners 是否应该触发连接到该历史的监听器
53
- * @returns
54
54
  */
55
55
  go: (delta: number, triggerListeners?: boolean) => void;
56
56
  /**
57
57
  *
58
58
  * @param to 要设置的地址
59
59
  * @param data 可选的 HistoryState 以关联该导航记录
60
- * @returns
61
60
  */
62
61
  push: (to: string, data?: any) => void;
63
62
  /**
64
63
  *
65
64
  * @param to 要设置的地址
66
65
  * @param data 可选的 HistoryState 以关联该导航记录
67
- * @returns
68
66
  */
69
67
  replace: (to: string, data?: any) => void;
68
+ [key: string]: any;
70
69
  };
71
- matcher: any & {
70
+ matcher: {
72
71
  addRoute: (...args: any[]) => any;
73
72
  addRoutes: (...args: any[]) => any;
74
73
  getRoutes: () => any;
75
74
  match: (...args: any[]) => any;
75
+ [key: string]: any;
76
76
  };
77
77
  mode: string;
78
+ options: {
79
+ mode: string;
80
+ routes: any[];
81
+ scrollBehavior: (...args: any[]) => any;
82
+ [key: string]: any;
83
+ };
78
84
  resolveHooks: ((...args: any[]) => any)[];
79
- currentRoute: any;
85
+ currentRoute: Vue2Object["$route"];
80
86
  beforeEach: (
81
87
  callback:
82
88
  | ((
@@ -108,6 +114,13 @@ export declare interface Vue2Object {
108
114
  /** 移除上一个添加的监听 */
109
115
  | (() => void)
110
116
  ) => void;
117
+ push: (...args: any[]) => void;
118
+ back: () => void;
119
+ go: (...args: any[]) => void;
120
+ replace: (...args: any[]) => void;
121
+ addRoute: (...args: any[]) => void;
122
+ addRoutes: (...args: any[]) => void;
123
+ [key: string]: any;
111
124
  };
112
125
  $ssrContext: any;
113
126