umt 2.16.0 → 2.17.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 (275) hide show
  1. package/README.md +42 -0
  2. package/module/Array/chunk.js.map +1 -1
  3. package/module/Array/uniqBy.js.map +1 -1
  4. package/module/Async/debounceAsync.d.ts +18 -0
  5. package/module/Async/debounceAsync.js +59 -0
  6. package/module/Async/debounceAsync.js.map +1 -0
  7. package/module/Async/index.d.ts +5 -0
  8. package/module/Async/index.js +5 -0
  9. package/module/Async/index.js.map +1 -1
  10. package/module/Async/pSettled.d.ts +19 -0
  11. package/module/Async/pSettled.js +54 -0
  12. package/module/Async/pSettled.js.map +1 -0
  13. package/module/Async/retry.d.ts +22 -0
  14. package/module/Async/retry.js +49 -0
  15. package/module/Async/retry.js.map +1 -0
  16. package/module/Async/throttleAsync.d.ts +18 -0
  17. package/module/Async/throttleAsync.js +41 -0
  18. package/module/Async/throttleAsync.js.map +1 -0
  19. package/module/Async/waitFor.d.ts +18 -0
  20. package/module/Async/waitFor.js +32 -0
  21. package/module/Async/waitFor.js.map +1 -0
  22. package/module/Date/addDuration.d.ts +15 -0
  23. package/module/Date/addDuration.js +40 -0
  24. package/module/Date/addDuration.js.map +1 -0
  25. package/module/Date/diff.d.ts +14 -0
  26. package/module/Date/diff.js +45 -0
  27. package/module/Date/diff.js.map +1 -0
  28. package/module/Date/durationUnit.d.ts +12 -0
  29. package/module/Date/durationUnit.js +2 -0
  30. package/module/Date/durationUnit.js.map +1 -0
  31. package/module/Date/endOf.d.ts +13 -0
  32. package/module/Date/endOf.js +58 -0
  33. package/module/Date/endOf.js.map +1 -0
  34. package/module/Date/formatRelative.d.ts +13 -0
  35. package/module/Date/formatRelative.js +35 -0
  36. package/module/Date/formatRelative.js.map +1 -0
  37. package/module/Date/index.d.ts +10 -0
  38. package/module/Date/index.js +10 -0
  39. package/module/Date/index.js.map +1 -1
  40. package/module/Date/isBusinessDay.d.ts +10 -0
  41. package/module/Date/isBusinessDay.js +18 -0
  42. package/module/Date/isBusinessDay.js.map +1 -0
  43. package/module/Date/isSameDay.d.ts +10 -0
  44. package/module/Date/isSameDay.js +13 -0
  45. package/module/Date/isSameDay.js.map +1 -0
  46. package/module/Date/isWeekend.d.ts +9 -0
  47. package/module/Date/isWeekend.js +13 -0
  48. package/module/Date/isWeekend.js.map +1 -0
  49. package/module/Date/msByUnit.d.ts +2 -0
  50. package/module/Date/msByUnit.js +10 -0
  51. package/module/Date/msByUnit.js.map +1 -0
  52. package/module/Date/startOf.d.ts +13 -0
  53. package/module/Date/startOf.js +58 -0
  54. package/module/Date/startOf.js.map +1 -0
  55. package/module/Date/subDuration.d.ts +13 -0
  56. package/module/Date/subDuration.js +14 -0
  57. package/module/Date/subDuration.js.map +1 -0
  58. package/module/Error/index.d.ts +0 -1
  59. package/module/Error/index.js +0 -1
  60. package/module/Error/index.js.map +1 -1
  61. package/module/Object/deepClone.js.map +1 -1
  62. package/module/Object/flattenObject.d.ts +11 -0
  63. package/module/Object/flattenObject.js +29 -0
  64. package/module/Object/flattenObject.js.map +1 -0
  65. package/module/Object/get.d.ts +1 -0
  66. package/module/Object/get.js +26 -0
  67. package/module/Object/get.js.map +1 -0
  68. package/module/Object/has.d.ts +0 -19
  69. package/module/Object/has.js +4 -4
  70. package/module/Object/has.js.map +1 -1
  71. package/module/Object/index.d.ts +8 -0
  72. package/module/Object/index.js +8 -0
  73. package/module/Object/index.js.map +1 -1
  74. package/module/Object/invert.d.ts +12 -0
  75. package/module/Object/invert.js +20 -0
  76. package/module/Object/invert.js.map +1 -0
  77. package/module/Object/mergeDeep.js.map +1 -1
  78. package/module/Object/omitBy.d.ts +11 -0
  79. package/module/Object/omitBy.js +21 -0
  80. package/module/Object/omitBy.js.map +1 -0
  81. package/module/Object/pathSegments.d.ts +1 -0
  82. package/module/Object/pathSegments.js +2 -0
  83. package/module/Object/pathSegments.js.map +1 -0
  84. package/module/Object/pickBy.d.ts +11 -0
  85. package/module/Object/pickBy.js +21 -0
  86. package/module/Object/pickBy.js.map +1 -0
  87. package/module/Object/set.d.ts +19 -0
  88. package/module/Object/set.js +38 -0
  89. package/module/Object/set.js.map +1 -0
  90. package/module/Object/unflattenObject.d.ts +15 -0
  91. package/module/Object/unflattenObject.js +23 -0
  92. package/module/Object/unflattenObject.js.map +1 -0
  93. package/module/Random/index.d.ts +7 -0
  94. package/module/Random/index.js +8 -0
  95. package/module/Random/index.js.map +1 -0
  96. package/module/Random/randomBoolean.d.ts +9 -0
  97. package/module/Random/randomBoolean.js +10 -0
  98. package/module/Random/randomBoolean.js.map +1 -0
  99. package/module/Random/randomChoice.d.ts +9 -0
  100. package/module/Random/randomChoice.js +13 -0
  101. package/module/Random/randomChoice.js.map +1 -0
  102. package/module/Random/randomFloat.d.ts +9 -0
  103. package/module/Random/randomFloat.js +10 -0
  104. package/module/Random/randomFloat.js.map +1 -0
  105. package/module/Random/randomInt.d.ts +9 -0
  106. package/module/Random/randomInt.js +14 -0
  107. package/module/Random/randomInt.js.map +1 -0
  108. package/module/Random/randomUuid.d.ts +9 -0
  109. package/module/Random/randomUuid.js +31 -0
  110. package/module/Random/randomUuid.js.map +1 -0
  111. package/module/Random/seededRandom.d.ts +11 -0
  112. package/module/Random/seededRandom.js +31 -0
  113. package/module/Random/seededRandom.js.map +1 -0
  114. package/module/Random/weightedChoice.d.ts +15 -0
  115. package/module/Random/weightedChoice.js +34 -0
  116. package/module/Random/weightedChoice.js.map +1 -0
  117. package/module/String/capitalize.d.ts +12 -0
  118. package/module/String/capitalize.js +18 -0
  119. package/module/String/capitalize.js.map +1 -0
  120. package/module/String/capitalizeWord.d.ts +1 -0
  121. package/module/String/capitalizeWord.js +2 -0
  122. package/module/String/capitalizeWord.js.map +1 -0
  123. package/module/String/dedent.d.ts +19 -0
  124. package/module/String/dedent.js +56 -0
  125. package/module/String/dedent.js.map +1 -0
  126. package/module/String/index.d.ts +10 -0
  127. package/module/String/index.js +10 -0
  128. package/module/String/index.js.map +1 -1
  129. package/module/String/mask.d.ts +20 -0
  130. package/module/String/mask.js +24 -0
  131. package/module/String/mask.js.map +1 -0
  132. package/module/String/pascalCase.d.ts +9 -0
  133. package/module/String/pascalCase.js +14 -0
  134. package/module/String/pascalCase.js.map +1 -0
  135. package/module/String/snakeCase.d.ts +9 -0
  136. package/module/String/snakeCase.js +13 -0
  137. package/module/String/snakeCase.js.map +1 -0
  138. package/module/String/titleCase.d.ts +9 -0
  139. package/module/String/titleCase.js +14 -0
  140. package/module/String/titleCase.js.map +1 -0
  141. package/module/String/uncapitalize.d.ts +10 -0
  142. package/module/String/uncapitalize.js +16 -0
  143. package/module/String/uncapitalize.js.map +1 -0
  144. package/module/String/wordCount.d.ts +10 -0
  145. package/module/String/wordCount.js +12 -0
  146. package/module/String/wordCount.js.map +1 -0
  147. package/module/String/words.d.ts +12 -0
  148. package/module/String/words.js +21 -0
  149. package/module/String/words.js.map +1 -0
  150. package/module/Tool/createPipeline.d.ts +1 -1
  151. package/module/Tool/createPipeline.js +8 -6
  152. package/module/Tool/createPipeline.js.map +1 -1
  153. package/module/Tool/pipe.js.map +1 -1
  154. package/module/URL/buildUrl.d.ts +10 -0
  155. package/module/URL/buildUrl.js +10 -4
  156. package/module/URL/buildUrl.js.map +1 -1
  157. package/module/URL/parseQueryString.d.ts +6 -0
  158. package/module/URL/parseQueryString.js +6 -4
  159. package/module/URL/parseQueryString.js.map +1 -1
  160. package/module/Validate/isNumber.js.map +1 -1
  161. package/module/Validate/object/core.js +0 -1
  162. package/module/Validate/object/core.js.map +1 -1
  163. package/module/es5/Async/debounceAsync.d.ts +18 -0
  164. package/module/es5/Async/debounceAsync.js +103 -0
  165. package/module/es5/Async/index.d.ts +5 -0
  166. package/module/es5/Async/index.js +55 -0
  167. package/module/es5/Async/pSettled.d.ts +19 -0
  168. package/module/es5/Async/pSettled.js +68 -0
  169. package/module/es5/Async/retry.d.ts +22 -0
  170. package/module/es5/Async/retry.js +106 -0
  171. package/module/es5/Async/throttleAsync.d.ts +18 -0
  172. package/module/es5/Async/throttleAsync.js +46 -0
  173. package/module/es5/Async/waitFor.d.ts +18 -0
  174. package/module/es5/{Error/retry.js → Async/waitFor.js} +68 -74
  175. package/module/es5/Date/addDuration.d.ts +15 -0
  176. package/module/es5/Date/addDuration.js +45 -0
  177. package/module/es5/Date/diff.d.ts +14 -0
  178. package/module/es5/Date/diff.js +40 -0
  179. package/module/es5/Date/durationUnit.d.ts +12 -0
  180. package/module/es5/Date/durationUnit.js +5 -0
  181. package/module/es5/Date/endOf.d.ts +13 -0
  182. package/module/es5/Date/endOf.js +72 -0
  183. package/module/es5/Date/formatRelative.d.ts +13 -0
  184. package/module/es5/Date/formatRelative.js +61 -0
  185. package/module/es5/Date/index.d.ts +10 -0
  186. package/module/es5/Date/index.js +110 -0
  187. package/module/es5/Date/isBusinessDay.d.ts +10 -0
  188. package/module/es5/Date/isBusinessDay.js +26 -0
  189. package/module/es5/Date/isSameDay.d.ts +10 -0
  190. package/module/es5/Date/isSameDay.js +18 -0
  191. package/module/es5/Date/isWeekend.d.ts +9 -0
  192. package/module/es5/Date/isWeekend.js +18 -0
  193. package/module/es5/Date/msByUnit.d.ts +2 -0
  194. package/module/es5/Date/msByUnit.js +15 -0
  195. package/module/es5/Date/startOf.d.ts +13 -0
  196. package/module/es5/Date/startOf.js +72 -0
  197. package/module/es5/Date/subDuration.d.ts +13 -0
  198. package/module/es5/Date/subDuration.js +21 -0
  199. package/module/es5/Error/index.d.ts +0 -1
  200. package/module/es5/Error/index.js +0 -11
  201. package/module/es5/Object/flattenObject.d.ts +11 -0
  202. package/module/es5/Object/flattenObject.js +35 -0
  203. package/module/es5/Object/get.d.ts +1 -0
  204. package/module/es5/Object/get.js +42 -0
  205. package/module/es5/Object/has.d.ts +0 -19
  206. package/module/es5/Object/has.js +4 -4
  207. package/module/es5/Object/index.d.ts +8 -0
  208. package/module/es5/Object/index.js +88 -0
  209. package/module/es5/Object/invert.d.ts +12 -0
  210. package/module/es5/Object/invert.js +26 -0
  211. package/module/es5/Object/omitBy.d.ts +11 -0
  212. package/module/es5/Object/omitBy.js +27 -0
  213. package/module/es5/Object/pathSegments.d.ts +1 -0
  214. package/module/es5/Object/pathSegments.js +9 -0
  215. package/module/es5/Object/pickBy.d.ts +11 -0
  216. package/module/es5/Object/pickBy.js +27 -0
  217. package/module/es5/Object/set.d.ts +19 -0
  218. package/module/es5/Object/set.js +44 -0
  219. package/module/es5/Object/unflattenObject.d.ts +15 -0
  220. package/module/es5/Object/unflattenObject.js +30 -0
  221. package/module/es5/Random/index.d.ts +7 -0
  222. package/module/es5/Random/index.js +82 -0
  223. package/module/es5/Random/randomBoolean.d.ts +9 -0
  224. package/module/es5/Random/randomBoolean.js +18 -0
  225. package/module/es5/Random/randomChoice.d.ts +9 -0
  226. package/module/es5/Random/randomChoice.js +18 -0
  227. package/module/es5/Random/randomFloat.d.ts +9 -0
  228. package/module/es5/Random/randomFloat.js +17 -0
  229. package/module/es5/Random/randomInt.d.ts +9 -0
  230. package/module/es5/Random/randomInt.js +19 -0
  231. package/module/es5/Random/randomUuid.d.ts +9 -0
  232. package/module/es5/Random/randomUuid.js +38 -0
  233. package/module/es5/Random/seededRandom.d.ts +11 -0
  234. package/module/es5/Random/seededRandom.js +46 -0
  235. package/module/es5/Random/weightedChoice.d.ts +15 -0
  236. package/module/es5/Random/weightedChoice.js +50 -0
  237. package/module/es5/String/capitalize.d.ts +12 -0
  238. package/module/es5/String/capitalize.js +35 -0
  239. package/module/es5/String/capitalizeWord.d.ts +1 -0
  240. package/module/es5/String/capitalizeWord.js +9 -0
  241. package/module/es5/String/dedent.d.ts +19 -0
  242. package/module/es5/String/dedent.js +82 -0
  243. package/module/es5/String/index.d.ts +10 -0
  244. package/module/es5/String/index.js +110 -0
  245. package/module/es5/String/mask.d.ts +20 -0
  246. package/module/es5/String/mask.js +39 -0
  247. package/module/es5/String/pascalCase.d.ts +9 -0
  248. package/module/es5/String/pascalCase.js +21 -0
  249. package/module/es5/String/snakeCase.d.ts +9 -0
  250. package/module/es5/String/snakeCase.js +20 -0
  251. package/module/es5/String/titleCase.d.ts +9 -0
  252. package/module/es5/String/titleCase.js +21 -0
  253. package/module/es5/String/uncapitalize.d.ts +10 -0
  254. package/module/es5/String/uncapitalize.js +33 -0
  255. package/module/es5/String/wordCount.d.ts +10 -0
  256. package/module/es5/String/wordCount.js +19 -0
  257. package/module/es5/String/words.d.ts +12 -0
  258. package/module/es5/String/words.js +25 -0
  259. package/module/es5/Tool/createPipeline.d.ts +1 -1
  260. package/module/es5/Tool/createPipeline.js +7 -10
  261. package/module/es5/URL/buildUrl.d.ts +10 -0
  262. package/module/es5/URL/buildUrl.js +10 -4
  263. package/module/es5/URL/parseQueryString.d.ts +6 -0
  264. package/module/es5/URL/parseQueryString.js +6 -4
  265. package/module/es5/Validate/object/core.js +0 -1
  266. package/module/es5/index.d.ts +1 -0
  267. package/module/es5/index.js +20 -9
  268. package/module/index.d.ts +1 -0
  269. package/module/index.js +1 -0
  270. package/module/index.js.map +1 -1
  271. package/package.json +30 -25
  272. package/module/Error/retry.d.ts +0 -37
  273. package/module/Error/retry.js +0 -47
  274. package/module/Error/retry.js.map +0 -1
  275. package/module/es5/Error/retry.d.ts +0 -37
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.debounceAsync = void 0;
7
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
8
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
9
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
+ /**
11
+ * Creates a debounced async function. Subsequent calls within `wait` ms reset
12
+ * the timer and share a single resolution; the latest arguments win.
13
+ *
14
+ * @template A - Argument tuple type
15
+ * @template R - Resolved value type
16
+ * @param {(...args: A) => Promise<R>} function_ - Async function to debounce
17
+ * @param {number} wait - Debounce window in milliseconds
18
+ * @returns {DebouncedAsyncFunction<A, R>} Debounced wrapper with cancel support
19
+ * @example
20
+ * const search = debounceAsync(query, 300);
21
+ * await search("foo");
22
+ */
23
+ var debounceAsync = exports.debounceAsync = function debounceAsync(function_, wait) {
24
+ var timer;
25
+ var pendingResolvers = [];
26
+ var pendingRejecters = [];
27
+ var flushPromises = function flushPromises() {
28
+ var resolvers = pendingResolvers;
29
+ var rejecters = pendingRejecters;
30
+ pendingResolvers = [];
31
+ pendingRejecters = [];
32
+ return {
33
+ resolvers: resolvers,
34
+ rejecters: rejecters
35
+ };
36
+ };
37
+ var debounced = function debounced() {
38
+ for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) {
39
+ arguments_[_key] = arguments[_key];
40
+ }
41
+ if (timer) {
42
+ clearTimeout(timer);
43
+ }
44
+ return new Promise(function (resolve, reject) {
45
+ pendingResolvers.push(resolve);
46
+ pendingRejecters.push(reject);
47
+ timer = setTimeout(function () {
48
+ timer = undefined;
49
+ var _flushPromises = flushPromises(),
50
+ resolvers = _flushPromises.resolvers,
51
+ rejecters = _flushPromises.rejecters;
52
+ function_.apply(void 0, arguments_).then(function (value) {
53
+ var _iterator = _createForOfIteratorHelper(resolvers),
54
+ _step;
55
+ try {
56
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
57
+ var resolver = _step.value;
58
+ resolver(value);
59
+ }
60
+ } catch (err) {
61
+ _iterator.e(err);
62
+ } finally {
63
+ _iterator.f();
64
+ }
65
+ }, function (error) {
66
+ var _iterator2 = _createForOfIteratorHelper(rejecters),
67
+ _step2;
68
+ try {
69
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
70
+ var rejecter = _step2.value;
71
+ rejecter(error);
72
+ }
73
+ } catch (err) {
74
+ _iterator2.e(err);
75
+ } finally {
76
+ _iterator2.f();
77
+ }
78
+ });
79
+ }, wait);
80
+ });
81
+ };
82
+ debounced.cancel = function () {
83
+ if (timer) {
84
+ clearTimeout(timer);
85
+ timer = undefined;
86
+ }
87
+ var _flushPromises2 = flushPromises(),
88
+ rejecters = _flushPromises2.rejecters;
89
+ var _iterator3 = _createForOfIteratorHelper(rejecters),
90
+ _step3;
91
+ try {
92
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
93
+ var rejecter = _step3.value;
94
+ rejecter(new Error("debounceAsync cancelled"));
95
+ }
96
+ } catch (err) {
97
+ _iterator3.e(err);
98
+ } finally {
99
+ _iterator3.f();
100
+ }
101
+ };
102
+ return debounced;
103
+ };
@@ -1,4 +1,9 @@
1
+ export * from "./debounceAsync";
1
2
  export * from "./defer";
