util-helpers 4.21.6 → 4.22.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.
@@ -4,16 +4,21 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.utilHelpers = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
+ var nativeUndefined$1 = void 0;
8
+ var stringUndefined = 'undefined';
9
+ var stringObject = 'object';
7
10
  var objectProto = Object.prototype;
8
11
  var objectProtoToString = objectProto.toString;
12
+ var objectProtoPropertyIsEnumerable = objectProto.propertyIsEnumerable;
13
+ var objectGetOwnPropertySymbols = Object.getOwnPropertySymbols;
9
14
  var objectKeys$1 = Object.keys;
10
- var symbolExisted = typeof Symbol !== 'undefined';
11
- var symbolProto = symbolExisted ? Symbol.prototype : undefined;
15
+ var symbolExisted = typeof Symbol !== stringUndefined;
16
+ var symbolProto = symbolExisted ? Symbol.prototype : nativeUndefined$1;
12
17
  var mathMin = Math.min;
13
18
  var numberIsFinite = Number.isFinite;
14
- var globalThisExisted = typeof globalThis === 'object' && globalThis;
15
- var globalExisted = typeof global === 'object' && global;
16
- var selfExisted = typeof self === 'object' && self;
19
+ var globalThisExisted = typeof globalThis === stringObject && globalThis;
20
+ var globalExisted = typeof global === stringObject && global;
21
+ var selfExisted = typeof self === stringObject && self;
17
22
  var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
18
23
  var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
19
24
  var numberTag = '[object Number]';
@@ -93,19 +98,26 @@
93
98
  return value != null && isLength(value.length) && !isFunction(value);
94
99
  }
95
100
 
96
- function keys(object) {
101
+ function getSymbols(object) {
102
+ if (!objectGetOwnPropertySymbols || object === null) {
103
+ return [];
104
+ }
105
+ return objectGetOwnPropertySymbols(object).filter(function (item) { return objectProtoPropertyIsEnumerable.call(object, item); });
106
+ }
107
+
108
+ function allKeys(object) {
97
109
  if (!isObject(object)) {
98
110
  return [];
99
111
  }
100
- return objectKeys$1(object);
112
+ return objectKeys$1(object).concat(getSymbols(object));
101
113
  }
102
114
 
103
115
  function createForEach(dir) {
104
- function forEach(collection, iteratee) {
116
+ var forEach = function (collection, iteratee) {
105
117
  if (iteratee === void 0) { iteratee = identity; }
106
- var _keys = !isArrayLike(collection) && keys(collection);
118
+ var _keys = !isArrayLike(collection) && allKeys(collection);
107
119
  var len = (_keys || collection).length;
108
- var i = dir > 0 ? 0 : len - 1;
120
+ var i = 0 ;
109
121
  while (i >= 0 && i < len) {
110
122
  var currentKey = _keys ? _keys[i] : i;
111
123
  if (iteratee(collection[currentKey], currentKey, collection) === false) {
@@ -114,18 +126,22 @@
114
126
  i += dir;
115
127
  }
116
128
  return collection;
117
- }
129
+ };
118
130
  return forEach;
119
131
  }
120
132
 
121
133
  var forEach = createForEach(1);
122
134
  var forEach$1 = forEach;
123
135
 
136
+ function isNumber(value) {
137
+ return typeof value === 'number' || getTag(value) === numberTag;
138
+ }
139
+
124
140
  function isNil(value) {
125
141
  return value == null;
126
142
  }
127
143
 
128
- var symbolToString = symbolProto ? symbolProto.toString : undefined;
144
+ var symbolToString = symbolProto ? symbolProto.toString : nativeUndefined$1;
129
145
  function baseToString(value) {
130
146
  if (typeof value === 'string') {
131
147
  return value;
@@ -143,7 +159,7 @@
143
159
  return isNil(value) ? '' : baseToString(value);
144
160
  }
145
161
 
146
- var blobExisted = typeof Blob !== 'undefined';
162
+ var blobExisted = typeof Blob !== stringUndefined;
147
163
  function isBlob(value) {
148
164
  if (blobExisted && value instanceof Blob) {
149
165
  return true;
@@ -161,10 +177,6 @@
161
177
  return numberIsFinite ? numberIsFinite(value) : typeof value === 'number' && root$1.isFinite(value);
162
178
  }
163
179
 
164
- function isNumber(value) {
165
- return typeof value === 'number' || getTag(value) === numberTag;
166
- }
167
-
168
180
  function isNaN(value) {
169
181
  return isNumber(value) && root$1.isNaN(value);
170
182
  }
@@ -210,22 +222,22 @@
210
222
  });
211
223
  }
212
224
 
213
- var reg$c = /^1[3456789]\d{9}$/;
225
+ var reg$b = /^1[3456789]\d{9}$/;
214
226
  function isMobile(value) {
215
227
  var valueStr = toString(value);
216
- return reg$c.test(valueStr);
228
+ return reg$b.test(valueStr);
217
229
  }
218
230
 
219
- var reg$b = /^(0\d{2,3}-)?([2-9]\d{6,7})(-\d{1,6})?$/;
231
+ var reg$a = /^(0\d{2,3}-)?([2-9]\d{6,7})(-\d{1,6})?$/;
220
232
  function isTelephone(value) {
221
233
  var valueStr = toString(value);
222
- return reg$b.test(valueStr);
234
+ return reg$a.test(valueStr);
223
235
  }
224
236
 
225
- var reg$a = /^\d{6}$/;
237
+ var reg$9 = /^\d{6}$/;
226
238
  function isPostcode(value) {
227
239
  var valueStr = toString(value);
228
- return reg$a.test(valueStr);
240
+ return reg$9.test(valueStr);
229
241
  }
230
242
 
231
243
  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;
@@ -258,31 +270,31 @@
258
270
  return false;
259
271
  }
