@whitesev/utils 2.9.12 → 2.9.13

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.
Files changed (73) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +128 -85
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +1 -1
  5. package/dist/index.amd.min.js.map +1 -1
  6. package/dist/index.cjs.js +128 -85
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +1 -1
  9. package/dist/index.cjs.min.js.map +1 -1
  10. package/dist/index.esm.js +128 -85
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +1 -1
  13. package/dist/index.esm.min.js.map +1 -1
  14. package/dist/index.iife.js +128 -85
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +1 -1
  17. package/dist/index.iife.min.js.map +1 -1
  18. package/dist/index.system.js +128 -85
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +1 -1
  21. package/dist/index.system.min.js.map +1 -1
  22. package/dist/index.umd.js +128 -85
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +1 -1
  25. package/dist/index.umd.min.js.map +1 -1
  26. package/dist/types/src/Dictionary.d.ts +2 -0
  27. package/dist/types/src/Utils.d.ts +5 -2
  28. package/dist/types/src/types/Httpx.d.ts +1344 -1344
  29. package/dist/types/src/types/Log.d.ts +19 -19
  30. package/dist/types/src/types/Progress.d.ts +20 -20
  31. package/dist/types/src/types/React.d.ts +119 -119
  32. package/dist/types/src/types/TryCatch.d.ts +9 -9
  33. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  34. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  35. package/dist/types/src/types/Vue2.d.ts +166 -166
  36. package/dist/types/src/types/WindowApi.d.ts +14 -14
  37. package/dist/types/src/types/ajaxHooker.d.ts +155 -155
  38. package/dist/types/src/types/env.d.ts +7 -7
  39. package/dist/types/src/types/global.d.ts +31 -31
  40. package/package.json +26 -24
  41. package/src/ColorConversion.ts +118 -118
  42. package/src/CommonUtil.ts +301 -301
  43. package/src/DOMUtils.ts +251 -251
  44. package/src/Dictionary.ts +205 -199
  45. package/src/GBKEncoder.ts +108 -108
  46. package/src/Hooks.ts +73 -73
  47. package/src/Httpx.ts +1457 -1457
  48. package/src/LockFunction.ts +65 -62
  49. package/src/Log.ts +233 -233
  50. package/src/ModuleRaid.js +378 -360
  51. package/src/Progress.ts +108 -108
  52. package/src/TryCatch.ts +86 -86
  53. package/src/Utils.ts +3860 -3852
  54. package/src/UtilsCommon.ts +14 -14
  55. package/src/UtilsGMCookie.ts +273 -273
  56. package/src/UtilsGMMenu.ts +460 -460
  57. package/src/Vue.ts +233 -233
  58. package/src/WindowApi.ts +59 -59
  59. package/src/ajaxHooker/ajaxHooker.js +606 -538
  60. package/src/ajaxHooker/ajaxHooker1.2.4.js +440 -438
  61. package/src/indexedDB.ts +497 -497
  62. package/src/types/Httpx.d.ts +1344 -1344
  63. package/src/types/Log.d.ts +19 -19
  64. package/src/types/Progress.d.ts +20 -20
  65. package/src/types/React.d.ts +119 -119
  66. package/src/types/TryCatch.d.ts +9 -9
  67. package/src/types/UtilsGMCookie.d.ts +93 -93
  68. package/src/types/UtilsGMMenu.d.ts +77 -77
  69. package/src/types/Vue2.d.ts +166 -166
  70. package/src/types/WindowApi.d.ts +14 -14
  71. package/src/types/ajaxHooker.d.ts +155 -155
  72. package/src/types/env.d.ts +7 -7
  73. package/src/types/global.d.ts +31 -31
