@whitesev/utils 1.1.8 → 1.2.0

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
@@ -27,7 +27,8 @@
27
27
  */
28
28
  hexToRgba(hex, opacity) {
29
29
  if (!this.isHex(hex)) {
30
- throw new TypeError("输入错误的hex" + hex);
30
+ // @ts-ignore
31
+ throw new TypeError("输入错误的hex", hex);
31
32
  }
32
33
  return hex && hex.replace(/\s+/g, "").length === 7
33
34
  ? "rgba(" +
@@ -48,17 +49,17 @@
48
49
  */
49
50
  hexToRgb(str) {
50
51
  if (!this.isHex(str)) {
51
- throw new TypeError("输入错误的hex" + str);
52
+ // @ts-ignore
53
+ throw new TypeError("输入错误的hex", str);
52
54
  }
53
55
  /* replace替换查找的到的字符串 */
54
56
  str = str.replace("#", "");
55
57
  /* match得到查询数组 */
56
58
  let hxs = str.match(/../g);
57
- if (hxs == null) {
58
- throw new TypeError("输入错误的hex" + str);
59
+ for (let index = 0; index < 3; index++) {
60
+ // @ts-ignore
61
+ hxs[index] = parseInt(hxs[index], 16);
59
62
  }
60
- for (let index = 0; index < 3; index++)
61
- hxs[index] = parseInt(hxs[index], 16).toString();
62
63
  return hxs;
63
64
  }
64
65
  /**
@@ -93,12 +94,15 @@
93
94
  */
94
95
  getDarkColor(color, level) {
95
96
  if (!this.isHex(color)) {
96
- throw new TypeError("输入错误的hex" + color);
97
+ // @ts-ignore
98
+ throw new TypeError("输入错误的hex", color);
97
99
  }
98
100
  let rgbc = this.hexToRgb(color);
99
- for (let index = 0; index < 3; index++)
101
+ for (let index = 0; index < 3; index++) {
100
102
  // @ts-ignore
101
- rgbc[index] = Math.floor(rgbc[index] * (1 - level)).toString();
103
+ rgbc[index] = Math.floor(rgbc[index] * (1 - level));
104
+ }
105
+ // @ts-ignore
102
106
  return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
103
107
  }
104
108
  /**
@@ -109,13 +113,15 @@
109
113
  */
110
114
  getLightColor(color, level) {
111
115
  if (!this.isHex(color)) {
112
- throw new TypeError("输入错误的hex" + color);
116
+ // @ts-ignore
117
+ throw new TypeError("输入错误的hex", color);
113
118
  }
114
119
  let rgbc = this.hexToRgb(color);
115
- for (let index = 0; index < 3; index++)
116
- rgbc[index] = Math.floor(
120
+ for (let index = 0; index < 3; index++) {
117
121
  // @ts-ignore
118
- (255 - rgbc[index]) * level + rgbc[index]).toString();
122
+ rgbc[index] = Math.floor((255 - rgbc[index]) * level + rgbc[index]);
123
+ }
124
+ // @ts-ignore
119
125
  return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
120
126
  }
121
127
  }