util-helpers 5.7.7 → 5.8.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.
@@ -423,7 +423,7 @@
423
423
  return reg$9.test(valueStr);
424
424
  }
425
425
 
426
- var regIdCard$1 = /^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[012]))(([0-2][1-9])|10|20|30|31)\d{3}(\d|X)$/i;
426
+ var regIdCard$1 = /^[1-9]\d{5}(19|20)?\d{2}((0[1-9])|(1[012]))(([0-2][1-9])|10|20|30|31)\d{3}(\d|X)?$/i;
427
427
  function check(id) {
428
428
  var index, sum;
429
429
  for (sum = index = 0; index < 17; index++) {
@@ -439,10 +439,16 @@
439
439
  }
440
440
  function isIdCard(value, options) {
441
441
  if (options === void 0) { options = {}; }
442
- var _a = options.checkCode, checkCode = _a === void 0 ? true : _a;
442
+ var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, checkCode = _b === void 0 ? true : _b;
443
443
  var valueStr = toString(value);
444
+ if (valueStr.length === 15 && loose) {
445
+ return regIdCard$1.test(valueStr);
446
+ }
444
447
  if (valueStr.length === 18 && regIdCard$1.test(valueStr)) {
445
- return checkCode ? check(valueStr) : true;
448
+ if (checkCode) {
449
+ return check(valueStr);
450
+ }
451
+ return true;
446
452
  }
447
453
  return false;
448
454
  }
@@ -2196,7 +2202,7 @@
2196
2202
  return internalFindTreeSelect(tree, predicate, childrenField);
2197
2203
  }
2198
2204
 
2199
- var VERSION = "5.7.7";
2205
+ var VERSION = "5.8.0";
2200
2206
 
2201
2207
  /**
2202
2208
  * 事件触发器,支持浏览器端和 node 端。
@@ -3222,7 +3228,61 @@
3222
3228
  return AsyncMemo;
3223
3229
  }());
3224
3230
 
3231
+ var ConcurrencyController = (function () {
3232
+ function ConcurrencyController(maxConcurrency) {
3233
+ if (maxConcurrency === void 0) { maxConcurrency = 2; }
3234
+ this.maxConcurrency = Math.max(maxConcurrency, 1);
3235
+ this.runningCount = 0;
3236
+ this.queue = [];
3237
+ this.isPaused = false;
3238
+ }
3239
+ ConcurrencyController.prototype.add = function (task) {
3240
+ var _this = this;
3241
+ return new Promise(function (resolve, reject) {
3242
+ _this.queue.push({ task: task, resolve: resolve, reject: reject });
3243
+ _this._run();
3244
+ });
3245
+ };
3246
+ ConcurrencyController.prototype._run = function () {
3247
+ var _this = this;
3248
+ if (this.isPaused)
3249
+ return;
3250
+ while (this.runningCount < this.maxConcurrency && this.queue.length > 0) {
3251
+ var _a = this.queue.shift(), task = _a.task, resolve = _a.resolve, reject = _a.reject;
3252
+ this.runningCount++;
3253
+ task()
3254
+ .then(resolve)
3255
+ .catch(reject)
3256
+ .finally(function () {
3257
+ _this.runningCount--;
3258
+ _this._run();
3259
+ });
3260
+ }
3261
+ };
3262
+ ConcurrencyController.prototype.getStatus = function () {
3263
+ return {
3264
+ running: this.runningCount,
3265
+ waiting: this.queue.length,
3266
+ maxConcurrency: this.maxConcurrency,
3267
+ paused: this.isPaused
3268
+ };
3269
+ };
3270
+ ConcurrencyController.prototype.setMaxConcurrency = function (maxConcurrency) {
3271
+ this.maxConcurrency = Math.max(maxConcurrency, 1);
3272
+ this._run();
3273
+ };
3274
+ ConcurrencyController.prototype.pause = function () {
3275
+ this.isPaused = true;
3276
+ };
3277
+ ConcurrencyController.prototype.resume = function () {
3278
+ this.isPaused = false;
3279
+ this._run();
3280
+ };
3281
+ return ConcurrencyController;
3282
+ }());
3283
+
3225
3284
  exports.AsyncMemo = AsyncMemo;
3285
+ exports.ConcurrencyController = ConcurrencyController;
3226
3286
  exports.VERSION = VERSION;
3227
3287
  exports.ajax = ajax;
3228
3288
  exports.bytesToSize = bytesToSize;