ut2 1.13.0 → 1.14.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.
Files changed (135) hide show
  1. package/README.md +3 -1
  2. package/dist/ut2.js +128 -34
  3. package/dist/ut2.js.map +1 -1
  4. package/dist/ut2.min.js +1 -1
  5. package/dist/ut2.min.js.map +1 -1
  6. package/es/findKey.js +1 -1
  7. package/es/guard.js +19 -0
  8. package/es/index.js +3 -1
  9. package/es/internals/helpers.js +1 -1
  10. package/es/retry.js +43 -0
  11. package/es/tryit.js +1 -1
  12. package/lib/findKey.js +3 -3
  13. package/lib/guard.js +21 -0
  14. package/lib/index.js +6 -2
  15. package/lib/internals/helpers.js +1 -1
  16. package/lib/retry.js +45 -0
  17. package/lib/tryit.js +2 -2
  18. package/package.json +4 -2
  19. package/types/after.d.ts +0 -1
  20. package/types/allKeys.d.ts +0 -1
  21. package/types/allKeysIn.d.ts +0 -1
  22. package/types/before.d.ts +0 -1
  23. package/types/camelCase.d.ts +1 -2
  24. package/types/capitalize.d.ts +0 -1
  25. package/types/castArray.d.ts +0 -1
  26. package/types/ceil.d.ts +1 -2
  27. package/types/chunk.d.ts +0 -1
  28. package/types/compact.d.ts +1 -2
  29. package/types/constant.d.ts +0 -1
  30. package/types/debounce.d.ts +0 -1
  31. package/types/delay.d.ts +0 -1
  32. package/types/difference.d.ts +0 -1
  33. package/types/eq.d.ts +1 -2
  34. package/types/escape.d.ts +1 -2
  35. package/types/escapeRegExp.d.ts +1 -2
  36. package/types/filter.d.ts +0 -1
  37. package/types/floor.d.ts +1 -2
  38. package/types/fromPairs.d.ts +0 -1
  39. package/types/groupBy.d.ts +0 -1
  40. package/types/guard.d.ts +22 -0
  41. package/types/identity.d.ts +0 -1
  42. package/types/inRange.d.ts +0 -1
  43. package/types/index.d.ts +3 -1
  44. package/types/internals/helpers.d.ts +2 -6
  45. package/types/internals/native.d.ts +6 -12
  46. package/types/internals/root.d.ts +2 -3
  47. package/types/internals/types.d.ts +4 -0
  48. package/types/intersection.d.ts +0 -1
  49. package/types/invert.d.ts +1 -2
  50. package/types/isArguments.d.ts +0 -1
  51. package/types/isArray.d.ts +0 -1
  52. package/types/isArrayBuffer.d.ts +0 -1
  53. package/types/isArrayLike.d.ts +0 -1
  54. package/types/isArrayLikeObject.d.ts +0 -1
  55. package/types/isBigInt.d.ts +0 -1
  56. package/types/isBlob.d.ts +2 -3
  57. package/types/isBoolean.d.ts +0 -1
  58. package/types/isBuffer.d.ts +0 -1
  59. package/types/isDataView.d.ts +0 -1
  60. package/types/isDate.d.ts +0 -1
  61. package/types/isElement.d.ts +0 -1
  62. package/types/isEmpty.d.ts +0 -1
  63. package/types/isEqual.d.ts +0 -1
  64. package/types/isError.d.ts +0 -1
  65. package/types/isFile.d.ts +1 -2
  66. package/types/isFinite.d.ts +0 -1
  67. package/types/isFunction.d.ts +0 -1
  68. package/types/isInteger.d.ts +0 -1
  69. package/types/isLength.d.ts +1 -2
  70. package/types/isMap.d.ts +0 -1
  71. package/types/isMatch.d.ts +0 -1
  72. package/types/isNaN.d.ts +0 -1
  73. package/types/isNil.d.ts +0 -1
  74. package/types/isNull.d.ts +0 -1
  75. package/types/isNumber.d.ts +0 -1
  76. package/types/isObject.d.ts +1 -2
  77. package/types/isObjectLike.d.ts +0 -1
  78. package/types/isPlainObject.d.ts +0 -1
  79. package/types/isPromiseLike.d.ts +0 -1
  80. package/types/isRegExp.d.ts +0 -1
  81. package/types/isSafeInteger.d.ts +0 -1
  82. package/types/isSet.d.ts +0 -1
  83. package/types/isString.d.ts +0 -1
  84. package/types/isSymbol.d.ts +0 -1
  85. package/types/isTypedArray.d.ts +1 -2
  86. package/types/isUndefined.d.ts +0 -1
  87. package/types/isWeakMap.d.ts +0 -1
  88. package/types/isWeakSet.d.ts +0 -1
  89. package/types/isWindow.d.ts +0 -1
  90. package/types/kebabCase.d.ts +1 -2
  91. package/types/keys.d.ts +0 -1
  92. package/types/keysIn.d.ts +0 -1
  93. package/types/lowerCase.d.ts +0 -1
  94. package/types/map.d.ts +0 -1
  95. package/types/merge.d.ts +0 -1
  96. package/types/min.d.ts +0 -1
  97. package/types/move.d.ts +1 -2
  98. package/types/negate.d.ts +0 -1
  99. package/types/noop.d.ts +0 -1
  100. package/types/nth.d.ts +0 -1
  101. package/types/nthArg.d.ts +0 -1
  102. package/types/omit.d.ts +0 -1
  103. package/types/omitBy.d.ts +1 -2
  104. package/types/once.d.ts +0 -1
  105. package/types/orderBy.d.ts +1 -1
  106. package/types/partition.d.ts +2 -3
  107. package/types/pascalCase.d.ts +1 -2
  108. package/types/pick.d.ts +0 -1
  109. package/types/pickBy.d.ts +1 -2
  110. package/types/random.d.ts +0 -1
  111. package/types/randomInt.d.ts +0 -1
  112. package/types/retry.d.ts +31 -0
  113. package/types/round.d.ts +1 -2
  114. package/types/shuffle.d.ts +0 -1
  115. package/types/sleep.d.ts +0 -1
  116. package/types/snakeCase.d.ts +1 -2
  117. package/types/throttle.d.ts +0 -1
  118. package/types/toFinite.d.ts +0 -1
  119. package/types/toInteger.d.ts +0 -1
  120. package/types/toLength.d.ts +1 -2
  121. package/types/toNumber.d.ts +0 -1
  122. package/types/toSafeInteger.d.ts +0 -1
  123. package/types/toString.d.ts +0 -1
  124. package/types/tryit.d.ts +1 -2
  125. package/types/unescape.d.ts +0 -1
  126. package/types/union.d.ts +0 -1
  127. package/types/uniq.d.ts +0 -1
  128. package/types/uniqueId.d.ts +0 -1
  129. package/types/unzip.d.ts +0 -1
  130. package/types/upperCase.d.ts +0 -1
  131. package/types/words.d.ts +1 -2
  132. package/types/xor.d.ts +0 -1
  133. package/types/zip.d.ts +0 -1
  134. package/es/node_modules/.pnpm/@rollup_plugin-typescript@11.1.6_rollup@4.18.0_tslib@2.6.3_typescript@5.5.2/node_modules/tslib/tslib.es6.js +0 -62
  135. package/lib/node_modules/.pnpm/@rollup_plugin-typescript@11.1.6_rollup@4.18.0_tslib@2.6.3_typescript@5.5.2/node_modules/tslib/tslib.es6.js +0 -66
