util-helpers 4.21.7 → 4.22.1

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,6 +222,12 @@
210
222
  });
211
223
  }
212
224
 
225
+ var idCounter = 0;
226
+ function uniqueId(prefix) {
227
+ var id = ++idCounter;
228
+ return toString(prefix) + id;
229
+ }
230
+
213
231
  var reg$b = /^1[3456789]\d{9}$/;
214
232
  function isMobile(value) {
215
233
  var valueStr = toString(value);
@@ -1553,7 +1571,7 @@
1553
1571
  return EmitterPro;
1554
1572
  }());
1555
1573
 
1556
- var Cache = (function (_super) {
1574
+ var Cache$1 = (function (_super) {
1557
1575
  __extends(Cache, _super);
1558
1576
  function Cache(options) {
1559
1577
  var _this = _super.call(this) || this;
@@ -1594,8 +1612,8 @@
1594
1612
  return Cache;
1595
1613
  }(EmitterPro));
1596
1614
 
1597
- var cache$2 = new Cache({ max: 1 });
1598
- cache$2.on('del', function (v) {
1615
+ var cache$3 = new Cache$1({ max: 1 });
1616
+ cache$3.on('del', function (v) {
1599
1617
  if (v.r) {
1600
1618
  try {
1601
1619
  revokeObjectURL(v.data.image.src);
@@ -1611,8 +1629,8 @@
1611
1629
  autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
1612
1630
  };
1613
1631
  return new Promise(function (resolve, reject) {
1614
- if (_cacheOptions.useCache && cache$2.has(img)) {
1615
- resolve(cache$2.get(img).data);
1632
+ if (_cacheOptions.useCache && cache$3.has(img)) {
1633
+ resolve(cache$3.get(img).data);
1616
1634
  }
1617
1635
  else {
1618
1636
  getFileBlob(img, ajaxOptions)
@@ -1622,7 +1640,7 @@
1622
1640
  image.onload = function () {
1623
1641
  var result = { blob: blob, image: image };
1624
1642
  if (_cacheOptions.useCache) {
1625
- cache$2.set(img, {
1643
+ cache$3.set(img, {
1626
1644
  data: result,
1627
1645
  r: _cacheOptions.autoRevokeOnDel
1628
1646
  });
@@ -1789,8 +1807,8 @@
1789
1807
  });
1790
1808
  }
1791
1809
 
1792
- var cache$1 = new Cache({ max: 1 });
1793
- cache$1.on('del', function (v) {
1810
+ var cache$2 = new Cache$1({ max: 1 });
1811
+ cache$2.on('del', function (v) {
1794
1812
  if (v.r) {
1795
1813
  try {
1796
1814
  revokeObjectURL(v.data.image.src);
@@ -1810,8 +1828,8 @@
1810
1828
  autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
1811
1829
  };
1812
1830
  return new Promise(function (resolve, reject) {
1813
- if (_cacheOptions.useCache && cache$1.has(img)) {
1814
- resolve(cache$1.get(img).data);
1831
+ if (_cacheOptions.useCache && cache$2.has(img)) {
1832
+ resolve(cache$2.get(img).data);
1815
1833
  }
1816
1834
  else {
1817
1835
  loadImageWithBlob(img, false, ajaxOptions)
@@ -1829,7 +1847,7 @@
1829
1847
  blob: blob
1830
1848
  };
1831
1849
  if (_cacheOptions.useCache) {
1832
- cache$1.set(img, {
1850
+ cache$2.set(img, {
1833
1851
  data: result,
1834
1852
  r: _cacheOptions.autoRevokeOnDel
1835
1853
  });
@@ -1841,8 +1859,8 @@
1841
1859
  });
1842
1860
  }
1843
1861
 
1844
- var cache = new Cache({ max: 1 });
1845
- cache.on('del', function (v) {
1862
+ var cache$1 = new Cache$1({ max: 1 });
1863
+ cache$1.on('del', function (v) {
1846
1864
  if (v.r) {
1847
1865
  try {
1848
1866
  revokeObjectURL(v.data.src);
@@ -1858,8 +1876,8 @@
1858
1876
  autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
1859
1877
  };
1860
1878
  return new Promise(function (resolve, reject) {
1861
- if (_cacheOptions.useCache && cache.has(img)) {
1862
- resolve(cache.get(img).data);
1879
+ if (_cacheOptions.useCache && cache$1.has(img)) {
1880
+ resolve(cache$1.get(img).data);
1863
1881
  }
1864
1882
  else {
1865
1883
  var imgIsBlob_1 = isBlob(img);
@@ -1870,7 +1888,7 @@
1870
1888
  }
1871
1889
  image_1.onload = function () {
1872
1890
  if (_cacheOptions.useCache) {
1873
- cache.set(img, {
1891
+ cache$1.set(img, {
1874
1892
  data: image_1,
1875
1893
  r: _cacheOptions.autoRevokeOnDel
1876
1894
  });
@@ -1936,7 +1954,7 @@
1936
1954
  }
1937
1955
  return prefix;
1938
1956
  }
1939
- function randomString(len, optionalChars) {
1957
+ function randomString$1(len, optionalChars) {
1940
1958
  if (len === void 0) { len = 0; }
1941
1959
  var realChars = typeof optionalChars === 'string' && optionalChars ? optionalChars : defaultChars;
1942
1960
  return internalRandomString(toNumber(len), realChars);
@@ -2225,10 +2243,380 @@
2225
2243
  return internalFindTreeSelect(tree, predicate, childrenField);
2226
2244
  }
2227
2245
 
2228
- var VERSION = "4.21.7";
2246
+ var VERSION = "4.22.1";
2247
+
2248
+ // 随机字符串
2249
+ function randomString() {
2250
+ return Math.random().toString(16).substring(2, 8);
2251
+ }
2252
+ // 内部自增id
2253
+ var uid = 1;
2254
+ // 返回唯一标识
2255
+ function getUniqueId() {
2256
+ return "".concat(randomString(), "_").concat(uid++);
2257
+ }
2258
+ // 是否支持 storage
2259
+ function isStorageSupported(storage) {
2260
+ try {
2261
+ var isSupport = typeof storage === 'object' &&
2262
+ storage !== null &&
2263
+ !!storage.setItem &&
2264
+ !!storage.getItem &&
2265
+ !!storage.removeItem;
2266
+ if (isSupport) {
2267
+ var key = getUniqueId();
2268
+ var value = '1';
2269
+ storage.setItem(key, value);
2270
+ if (storage.getItem(key) !== value) {
2271
+ return false;
2272
+ }
2273
+ storage.removeItem(key);
2274
+ }
2275
+ return isSupport;
2276
+ }
2277
+ catch (e) {
2278
+ console.error("[cache2] ".concat(storage, " is not supported. The default memory cache will be used."));
2279
+ return false;
2280
+ }
2281
+ }
2282
+ function parse(value, reviver) {
2283
+ try {
2284
+ return JSON.parse(value, reviver);
2285
+ }
2286
+ catch (e) {
2287
+ return value;
2288
+ }
2289
+ }
2290
+ function stringify(value, replacer) {
2291
+ return JSON.stringify(value, replacer);
2292
+ }
2293
+ var inWindow = typeof window !== 'undefined' && typeof window === 'object' && window.window === window;
2294
+
2295
+ var cache = {};
2296
+ var MemoryStorage = /** @class */ (function () {
2297
+ function MemoryStorage(scope) {
2298
+ if (scope === void 0) { scope = 'default'; }
2299
+ this.scope = scope;
2300
+ if (!cache[this.scope]) {
2301
+ cache[this.scope] = {};
2302
+ }
2303
+ this.data = cache[this.scope];
2304
+ }
2305
+ MemoryStorage.prototype.getItem = function (key) {
2306
+ return key in this.data ? this.data[key] : null;
2307
+ };
2308
+ MemoryStorage.prototype.setItem = function (key, value) {
2309
+ this.data[key] = value;
2310
+ };
2311
+ MemoryStorage.prototype.removeItem = function (key) {
2312
+ delete this.data[key];
2313
+ };
2314
+ MemoryStorage.prototype.clear = function () {
2315
+ cache[this.scope] = {};
2316
+ this.data = cache[this.scope];
2317
+ };
2318
+ return MemoryStorage;
2319
+ }());
2320
+
2321
+ var Storage = /** @class */ (function () {
2322
+ function Storage(storage, options) {
2323
+ if (options === void 0) { options = {}; }
2324
+ var isSupported = storage ? isStorageSupported(storage) : false;
2325
+ this.options = __assign({ needParsed: isSupported }, options);
2326
+ this.storage = isSupported ? storage : new MemoryStorage(this.options.memoryScope);
2327
+ }
2328
+ Storage.prototype.get = function (key) {
2329
+ var data = this.storage.getItem(key);
2330
+ return this.options.needParsed ? parse(data, this.options.reviver) : data;
2331
+ };
2332
+ Storage.prototype.set = function (key, data) {
2333
+ this.storage.setItem(key, this.options.needParsed ? stringify(data, this.options.replacer) : data);
2334
+ };
2335
+ Storage.prototype.del = function (key) {
2336
+ this.storage.removeItem(key);
2337
+ };
2338
+ Storage.prototype.clear = function () {
2339
+ if (typeof this.storage.clear === 'function') {
2340
+ this.storage.clear();
2341
+ }
2342
+ };
2343
+ return Storage;
2344
+ }());
2345
+
2346
+ var defaultPrefix = 'cache2_'; // 命名空间缓存键前缀,默认 cache2_ 。
2347
+ var defaultNamespace = 'default';
2348
+ var Cache = /** @class */ (function (_super) {
2349
+ __extends(Cache, _super);
2350
+ function Cache(namespace, options) {
2351
+ var _this = _super.call(this) || this;
2352
+ var ns = defaultNamespace, opts;
2353
+ if (typeof namespace === 'string') {
2354
+ ns = namespace;
2355
+ }
2356
+ else if (typeof namespace === 'object') {
2357
+ opts = namespace;
2358
+ }
2359
+ if (!opts && typeof options === 'object') {
2360
+ opts = options;
2361
+ }
2362
+ _this.options = __assign({ max: -1, stdTTL: 0, maxStrategy: 'limited', checkperiod: 0, prefix: defaultPrefix }, opts);
2363
+ _this.storage = new Storage(_this.options.storage, __assign({ memoryScope: ns }, opts));
2364
+ _this.cacheKey = (_this.options.prefix || '') + (ns || '') || getUniqueId();
2365
+ _this.startCheckperiod();
2366
+ return _this;
2367
+ }
2368
+ // 检查当前键值是否过期,如果过期将会自动删除
2369
+ Cache.prototype._check = function (key, data) {
2370
+ var ret = true;
2371
+ if (data.t !== 0 && data.t < Date.now()) {
2372
+ ret = false;
2373
+ this.del(key);
2374
+ this.emit('expired', key, data.v);
2375
+ }
2376
+ return ret;
2377
+ };
2378
+ Cache.prototype._wrap = function (value, ttl) {
2379
+ var now = Date.now();
2380
+ var currentTtl = typeof ttl === 'number' ? ttl : this.options.stdTTL;
2381
+ var livetime = currentTtl > 0 ? now + currentTtl : 0;
2382
+ return {
2383
+ v: value,
2384
+ t: livetime,
2385
+ n: now
2386
+ };
2387
+ };
2388
+ Cache.prototype._isLimited = function (len) {
2389
+ return this.options.max > -1 && len >= this.options.max;
2390
+ };
2391
+ Cache.prototype._getReplaceKey = function (keys, cacheValues) {
2392
+ var retkey = keys[0];
2393
+ keys.forEach(function (key) {
2394
+ if (cacheValues[key].t < cacheValues[retkey].t ||
2395
+ (cacheValues[key].t === cacheValues[retkey].t && cacheValues[key].n < cacheValues[retkey].n)) {
2396
+ retkey = key;
2397
+ }
2398
+ });
2399
+ return retkey;
2400
+ };
2401
+ Object.defineProperty(Cache.prototype, "cacheValues", {
2402
+ // 获取全部缓存数据,不处理过期数据和排序
2403
+ get: function () {
2404
+ return this.storage.get(this.cacheKey) || {};
2405
+ },
2406
+ enumerable: false,
2407
+ configurable: true
2408
+ });
2409
+ // 设置缓存数据
2410
+ Cache.prototype.setCacheValues = function (values) {
2411
+ this.storage.set(this.cacheKey, values);
2412
+ };
2413
+ // 从缓存中获取保存的值。如果未找到或已过期,则返回 undefined 。如果找到该值,则返回该值。
2414
+ Cache.prototype.get = function (key) {
2415
+ var data = this.cacheValues[key];
2416
+ if (data && this._check(key, data)) {
2417
+ return data.v;
2418
+ }
2419
+ return;
2420
+ };
2421
+ // 从缓存中获取多个保存的值。如果未找到或已过期,则返回一个空对象。如果找到该值,它会返回一个具有键值对的对象。
2422
+ Cache.prototype.mget = function (keys) {
2423
+ var _this = this;
2424
+ var ret = {};
2425
+ if (!Array.isArray(keys)) {
2426
+ return ret;
2427
+ }
2428
+ var cacheValues = this.cacheValues;
2429
+ keys.forEach(function (key) {
2430
+ var data = cacheValues[key];
2431
+ if (data && _this._check(key, data)) {
2432
+ ret[key] = data.v;
2433
+ }
2434
+ });
2435
+ return ret;
2436
+ };
2437
+ // 从缓存中获取全部保存的值。返回一个具有键值对的对象。
2438
+ Cache.prototype.getAll = function () {
2439
+ var keys = Object.keys(this.cacheValues);
2440
+ return this.mget(keys);
2441
+ };
2442
+ // 设置键值对。设置成功返回 true 。
2443
+ Cache.prototype.set = function (key, value, ttl) {
2444
+ if (this.options.max === 0) {
2445
+ return false;
2446
+ }
2447
+ var cacheValues = this.cacheValues;
2448
+ var keys = Object.keys(cacheValues);
2449
+ // 当前不存在该键值,并且数据量超过最大限制
2450
+ if (!cacheValues[key] && this._isLimited(keys.length)) {
2451
+ var validKeys = this.keys();
2452
+ if (this._isLimited(validKeys.length)) {
2453
+ // 如果最大限制策略是替换,将优先替换快过期的数据,如果都是一样的过期时间(0),按照先入先出规则处理。
2454
+ if (this.options.maxStrategy === 'replaced') {
2455
+ var replaceKey = this._getReplaceKey(validKeys, cacheValues);
2456
+ this.del(replaceKey);
2457
+ }
2458
+ else {
2459
+ // 如果是最大限制策略是不允许添加,返回 false 。
2460
+ return false;
2461
+ }
2462
+ }
2463
+ }
2464
+ cacheValues[key] = this._wrap(value, ttl);
2465
+ this.setCacheValues(cacheValues);
2466
+ this.emit('set', key, cacheValues[key].v);
2467
+ return true;
2468
+ };
2469
+ // 设置多个键值对。全部设置成功返回 true 。
2470
+ Cache.prototype.mset = function (keyValueSet) {
2471
+ var _this = this;
2472
+ // 该处不使用数组 some 方法,是因为不能某个失败,而导致其他就不在更新。
2473
+ var ret = true;
2474
+ keyValueSet.forEach(function (item) {
2475
+ var itemSetResult = _this.set(item.key, item.value, item.ttl);
2476
+ if (ret && !itemSetResult) {
2477
+ ret = false;
2478
+ }
2479
+ });
2480
+ return ret;
2481
+ };
2482
+ // 删除一个或多个键。返回已删除条目的数量。删除永远不会失败。
2483
+ Cache.prototype.del = function (key) {
2484
+ var _this = this;
2485
+ var cacheValues = this.cacheValues;
2486
+ var count = 0;
2487
+ var keys = Array.isArray(key) ? key : [key];
2488
+ keys.forEach(function (key) {
2489
+ if (cacheValues[key]) {
2490
+ count++;
2491
+ var oldData = cacheValues[key];
2492
+ delete cacheValues[key];
2493
+ _this.emit('del', key, oldData.v);
2494
+ }
2495
+ });
2496
+ if (count > 0) {
2497
+ this.setCacheValues(cacheValues);
2498
+ }
2499
+ return count;
2500
+ };
2501
+ // 删除当前所有缓存。
2502
+ Cache.prototype.clear = function () {
2503
+ this.storage.del(this.cacheKey);
2504
+ };
2505
+ // 返回所有现有键的数组。
2506
+ Cache.prototype.keys = function () {
2507
+ var _this = this;
2508
+ var cacheValues = this.cacheValues;
2509
+ var keys = Object.keys(cacheValues);
2510
+ return keys.filter(function (key) { return _this._check(key, cacheValues[key]); });
2511
+ };
2512
+ // 当前缓存是否包含某个键。
2513
+ Cache.prototype.has = function (key) {
2514
+ var data = this.cacheValues[key];
2515
+ return !!(data && this._check(key, data));
2516
+ };
2517
+ // 获取缓存值并从缓存中删除键。
2518
+ Cache.prototype.take = function (key) {
2519
+ var ret;
2520
+ var data = this.cacheValues[key];
2521
+ if (data && this._check(key, data)) {
2522
+ ret = data.v;
2523
+ this.del(key);
2524
+ }
2525
+ return ret;
2526
+ };
2527
+ // 重新定义一个键的 ttl 。如果找到并更新成功,则返回 true 。
2528
+ Cache.prototype.ttl = function (key, ttl) {
2529
+ var cacheValues = this.cacheValues;
2530
+ var data = cacheValues[key];
2531
+ if (data && this._check(key, data)) {
2532
+ cacheValues[key] = this._wrap(data.v, ttl);
2533
+ return true;
2534
+ }
2535
+ return false;
2536
+ };
2537
+ // 获取某个键的 ttl 。
2538
+ // 如果未找到键或已过期,返回 undefined 。
2539
+ // 如果 ttl 为 0 ,返回 0 。
2540
+ // 否则返回一个以毫秒为单位的时间戳,表示键值将过期的时间。
2541
+ Cache.prototype.getTtl = function (key) {
2542
+ var cacheValues = this.cacheValues;
2543
+ var data = cacheValues[key];
2544
+ if (data && this._check(key, data)) {
2545
+ return cacheValues[key].t;
2546
+ }
2547
+ return;
2548
+ };
2549
+ // 获取某个键值的最后修改时间
2550
+ // 如果未找到键或已过期,返回 undefined 。
2551
+ // 否则返回一个以毫秒为单位的时间戳,表示键值将过期的时间。
2552
+ Cache.prototype.getLastModified = function (key) {
2553
+ var cacheValues = this.cacheValues;
2554
+ var data = cacheValues[key];
2555
+ if (data && this._check(key, data)) {
2556
+ return cacheValues[key].n;
2557
+ }
2558
+ return;
2559
+ };
2560
+ // 启动定时校验过期数据
2561
+ Cache.prototype.startCheckperiod = function () {
2562
+ var _this = this;
2563
+ // 触发全部缓存数据是否过期校验
2564
+ this.keys();
2565
+ if (this.options.checkperiod > 0) {
2566
+ clearTimeout(this._checkTimeout);
2567
+ this._checkTimeout = setTimeout(function () {
2568
+ _this.startCheckperiod();
2569
+ }, this.options.checkperiod);
2570
+ }
2571
+ };
2572
+ // 停止定时校验过期数据
2573
+ Cache.prototype.stopCheckperiod = function () {
2574
+ clearTimeout(this._checkTimeout);
2575
+ };
2576
+ return Cache;
2577
+ }(EmitterPro));
2578
+
2579
+ new Storage(inWindow ? window.localStorage : undefined);
2580
+
2581
+ new Storage(inWindow ? window.sessionStorage : undefined);
2582
+
2583
+ var AsyncMemo = (function () {
2584
+ function AsyncMemo(options) {
2585
+ this.promiseCache = {};
2586
+ this.cache = new Cache(uniqueId('uh_async_memo'), options);
2587
+ }
2588
+ AsyncMemo.prototype.run = function (asyncFn, key, options) {
2589
+ var _this = this;
2590
+ if (!isString(key)) {
2591
+ return asyncFn();
2592
+ }
2593
+ var opts = __assign({ persisted: true }, options);
2594
+ if (opts.persisted) {
2595
+ var data = this.cache.get(key);
2596
+ if (data) {
2597
+ return Promise.resolve(data);
2598
+ }
2599
+ }
2600
+ if (!this.promiseCache[key]) {
2601
+ this.promiseCache[key] = asyncFn()
2602
+ .then(function (res) {
2603
+ delete _this.promiseCache[key];
2604
+ _this.cache.set(key, res, opts.ttl);
2605
+ return res;
2606
+ })
2607
+ .catch(function (err) {
2608
+ delete _this.promiseCache[key];
2609
+ return Promise.reject(err);
2610
+ });
2611
+ }
2612
+ return this.promiseCache[key];
2613
+ };
2614
+ return AsyncMemo;
2615
+ }());
2229
2616
 
2230
- var version = "4.21.7";
2617
+ var version = "4.22.1";
2231
2618
 
2619
+ exports.AsyncMemo = AsyncMemo;
2232
2620
  exports.VERSION = VERSION;
2233
2621
  exports.ajax = ajax;
2234
2622
  exports.blobToDataURL = blobToDataURL;
@@ -2282,7 +2670,7 @@
2282
2670
  exports.padZero = padZero;
2283
2671
  exports.parseIdCard = parseIdCard;
2284
2672
  exports.plus = plus;
2285
- exports.randomString = randomString;
2673
+ exports.randomString = randomString$1;
2286
2674
  exports.replaceChar = replaceChar;
2287
2675
  exports.round = _round;
2288
2676
  exports.safeDate = safeDate;