@whitesev/utils 2.9.4 → 2.9.6

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.
@@ -0,0 +1,2 @@
1
+ declare const _default: import("eslint/config").Config[];
2
+ export default _default;
@@ -1,39 +1,40 @@
1
1
  export declare class ColorConversion {
2
2
  /**
3
3
  * 判断是否是16进制颜色
4
- * @param str
4
+ * @param str 十六进制颜色,如`#000000`
5
5
  */
6
6
  isHex(str: string): boolean;
7
7
  /**
8
8
  * 16进制颜色转rgba
9
9
  *
10
10
  * 例如:`#ff0000` 转为 `rgba(123,123,123, 0.4)`
11
- * @param hex
12
- * @param opacity
11
+ * @param hex 十六进制颜色,如`#000000`
12
+ * @param opacity 透明度,0~1
13
13
  */
14
14
  hexToRgba(hex: string, opacity: number): string;
15
15
  /**
16
16
  * hex转rgb
17
- * @param str
17
+ * @param hex 十六进制颜色,如`#000000`
18
18
  */
19
- hexToRgb(str: string): RegExpMatchArray;
19
+ hexToRgb(hex: string): RegExpMatchArray;
20
20
  /**
21
21
  * rgb转hex
22
- * @param redValue
23
- * @param greenValue
24
- * @param blueValue
22
+ * @param redValue 红色值
23
+ * @param greenValue 绿色值
24
+ * @param blueValue 蓝色值
25
+ * @returns hex
25
26
  */
26
27
  rgbToHex(redValue: string | number, greenValue: string | number, blueValue: string | number): string;
27
28
  /**
28
29
  * 获取颜色变暗或亮
29
- * @param color 颜色
30
- * @param level 0~1.0
30
+ * @param color hex颜色,如`#000000`
31
+ * @param level 0~1.0 系数越大,颜色越变暗
31
32
  */
32
- getDarkColor(color: string, level: string): string;
33
+ getDarkColor(color: string, level: number | string): string;
33
34
  /**
34
35
  * 获取颜色变亮
35
- * @param color 颜色
36
- * @param level 0~1.0
36
+ * @param color hex颜色,如`#000000`
37
+ * @param level 0~1.0 系数越大,颜色越变亮
37
38
  */
38
- getLightColor(color: string, level: number): string;
39
+ getLightColor(color: string, level: number | string): string;
39
40
  }