260
272
 
261
- var reg$9 = /^[\da-z]+([-._]?[\da-z]+)*@[\da-z]+([-.]?[\da-z]+)*(\.[a-z]{2,})+$/i;
273
+ var reg$8 = /^[\da-z]+([-._]?[\da-z]+)*@[\da-z]+([-.]?[\da-z]+)*(\.[a-z]{2,})+$/i;
262
274
  function isEmail(value) {
263
275
  var valueStr = toString(value);
264
- return reg$9.test(valueStr);
276
+ return reg$8.test(valueStr);
265
277
  }
266
278
 
267
- var reg$8 = /^[1-9]\d{4,10}$/;
279
+ var reg$7 = /^[1-9]\d{4,10}$/;
268
280
  function isQQ(value) {
269
281
  var valueStr = toString(value);
270
- return reg$8.test(valueStr);
282
+ return reg$7.test(valueStr);
271
283
  }
272
284
 
273
- var reg$7 = /^[a-z]([-_a-z0-9]{5,19})+$/i;
285
+ var reg$6 = /^[a-z]([-_a-z0-9]{5,19})+$/i;
274
286
  function isWX(value) {
275
287
  var valueStr = toString(value);
276
- return reg$7.test(valueStr);
288
+ return reg$6.test(valueStr);
277
289
  }
278
290
 
279
- var reg$6 = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})|([A-Z0-9]{5}[DF])|([DF][A-Z0-9]{5}))$/;
291
+ var reg$5 = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})|([A-Z0-9]{5}[DF])|([DF][A-Z0-9]{5}))$/;
280
292
  function isVehicle(value) {
281
293
  var valueStr = toString(value);
282
- return reg$6.test(valueStr);
294
+ return reg$5.test(valueStr);
283
295
  }
284
296
 
285
- var reg$5 = /^[1-9]\d{9,20}$/;
297
+ var reg$4 = /^[1-9]\d{9,20}$/;
286
298
  var regLoose = /^\d{8,30}$/;
287
299
  function sumCheckCode$2(numStr) {
288
300
  var numArr = (numStr + '').replace(/\D/g, '').split('').reverse();
@@ -298,7 +310,7 @@
298
310
  if (options === void 0) { options = {}; }
299
311
  var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.luhn, luhn = _b === void 0 ? false : _b;
300
312
  var valueStr = toString(value);
301
- var validateResult = loose ? regLoose.test(valueStr) : reg$5.test(valueStr);
313
+ var validateResult = loose ? regLoose.test(valueStr) : reg$4.test(valueStr);
302
314
  if (validateResult && luhn) {
303
315
  var precode = valueStr.substring(0, valueStr.length - 1);
304
316
  var checkCode = valueStr[valueStr.length - 1];
@@ -469,10 +481,10 @@
469
481
  return validatePassword(value, { level: level, ignoreCase: ignoreCase, special: special }).validated;
470
482
  }
471
483
 
472
- var reg$4 = /^((e[\da-z])|(de)|(se)|(pe)|([khm][\da-z]))[\da-z]{7}$/i;
484
+ var reg$3 = /^((e[\da-z])|(de)|(se)|(pe)|([khm][\da-z]))[\da-z]{7}$/i;
473
485
  function isPassport(value) {
474
486
  var valueStr = toString(value);
475
- return reg$4.test(valueStr);
487
+ return reg$3.test(valueStr);
476
488
  }
477
489
 
478
490
  var URLExisted = typeof URL !== 'undefined';
@@ -516,16 +528,16 @@
516
528
  return reg.test(valueStr);
517
529
  }