package/README.md CHANGED
@@ -185,7 +185,8 @@ const debounced = debounce(() => {
185
185
  - [defaultTo](https://caijf.github.io/ut2/module-Util.html#.defaultTo) - 默认值。
186
186
  - [eq](https://caijf.github.io/ut2/module-Util.html#.eq) - 等于。
187
187
  - [gt](https://caijf.github.io/ut2/module-Util.html#.gt) - 大于。
188
- - [gte](https://caijf.github.io/ut2/module-Util.html#.gte) - 大于等于
188
+ - [gte](https://caijf.github.io/ut2/module-Util.html#.gte) - 大于等于。
189
+ - [guard](https://caijf.github.io/ut2/module-Util.html#.guard) - 函数守卫。
189
190
  - [identity](https://caijf.github.io/ut2/module-Util.html#.identity) - 返回第一个参数的函数。
190
191
  - [list](https://caijf.github.io/ut2/module-Util.html#.list) - 迭代执行次数。
191
192
  - [lt](https://caijf.github.io/ut2/module-Util.html#.lt) - 小于。
@@ -193,6 +194,7 @@ const debounced = debounce(() => {
193
194
  - [noop](https://caijf.github.io/ut2/module-Util.html#.noop) - 空函数。
194
195
  - [nthArg](https://caijf.github.io/ut2/module-Util.html#.nthArg) - 返回指定位置参数的函数。
195
196
  - [range](https://caijf.github.io/ut2/module-Util.html#.range) - 创建升序或降序的数字数组。
197
+ - [retry](https://caijf.github.io/ut2/module-Util.html#.retry) - 异步函数错误重试。
196
198
  - [sleep](https://caijf.github.io/ut2/module-Util.html#.sleep) - 返回 `promise` 延迟。
197
199
  - [toFinite](https://caijf.github.io/ut2/module-Util.html#.toFinite) - 转为有限数字。
198
200
  - [toInteger](https://caijf.github.io/ut2/module-Util.html#.toInteger) - 转为整数。
package/dist/ut2.js CHANGED
@@ -606,7 +606,7 @@
606
606
  return value == null || value !== value ? defaultValue : value;
607
607
  };
608
608
 
609
- var VERSION = "1.13.0";
609
+ var VERSION = "1.14.0";
610
610
  var isBrowser = typeof window !== stringUndefined && isObjectLike(window) && typeof document !== stringUndefined && isObjectLike(document) && window.document === document;
611
611
  var supportedArgumentsType = getTag((function () { return arguments; })()) === argumentsTag;
612
612
  var FUNC_ERROR_TEXT = 'Expected a function';
@@ -1444,9 +1444,47 @@
1444
1444
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1445
1445
  PERFORMANCE OF THIS SOFTWARE.
1446
1446
  ***************************************************************************** */
1447
- /* global Reflect, Promise, SuppressedError, Symbol */
1447
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1448
1448
 
1449
1449
 
1450
+ function __awaiter(thisArg, _arguments, P, generator) {
1451
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1452
+ return new (P || (P = Promise))(function (resolve, reject) {
1453
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1454
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1455
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1456
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1457
+ });
1458
+ }
1459
+
1460
+ function __generator(thisArg, body) {
1461
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
1462
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1463
+ function verb(n) { return function (v) { return step([n, v]); }; }
1464
+ function step(op) {
1465
+ if (f) throw new TypeError("Generator is already executing.");
1466
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
1467
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1468
+ if (y = 0, t) op = [op[0] & 2, t.value];
1469
+ switch (op[0]) {
1470
+ case 0: case 1: t = op; break;
1471
+ case 4: _.label++; return { value: op[1], done: false };
1472
+ case 5: _.label++; y = op[1]; op = [0]; continue;
1473
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
1474
+ default:
1475
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1476
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1477
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1478
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1479
+ if (t[2]) _.ops.pop();
1480
+ _.trys.pop(); continue;
1481
+ }
1482
+ op = body.call(thisArg, _);
1483
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1484
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1485
+ }
1486
+ }
1487
+
1450
1488
  function __values(o) {
1451
1489
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1452
1490
  if (m) return m.call(o);
@@ -1791,6 +1829,38 @@
1791
1829
 
1792
1830
  var gte = createOperation(baseGte);
1793
1831
 
1832
+ var guard = function (fn, shouldGuard) {
1833
+ var _guard = function (err) {
1834
+ if (shouldGuard && !shouldGuard(err)) {
1835
+ throw err;
1836
+ }
1837
+ return undefined;
1838
+ };
1839
+ try {
1840
+ var result = fn();
1841
+ return isPromiseLike(result) ? result.catch(_guard) : result;
1842
+ }
1843
+ catch (err) {
1844
+ return _guard(err);
1845
+ }
1846
+ };
1847
+
1848
+ var list = function (n, iteratee) {
1849
+ if (iteratee === void 0) { iteratee = identity; }
1850
+ if (n < 1 || n > MAX_SAFE_INTEGER) {
1851
+ return [];
1852
+ }
1853
+ var index = 0;
1854
+ var length = mathMin(isInteger(n) ? n : mathFloor(isFinite(n) ? n : 0), MAX_ARRAY_LENGTH);
1855
+ var result = Array(length);
1856
+ var func = typeof iteratee === 'function' ? iteratee : identity;
1857
+ while (index < length) {
1858
+ result[index] = func(index);
1859
+ index++;
1860
+ }
1861
+ return result;
1862
+ };
1863
+
1794
1864
  var lt = createOperation(baseLt);
1795
1865
 
1796
1866
  var lte = createOperation(baseLte);
@@ -1838,38 +1908,6 @@
1838
1908
  });
1839
1909
  }
1840
1910
 
1841
- var list = function (n, iteratee) {
1842
- if (iteratee === void 0) { iteratee = identity; }
1843
- if (n < 1 || n > MAX_SAFE_INTEGER) {
1844
- return [];
1845
- }
1846
- var index = 0;
1847
- var length = mathMin(isInteger(n) ? n : mathFloor(isFinite(n) ? n : 0), MAX_ARRAY_LENGTH);
1848
- var result = Array(length);
1849
- var func = typeof iteratee === 'function' ? iteratee : identity;
1850
- while (index < length) {
1851
- result[index] = func(index);
1852
- index++;
1853
- }
1854
- return result;
1855
- };
1856
-
1857
- var times = list;
1858
-
1859
- function toSafeInteger(value) {
1860
- if (!value) {
1861
- return value === 0 ? value : 0;
1862
- }
1863
- value = toInteger(value);
1864
- if (value > MAX_SAFE_INTEGER) {
1865
- return MAX_SAFE_INTEGER;
1866
- }
1867
- if (value < MIN_SAFE_INTEGER) {
1868
- return MIN_SAFE_INTEGER;
1869
- }
1870
- return value;
1871
- }
1872
-
1873
1911
  var tryit = function (fn) {
1874
1912
  return function () {
1875
1913
  var args = [];
@@ -1895,6 +1933,60 @@
1895
1933
  };
1896
1934
  };
1897
1935
 
1936
+ function retry(fn, options) {
1937
+ return __awaiter(this, void 0, void 0, function () {
1938
+ var _a, _b, times, delay, backoff, exit, i, _c, err, result;
1939
+ return __generator(this, function (_d) {
1940
+ switch (_d.label) {
1941
+ case 0:
1942
+ _a = options || {}, _b = _a.times, times = _b === void 0 ? 3 : _b, delay = _a.delay, backoff = _a.backoff, exit = _a.exit;
1943
+ i = 1;
1944
+ _d.label = 1;
1945
+ case 1:
1946
+ if (!(i <= times)) return [3, 7];
1947
+ return [4, tryit(fn)()];
1948
+ case 2:
1949
+ _c = __read.apply(void 0, [_d.sent(), 2]), err = _c[0], result = _c[1];
1950
+ if (!err)
1951
+ return [2, result];
1952
+ if ((exit && exit(err, i)) || i === times)
1953
+ throw err;
1954
+ if (!delay) return [3, 4];
1955
+ return [4, sleep(delay)];
1956
+ case 3:
1957
+ _d.sent();
1958
+ _d.label = 4;
1959
+ case 4:
1960
+ if (!backoff) return [3, 6];
1961
+ return [4, sleep(backoff(i))];
1962
+ case 5:
1963
+ _d.sent();
1964
+ _d.label = 6;
1965
+ case 6:
1966
+ i++;
1967
+ return [3, 1];
1968
+ case 7: return [2];
1969
+ }
1970
+ });
1971
+ });
1972
+ }
1973
+
1974
+ var times = list;
1975
+
1976
+ function toSafeInteger(value) {
1977
+ if (!value) {
1978
+ return value === 0 ? value : 0;
1979
+ }
1980
+ value = toInteger(value);
1981
+ if (value > MAX_SAFE_INTEGER) {
1982
+ return MAX_SAFE_INTEGER;
1983
+ }
1984
+ if (value < MIN_SAFE_INTEGER) {
1985
+ return MIN_SAFE_INTEGER;
1986
+ }
1987
+ return value;
1988
+ }
1989
+
1898
1990
  var idCounter = 0;
1899
1991
  var defaultPrefix = '_' + mathRandom().toString(36).substring(2, 4);
1900
1992
  function uniqueId(prefix) {
@@ -1940,6 +2032,7 @@
1940
2032
  exports.groupBy = groupBy;
1941
2033
  exports.gt = gt;
1942
2034
  exports.gte = gte;
2035
+ exports.guard = guard;
1943
2036
  exports.identity = identity;
1944
2037
  exports.inRange = inRange;
1945
2038
  exports.intersection = intersection;
@@ -2017,6 +2110,7 @@
2017
2110
  exports.range = range;
2018
2111
  exports.reduce = reduce;
2019
2112
  exports.reduceRight = reduceRight;
2113
+ exports.retry = retry;
2020
2114
  exports.root = root;
2021
2115
  exports.round = round;
2022
2116
  exports.shuffle = shuffle;