2
3
  export * from "./parallel";
4
+ export * from "./pSettled";
5
+ export * from "./retry";
3
6
  export * from "./sleep";
7
+ export * from "./throttleAsync";
4
8
  export * from "./timeout";
9
+ export * from "./waitFor";
@@ -3,6 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _debounceAsync = require("./debounceAsync");
7
+ Object.keys(_debounceAsync).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _debounceAsync[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return _debounceAsync[key];
14
+ }
15
+ });
16
+ });
6
17
  var _defer = require("./defer");
7
18
  Object.keys(_defer).forEach(function (key) {
8
19
  if (key === "default" || key === "__esModule") return;
@@ -25,6 +36,28 @@ Object.keys(_parallel).forEach(function (key) {
25
36
  }
26
37
  });
27
38
  });
39
+ var _pSettled = require("./pSettled");
40
+ Object.keys(_pSettled).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _pSettled[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function get() {
46
+ return _pSettled[key];
47
+ }
48
+ });
49
+ });
50
+ var _retry = require("./retry");
51
+ Object.keys(_retry).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _retry[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _retry[key];
58
+ }
59
+ });
60
+ });
28
61
  var _sleep = require("./sleep");
29
62
  Object.keys(_sleep).forEach(function (key) {
30
63
  if (key === "default" || key === "__esModule") return;
@@ -36,6 +69,17 @@ Object.keys(_sleep).forEach(function (key) {
36
69
  }
37
70
  });
38
71
  });