518
530
 
519
- var reg$3 = /^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
531
+ var reg$2 = /^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
520
532
  function isIPv4(value) {
521
533
  var valueStr = toString(value);
522
- return reg$3.test(valueStr);
534
+ return reg$2.test(valueStr);
523
535
  }
524
536
 
525
- var reg$2 = /^((([0-9A-F]{1,4}:){7}([0-9A-F]{1,4}|:))|(([0-9A-F]{1,4}:){6}(:[0-9A-F]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){5}(((:[0-9A-F]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){4}(((:[0-9A-F]{1,4}){1,3})|((:[0-9A-F]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){3}(((:[0-9A-F]{1,4}){1,4})|((:[0-9A-F]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){2}(((:[0-9A-F]{1,4}){1,5})|((:[0-9A-F]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){1}(((:[0-9A-F]{1,4}){1,6})|((:[0-9A-F]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(:(((:[0-9A-F]{1,4}){1,7})|((:[0-9A-F]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:)))(%.+)?$/i;
537
+ var reg$1 = /^((([0-9A-F]{1,4}:){7}([0-9A-F]{1,4}|:))|(([0-9A-F]{1,4}:){6}(:[0-9A-F]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){5}(((:[0-9A-F]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){4}(((:[0-9A-F]{1,4}){1,3})|((:[0-9A-F]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){3}(((:[0-9A-F]{1,4}){1,4})|((:[0-9A-F]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){2}(((:[0-9A-F]{1,4}){1,5})|((:[0-9A-F]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){1}(((:[0-9A-F]{1,4}){1,6})|((:[0-9A-F]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(:(((:[0-9A-F]{1,4}){1,7})|((:[0-9A-F]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:)))(%.+)?$/i;
526
538
  function isIPv6(value) {
527
539
  var valueStr = toString(value);
528
- return reg$2.test(valueStr);
540
+ return reg$1.test(valueStr);
529
541
  }
530
542
 
531
543
  var protocalReg = '[\\w-.]+:\\/\\/';
@@ -598,10 +610,10 @@
598
610
  return loose ? singleRegTWCard.test(valueStr) : false;
599
611
  }
600
612
 
601
- var reg$1 = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
613
+ var reg = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
602
614
  function isSwiftCode(value) {
603
615
  var valueStr = toString(value);
604
- return reg$1.test(valueStr);
616
+ return reg.test(valueStr);
605
617
  }
606
618
 
607
619
  function isValidNumber(value, strict) {
@@ -760,6 +772,8 @@
760
772
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
761
773
  };
762
774
 
775
+ var radixReg = /^[-+]?0[b|o|x]\d+/i;
776
+ var dotNumberStringReg = /^\.\d+/;
763
777
  function transformEffectiveNumber(value) {
764
778
  var ret;
765
779
  if (isString(value)) {
@@ -767,6 +781,9 @@
767
781
  if (ret === '') {
768
782
  ret = Number(ret);
769
783
  }
784
+ else if (radixReg.test(ret) || dotNumberStringReg.test(ret)) {
785
+ ret = toNumber(ret);
786
+ }
770
787
  else if (isNaN(Number(ret))) {
771
788
  ret = Number.NaN;
772
789
  }
@@ -820,47 +837,9 @@
820
837
  }
821
838
  return num;
822
839
  }
823
- function scientificToNumber(num) {
824
- var strNum = String(num);
825
- if (!isScientificNumber(strNum)) {
826
- return num;
827
- }
828
- var ret;
829
- var zero = '0';
830
- var parts = strNum.toLowerCase().split('e');
831
- var e = parts.pop();
832
- var l = Math.abs(e);
833
- var sign = e / l;
834
- var coeff_array = parts[0].split('.');
835
- if (sign === -1) {
836
- var intVal = trimLeftZero(coeff_array[0]);
837
- if (intVal.length > l) {
838
- var thanLen = intVal.length - l;
839
- var dec = coeff_array[1] || '';
840
- ret = intVal.slice(0, thanLen);
841
- if (intVal.slice(thanLen) !== '0' || dec) {
842
- ret += '.' + intVal.slice(thanLen) + dec;
843
- }
844
- }
845
- else {
846
- ret = zero + '.' + new Array(l - intVal.length + 1).join(zero) + coeff_array.join('');
847
- }
848
- }
849
- else {
850
- var dec = coeff_array[1] || '';
851
- if (l - dec.length < 0) {
852
- ret = trimLeftZero(coeff_array[0] + dec.substring(0, l)) + '.' + dec.substring(l);
853
- }
854
- else {
855
- ret = coeff_array.join('') + new Array(l - dec.length + 1).join(zero);
856
- }
857
- }
858
- return trimLeftZero(ret);
859
- }
860
840
 
861
- var reg = /^[+-]?\d*\.?\d*$/;
862
841
  function checkNumber(num) {
863
- if ((typeof num !== 'number' && typeof num !== 'string') || (typeof num === 'number' && isNaN(num)) || (typeof num === 'string' && (!(reg.test(num) || isScientificNumber(num)) || num === ''))) {
842
+ if (!isValidNumber(num)) {
864
843
  devWarn("".concat(num, " invalid parameter."));
865
844
  return false;
866
845
  }
@@ -914,7 +893,7 @@
914
893
  symbol = typeof symbol === 'string' ? symbol : '';
915
894
  thousand = typeof thousand === 'string' ? thousand : ',';
916
895
  decimal = typeof decimal === 'string' ? decimal : '.';
917
- var strNum = scientificToNumber(num) + '';
896
+ var strNum = transformEffectiveNumber(num) + '';
918
897
  var _d = __read(strNum.split('.'), 2), intStr = _d[0], decStr = _d[1];
919
898
  return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
920
899
  };
@@ -1586,7 +1565,7 @@
1586
1565
  return EmitterPro;
1587
1566
  }());
1588
1567
 
1589
- var Cache = (function (_super) {
1568
+ var Cache$1 = (function (_super) {
1590
1569
  __extends(Cache, _super);
1591
1570
  function Cache(options) {
1592
1571
  var _this = _super.call(this) || this;
@@ -1627,8 +1606,8 @@
1627
1606
  return Cache;
1628
1607
  }(EmitterPro));
1629
1608
 
1630
- var cache$2 = new Cache({ max: 1 });
1631
- cache$2.on('del', function (v) {
1609
+ var cache$3 = new Cache$1({ max: 1 });
1610
+ cache$3.on('del', function (v) {
1632
1611
  if (v.r) {
1633
1612
  try {
1634
1613
  revokeObjectURL(v.data.image.src);
@@ -1644,8 +1623,8 @@
1644
1623
  autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
1645
1624
  };
1646
1625
  return new Promise(function (resolve, reject) {
1647
- if (_cacheOptions.useCache && cache$2.has(img)) {
1648
- resolve(cache$2.get(img).data);
1626
+ if (_cacheOptions.useCache && cache$3.has(img)) {
1627
+ resolve(cache$3.get(img).data);
1649
1628
  }
1650
1629
  else {
1651
1630
  getFileBlob(img, ajaxOptions)
@@ -1655,7 +1634,7 @@
1655
1634
  image.onload = function () {
1656
1635
  var result = { blob: blob, image: image };
1657
1636
  if (_cacheOptions.useCache) {
1658
- cache$2.set(img, {
1637
+ cache$3.set(img, {
1659
1638
  data: result,
1660
1639
  r: _cacheOptions.autoRevokeOnDel
1661
1640
  });
@@ -1822,8 +1801,8 @@
1822
1801
  });
1823
1802
  }
1824
1803
 
1825
- var cache$1 = new Cache({ max: 1 });
1826
- cache$1.on('del', function (v) {
1804
+ var cache$2 = new Cache$1({ max: 1 });
1805
+ cache$2.on('del', function (v) {
1827
1806
  if (v.r) {
1828
1807
  try {
1829
1808
  revokeObjectURL(v.data.image.src);
@@ -1843,8 +1822,8 @@
1843
1822
  autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
1844
1823
  };
1845
1824
  return new Promise(function (resolve, reject) {
1846
- if (_cacheOptions.useCache && cache$1.has(img)) {
1847
- resolve(cache$1.get(img).data);
1825
+ if (_cacheOptions.useCache && cache$2.has(img)) {
1826
+ resolve(cache$2.get(img).data);
1848
1827
  }
1849
1828
  else {
1850
1829
  loadImageWithBlob(img, false, ajaxOptions)
@@ -1862,7 +1841,7 @@
1862
1841
  blob: blob
1863
1842
  };
1864
1843
  if (_cacheOptions.useCache) {
1865
- cache$1.set(img, {
1844
+ cache$2.set(img, {
1866
1845
  data: result,
1867
1846
  r: _cacheOptions.autoRevokeOnDel
1868
1847
  });
@@ -1874,8 +1853,8 @@
1874
1853
  });
1875
1854
  }
1876
1855
 
1877
- var cache = new Cache({ max: 1 });
1878
- cache.on('del', function (v) {
1856
+ var cache$1 = new Cache$1({ max: 1 });
1857
+ cache$1.on('del', function (v) {
1879
1858
  if (v.r) {
1880
1859
  try {
1881
1860
  revokeObjectURL(v.data.src);
@@ -1891,8 +1870,8 @@
1891
1870
  autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
1892
1871
  };
1893
1872
  return new Promise(function (resolve, reject) {
1894
- if (_cacheOptions.useCache && cache.has(img)) {
1895
- resolve(cache.get(img).data);
1873
+ if (_cacheOptions.useCache && cache$1.has(img)) {
1874
+ resolve(cache$1.get(img).data);
1896
1875
  }
1897
1876
  else {
1898
1877
  var imgIsBlob_1 = isBlob(img);
@@ -1903,7 +1882,7 @@
1903
1882
  }
1904
1883
  image_1.onload = function () {
1905
1884
  if (_cacheOptions.useCache) {
1906
- cache.set(img, {
1885
+ cache$1.set(img, {
1907
1886
  data: image_1,
1908
1887
  r: _cacheOptions.autoRevokeOnDel
1909
1888
  });
@@ -1969,7 +1948,7 @@
1969
1948
  }
1970
1949
  return prefix;
1971
1950
  }
1972
- function randomString(len, optionalChars) {
1951
+ function randomString$1(len, optionalChars) {
1973
1952
  if (len === void 0) { len = 0; }
1974
1953
  var realChars = typeof optionalChars === 'string' && optionalChars ? optionalChars : defaultChars;
1975
1954
  return internalRandomString(toNumber(len), realChars);
@@ -2258,10 +2237,380 @@
2258
2237
  return internalFindTreeSelect(tree, predicate, childrenField);
2259
2238
  }
2260
2239
 
2261
- var VERSION = "4.21.6";
2240
+ var VERSION = "4.22.0";
2241
+
2242
+ // 随机字符串
2243
+ function randomString() {
2244
+ return Math.random().toString(16).substring(2, 8);
2245
+ }
2246
+ // 内部自增id
2247
+ var uid = 1;
2248
+ // 返回唯一标识
2249
+ function getUniqueId() {
2250
+ return "".concat(randomString(), "_").concat(uid++);
2251
+ }
2252
+ // 是否支持 storage
2253
+ function isStorageSupported(storage) {
2254
+ try {
2255
+ var isSupport = typeof storage === 'object' &&
2256
+ storage !== null &&
2257
+ !!storage.setItem &&
2258
+ !!storage.getItem &&
2259
+ !!storage.removeItem;
2260
+ if (isSupport) {
2261
+ var key = getUniqueId();
2262
+ var value = '1';
2263
+ storage.setItem(key, value);
2264
+ if (storage.getItem(key) !== value) {
2265
+ return false;
2266
+ }
2267
+ storage.removeItem(key);
2268
+ }
2269
+ return isSupport;
2270
+ }
2271
+ catch (e) {
2272
+ console.error("[cache2] ".concat(storage, " is not supported. The default memory cache will be used."));
2273
+ return false;
2274
+ }
2275
+ }
2276
+ function parse(value, reviver) {
2277
+ try {
2278
+ return JSON.parse(value, reviver);
2279
+ }
2280
+ catch (e) {
2281
+ return value;
2282
+ }
2283
+ }
2284
+ function stringify(value, replacer) {
2285
+ return JSON.stringify(value, replacer);
2286
+ }
2287
+ var inWindow = typeof window !== 'undefined' && typeof window === 'object' && window.window === window;
2288
+
2289
+ var cache = {};
2290
+ var MemoryStorage = /** @class */ (function () {
2291
+ function MemoryStorage(scope) {
2292
+ if (scope === void 0) { scope = 'default'; }
2293
+ this.scope = scope;
2294
+ if (!cache[this.scope]) {
2295
+ cache[this.scope] = {};
2296
+ }
2297
+ this.data = cache[this.scope];
2298
+ }
2299
+ MemoryStorage.prototype.getItem = function (key) {
2300
+ return key in this.data ? this.data[key] : null;
2301
+ };
2302
+ MemoryStorage.prototype.setItem = function (key, value) {
2303
+ this.data[key] = value;
2304
+ };
2305
+ MemoryStorage.prototype.removeItem = function (key) {
2306
+ delete this.data[key];
2307
+ };
2308
+ MemoryStorage.prototype.clear = function () {
2309
+ cache[this.scope] = {};
2310
+ this.data = cache[this.scope];
2311
+ };
2312
+ return MemoryStorage;
2313
+ }());
2314
+
2315
+ var Storage = /** @class */ (function () {
2316
+ function Storage(storage, options) {
2317
+ if (options === void 0) { options = {}; }
2318
+ var isSupported = storage ? isStorageSupported(storage) : false;
2319
+ this.options = __assign({ needParsed: isSupported }, options);
2320
+ this.storage = isSupported ? storage : new MemoryStorage(this.options.memoryScope);
2321
+ }
2322
+ Storage.prototype.get = function (key) {
2323
+ var data = this.storage.getItem(key);
2324
+ return this.options.needParsed ? parse(data, this.options.reviver) : data;
2325
+ };
2326
+ Storage.prototype.set = function (key, data) {
2327
+ this.storage.setItem(key, this.options.needParsed ? stringify(data, this.options.replacer) : data);
2328
+ };
2329
+ Storage.prototype.del = function (key) {
2330
+ this.storage.removeItem(key);
2331
+ };
2332
+ Storage.prototype.clear = function () {
2333
+ if (typeof this.storage.clear === 'function') {
2334
+ this.storage.clear();
2335
+ }
2336
+ };
2337
+ return Storage;
2338
+ }());
2339
+
2340
+ var defaultPrefix = 'cache2_'; // 命名空间缓存键前缀,默认 cache2_ 。
2341
+ var defaultNamespace = 'default';
2342
+ var Cache = /** @class */ (function (_super) {
2343
+ __extends(Cache, _super);
2344
+ function Cache(namespace, options) {
2345
+ var _this = _super.call(this) || this;
2346
+ var ns = defaultNamespace, opts;
2347
+ if (typeof namespace === 'string') {
2348
+ ns = namespace;
2349
+ }
2350
+ else if (typeof namespace === 'object') {
2351
+ opts = namespace;
2352
+ }
2353
+ if (!opts && typeof options === 'object') {
2354
+ opts = options;
2355
+ }
2356
+ _this.options = __assign({ max: -1, stdTTL: 0, maxStrategy: 'limited', checkperiod: 0, prefix: defaultPrefix }, opts);
2357
+ _this.storage = new Storage(_this.options.storage, __assign({ memoryScope: ns }, opts));
2358
+ _this.cacheKey = (_this.options.prefix || '') + (ns || '') || getUniqueId();
2359
+ _this.startCheckperiod();
2360
+ return _this;
2361
+ }
2362
+ // 检查当前键值是否过期,如果过期将会自动删除
2363
+ Cache.prototype._check = function (key, data) {
2364
+ var ret = true;
2365
+ if (data.t !== 0 && data.t < Date.now()) {
2366
+ ret = false;
2367
+ this.del(key);
2368
+ this.emit('expired', key, data.v);
2369
+ }
2370
+ return ret;
2371
+ };
2372
+ Cache.prototype._wrap = function (value, ttl) {
2373
+ var now = Date.now();
2374
+ var currentTtl = typeof ttl === 'number' ? ttl : this.options.stdTTL;
2375
+ var livetime = currentTtl > 0 ? now + currentTtl : 0;
2376
+ return {
2377
+ v: value,
2378
+ t: livetime,
2379
+ n: now
2380
+ };
2381
+ };
2382
+ Cache.prototype._isLimited = function (len) {
2383
+ return this.options.max > -1 && len >= this.options.max;
2384
+ };
2385
+ Cache.prototype._getReplaceKey = function (keys, cacheValues) {
2386
+ var retkey = keys[0];
2387
+ keys.forEach(function (key) {
2388
+ if (cacheValues[key].t < cacheValues[retkey].t ||
2389
+ (cacheValues[key].t === cacheValues[retkey].t && cacheValues[key].n < cacheValues[retkey].n)) {
2390
+ retkey = key;
2391
+ }
2392
+ });
2393
+ return retkey;
2394
+ };
2395
+ Object.defineProperty(Cache.prototype, "cacheValues", {
2396
+ // 获取全部缓存数据,不处理过期数据和排序
2397
+ get: function () {
2398
+ return this.storage.get(this.cacheKey) || {};
2399
+ },
2400
+ enumerable: false,
2401
+ configurable: true
2402
+ });
2403
+ // 设置缓存数据
2404
+ Cache.prototype.setCacheValues = function (values) {
2405
+ this.storage.set(this.cacheKey, values);
2406
+ };
2407
+ // 从缓存中获取保存的值。如果未找到或已过期,则返回 undefined 。如果找到该值,则返回该值。
2408
+ Cache.prototype.get = function (key) {
2409
+ var data = this.cacheValues[key];
2410
+ if (data && this._check(key, data)) {
2411
+ return data.v;
2412
+ }
2413
+ return;
2414
+ };
2415
+ // 从缓存中获取多个保存的值。如果未找到或已过期,则返回一个空对象。如果找到该值,它会返回一个具有键值对的对象。
2416
+ Cache.prototype.mget = function (keys) {
2417
+ var _this = this;
2418
+ var ret = {};
2419
+ if (!Array.isArray(keys)) {
2420
+ return ret;
2421
+ }
2422
+ var cacheValues = this.cacheValues;
2423
+ keys.forEach(function (key) {
2424
+ var data = cacheValues[key];
2425
+ if (data && _this._check(key, data)) {
2426
+ ret[key] = data.v;
2427
+ }
2428
+ });
2429
+ return ret;
2430
+ };
2431
+ // 从缓存中获取全部保存的值。返回一个具有键值对的对象。
2432
+ Cache.prototype.getAll = function () {
2433
+ var keys = Object.keys(this.cacheValues);
2434
+ return this.mget(keys);
2435
+ };
2436
+ // 设置键值对。设置成功返回 true 。
2437
+ Cache.prototype.set = function (key, value, ttl) {
2438
+ if (this.options.max === 0) {
2439
+ return false;
2440
+ }
2441
+ var cacheValues = this.cacheValues;
2442
+ var keys = Object.keys(cacheValues);
2443
+ // 当前不存在该键值,并且数据量超过最大限制
2444
+ if (!cacheValues[key] && this._isLimited(keys.length)) {
2445
+ var validKeys = this.keys();
2446
+ if (this._isLimited(validKeys.length)) {
2447
+ // 如果最大限制策略是替换,将优先替换快过期的数据,如果都是一样的过期时间(0),按照先入先出规则处理。
2448
+ if (this.options.maxStrategy === 'replaced') {
2449
+ var replaceKey = this._getReplaceKey(validKeys, cacheValues);
2450
+ this.del(replaceKey);
2451
+ }
2452
+ else {
2453
+ // 如果是最大限制策略是不允许添加,返回 false 。
2454
+ return false;
2455
+ }
2456
+ }
2457
+ }
2458
+ cacheValues[key] = this._wrap(value, ttl);
2459
+ this.setCacheValues(cacheValues);
2460
+ this.emit('set', key, cacheValues[key].v);
2461
+ return true;
2462
+ };
2463
+ // 设置多个键值对。全部设置成功返回 true 。
2464
+ Cache.prototype.mset = function (keyValueSet) {
2465
+ var _this = this;
2466
+ // 该处不使用数组 some 方法,是因为不能某个失败,而导致其他就不在更新。
2467
+ var ret = true;
2468
+ keyValueSet.forEach(function (item) {
2469
+ var itemSetResult = _this.set(item.key, item.value, item.ttl);
2470
+ if (ret && !itemSetResult) {
2471
+ ret = false;
2472
+ }
2473
+ });
2474
+ return ret;
2475
+ };
2476
+ // 删除一个或多个键。返回已删除条目的数量。删除永远不会失败。
2477
+ Cache.prototype.del = function (key) {
2478
+ var _this = this;
2479
+ var cacheValues = this.cacheValues;
2480
+ var count = 0;
2481
+ var keys = Array.isArray(key) ? key : [key];
2482
+ keys.forEach(function (key) {
2483
+ if (cacheValues[key]) {
2484
+ count++;
2485
+ var oldData = cacheValues[key];
2486
+ delete cacheValues[key];
2487
+ _this.emit('del', key, oldData.v);
2488
+ }
2489
+ });
2490
+ if (count > 0) {
2491
+ this.setCacheValues(cacheValues);
2492
+ }
2493
+ return count;
2494
+ };
2495
+ // 删除当前所有缓存。
2496
+ Cache.prototype.clear = function () {
2497
+ this.storage.del(this.cacheKey);
2498
+ };
2499
+ // 返回所有现有键的数组。
2500
+ Cache.prototype.keys = function () {
2501
+ var _this = this;
2502
+ var cacheValues = this.cacheValues;
2503
+ var keys = Object.keys(cacheValues);
2504
+ return keys.filter(function (key) { return _this._check(key, cacheValues[key]); });
2505
+ };
2506
+ // 当前缓存是否包含某个键。
2507
+ Cache.prototype.has = function (key) {
2508
+ var data = this.cacheValues[key];
2509
+ return !!(data && this._check(key, data));
2510
+ };
2511
+ // 获取缓存值并从缓存中删除键。
2512
+ Cache.prototype.take = function (key) {
2513
+ var ret;
2514
+ var data = this.cacheValues[key];
2515
+ if (data && this._check(key, data)) {
2516
+ ret = data.v;
2517
+ this.del(key);
2518
+ }
2519
+ return ret;
2520
+ };
2521
+ // 重新定义一个键的 ttl 。如果找到并更新成功,则返回 true 。
2522
+ Cache.prototype.ttl = function (key, ttl) {
2523
+ var cacheValues = this.cacheValues;
2524
+ var data = cacheValues[key];
2525
+ if (data && this._check(key, data)) {
2526
+ cacheValues[key] = this._wrap(data.v, ttl);
2527
+ return true;
2528
+ }
2529
+ return false;
2530
+ };
2531
+ // 获取某个键的 ttl 。
2532
+ // 如果未找到键或已过期,返回 undefined 。
2533
+ // 如果 ttl 为 0 ,返回 0 。
2534
+ // 否则返回一个以毫秒为单位的时间戳,表示键值将过期的时间。
2535
+ Cache.prototype.getTtl = function (key) {
2536
+ var cacheValues = this.cacheValues;
2537
+ var data = cacheValues[key];
2538
+ if (data && this._check(key, data)) {
2539
+ return cacheValues[key].t;
2540
+ }
2541
+ return;
2542
+ };
2543
+ // 获取某个键值的最后修改时间
2544
+ // 如果未找到键或已过期,返回 undefined 。
2545
+ // 否则返回一个以毫秒为单位的时间戳,表示键值将过期的时间。
2546
+ Cache.prototype.getLastModified = function (key) {
2547
+ var cacheValues = this.cacheValues;
2548
+ var data = cacheValues[key];
2549
+ if (data && this._check(key, data)) {
2550
+ return cacheValues[key].n;
2551
+ }
2552
+ return;
2553
+ };
2554
+ // 启动定时校验过期数据
2555
+ Cache.prototype.startCheckperiod = function () {
2556
+ var _this = this;
2557
+ // 触发全部缓存数据是否过期校验
2558
+ this.keys();
2559
+ if (this.options.checkperiod > 0) {
2560
+ clearTimeout(this._checkTimeout);
2561
+ this._checkTimeout = setTimeout(function () {
2562
+ _this.startCheckperiod();
2563
+ }, this.options.checkperiod);
2564
+ }
2565
+ };
2566
+ // 停止定时校验过期数据
2567
+ Cache.prototype.stopCheckperiod = function () {
2568
+ clearTimeout(this._checkTimeout);
2569
+ };
2570
+ return Cache;
2571
+ }(EmitterPro));
2572
+
2573
+ new Storage(inWindow ? window.localStorage : undefined);
2574
+
2575
+ new Storage(inWindow ? window.sessionStorage : undefined);
2576
+
2577
+ var AsyncMemo = (function () {
2578
+ function AsyncMemo(options) {
2579
+ this.promiseCache = {};
2580
+ this.cache = new Cache('uh_async_memo', options);
2581
+ }
2582
+ AsyncMemo.prototype.run = function (asyncFn, key, options) {
2583
+ var _this = this;
2584
+ if (!isString(key)) {
2585
+ return asyncFn();
2586
+ }
2587
+ var opts = __assign({ persisted: true }, options);
2588
+ if (opts.persisted) {
2589
+ var data = this.cache.get(key);
2590
+ if (data) {
2591
+ return Promise.resolve(data);
2592
+ }
2593
+ }
2594
+ if (!this.promiseCache[key]) {
2595
+ this.promiseCache[key] = asyncFn()
2596
+ .then(function (res) {
2597
+ delete _this.promiseCache[key];
2598
+ _this.cache.set(key, res, opts.ttl);
2599
+ return res;
2600
+ })
2601
+ .catch(function (err) {
2602
+ delete _this.promiseCache[key];
2603
+ return Promise.reject(err);
2604
+ });
2605
+ }
2606
+ return this.promiseCache[key];
2607
+ };
2608
+ return AsyncMemo;
2609
+ }());
2262
2610
 
2263
- var version = "4.21.6";
2611
+ var version = "4.22.0";
2264
2612
 
2613
+ exports.AsyncMemo = AsyncMemo;
2265
2614
  exports.VERSION = VERSION;
2266
2615
  exports.ajax = ajax;
2267
2616
  exports.blobToDataURL = blobToDataURL;
@@ -2315,7 +2664,7 @@
2315
2664
  exports.padZero = padZero;
2316
2665
  exports.parseIdCard = parseIdCard;
2317
2666
  exports.plus = plus;
2318
- exports.randomString = randomString;
2667
+ exports.randomString = randomString$1;
2319
2668
  exports.replaceChar = replaceChar;
2320
2669
  exports.round = _round;
2321
2670
  exports.safeDate = safeDate;