@whitesev/utils 1.1.1 → 1.1.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/dist/index.esm.js CHANGED
@@ -1,5 +1,4 @@
1
1
  class ColorConversion {
2
- constructor() { }
3
2
  /**
4
3
  * 判断是否是16进制颜色
5
4
  * @param str
@@ -195,25 +194,23 @@ class GBKEncoder {
195
194
  }
196
195
  /**
197
196
  * 解码
198
- * @param {string} str
197
+ * @param str
199
198
  */
200
199
  decode(str) {
201
200
  var GBKMatcher = /%[0-9A-F]{2}%[0-9A-F]{2}/;
202
201
  var UTFMatcher = /%[0-9A-F]{2}/;
203
- var gbk = true, utf = true;
202
+ var utf = true;
203
+ let that = this;
204
204
  while (utf) {
205
- // @ts-ignore
206
- gbk = str.match(GBKMatcher);
207
- // @ts-ignore
208
- utf = str.match(UTFMatcher);
209
- // @ts-ignore
210
- if (gbk && gbk in G2Uhash) {
211
- // @ts-ignore
212
- str = str.replace(gbk, String.fromCharCode("0x" + G2Uhash[gbk]));
205
+ let gbkMatch = str.match(GBKMatcher);
206
+ let utfMatch = str.match(UTFMatcher);
207
+ utf = Boolean(utfMatch);
208
+ if (gbkMatch && gbkMatch in that.#G2Uhash) {
209
+ str = str.replace(gbkMatch, String.fromCharCode(("0x" + that.#G2Uhash[gbkMatch])));
213
210
  }
214
211
  else {
215
212
  // @ts-ignore
216
- str = str.replace(utf, decodeURIComponent(utf));
213
+ str = str.replace(utfMatch, decodeURIComponent(utfMatch));
217
214
  }
218
215
  }
219
216
  return str;
@@ -2476,6 +2473,7 @@ class LockFunction {
2476
2473
  run;
2477
2474
  isLock;
2478
2475
  constructor(callback, context, delayTime) {
2476
+ let that = this;
2479
2477
  this.#callback = callback;
2480
2478
  if (typeof context === "number") {
2481
2479
  this.#delayTime = context;
@@ -2489,32 +2487,32 @@ class LockFunction {
2489
2487
  * 锁
2490
2488
  */
2491
2489
  this.lock = function () {
2492
- this.#flag = true;
2490
+ that.#flag = true;
2493
2491
  };
2494
2492
  /**
2495
2493
  * 解锁
2496
2494
  */
2497
2495
  this.unlock = function () {
2498
2496
  setTimeout(() => {
2499
- this.#flag = false;
2500
- }, this.#delayTime);
2497
+ that.#flag = false;
2498
+ }, that.#delayTime);
2501
2499
  };
2502
2500
  /**
2503
2501
  * 判断是否被锁
2504
2502
  */
2505
2503
  this.isLock = function () {
2506
- return this.#flag;
2504
+ return that.#flag;
2507
2505
  };
2508
2506
  /**
2509
2507
  * 执行
2510
2508
  */
2511
2509
  this.run = async function (...args) {
2512
- if (this.isLock()) {
2510
+ if (that.isLock()) {
2513
2511
  return;
2514
2512
  }
2515
- this.lock();
2516
- await this.#callback.apply(this.#context, args);
2517
- this.unlock();
2513
+ that.lock();
2514
+ await that.#callback.apply(that.#context, args);
2515
+ that.unlock();
2518
2516
  };
2519
2517
  }
2520
2518
  }