72
+ var _throttleAsync = require("./throttleAsync");
73
+ Object.keys(_throttleAsync).forEach(function (key) {
74
+ if (key === "default" || key === "__esModule") return;
75
+ if (key in exports && exports[key] === _throttleAsync[key]) return;
76
+ Object.defineProperty(exports, key, {
77
+ enumerable: true,
78
+ get: function get() {
79
+ return _throttleAsync[key];
80
+ }
81
+ });
82
+ });
39
83
  var _timeout = require("./timeout");
40
84
  Object.keys(_timeout).forEach(function (key) {
41
85
  if (key === "default" || key === "__esModule") return;
@@ -46,4 +90,15 @@ Object.keys(_timeout).forEach(function (key) {
46
90
  return _timeout[key];
47
91
  }
48
92
  });
93
+ });
94
+ var _waitFor = require("./waitFor");
95
+ Object.keys(_waitFor).forEach(function (key) {
96
+ if (key === "default" || key === "__esModule") return;
97
+ if (key in exports && exports[key] === _waitFor[key]) return;
98
+ Object.defineProperty(exports, key, {
99
+ enumerable: true,
100
+ get: function get() {
101
+ return _waitFor[key];
102
+ }
103
+ });
49
104
  });
@@ -0,0 +1,19 @@
1
+ export type SettledResult<T> = {
2
+ status: "fulfilled";
3
+ value: T;
4
+ } | {
5
+ status: "rejected";
6
+ reason: unknown;
7
+ };
8
+ /**
9
+ * Awaits all promises and returns their settled results, with an optional
10
+ * concurrency limit applied during execution.
11
+ *
12
+ * @template T - Resolved value type
13
+ * @param {Iterable<Promise<T> | (() => Promise<T>)>} tasks - Promises or thunks
14
+ * @param {number} [limit] - Maximum concurrent in-flight tasks; unlimited when omitted
15
+ * @returns {Promise<SettledResult<T>[]>} Settled results in input order
16
+ * @example
17
+ * await pSettled([Promise.resolve(1), Promise.reject(new Error("x"))]);
18
+ */
19
+ export declare const pSettled: <T>(tasks: Iterable<Promise<T> | (() => Promise<T>)>, limit?: number) => Promise<SettledResult<T>[]>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pSettled = void 0;
7
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
8
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
11
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
12
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
+ /**
14
+ * Awaits all promises and returns their settled results, with an optional
15
+ * concurrency limit applied during execution.
16
+ *
17
+ * @template T - Resolved value type
18
+ * @param {Iterable<Promise<T> | (() => Promise<T>)>} tasks - Promises or thunks
19
+ * @param {number} [limit] - Maximum concurrent in-flight tasks; unlimited when omitted
20
+ * @returns {Promise<SettledResult<T>[]>} Settled results in input order
21
+ * @example
22
+ * await pSettled([Promise.resolve(1), Promise.reject(new Error("x"))]);
23
+ */
24
+ var pSettled = exports.pSettled = function pSettled(tasks, limit) {
25
+ var items = _toConsumableArray(tasks);
26
+ var results = Array.from({
27
+ length: items.length
28
+ });
29
+ if (items.length === 0) {
30
+ return Promise.resolve(results);
31
+ }
32
+ var effectiveLimit = limit && limit > 0 ? limit : items.length;
33
+ var nextIndex = 0;
34
+ var resolvedCount = 0;
35
+ return new Promise(function (resolve) {
36
+ var _runNext = function runNext() {
37
+ if (nextIndex >= items.length) {
38
+ return;
39
+ }
40
+ var currentIndex = nextIndex;
41
+ nextIndex += 1;
42
+ var task = items[currentIndex];
43
+ var promise = typeof task === "function" ? Promise.resolve().then(task) : Promise.resolve(task);
44
+ promise.then(function (value) {
45
+ results[currentIndex] = {
46
+ status: "fulfilled",
47
+ value: value
48
+ };
49
+ }, function (error) {
50
+ results[currentIndex] = {
51
+ status: "rejected",
52
+ reason: error
53
+ };
54
+ }).then(function () {
55
+ resolvedCount += 1;
56
+ if (resolvedCount === items.length) {
57
+ resolve(results);
58
+ } else {
59
+ _runNext();
60
+ }
61
+ });
62
+ };
63
+ var initialBatch = Math.min(effectiveLimit, items.length);
64
+ for (var index = 0; index < initialBatch; index += 1) {
65
+ _runNext();
66
+ }
67
+ });
68
+ };
@@ -0,0 +1,22 @@
1
+ export interface RetryOptions {
2
+ retries?: number;
3
+ delay?: number;
4
+ backoff?: "fixed" | "exponential" | "linear";
5
+ jitter?: boolean;
6
+ shouldRetry?: (error: unknown, attempt: number) => boolean;
7
+ onRetry?: (error: unknown, attempt: number) => void;
8
+ signal?: AbortSignal;
9
+ }
10
+ /**
11
+ * Retries an async function until it succeeds or the retry budget is exhausted.
12
+ * Supports fixed, linear, or exponential backoff, optional jitter, and
13
+ * AbortSignal cancellation.
14
+ *
15
+ * @template T - Return type of the function
16
+ * @param {() => Promise<T>} function_ - The async function to invoke
17
+ * @param {RetryOptions} [options] - Retry configuration
18
+ * @returns {Promise<T>} Result of the first successful invocation
19
+ * @example
20
+ * await retry(() => fetch("/api"), { retries: 5, backoff: "exponential", jitter: true });
21
+ */
22
+ export declare const retry: <T>(function_: () => Promise<T>, options?: RetryOptions) => Promise<T>;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.retry = void 0;
7
+ var _sleep = require("./sleep");
8
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
9
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
10
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
11
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
12
+ var computeDelay = function computeDelay(baseDelay, attemptNumber, backoff, jitter) {
13
+ var waitMs = baseDelay;
14
+ if (backoff === "linear") {
15
+ waitMs = baseDelay * attemptNumber;
16
+ } else if (backoff === "exponential") {
17
+ waitMs = baseDelay * Math.pow(2, attemptNumber - 1);
18
+ }
19
+ if (jitter) {
20
+ waitMs *= Math.random();
21
+ }
22
+ return waitMs;
23
+ };
24
+
25
+ /**
26
+ * Retries an async function until it succeeds or the retry budget is exhausted.
27
+ * Supports fixed, linear, or exponential backoff, optional jitter, and
28
+ * AbortSignal cancellation.
29
+ *
30
+ * @template T - Return type of the function
31
+ * @param {() => Promise<T>} function_ - The async function to invoke
32
+ * @param {RetryOptions} [options] - Retry configuration
33
+ * @returns {Promise<T>} Result of the first successful invocation
34
+ * @example
35
+ * await retry(() => fetch("/api"), { retries: 5, backoff: "exponential", jitter: true });
36
+ */
37
+ var retry = exports.retry = /*#__PURE__*/function () {
38
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(function_) {
39
+ var options,
40
+ _options$retries,
41
+ retries,
42
+ _options$delay,
43
+ delay,
44
+ _options$backoff,
45
+ backoff,
46
+ _options$jitter,
47
+ jitter,
48
+ _options$shouldRetry,
49
+ shouldRetry,
50
+ onRetry,
51
+ signal,
52
+ attemptNumber,
53
+ _signal$reason,
54
+ remaining,
55
+ _args = arguments,
56
+ _t;
57
+ return _regenerator().w(function (_context) {
58
+ while (1) switch (_context.p = _context.n) {
59
+ case 0:
60
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
61
+ _options$retries = options.retries, retries = _options$retries === void 0 ? 3 : _options$retries, _options$delay = options.delay, delay = _options$delay === void 0 ? 1000 : _options$delay, _options$backoff = options.backoff, backoff = _options$backoff === void 0 ? "fixed" : _options$backoff, _options$jitter = options.jitter, jitter = _options$jitter === void 0 ? false : _options$jitter, _options$shouldRetry = options.shouldRetry, shouldRetry = _options$shouldRetry === void 0 ? function () {
62
+ return true;
63
+ } : _options$shouldRetry, onRetry = options.onRetry, signal = options.signal;
64
+ attemptNumber = 0;
65
+ case 1:
66
+ if (!true) {
67
+ _context.n = 7;
68
+ break;
69
+ }
70
+ if (!(signal !== null && signal !== void 0 && signal.aborted)) {
71
+ _context.n = 2;
72
+ break;
73
+ }
74
+ throw (_signal$reason = signal.reason) !== null && _signal$reason !== void 0 ? _signal$reason : new Error("Aborted");
75
+ case 2:
76
+ _context.p = 2;
77
+ _context.n = 3;
78
+ return function_();
79
+ case 3:
80
+ return _context.a(2, _context.v);
81
+ case 4:
82
+ _context.p = 4;
83
+ _t = _context.v;
84
+ remaining = retries - attemptNumber;
85
+ if (!(remaining <= 0 || !shouldRetry(_t, attemptNumber))) {
86
+ _context.n = 5;
87
+ break;
88
+ }
89
+ throw _t;
90
+ case 5:
91
+ onRetry === null || onRetry === void 0 || onRetry(_t, attemptNumber);
92
+ _context.n = 6;
93
+ return (0, _sleep.sleep)(computeDelay(delay, attemptNumber + 1, backoff, jitter));
94
+ case 6:
95
+ attemptNumber += 1;
96
+ _context.n = 1;
97
+ break;
98
+ case 7:
99
+ return _context.a(2);
100
+ }
101
+ }, _callee, null, [[2, 4]]);
102
+ }));
103
+ return function retry(_x) {
104
+ return _ref.apply(this, arguments);
105
+ };
106
+ }();
@@ -0,0 +1,18 @@
1
+ export interface ThrottledAsyncFunction<A extends unknown[], R> {
2
+ (...arguments_: A): Promise<R>;
3
+ cancel: () => void;
4
+ }
5
+ /**
6
+ * Creates a throttled async function. Coalesces concurrent calls within the
7
+ * `wait` window so only one underlying invocation runs; all callers in the
8
+ * window receive the same result.
9
+ *
10
+ * @template A - Argument tuple type
11
+ * @template R - Resolved value type
12
+ * @param {(...args: A) => Promise<R>} function_ - Async function to throttle
13
+ * @param {number} wait - Window length in milliseconds
14
+ * @returns {ThrottledAsyncFunction<A, R>} Throttled wrapper with cancel support
15
+ * @example
16
+ * const fetchUser = throttleAsync(loadUser, 1000);
17
+ */
18
+ export declare const throttleAsync: <A extends unknown[], R>(function_: (...arguments_: A) => Promise<R>, wait: number) => ThrottledAsyncFunction<A, R>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.throttleAsync = void 0;
7
+ /**
8
+ * Creates a throttled async function. Coalesces concurrent calls within the
9
+ * `wait` window so only one underlying invocation runs; all callers in the
10
+ * window receive the same result.
11
+ *
12
+ * @template A - Argument tuple type
13
+ * @template R - Resolved value type
14
+ * @param {(...args: A) => Promise<R>} function_ - Async function to throttle
15
+ * @param {number} wait - Window length in milliseconds
16
+ * @returns {ThrottledAsyncFunction<A, R>} Throttled wrapper with cancel support
17
+ * @example
18
+ * const fetchUser = throttleAsync(loadUser, 1000);
19
+ */
20
+ var throttleAsync = exports.throttleAsync = function throttleAsync(function_, wait) {
21
+ var inflight;
22
+ var lockedUntil = 0;
23
+ var throttled = function throttled() {
24
+ if (inflight) {
25
+ return inflight;
26
+ }
27
+ if (Date.now() < lockedUntil) {
28
+ return Promise.reject(new Error("throttleAsync window not elapsed"));
29
+ }
30
+ var current = function_.apply(void 0, arguments);
31
+ inflight = current;
32
+ var cleanup = function cleanup() {
33
+ if (inflight === current) {
34
+ inflight = undefined;
35
+ lockedUntil = Date.now() + wait;
36
+ }
37
+ };
38
+ current.then(cleanup, cleanup);
39
+ return current;
40
+ };
41
+ throttled.cancel = function () {
42
+ inflight = undefined;
43
+ lockedUntil = 0;
44
+ };
45
+ return throttled;
46
+ };
@@ -0,0 +1,18 @@
1
+ export interface WaitForOptions {
2
+ timeout?: number;
3
+ interval?: number;
4
+ signal?: AbortSignal;
5
+ }
6
+ /**
7
+ * Repeatedly evaluates a condition until it returns a truthy value or the
8
+ * timeout elapses. Resolves with the final truthy value.
9
+ *
10
+ * @template T - Truthy result type
11
+ * @param {() => T | Promise<T>} condition - Condition predicate
12
+ * @param {WaitForOptions} [options] - Polling configuration
13
+ * @returns {Promise<NonNullable<T>>} The first truthy value
14
+ * @throws {Error} When the timeout elapses or the signal aborts
15
+ * @example
16
+ * await waitFor(() => document.querySelector("#root"), { interval: 100 });
17
+ */
18
+ export declare const waitFor: <T>(condition: () => T | Promise<T>, options?: WaitForOptions) => Promise<NonNullable<T>>;
@@ -3,86 +3,80 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.retry = void 0;
6
+ exports.waitFor = void 0;
7
+ var _sleep = require("./sleep");
7
8
  function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
