@whitesev/utils 2.11.1 → 2.11.3

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/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.11.1",
4
+ "version": "2.11.3",
5
5
  "description": "一个常用的工具库",
6
6
  "keywords": [
7
7
  "ScriptCat",
@@ -83,10 +83,18 @@ export class ColorConversion {
83
83
  if (isNaN(level)) {
84
84
  throw new TypeError(`输入错误的level:${level}`);
85
85
  }
86
+ if (level < 0 || level > 1) {
87
+ throw new TypeError(`level must between 0~1.0: ${level}`);
88
+ }
86
89
  const rgbc = this.hexToRgb(color);
87
90
  for (let index = 0; index < 3; index++) {
88
91
  const rgbcItemValue = rgbc[index];
89
- const value = Math.floor(Number(rgbcItemValue) * (1 - level));
92
+ let value = Math.floor(Number(rgbcItemValue) * (1 - level));
93
+ if (value > 255) {
94
+ value = 255;
95
+ } else if (value < 0) {
96
+ value = 0;
97
+ }
90
98
  Reflect.set(rgbc, index, value);
91
99
  }
92
100
 
@@ -107,10 +115,18 @@ export class ColorConversion {
107
115
  if (isNaN(level)) {
108
116
  throw new TypeError(`输入错误的level:${level}`);
109
117
  }
118
+ if (level < 0 || level > 1) {
119
+ throw new TypeError(`level must between 0~1.0: ${level}`);
120
+ }
110
121
  const rgbc = this.hexToRgb(color);
111
122
  for (let index = 0; index < 3; index++) {
112
123
  const rgbcItemValue = Number(rgbc[index]);
113
- const value = Math.floor(255 - rgbcItemValue * level + rgbcItemValue);
124
+ let value = Math.floor(255 - rgbcItemValue * level + rgbcItemValue);
125
+ if (value > 255) {
126
+ value = 255;
127
+ } else if (value < 0) {
128
+ value = 0;
129
+ }
114
130
  Reflect.set(rgbc, index, value);
115
131
  }
116
132
  return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
package/src/Utils.ts CHANGED
@@ -3268,12 +3268,26 @@ class Utils {
3268
3268
  }
3269
3269
  return result;
3270
3270
  } else {
3271
- return Array.from(uniqueArrayData).filter(
3272
- (item) =>
3273
- !Array.from(compareArrayData).some(function (item2) {
3274
- return compareFun(item, item2);
3275
- })
3276
- );
3271
+ const compareSet = new Set(compareArrayData);
3272
+ const result: T[] = [];
3273
+
3274
+ for (let i = 0; i < uniqueArrayData.length; i++) {
3275
+ const item = uniqueArrayData[i];
3276
+ let flag = false;
3277
+
3278
+ for (const compareItem of compareSet) {
3279
+ if (compareFun(item, compareItem)) {
3280
+ flag = true;
3281
+ break;
3282
+ }
3283
+ }
3284
+
3285
+ if (!flag) {
3286
+ result.push(item);
3287
+ }
3288
+ }
3289
+
3290
+ return result;
3277
3291
  }
3278
3292
  }
3279
3293
  /**