@@ -1,118 +1,118 @@
1
- export class ColorConversion {
2
- /**
3
- * 判断是否是16进制颜色
4
- * @param str 十六进制颜色,如`#000000`
5
- */
6
- isHex(str: string): boolean {
7
- if (typeof str !== "string") {
8
- return false;
9
- }
10
- if (!str.match(/^(#|)[0-9a-fA-F]{6}$/)) {
11
- return false;
12
- }
13
- return true;
14
- }
15
- /**
16
- * 16进制颜色转rgba
17
- *
18
- * 例如:`#ff0000` 转为 `rgba(123,123,123, 0.4)`
19
- * @param hex 十六进制颜色,如`#000000`
20
- * @param opacity 透明度,0~1
21
- */
22
- hexToRgba(hex: string, opacity: number): string {
23
- if (!this.isHex(hex)) {
24
- throw new TypeError(`输入错误的hex:${hex}`);
25
- }
26
- return hex && hex.replace(/\s+/g, "").length === 7
27
- ? `rgba(${parseInt(`0x${hex.slice(1, 3)}`)},${parseInt(`0x${hex.slice(3, 5)}`)},${parseInt(
28
- `0x${hex.slice(5, 7)}`
29
- )},${opacity})`
30
- : "";
31
- }
32
- /**
33
- * hex转rgb
34
- * @param hex 十六进制颜色,如`#000000`
35
- */
36
- hexToRgb(hex: string) {
37
- if (!this.isHex(hex)) {
38
- throw new TypeError(`输入错误的hex:${hex}`);
39
- }
40
- /* replace替换查找的到的字符串 */
41
- hex = hex.replace("#", "");
42
- /* match得到查询数组 */
43
- const hxs = hex.match(/../g)!;
44
- for (let index = 0; index < 3; index++) {
45
- const value = parseInt(hxs[index], 16);
46
- Reflect.set(hxs, index, value);
47
- }
48
-
49
- return hxs;
50
- }
51
- /**
52
- * rgb转hex
53
- * @param redValue 红色值
54
- * @param greenValue 绿色值
55
- * @param blueValue 蓝色值
56
- * @returns hex
57
- */
58
- rgbToHex(redValue: string | number, greenValue: string | number, blueValue: string | number): string {
59
- /* 验证输入的rgb值是否合法 */
60
- const validPattern = /^\d{1,3}$/;
61
- if (
62
- !validPattern.test(redValue.toString()) ||
63
- !validPattern.test(greenValue.toString()) ||
64
- !validPattern.test(blueValue.toString())
65
- )
66
- throw new TypeError("输入错误的rgb颜色值");
67
- const hexs = [redValue.toString(16), greenValue.toString(16), blueValue.toString(16)];
68
- for (let index = 0; index < 3; index++) if (hexs[index].length == 1) hexs[index] = `0${hexs[index]}`;
69
- return `#${hexs.join("")}`;
70
- }
71
- /**
72
- * 获取颜色变暗或亮
73
- * @param color hex颜色,如`#000000`
74
- * @param level 0~1.0 系数越大,颜色越变暗
75
- */
76
- getDarkColor(color: string, level: number | string): string {
77
- if (!this.isHex(color)) {
78
- throw new TypeError(`输入错误的hex:${color}`);
79
- }
80
- if (typeof level !== "number") {
81
- level = Number(level);
82
- }
83
- if (isNaN(level)) {
84
- throw new TypeError(`输入错误的level:${level}`);
85
- }
86
- const rgbc = this.hexToRgb(color);
87
- for (let index = 0; index < 3; index++) {
88
- const rgbcItemValue = rgbc[index];
89
- const value = Math.floor(Number(rgbcItemValue) * (1 - level));
90
- Reflect.set(rgbc, index, value);
91
- }
92
-
93
- return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
94
- }
95
- /**
96
- * 获取颜色变亮
97
- * @param color hex颜色,如`#000000`
98
- * @param level 0~1.0 系数越大,颜色越变亮
99
- */
100
- getLightColor(color: string, level: number | string): string {
101
- if (!this.isHex(color)) {
102
- throw new TypeError(`输入错误的hex:${color}`);
103
- }
104
- if (typeof level !== "number") {
105
- level = Number(level);
106
- }
107
- if (isNaN(level)) {
108
- throw new TypeError(`输入错误的level:${level}`);
109
- }
110
- const rgbc = this.hexToRgb(color);
111
- for (let index = 0; index < 3; index++) {
112
- const rgbcItemValue = Number(rgbc[index]);
113
- const value = Math.floor(255 - rgbcItemValue * level + rgbcItemValue);
114
- Reflect.set(rgbc, index, value);
115
- }
116
- return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
117
- }
118
- }
1
+ export class ColorConversion {
2
+ /**
3
+ * 判断是否是16进制颜色
4
+ * @param str 十六进制颜色,如`#000000`
5
+ */
6
+ isHex(str: string): boolean {
7
+ if (typeof str !== "string") {
8
+ return false;
9
+ }
10
+ if (!str.match(/^(#|)[0-9a-fA-F]{6}$/)) {
11
+ return false;
12
+ }
13
+ return true;
14
+ }
15
+ /**
16
+ * 16进制颜色转rgba
17
+ *
18
+ * 例如:`#ff0000` 转为 `rgba(123,123,123, 0.4)`
19
+ * @param hex 十六进制颜色,如`#000000`
20
+ * @param opacity 透明度,0~1
21
+ */
22
+ hexToRgba(hex: string, opacity: number): string {
23
+ if (!this.isHex(hex)) {
24
+ throw new TypeError(`输入错误的hex:${hex}`);
25
+ }
26
+ return hex && hex.replace(/\s+/g, "").length === 7
27
+ ? `rgba(${parseInt(`0x${hex.slice(1, 3)}`)},${parseInt(`0x${hex.slice(3, 5)}`)},${parseInt(
28
+ `0x${hex.slice(5, 7)}`
29
+ )},${opacity})`
30
+ : "";
31
+ }
32
+ /**
33
+ * hex转rgb
34
+ * @param hex 十六进制颜色,如`#000000`
35
+ */
36
+ hexToRgb(hex: string) {
37
+ if (!this.isHex(hex)) {
38
+ throw new TypeError(`输入错误的hex:${hex}`);
39
+ }
40
+ /* replace替换查找的到的字符串 */
41
+ hex = hex.replace("#", "");
42
+ /* match得到查询数组 */
43
+ const hxs = hex.match(/../g)!;
44
+ for (let index = 0; index < 3; index++) {
45
+ const value = parseInt(hxs[index], 16);
46
+ Reflect.set(hxs, index, value);
47
+ }
48
+
49
+ return hxs;
50
+ }
51
+ /**
52
+ * rgb转hex
53
+ * @param redValue 红色值
54
+ * @param greenValue 绿色值
55
+ * @param blueValue 蓝色值
56
+ * @returns hex
57
+ */
58
+ rgbToHex(redValue: string | number, greenValue: string | number, blueValue: string | number): string {
59
+ /* 验证输入的rgb值是否合法 */
60
+ const validPattern = /^\d{1,3}$/;
61
+ if (
62
+ !validPattern.test(redValue.toString()) ||
63
+ !validPattern.test(greenValue.toString()) ||
64
+ !validPattern.test(blueValue.toString())
65
+ )
66
+ throw new TypeError("输入错误的rgb颜色值");
67
+ const hexs = [redValue.toString(16), greenValue.toString(16), blueValue.toString(16)];
68
+ for (let index = 0; index < 3; index++) if (hexs[index].length == 1) hexs[index] = `0${hexs[index]}`;
69
+ return `#${hexs.join("")}`;
70
+ }
71
+ /**
72
+ * 获取颜色变暗或亮
73
+ * @param color hex颜色,如`#000000`
74
+ * @param level 0~1.0 系数越大,颜色越变暗
75
+ */
76
+ getDarkColor(color: string, level: number | string): string {
77
+ if (!this.isHex(color)) {
78
+ throw new TypeError(`输入错误的hex:${color}`);
79
+ }
80
+ if (typeof level !== "number") {
81
+ level = Number(level);
82
+ }
83
+ if (isNaN(level)) {
84
+ throw new TypeError(`输入错误的level:${level}`);
85
+ }
86
+ const rgbc = this.hexToRgb(color);
87
+ for (let index = 0; index < 3; index++) {
88
+ const rgbcItemValue = rgbc[index];
89
+ const value = Math.floor(Number(rgbcItemValue) * (1 - level));
90
+ Reflect.set(rgbc, index, value);
91
+ }
92
+
93
+ return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
94
+ }
95
+ /**
96
+ * 获取颜色变亮
97
+ * @param color hex颜色,如`#000000`
98
+ * @param level 0~1.0 系数越大,颜色越变亮
99
+ */
100
+ getLightColor(color: string, level: number | string): string {
101
+ if (!this.isHex(color)) {
102
+ throw new TypeError(`输入错误的hex:${color}`);
103
+ }
104
+ if (typeof level !== "number") {
105
+ level = Number(level);
106
+ }
107
+ if (isNaN(level)) {
108
+ throw new TypeError(`输入错误的level:${level}`);
109
+ }
110
+ const rgbc = this.hexToRgb(color);
111
+ for (let index = 0; index < 3; index++) {
112
+ const rgbcItemValue = Number(rgbc[index]);
113
+ const value = Math.floor(255 - rgbcItemValue * level + rgbcItemValue);
114
+ Reflect.set(rgbc, index, value);
115
+ }
116
+ return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
117
+ }
118
+ }