8
9
  function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
9
10
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
10
11
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
11
12
  /**
12
- * Retries a given async function with configurable retry logic
13
- *
14
- * @template T - The return type of the function
15
- * @param function_ - The async function to retry
16
- * @param options - Configuration options for retry behavior
17
- * @param options.retries - Maximum number of retry attempts (default: 3)
18
- * @param options.delay - Delay between retries in milliseconds (default: 1000)
19
- * @param options.shouldRetry - Function to determine if an error should trigger a retry (default: always retry)
20
- * @returns Promise that resolves with the function result or rejects with the final error
13
+ * Repeatedly evaluates a condition until it returns a truthy value or the
14
+ * timeout elapses. Resolves with the final truthy value.
21
15
  *
16
+ * @template T - Truthy result type
17
+ * @param {() => T | Promise<T>} condition - Condition predicate
18
+ * @param {WaitForOptions} [options] - Polling configuration
19
+ * @returns {Promise<NonNullable<T>>} The first truthy value
20
+ * @throws {Error} When the timeout elapses or the signal aborts
22
21
  * @example
23
- * ```typescript
24
- * // Basic usage with default options
25
- * const result = await retry(async () => {
26
- * const response = await fetch('/api/data');
27
- * if (!response.ok) throw new Error('Failed to fetch');
28
- * return response.json();
29
- * });
30
- *
31
- * // Custom retry configuration
32
- * const result = await retry(
33
- * () => riskyOperation(),
34
- * {
35
- * retries: 5,
36
- * delay: 2000,
37
- * shouldRetry: (error) => error instanceof NetworkError
38
- * }
39
- * );
40
- * ```
22
+ * await waitFor(() => document.querySelector("#root"), { interval: 100 });
41
23
  */
