@whitesev/utils 2.9.4 → 2.9.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.
@@ -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}
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.5",
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",
42
+ "@eslint/js": "^9.38.0",
43
43
  "@rollup/plugin-commonjs": "^28.0.8",
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.2.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,20 @@ 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
+ }
79
83
  const rgbc = this.hexToRgb(color);
80
84
  for (let index = 0; index < 3; index++) {
81
85
  const rgbcItemValue = rgbc[index];
82
- const value = Math.floor(Number(rgbcItemValue) * (1 - Number(level)));
86
+ const value = Math.floor(Number(rgbcItemValue) * (1 - level));
83
87
  Reflect.set(rgbc, index, value);
84
88
  }
85
89
 
@@ -87,13 +91,16 @@ export class ColorConversion {
87
91
  }
88
92
  /**
89
93
  * 获取颜色变亮
90
- * @param color 颜色
91
- * @param level 0~1.0
94
+ * @param color hex颜色,如`#000000`
95
+ * @param level 0~1.0 系数越大,颜色越变亮
92
96
  */
93
- getLightColor(color: string, level: number): string {
97
+ getLightColor(color: string, level: number | string): string {
94
98
  if (!this.isHex(color)) {
95
99
  throw new TypeError(`输入错误的hex:${color}`);
96
100
  }
101
+ if (typeof level !== "number") {
102
+ level = Number(level);
103
+ }
97
104
  const rgbc = this.hexToRgb(color);
98
105
  for (let index = 0; index < 3; index++) {
99
106
  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}