@@ -1120,6 +1120,9 @@ declare class Utils {
1120
1120
  * 复制到剪贴板
1121
1121
  * @param data 需要复制到剪贴板的文本
1122
1122
  * @param info (可选)默认:text/plain
1123
+ * @returns
1124
+ * + true 复制成功
1125
+ * + false 复制失败
1123
1126
  * @example
1124
1127
  * Utils.copy({1:2});
1125
1128
  * > {"1":2}
@@ -24,7 +24,7 @@ export declare class UtilsGMCookie {
24
24
  };
25
25
  list(option: UtilsGMCookieListOptions | object, callback?: (data: UtilsGMCookieResult[], error?: Error) => void): void;
26
26
  /**
27
- * 获取多组Cookie
27
+ * 获取多组Cookie
28
28
  * @param option 配置
29
29
  **/
30
30
  getList(option: UtilsGMCookieListOptions | object): UtilsGMCookieResult[];
@@ -41,7 +41,8 @@ export declare class UtilsGMCookie {
41
41
  */
42
42
  delete(option: UtilsGMCookieDeleteOptions, callback?: (error?: Error) => void): void;
43
43
  /**
44
- * 解析cookie字符串
44
+ * 解析cookie字符串,按`;`分割
45
+ *
45
46
  * 例如:document.cookie
46
47
  * @param cookieStr
47
48
  */
@@ -73,7 +73,7 @@ export declare class GMMenu {
73
73
  * 根据键值获取callback函数
74
74
  * @param menuKey 菜单-键key
75
75
  */
76
- getCallBack(menuKey: string): ((...args: any[]) => any) | undefined;
76
+ getCallBack(menuKey: string): ((data: import("./types/UtilsGMMenu").UtilsGMMenuClickCallBackData) => void) | undefined;
77
77
  /**
78
78
  * 获取当enable为true时默认显示在菜单中前面的emoji图标
79
79
  */
@@ -101,17 +101,17 @@ export declare class GMMenu {
101
101
  setEnable(menuKey: string, value: boolean): void;
102
102
  /**
103
103
  * 设置当enable为true时默认显示在菜单中前面的emoji图标
104
- * @param emojiString
104
+ * @param emojiString emoji字符串
105
105
  */
106
106
  setEnableTrueEmoji(emojiString: string): void;
107
107
  /**
108
108
  * 设置当enable为false时默认显示在菜单中前面的emoji图标
109
- * @param emojiString
109
+ * @param emojiString emoji字符串
110
110
  */
111
111
  setEnableFalseEmoji(emojiString: string): void;
112
112
  /**
113
113
  * 设置本地存储的菜单外部的键名
114
- * @param keyName
114
+ * @param keyName 键名
115
115
  */
116
116
  setLocalStorageKeyName(keyName: string): void;
117
117
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@whitesev/utils",
4
- "version": "2.9.4",
4
+ "version": "2.9.6",
5
5
  "type": "module",
6
6
  "description": "一个常用的工具库",
7
7
  "main": "dist/index.cjs.js",
@@ -39,24 +39,24 @@
39
39
  "worker-timers": "^8.0.25"
40
40
  },
41
41
  "devDependencies": {
42
- "@eslint/js": "^9.37.0",
43
- "@rollup/plugin-commonjs": "^28.0.8",
42
+ "@eslint/js": "^9.38.0",
43
+ "@rollup/plugin-commonjs": "^28.0.9",
44
44
  "@rollup/plugin-json": "^6.1.0",
45
45
  "@rollup/plugin-node-resolve": "^16.0.3",
46
46
  "@rollup/plugin-terser": "^0.4.4",
47
- "@rollup/plugin-typescript": "^12.1.4",
48
- "browserslist": "^4.26.3",
47
+ "@rollup/plugin-typescript": "^12.3.0",
48
+ "browserslist": "^4.27.0",
49
49
  "caniuse-lite": "^1.0.30001751",
50
- "eslint": "^9.37.0",
50
+ "eslint": "^9.38.0",
51
51
  "eslint-config-prettier": "^10.1.8",
52
52
  "eslint-plugin-compat": "^6.0.2",
53
53
  "eslint-plugin-prettier": "^5.5.4",
54
54
  "globals": "^16.4.0",
55
- "rollup": "^4.52.4",
55
+ "rollup": "^4.52.5",
56
56
  "rollup-plugin-clear": "^2.0.7",
57
57
  "tslib": "^2.8.1",
58
58
  "typescript": "^5.9.3",
59
- "typescript-eslint": "^8.46.1"
59
+ "typescript-eslint": "^8.46.2"
60
60
  },
61
61
  "scripts": {
62
62
  "lint": "eslint .",
@@ -1,7 +1,7 @@
1
1
  export class ColorConversion {
2
2
  /**
3
3
  * 判断是否是16进制颜色
4
- * @param str
4
+ * @param str 十六进制颜色,如`#000000`
5
5
  */
6
6
  isHex(str: string): boolean {
7
7
  if (typeof str !== "string") {
@@ -16,8 +16,8 @@ export class ColorConversion {
16
16
  * 16进制颜色转rgba
17
17
  *
18
18
  * 例如:`#ff0000` 转为 `rgba(123,123,123, 0.4)`
19
- * @param hex
20
- * @param opacity
19
+ * @param hex 十六进制颜色,如`#000000`
20
+ * @param opacity 透明度,0~1
21
21
  */
22
22
  hexToRgba(hex: string, opacity: number): string {
23
23
  if (!this.isHex(hex)) {
@@ -31,16 +31,16 @@ export class ColorConversion {
31
31
  }
32
32
  /**
33
33
  * hex转rgb
34
- * @param str
34
+ * @param hex 十六进制颜色,如`#000000`
35
35
  */
36
- hexToRgb(str: string) {
37
- if (!this.isHex(str)) {
38
- throw new TypeError(`输入错误的hex:${str}`);
36
+ hexToRgb(hex: string) {
37
+ if (!this.isHex(hex)) {
38
+ throw new TypeError(`输入错误的hex:${hex}`);
39
39
  }
40
40
  /* replace替换查找的到的字符串 */
41
- str = str.replace("#", "");
41
+ hex = hex.replace("#", "");
42
42
  /* match得到查询数组 */
43
- const hxs = str.match(/../g)!;
43
+ const hxs = hex.match(/../g)!;
44
44
  for (let index = 0; index < 3; index++) {
45
45
  const value = parseInt(hxs[index], 16);
46
46
  Reflect.set(hxs, index, value);
@@ -50,9 +50,10 @@ export class ColorConversion {
50
50
  }
51
51
  /**
52
52
  * rgb转hex
53
- * @param redValue
54
- * @param greenValue
55
- * @param blueValue
53
+ * @param redValue 红色值
54
+ * @param greenValue 绿色值
55
+ * @param blueValue 蓝色值
56
+ * @returns hex
56
57
  */
57
58
  rgbToHex(redValue: string | number, greenValue: string | number, blueValue: string | number): string {
58
59
  /* 验证输入的rgb值是否合法 */
@@ -69,17 +70,23 @@ export class ColorConversion {
69
70
  }
70
71
  /**
71
72
  * 获取颜色变暗或亮
72
- * @param color 颜色
73
- * @param level 0~1.0
73
+ * @param color hex颜色,如`#000000`
74
+ * @param level 0~1.0 系数越大,颜色越变暗
74
75
  */
75
- getDarkColor(color: string, level: string): string {
76
+ getDarkColor(color: string, level: number | string): string {
76
77
  if (!this.isHex(color)) {
77
78
  throw new TypeError(`输入错误的hex:${color}`);
78
79
  }
80
+ if (typeof level !== "number") {
81
+ level = Number(level);
82
+ }
83
+ if (isNaN(level)) {
84
+ throw new TypeError(`输入错误的level:${level}`);
85
+ }
79
86
  const rgbc = this.hexToRgb(color);
80
87
  for (let index = 0; index < 3; index++) {
81
88
  const rgbcItemValue = rgbc[index];
82
- const value = Math.floor(Number(rgbcItemValue) * (1 - Number(level)));
89
+ const value = Math.floor(Number(rgbcItemValue) * (1 - level));
83
90
  Reflect.set(rgbc, index, value);
84
91
  }
85
92
 
@@ -87,13 +94,19 @@ export class ColorConversion {
87
94
  }
88
95
  /**
89
96
  * 获取颜色变亮
90
- * @param color 颜色
91
- * @param level 0~1.0
97
+ * @param color hex颜色,如`#000000`
98
+ * @param level 0~1.0 系数越大,颜色越变亮
92
99
  */
93
- getLightColor(color: string, level: number): string {
100
+ getLightColor(color: string, level: number | string): string {
94
101
  if (!this.isHex(color)) {
95
102
  throw new TypeError(`输入错误的hex:${color}`);
96
103
  }
104
+ if (typeof level !== "number") {
105
+ level = Number(level);
106
+ }
107
+ if (isNaN(level)) {
108
+ throw new TypeError(`输入错误的level:${level}`);
109
+ }
97
110
  const rgbc = this.hexToRgb(color);
98
111
  for (let index = 0; index < 3; index++) {
99
112
  const rgbcItemValue = Number(rgbc[index]);
package/src/Utils.ts CHANGED
@@ -2544,6 +2544,9 @@ class Utils {
2544
2544
  * 复制到剪贴板
2545
2545
  * @param data 需要复制到剪贴板的文本
2546
2546
  * @param info (可选)默认:text/plain
2547
+ * @returns
2548
+ * + true 复制成功
2549
+ * + false 复制失败
2547
2550
  * @example
2548
2551
  * Utils.copy({1:2});
2549
2552
  * > {"1":2}
@@ -134,7 +134,7 @@ export class UtilsGMCookie {
134
134
  }
135
135
  }
136
136
  /**
137
- * 获取多组Cookie
137
+ * 获取多组Cookie
138
138
  * @param option 配置
139
139
  **/
140
140
  getList(option: UtilsGMCookieListOptions | object): UtilsGMCookieResult[] {
@@ -246,7 +246,8 @@ export class UtilsGMCookie {
246
246
  }
247
247
  }
248
248
  /**
249
- * 解析cookie字符串
249
+ * 解析cookie字符串,按`;`分割
250
+ *
250
251
  * 例如:document.cookie
251
252
  * @param cookieStr
252
253
  */
@@ -370,7 +370,7 @@ export class GMMenu {
370
370
  * 根据键值获取callback函数
371
371
  * @param menuKey 菜单-键key
372
372
  */
373
- getCallBack(menuKey: string): ((...args: any[]) => any) | undefined {
373
+ getCallBack(menuKey: string) {
374
374
  return this.MenuHandle.getMenuHandledOption(menuKey)?.callback;
375
375
  }
376
376
  /**
@@ -410,31 +410,31 @@ export class GMMenu {
410
410
  }
411
411
  /**
412
412
  * 设置当enable为true时默认显示在菜单中前面的emoji图标
413
- * @param emojiString
413
+ * @param emojiString emoji字符串
414
414
  */
415
415
  setEnableTrueEmoji(emojiString: string) {
416
416
  if (typeof emojiString !== "string") {
417
- throw new Error("参数emojiString必须是string类型");
417
+ throw new TypeError("参数emojiString必须是string类型");
418
418
  }
419
419
  this.MenuHandle.$emoji.success = emojiString;
420
420
  }
421
421
  /**
422
422
  * 设置当enable为false时默认显示在菜单中前面的emoji图标
423
- * @param emojiString
423
+ * @param emojiString emoji字符串
424
424
  */
425
425
  setEnableFalseEmoji(emojiString: string) {
426
426
  if (typeof emojiString !== "string") {
427
- throw new Error("参数emojiString必须是string类型");
427
+ throw new TypeError("参数emojiString必须是string类型");
428
428
  }
429
429
  this.MenuHandle.$emoji.error = emojiString;
430
430
  }
431
431
  /**
432
432
  * 设置本地存储的菜单外部的键名
433
- * @param keyName
433
+ * @param keyName 键名
434
434
  */
435
435
  setLocalStorageKeyName(keyName: string) {
436
436
  if (typeof keyName !== "string") {
437
- throw new Error("参数keyName必须是string类型");
437
+ throw new TypeError("参数keyName必须是string类型");
438
438
  }
439
439
  this.MenuHandle.$data.key = keyName;
440
440
  }