42
- var retry = exports.retry = function retry(function_) {
43
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
44
- var _options$retries = options.retries,
45
- retries = _options$retries === void 0 ? 3 : _options$retries,
46
- _options$delay = options.delay,
47
- delay = _options$delay === void 0 ? 1000 : _options$delay,
48
- _options$shouldRetry = options.shouldRetry,
49
- shouldRetry = _options$shouldRetry === void 0 ? function () {
50
- return true;
51
- } : _options$shouldRetry;
52
- var _attempt = /*#__PURE__*/function () {
53
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(remainingAttempts) {
54
- var _t;
55
- return _regenerator().w(function (_context) {
56
- while (1) switch (_context.p = _context.n) {
57
- case 0:
58
- _context.p = 0;
59
- _context.n = 1;
60
- return function_();
61
- case 1:
62
- return _context.a(2, _context.v);
63
- case 2:
64
- _context.p = 2;
65
- _t = _context.v;
66
- if (!(remainingAttempts <= 0 || !shouldRetry(_t))) {
67
- _context.n = 3;
68
- break;
69
- }
70
- throw _t;
71
- case 3:
24
+ var waitFor = exports.waitFor = /*#__PURE__*/function () {
25
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(condition) {
26
+ var options,
27
+ _options$timeout,
28
+ timeout,
29
+ _options$interval,
30
+ interval,
31
+ signal,
32
+ startTime,
33
+ _signal$reason,
34
+ value,
35
+ _args = arguments;
36
+ return _regenerator().w(function (_context) {
37
+ while (1) switch (_context.n) {
38
+ case 0:
39
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
40
+ _options$timeout = options.timeout, timeout = _options$timeout === void 0 ? 5000 : _options$timeout, _options$interval = options.interval, interval = _options$interval === void 0 ? 100 : _options$interval, signal = options.signal;
41
+ startTime = Date.now();
42
+ case 1:
43
+ if (!true) {
44
+ _context.n = 7;
45
+ break;
46
+ }
47
+ if (!(signal !== null && signal !== void 0 && signal.aborted)) {
48
+ _context.n = 2;
49
+ break;
50
+ }
51
+ throw (_signal$reason = signal.reason) !== null && _signal$reason !== void 0 ? _signal$reason : new Error("Aborted");
52
+ case 2:
53
+ _context.n = 3;
54
+ return condition();
55
+ case 3:
56
+ value = _context.v;
57
+ if (!value) {
72
58
  _context.n = 4;
73
- return new Promise(function (resolve) {
74
- return setTimeout(function () {
75
- return resolve(_attempt(remainingAttempts - 1));
76
- }, delay);
77
- });
78
- case 4:
79
- return _context.a(2, _context.v);
80
- }
81
- }, _callee, null, [[0, 2]]);
82
- }));
83
- return function attempt(_x) {
84
- return _ref.apply(this, arguments);
85
- };
86
- }();
87
- return _attempt(retries);
88
- };
59
+ break;
60
+ }
61
+ return _context.a(2, value);
62
+ case 4:
63
+ if (!(Date.now() - startTime >= timeout)) {
64
+ _context.n = 5;
65
+ break;
66
+ }
67
+ throw new Error("waitFor timed out after ".concat(timeout, "ms"));
68
+ case 5:
69
+ _context.n = 6;
70
+ return (0, _sleep.sleep)(interval);
71
+ case 6:
72
+ _context.n = 1;
73
+ break;
74
+ case 7:
75
+ return _context.a(2);
76
+ }
77
+ }, _callee);
78
+ }));
79
+ return function waitFor(_x) {
80
+ return _ref.apply(this, arguments);
81
+ };
82
+ }();