util-helpers 4.21.7 → 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
  }
@@ -1553,7 +1565,7 @@
1553
1565
  return EmitterPro;
1554
1566
  }());
1555
1567
 
1556
- var Cache = (function (_super) {
1568
+ var Cache$1 = (function (_super) {
1557
1569
  __extends(Cache, _super);
1558
1570
  function Cache(options) {
1559
1571
  var _this = _super.call(this) || this;
@@ -1594,8 +1606,8 @@
1594
1606
  return Cache;
1595
1607
  }(EmitterPro));
1596
1608
 
1597
- var cache$2 = new Cache({ max: 1 });
1598
- cache$2.on('del', function (v) {
1609
+ var cache$3 = new Cache$1({ max: 1 });
1610
+ cache$3.on('del', function (v) {
1599
1611
  if (v.r) {
1600
1612
  try {
1601
1613
  revokeObjectURL(v.data.image.src);
@@ -1611,8 +1623,8 @@
1611
1623
  autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
1612
1624
  };
1613
1625
  return new Promise(function (resolve, reject) {
1614
- if (_cacheOptions.useCache && cache$2.has(img)) {
1615
- resolve(cache$2.get(img).data);
1626
+ if (_cacheOptions.useCache && cache$3.has(img)) {
1627
+ resolve(cache$3.get(img).data);
1616
1628
  }
1617
1629
  else {
1618
1630
  getFileBlob(img, ajaxOptions)
@@ -1622,7 +1634,7 @@
1622
1634
  image.onload = function () {
1623
1635
  var result = { blob: blob, image: image };
1624
1636
  if (_cacheOptions.useCache) {
1625
- cache$2.set(img, {
1637
+ cache$3.set(img, {
1626
1638
  data: result,
1627
1639
  r: _cacheOptions.autoRevokeOnDel
1628
1640
  });
@@ -1789,8 +1801,8 @@
1789
1801
  });
1790
1802
  }
1791
1803
 
1792
- var cache$1 = new Cache({ max: 1 });
1793
- cache$1.on('del', function (v) {
1804
+ var cache$2 = new Cache$1({ max: 1 });
1805
+ cache$2.on('del', function (v) {
1794
1806
  if (v.r) {
1795
1807
  try {
1796
1808
  revokeObjectURL(v.data.image.src);
@@ -1810,8 +1822,8 @@
1810
1822
  autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
1811
1823
  };
1812
1824
  return new Promise(function (resolve, reject) {
1813
- if (_cacheOptions.useCache && cache$1.has(img)) {
1814
- resolve(cache$1.get(img).data);
1825
+ if (_cacheOptions.useCache && cache$2.has(img)) {
1826
+ resolve(cache$2.get(img).data);
1815
1827
  }
1816
1828
  else {
1817
1829
  loadImageWithBlob(img, false, ajaxOptions)
@@ -1829,7 +1841,7 @@
1829
1841
  blob: blob
1830
1842
  };
1831
1843
  if (_cacheOptions.useCache) {
1832
- cache$1.set(img, {
1844
+ cache$2.set(img, {
1833
1845
  data: result,
1834
1846
  r: _cacheOptions.autoRevokeOnDel
1835
1847
  });
@@ -1841,8 +1853,8 @@
1841
1853
  });
1842
1854
  }
1843
1855
 
1844
- var cache = new Cache({ max: 1 });
1845
- cache.on('del', function (v) {
1856
+ var cache$1 = new Cache$1({ max: 1 });
1857
+ cache$1.on('del', function (v) {
1846
1858
  if (v.r) {
1847
1859
  try {
1848
1860
  revokeObjectURL(v.data.src);
@@ -1858,8 +1870,8 @@
1858
1870
  autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
1859
1871
  };
1860
1872
  return new Promise(function (resolve, reject) {
1861
- if (_cacheOptions.useCache && cache.has(img)) {
1862
- resolve(cache.get(img).data);
1873
+ if (_cacheOptions.useCache && cache$1.has(img)) {
1874
+ resolve(cache$1.get(img).data);
1863
1875
  }
1864
1876
  else {
1865
1877
  var imgIsBlob_1 = isBlob(img);
@@ -1870,7 +1882,7 @@
1870
1882
  }
1871
1883
  image_1.onload = function () {
1872
1884
  if (_cacheOptions.useCache) {
1873
- cache.set(img, {
1885
+ cache$1.set(img, {
1874
1886
  data: image_1,
1875
1887
  r: _cacheOptions.autoRevokeOnDel
1876
1888
  });
@@ -1936,7 +1948,7 @@
1936
1948
  }
1937
1949
  return prefix;
1938
1950
  }
1939
- function randomString(len, optionalChars) {
1951
+ function randomString$1(len, optionalChars) {
1940
1952
  if (len === void 0) { len = 0; }
1941
1953
  var realChars = typeof optionalChars === 'string' && optionalChars ? optionalChars : defaultChars;
1942
1954
  return internalRandomString(toNumber(len), realChars);
@@ -2225,10 +2237,380 @@
2225
2237
  return internalFindTreeSelect(tree, predicate, childrenField);
2226
2238
  }
2227
2239
 
2228
- var VERSION = "4.21.7";
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
+ }());
2229
2610
 
2230
- var version = "4.21.7";
2611
+ var version = "4.22.0";
2231
2612
 
2613
+ exports.AsyncMemo = AsyncMemo;
2232
2614
  exports.VERSION = VERSION;
2233
2615
  exports.ajax = ajax;
2234
2616
  exports.blobToDataURL = blobToDataURL;
@@ -2282,7 +2664,7 @@
2282
2664
  exports.padZero = padZero;
2283
2665
  exports.parseIdCard = parseIdCard;
2284
2666
  exports.plus = plus;
2285
- exports.randomString = randomString;
2667
+ exports.randomString = randomString$1;
2286
2668
  exports.replaceChar = replaceChar;
2287
2669
  exports.round = _round;
2288
2670
  exports.safeDate = safeDate;