modern-ts 0.8.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 (261) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +223 -0
  3. package/README.zh-CN.md +223 -0
  4. package/dist/chunks/Errors-BWEYu-AB.cjs +2 -0
  5. package/dist/chunks/Errors-BWEYu-AB.cjs.map +1 -0
  6. package/dist/chunks/Errors-DwUAvFIF.mjs +63 -0
  7. package/dist/chunks/Errors-DwUAvFIF.mjs.map +1 -0
  8. package/dist/chunks/Math-CGEH1ClN.mjs +68 -0
  9. package/dist/chunks/Math-CGEH1ClN.mjs.map +1 -0
  10. package/dist/chunks/Math-CWZVxSF-.cjs +2 -0
  11. package/dist/chunks/Math-CWZVxSF-.cjs.map +1 -0
  12. package/dist/chunks/base-B9k8Lqvf.mjs +56 -0
  13. package/dist/chunks/base-B9k8Lqvf.mjs.map +1 -0
  14. package/dist/chunks/base-BTXL1y_I.cjs +2 -0
  15. package/dist/chunks/base-BTXL1y_I.cjs.map +1 -0
  16. package/dist/chunks/base-BpECeKwU.mjs +19 -0
  17. package/dist/chunks/base-BpECeKwU.mjs.map +1 -0
  18. package/dist/chunks/base-BvHqpP_s.cjs +2 -0
  19. package/dist/chunks/base-BvHqpP_s.cjs.map +1 -0
  20. package/dist/chunks/base-K-RHLZ-S.mjs +46 -0
  21. package/dist/chunks/base-K-RHLZ-S.mjs.map +1 -0
  22. package/dist/chunks/base-r6kn0B0D.cjs +2 -0
  23. package/dist/chunks/base-r6kn0B0D.cjs.map +1 -0
  24. package/dist/chunks/combine-async-DcG-3p8i.cjs +2 -0
  25. package/dist/chunks/combine-async-DcG-3p8i.cjs.map +1 -0
  26. package/dist/chunks/combine-async-Dcg4ya1R.mjs +236 -0
  27. package/dist/chunks/combine-async-Dcg4ya1R.mjs.map +1 -0
  28. package/dist/chunks/delay-CG3cD7bk.cjs +2 -0
  29. package/dist/chunks/delay-CG3cD7bk.cjs.map +1 -0
  30. package/dist/chunks/delay-CKIXpP71.mjs +32 -0
  31. package/dist/chunks/delay-CKIXpP71.mjs.map +1 -0
  32. package/dist/chunks/helper-BVabbpmX.mjs +165 -0
  33. package/dist/chunks/helper-BVabbpmX.mjs.map +1 -0
  34. package/dist/chunks/helper-tsqZMRHW.cjs +3 -0
  35. package/dist/chunks/helper-tsqZMRHW.cjs.map +1 -0
  36. package/dist/chunks/local-8JVtLN0O.mjs +10 -0
  37. package/dist/chunks/local-8JVtLN0O.mjs.map +1 -0
  38. package/dist/chunks/local-Da4yU-nE.cjs +2 -0
  39. package/dist/chunks/local-Da4yU-nE.cjs.map +1 -0
  40. package/dist/chunks/types-B7X_LBjM.cjs +2 -0
  41. package/dist/chunks/types-B7X_LBjM.cjs.map +1 -0
  42. package/dist/chunks/types-DE2SnSbz.mjs +5 -0
  43. package/dist/chunks/types-DE2SnSbz.mjs.map +1 -0
  44. package/dist/index.cjs +2 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.mjs +759 -0
  47. package/dist/index.mjs.map +1 -0
  48. package/dist/subpath/Arr.cjs +2 -0
  49. package/dist/subpath/Arr.cjs.map +1 -0
  50. package/dist/subpath/Arr.mjs +539 -0
  51. package/dist/subpath/Arr.mjs.map +1 -0
  52. package/dist/subpath/Concurrent.cjs +15 -0
  53. package/dist/subpath/Concurrent.cjs.map +1 -0
  54. package/dist/subpath/Concurrent.mjs +4044 -0
  55. package/dist/subpath/Concurrent.mjs.map +1 -0
  56. package/dist/subpath/FetchQ.cjs +2 -0
  57. package/dist/subpath/FetchQ.cjs.map +1 -0
  58. package/dist/subpath/FetchQ.mjs +519 -0
  59. package/dist/subpath/FetchQ.mjs.map +1 -0
  60. package/dist/subpath/Fit.cjs +2 -0
  61. package/dist/subpath/Fit.cjs.map +1 -0
  62. package/dist/subpath/Fit.mjs +914 -0
  63. package/dist/subpath/Fit.mjs.map +1 -0
  64. package/dist/subpath/Lazy.cjs +2 -0
  65. package/dist/subpath/Lazy.cjs.map +1 -0
  66. package/dist/subpath/Lazy.mjs +72 -0
  67. package/dist/subpath/Lazy.mjs.map +1 -0
  68. package/dist/subpath/Maps.cjs +2 -0
  69. package/dist/subpath/Maps.cjs.map +1 -0
  70. package/dist/subpath/Maps.mjs +123 -0
  71. package/dist/subpath/Maps.mjs.map +1 -0
  72. package/dist/subpath/Maybe.cjs +2 -0
  73. package/dist/subpath/Maybe.cjs.map +1 -0
  74. package/dist/subpath/Maybe.mjs +329 -0
  75. package/dist/subpath/Maybe.mjs.map +1 -0
  76. package/dist/subpath/Reactive.cjs +2 -0
  77. package/dist/subpath/Reactive.cjs.map +1 -0
  78. package/dist/subpath/Reactive.mjs +1204 -0
  79. package/dist/subpath/Reactive.mjs.map +1 -0
  80. package/dist/subpath/Reader.cjs +2 -0
  81. package/dist/subpath/Reader.cjs.map +1 -0
  82. package/dist/subpath/Reader.mjs +75 -0
  83. package/dist/subpath/Reader.mjs.map +1 -0
  84. package/dist/subpath/ReaderT.cjs +2 -0
  85. package/dist/subpath/ReaderT.cjs.map +1 -0
  86. package/dist/subpath/ReaderT.mjs +148 -0
  87. package/dist/subpath/ReaderT.mjs.map +1 -0
  88. package/dist/subpath/Resource.cjs +2 -0
  89. package/dist/subpath/Resource.cjs.map +1 -0
  90. package/dist/subpath/Resource.mjs +150 -0
  91. package/dist/subpath/Resource.mjs.map +1 -0
  92. package/dist/subpath/Result.cjs +2 -0
  93. package/dist/subpath/Result.cjs.map +1 -0
  94. package/dist/subpath/Result.mjs +337 -0
  95. package/dist/subpath/Result.mjs.map +1 -0
  96. package/dist/subpath/Sets.cjs +2 -0
  97. package/dist/subpath/Sets.cjs.map +1 -0
  98. package/dist/subpath/Sets.mjs +92 -0
  99. package/dist/subpath/Sets.mjs.map +1 -0
  100. package/dist/subpath/Str.cjs +2 -0
  101. package/dist/subpath/Str.cjs.map +1 -0
  102. package/dist/subpath/Str.mjs +114 -0
  103. package/dist/subpath/Str.mjs.map +1 -0
  104. package/dist/subpath/TxScope.cjs +2 -0
  105. package/dist/subpath/TxScope.cjs.map +1 -0
  106. package/dist/subpath/TxScope.mjs +138 -0
  107. package/dist/subpath/TxScope.mjs.map +1 -0
  108. package/dist/subpath/TypeTool.cjs +2 -0
  109. package/dist/subpath/TypeTool.cjs.map +1 -0
  110. package/dist/subpath/TypeTool.mjs +9 -0
  111. package/dist/subpath/TypeTool.mjs.map +1 -0
  112. package/dist/subpath/Utils.cjs +2 -0
  113. package/dist/subpath/Utils.cjs.map +1 -0
  114. package/dist/subpath/Utils.mjs +835 -0
  115. package/dist/subpath/Utils.mjs.map +1 -0
  116. package/dist/subpath/VirtualTime.cjs +2 -0
  117. package/dist/subpath/VirtualTime.cjs.map +1 -0
  118. package/dist/subpath/VirtualTime.mjs +1186 -0
  119. package/dist/subpath/VirtualTime.mjs.map +1 -0
  120. package/dist/types/Arr.d.ts +2 -0
  121. package/dist/types/Concurrent/Lock/condition_variable.d.ts +138 -0
  122. package/dist/types/Concurrent/Lock/mutex.d.ts +185 -0
  123. package/dist/types/Concurrent/Lock/rwlock.d.ts +253 -0
  124. package/dist/types/Concurrent/Lock/semaphore.d.ts +208 -0
  125. package/dist/types/Concurrent/Valve/__export__.d.ts +5 -0
  126. package/dist/types/Concurrent/Valve/circuit-breaker.d.ts +146 -0
  127. package/dist/types/Concurrent/Valve/leaky-bucket.d.ts +115 -0
  128. package/dist/types/Concurrent/Valve/sliding-window.d.ts +91 -0
  129. package/dist/types/Concurrent/Valve/token-bucket.d.ts +68 -0
  130. package/dist/types/Concurrent/__export__.d.ts +15 -0
  131. package/dist/types/Concurrent/barrier.d.ts +255 -0
  132. package/dist/types/Concurrent/channel.d.ts +239 -0
  133. package/dist/types/Concurrent/delay.d.ts +42 -0
  134. package/dist/types/Concurrent/ext/map.d.ts +82 -0
  135. package/dist/types/Concurrent/ext/other.d.ts +113 -0
  136. package/dist/types/Concurrent/ext/race.d.ts +31 -0
  137. package/dist/types/Concurrent/ext/some.d.ts +64 -0
  138. package/dist/types/Concurrent/limiter.d.ts +131 -0
  139. package/dist/types/Concurrent/scheduler.d.ts +171 -0
  140. package/dist/types/Concurrent/task-scope.d.ts +282 -0
  141. package/dist/types/Concurrent.d.ts +2 -0
  142. package/dist/types/Errors.d.ts +66 -0
  143. package/dist/types/FetchQ.d.ts +2 -0
  144. package/dist/types/Fit/__export__.d.ts +5 -0
  145. package/dist/types/Fit/base.d.ts +325 -0
  146. package/dist/types/Fit/parser.d.ts +110 -0
  147. package/dist/types/Fit/standard-schema.d.ts +127 -0
  148. package/dist/types/Fit/sugar.d.ts +274 -0
  149. package/dist/types/Fit/tool.d.ts +585 -0
  150. package/dist/types/Fit.d.ts +2 -0
  151. package/dist/types/Lazy.d.ts +2 -0
  152. package/dist/types/Maps.d.ts +2 -0
  153. package/dist/types/Maybe/__export__.d.ts +6 -0
  154. package/dist/types/Maybe/base.d.ts +62 -0
  155. package/dist/types/Maybe/consumers-async.d.ts +58 -0
  156. package/dist/types/Maybe/consumers.d.ts +63 -0
  157. package/dist/types/Maybe/operators-async.d.ts +145 -0
  158. package/dist/types/Maybe/operators.d.ts +177 -0
  159. package/dist/types/Maybe/types.d.ts +12 -0
  160. package/dist/types/Maybe.d.ts +2 -0
  161. package/dist/types/MockClock/Timeline.d.ts +392 -0
  162. package/dist/types/MockClock/TimerHandle.d.ts +159 -0
  163. package/dist/types/MockClock/TimerHeap.d.ts +21 -0
  164. package/dist/types/MockClock/VirtualTimeManager.d.ts +23 -0
  165. package/dist/types/MockClock/__export__.d.ts +104 -0
  166. package/dist/types/MockClock/hooks/__export__.d.ts +9 -0
  167. package/dist/types/MockClock/hooks/hookAbortSignal.d.ts +3 -0
  168. package/dist/types/MockClock/hooks/hookDate.d.ts +3 -0
  169. package/dist/types/MockClock/hooks/hookIntl.d.ts +3 -0
  170. package/dist/types/MockClock/hooks/hookMessageChannel.d.ts +3 -0
  171. package/dist/types/MockClock/hooks/hookMicrotasks.d.ts +3 -0
  172. package/dist/types/MockClock/hooks/hookOs.d.ts +3 -0
  173. package/dist/types/MockClock/hooks/hookPerformance.d.ts +3 -0
  174. package/dist/types/MockClock/hooks/hookProcess.d.ts +3 -0
  175. package/dist/types/MockClock/hooks/hookTimers.d.ts +3 -0
  176. package/dist/types/MockClock/types.d.ts +103 -0
  177. package/dist/types/Other/FetchQ.d.ts +320 -0
  178. package/dist/types/Other/deque.d.ts +59 -0
  179. package/dist/types/Other/disjointSet.d.ts +53 -0
  180. package/dist/types/Other/heap.d.ts +41 -0
  181. package/dist/types/Other/lazy.d.ts +127 -0
  182. package/dist/types/Other/queue.d.ts +42 -0
  183. package/dist/types/Other/secret.d.ts +111 -0
  184. package/dist/types/Other/stack.d.ts +40 -0
  185. package/dist/types/Reactive/__export__.d.ts +4 -0
  186. package/dist/types/Reactive/event_emitter.d.ts +195 -0
  187. package/dist/types/Reactive/flow-combination.d.ts +74 -0
  188. package/dist/types/Reactive/flow.d.ts +180 -0
  189. package/dist/types/Reactive/pace.d.ts +80 -0
  190. package/dist/types/Reactive.d.ts +2 -0
  191. package/dist/types/Reader/__export-readerT__.d.ts +4 -0
  192. package/dist/types/Reader/__export-reader__.d.ts +4 -0
  193. package/dist/types/Reader/local.d.ts +39 -0
  194. package/dist/types/Reader/reader-async.d.ts +84 -0
  195. package/dist/types/Reader/reader.d.ts +96 -0
  196. package/dist/types/Reader/readerT-async.d.ts +186 -0
  197. package/dist/types/Reader/readerT.d.ts +178 -0
  198. package/dist/types/Reader/types.d.ts +37 -0
  199. package/dist/types/Reader.d.ts +2 -0
  200. package/dist/types/ReaderT.d.ts +2 -0
  201. package/dist/types/Resource/TxScope-async.d.ts +86 -0
  202. package/dist/types/Resource/TxScope.d.ts +85 -0
  203. package/dist/types/Resource/__export-TxScope__.d.ts +2 -0
  204. package/dist/types/Resource/__export-resource__.d.ts +2 -0
  205. package/dist/types/Resource/resource-async.d.ts +79 -0
  206. package/dist/types/Resource/resource.d.ts +78 -0
  207. package/dist/types/Resource/types.d.ts +79 -0
  208. package/dist/types/Resource.d.ts +2 -0
  209. package/dist/types/Result/Consumers/branch-async.d.ts +77 -0
  210. package/dist/types/Result/Consumers/branch.d.ts +70 -0
  211. package/dist/types/Result/Consumers/inspect.d.ts +66 -0
  212. package/dist/types/Result/Operators/Async/combine-async.d.ts +69 -0
  213. package/dist/types/Result/Operators/Async/partition-async.d.ts +29 -0
  214. package/dist/types/Result/Operators/Async/reduce-async.d.ts +15 -0
  215. package/dist/types/Result/Operators/Async/transform-async.d.ts +90 -0
  216. package/dist/types/Result/Operators/combine.d.ts +60 -0
  217. package/dist/types/Result/Operators/flatten.d.ts +26 -0
  218. package/dist/types/Result/Operators/partition.d.ts +25 -0
  219. package/dist/types/Result/Operators/reduce.d.ts +12 -0
  220. package/dist/types/Result/Operators/transform.d.ts +70 -0
  221. package/dist/types/Result/__export__.d.ts +14 -0
  222. package/dist/types/Result/base.d.ts +115 -0
  223. package/dist/types/Result/types.d.ts +34 -0
  224. package/dist/types/Result.d.ts +2 -0
  225. package/dist/types/Sets.d.ts +2 -0
  226. package/dist/types/Str.d.ts +2 -0
  227. package/dist/types/TxScope.d.ts +2 -0
  228. package/dist/types/TypeTool.d.ts +2 -0
  229. package/dist/types/Utils/Array/__export__.d.ts +10 -0
  230. package/dist/types/Utils/Array/filtering.d.ts +89 -0
  231. package/dist/types/Utils/Array/flatten.d.ts +45 -0
  232. package/dist/types/Utils/Array/grouping.d.ts +44 -0
  233. package/dist/types/Utils/Array/iteration.d.ts +86 -0
  234. package/dist/types/Utils/Array/operators.d.ts +62 -0
  235. package/dist/types/Utils/Array/randomization.d.ts +76 -0
  236. package/dist/types/Utils/Array/set.d.ts +108 -0
  237. package/dist/types/Utils/Array/slice.d.ts +189 -0
  238. package/dist/types/Utils/Array/sorting.d.ts +55 -0
  239. package/dist/types/Utils/Array/zip.d.ts +93 -0
  240. package/dist/types/Utils/Functions/__export__.d.ts +5 -0
  241. package/dist/types/Utils/Functions/base.d.ts +157 -0
  242. package/dist/types/Utils/Functions/curry.d.ts +73 -0
  243. package/dist/types/Utils/Functions/debounce.d.ts +240 -0
  244. package/dist/types/Utils/Functions/defer.d.ts +43 -0
  245. package/dist/types/Utils/Functions/pipe.d.ts +205 -0
  246. package/dist/types/Utils/Map.d.ts +284 -0
  247. package/dist/types/Utils/Math.d.ts +225 -0
  248. package/dist/types/Utils/Object/__export__.d.ts +2 -0
  249. package/dist/types/Utils/Object/base.d.ts +131 -0
  250. package/dist/types/Utils/Object/clone.d.ts +81 -0
  251. package/dist/types/Utils/Predicates.d.ts +361 -0
  252. package/dist/types/Utils/Set.d.ts +105 -0
  253. package/dist/types/Utils/String.d.ts +217 -0
  254. package/dist/types/Utils/__export__.d.ts +9 -0
  255. package/dist/types/Utils/type-tool.d.ts +168 -0
  256. package/dist/types/Utils.d.ts +2 -0
  257. package/dist/types/VirtualTime.d.ts +2 -0
  258. package/dist/types/helper.d.ts +71 -0
  259. package/dist/types/index.d.ts +21 -0
  260. package/dist/types/unknown-error.d.ts +98 -0
  261. package/package.json +179 -0
@@ -0,0 +1,114 @@
1
+ import { P as u } from "../chunks/Errors-DwUAvFIF.mjs";
2
+ const f = {
3
+ "&": "&",
4
+ "<": "&lt;",
5
+ ">": "&gt;",
6
+ '"': "&quot;",
7
+ "'": "&#39;"
8
+ }, C = {
9
+ "&amp;": "&",
10
+ "&lt;": "<",
11
+ "&gt;": ">",
12
+ "&quot;": '"',
13
+ "&#39;": "'"
14
+ }, E = /[&<>"']/g, _ = /&(?:amp|lt|gt|quot|#39);/g, d = /[A-Z]{2,}(?=[A-Z][a-z]+|[0-9]|$)|[A-Z]?[a-z]+[0-9]*|[A-Z]+[0-9]*|[0-9]+[a-z]+|[0-9]+/g, P = /[\p{L}\p{N}]+/gu, L = /^\s+/, h = /\s+$/, A = (e, t) => {
15
+ if (t === void 0) return e.trim();
16
+ if (!t) return e;
17
+ const n = p(t);
18
+ return e.replace(new RegExp(`^[${n}]+|[${n}]+$`, "g"), "");
19
+ }, R = (e, t) => {
20
+ if (t === void 0) return e.replace(L, "");
21
+ if (!t) return e;
22
+ const n = p(t);
23
+ return e.replace(new RegExp(`^[${n}]+`), "");
24
+ }, w = (e, t) => {
25
+ if (t === void 0) return e.replace(h, "");
26
+ if (!t) return e;
27
+ const n = p(t);
28
+ return e.replace(new RegExp(`[${n}]+$`), "");
29
+ }, M = (e, t, n = " ") => {
30
+ if (!Number.isFinite(t) || t < 0)
31
+ throw new u("Length must be a finite non-negative number");
32
+ const r = e.length;
33
+ if (r >= t || n.length === 0) return e;
34
+ const a = t - r, c = Math.floor(a / 2), o = a - c, l = n.repeat(Math.ceil(c / n.length)).slice(0, c), g = n.repeat(Math.ceil(o / n.length)).slice(0, o);
35
+ return l + e + g;
36
+ }, m = (e) => e.normalize("NFD").replace(/[\u0300-\u036f]/g, ""), p = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), S = (e) => e.replace(E, (t) => f[t]), b = (e) => e.replace(_, (t) => C[t]), j = (e) => [...e].reverse().join(""), s = (e) => m(e).match(d) || [], i = (e) => e && e.charAt(0).toUpperCase() + e.slice(1).toLowerCase(), $ = (e) => s(e).map(i).join(" ").replace(
37
+ /([a-z])(\d)|(\d)([a-z])/gi,
38
+ (t, n, r, a, c) => `${n || a} ${r || c}`
39
+ ).split(" ").map(i).join(" ").trim(), z = (e) => {
40
+ const t = s(e);
41
+ return t.length ? t[0].toLowerCase() + t.slice(1).map(i).join("") : "";
42
+ }, v = (e) => e && e.charAt(0).toUpperCase() + e.slice(1).toLowerCase(), T = (e) => s(e).map((t) => t.toUpperCase()).join("_"), N = (e) => s(e).map((t) => t.toLowerCase()).join("-"), U = (e) => s(e).map((t) => t.toLowerCase()).join(" "), G = (e) => e && e.charAt(0).toLowerCase() + e.slice(1), X = (e) => s(e).map(i).join(""), k = (e) => s(e).map((t) => t.toLowerCase()).join("_"), x = (e) => s(e).map((t) => t.toUpperCase()).join(" "), y = (e) => e && e.charAt(0).toUpperCase() + e.slice(1), D = (e) => e.match(P) || [], F = (e, t) => {
43
+ if (!Number.isInteger(e) || e < 0)
44
+ throw new u("Length must be a non-negative integer");
45
+ const n = t ?? "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
46
+ if (n.length === 0) return "";
47
+ let r = "";
48
+ for (let a = 0; a < e; a++)
49
+ r += n.charAt(Math.floor(Math.random() * n.length));
50
+ return r;
51
+ }, I = (e, t) => e.replace(/\{\{([^}]+)\}\}/g, (n, r) => {
52
+ const c = r.trim().split(".");
53
+ let o = t;
54
+ for (const l of c) {
55
+ if (o === null || typeof o != "object") {
56
+ o = void 0;
57
+ break;
58
+ }
59
+ o = o[l];
60
+ }
61
+ return o == null ? "" : String(o);
62
+ }), H = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
63
+ __proto__: null,
64
+ camelCase: z,
65
+ capitalize: v,
66
+ constantCase: T,
67
+ deburr: m,
68
+ escape: S,
69
+ escapeRegExp: p,
70
+ kebabCase: N,
71
+ lowerCase: U,
72
+ lowerFirst: G,
73
+ pad: M,
74
+ pascalCase: X,
75
+ randomString: F,
76
+ reverseString: j,
77
+ snakeCase: k,
78
+ startCase: $,
79
+ template: I,
80
+ trim: A,
81
+ trimEnd: w,
82
+ trimStart: R,
83
+ unescape: b,
84
+ upperCase: x,
85
+ upperFirst: y,
86
+ words: D
87
+ }, Symbol.toStringTag, { value: "Module" }));
88
+ export {
89
+ H as S,
90
+ z as camelCase,
91
+ v as capitalize,
92
+ T as constantCase,
93
+ m as deburr,
94
+ S as escape,
95
+ p as escapeRegExp,
96
+ N as kebabCase,
97
+ U as lowerCase,
98
+ G as lowerFirst,
99
+ M as pad,
100
+ X as pascalCase,
101
+ F as randomString,
102
+ j as reverseString,
103
+ k as snakeCase,
104
+ $ as startCase,
105
+ I as template,
106
+ A as trim,
107
+ w as trimEnd,
108
+ R as trimStart,
109
+ b as unescape,
110
+ x as upperCase,
111
+ y as upperFirst,
112
+ D as words
113
+ };
114
+ //# sourceMappingURL=Str.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Str.mjs","sources":["../../src/Utils/String.ts"],"sourcesContent":["// ========================================\r\n// ./src/Utils/String.ts\r\n// ========================================\r\n// cSpell:ignore deburr\r\n\r\nimport {ParameterError} from 'src/Errors';\r\n\r\n// ------ 常量预编译 ------\r\nconst HTML_ESCAPE_MAP: Record<string, string> = {\r\n '&': '&amp;',\r\n '<': '&lt;',\r\n '>': '&gt;',\r\n '\"': '&quot;',\r\n \"'\": '&#39;',\r\n} as const;\r\n\r\nconst HTML_UNESCAPE_MAP: Record<string, string> = {\r\n '&amp;': '&',\r\n '&lt;': '<',\r\n '&gt;': '>',\r\n '&quot;': '\"',\r\n '&#39;': \"'\",\r\n} as const;\r\n\r\nconst HTML_ESCAPE_REGEXP = /[&<>\"']/g;\r\nconst HTML_UNESCAPE_REGEXP = /&(?:amp|lt|gt|quot|#39);/g;\r\nconst WORD_SPLIT_REGEXP =\r\n /[A-Z]{2,}(?=[A-Z][a-z]+|[0-9]|$)|[A-Z]?[a-z]+[0-9]*|[A-Z]+[0-9]*|[0-9]+[a-z]+|[0-9]+/g;\r\nconst UNICODE_WORD_REGEXP = /[\\p{L}\\p{N}]+/gu;\r\n\r\nconst TRIM_START_REGEXP = /^\\s+/;\r\nconst TRIM_END_REGEXP = /\\s+$/;\r\n\r\n// ------ 修剪与填充 ------\r\n\r\n/**\r\n * Removes whitespace or specified characters from both ends of a string\r\n * @param str - String to trim\r\n * @param chars - Characters to trim (defaults to whitespace). If provided, removes all characters in this string from both ends.\r\n * @returns Trimmed string. Returns empty string if input is empty.\r\n * @example\r\n * trim(' hello ') // 'hello'\r\n * trim('--hello--', '-') // 'hello'\r\n * trim('', '-') // ''\r\n */\r\nexport const trim = (str: string, chars?: string): string => {\r\n if (chars === undefined) return str.trim();\r\n if (!chars) return str;\r\n\r\n const safeChars = escapeRegExp(chars);\r\n return str.replace(new RegExp(`^[${safeChars}]+|[${safeChars}]+$`, 'g'), '');\r\n};\r\n\r\n/**\r\n * Removes whitespace or specified characters from the start of a string\r\n * @param str - String to trim\r\n * @param chars - Characters to trim (defaults to whitespace). If provided, removes all characters in this string from the start.\r\n * @returns Trimmed string. Returns empty string if input is empty.\r\n * @example\r\n * trimStart(' hello ') // 'hello '\r\n * trimStart('--hello', '-') // 'hello'\r\n */\r\nexport const trimStart = (str: string, chars?: string): string => {\r\n if (chars === undefined) return str.replace(TRIM_START_REGEXP, '');\r\n if (!chars) return str;\r\n\r\n const safeChars = escapeRegExp(chars);\r\n return str.replace(new RegExp(`^[${safeChars}]+`), '');\r\n};\r\n\r\n/**\r\n * Removes whitespace or specified characters from the end of a string\r\n * @param str - String to trim\r\n * @param chars - Characters to trim (defaults to whitespace). If provided, removes all characters in this string from the end.\r\n * @returns Trimmed string. Returns empty string if input is empty.\r\n * @example\r\n * trimEnd(' hello ') // ' hello'\r\n * trimEnd('hello--', '-') // 'hello'\r\n */\r\nexport const trimEnd = (str: string, chars?: string): string => {\r\n if (chars === undefined) return str.replace(TRIM_END_REGEXP, '');\r\n if (!chars) return str;\r\n\r\n const safeChars = escapeRegExp(chars);\r\n return str.replace(new RegExp(`[${safeChars}]+$`), '');\r\n};\r\n\r\n/**\r\n * Pads a string on both sides with specified characters to reach given length\r\n * @param str - String to pad\r\n * @param length - Target length after padding. If str length >= length, returns original string.\r\n * @param chars - Padding characters (defaults to space). If empty string, returns original string.\r\n * @returns Padded string. Returns original string if padding not needed or chars empty.\r\n * @throws If length is negative\r\n * @example\r\n * pad('hi', 5) // ' hi '\r\n * pad('hi', 5, '-') // '--hi-'\r\n * pad('hello', 3) // 'hello'\r\n * pad('hi', 6, 'abc') // 'abhiab'\r\n */\r\nexport const pad = (\r\n str: string,\r\n length: number,\r\n chars: string = ' ',\r\n): string => {\r\n if (!Number.isFinite(length) || length < 0) {\r\n throw new ParameterError('Length must be a finite non-negative number');\r\n }\r\n const strLen = str.length;\r\n // 提前检查 chars 长度,避免后续计算\r\n if (strLen >= length || chars.length === 0) return str;\r\n\r\n const totalPad = length - strLen;\r\n const leftPad = Math.floor(totalPad / 2);\r\n const rightPad = totalPad - leftPad;\r\n\r\n const repeatLeft = chars\r\n .repeat(Math.ceil(leftPad / chars.length))\r\n .slice(0, leftPad);\r\n const repeatRight = chars\r\n .repeat(Math.ceil(rightPad / chars.length))\r\n .slice(0, rightPad);\r\n\r\n return repeatLeft + str + repeatRight;\r\n};\r\n\r\n// ------ 转义处理 ------\r\n\r\n/**\r\n * Removes diacritical marks (accents) from characters using Unicode normalization\r\n * @param str - String to process\r\n * @returns String with diacritical marks removed. Returns empty string if input is empty.\r\n * @example\r\n * deburr('déjà vu') // 'deja vu'\r\n * deburr('') // ''\r\n */\r\nexport const deburr = (str: string): string =>\r\n str.normalize('NFD').replace(/[\\u0300-\\u036f]/g, '');\r\n\r\n/**\r\n * Escapes special regex characters in a string\r\n * @param str - String containing regex special characters\r\n * @returns Escaped string safe for use in regex construction. Returns empty string if input is empty.\r\n * @example\r\n * escapeRegExp('[test].*') // '\\\\[test\\\\]\\\\.\\\\*'\r\n */\r\nexport const escapeRegExp = (str: string): string =>\r\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\r\n\r\n/**\r\n * Escapes HTML special characters (&, <, >, \", ')\r\n * @param str - String containing HTML\r\n * @returns Escaped string with HTML entities. Returns empty string if input is empty.\r\n * @example\r\n * escape('<div>\"test\"</div>') // '&lt;div&gt;&quot;test&quot;&lt;/div&gt;'\r\n */\r\nexport const escape = (str: string): string =>\r\n str.replace(HTML_ESCAPE_REGEXP, (match) => HTML_ESCAPE_MAP[match]);\r\n\r\n/**\r\n * Unescapes HTML entities (&amp;, &lt;, &gt;, &quot;, &#39;)\r\n * @param str - String with HTML entities\r\n * @returns Unescaped string. Returns empty string if input is empty.\r\n * @example\r\n * unescape('&lt;div&gt;') // '<div>'\r\n */\r\nexport const unescape = (str: string): string =>\r\n str.replace(HTML_UNESCAPE_REGEXP, (match) => HTML_UNESCAPE_MAP[match]);\r\n\r\n// ------ Unicode 安全操作 ------\r\n\r\n/**\r\n * Reverses a string while preserving Unicode characters and emojis\r\n * @param str - String to reverse\r\n * @returns Reversed string. Returns empty string if input is empty.\r\n * @example\r\n * reverseString('hello') // 'olleh'\r\n * reverseString('👍👋') // '👋👍'\r\n */\r\nexport const reverseString = (str: string): string =>\r\n [...str].reverse().join('');\r\n\r\n// ------ 大小写转换核心 ------\r\nconst splitWordsForCase = (str: string): string[] => {\r\n const normalized = deburr(str);\r\n return normalized.match(WORD_SPLIT_REGEXP) || [];\r\n};\r\n\r\nconst capitalizeWord = (word: string): string =>\r\n word ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() : word;\r\n\r\n/**\r\n * Converts string to Start Case (capitalizes first letter of each word)\r\n * @param str - String to convert\r\n * @returns Start case string. Returns empty string if input contains no words.\r\n * @remarks Handles alphanumeric boundaries (e.g., \"test123\" becomes \"Test 123\")\r\n * @example\r\n * startCase('hello world') // 'Hello World'\r\n * startCase('hello-world') // 'Hello World'\r\n * startCase('test123abc') // 'Test 123 Abc'\r\n */\r\nexport const startCase = (str: string): string => {\r\n return splitWordsForCase(str)\r\n .map(capitalizeWord)\r\n .join(' ')\r\n .replace(\r\n /([a-z])(\\d)|(\\d)([a-z])/gi,\r\n (_, p1, p2, p3, p4) => `${p1 || p3} ${p2 || p4}`,\r\n )\r\n .split(' ')\r\n .map(capitalizeWord)\r\n .join(' ')\r\n .trim();\r\n};\r\n\r\n// ------ 大小写转换函数 ------\r\n\r\n/**\r\n * Converts string to camelCase\r\n * @param str - String to convert\r\n * @returns camelCase string. Returns empty string if input contains no words.\r\n * @example\r\n * camelCase('Hello World') // 'helloWorld'\r\n * camelCase('hello-world') // 'helloWorld'\r\n * camelCase('') // ''\r\n */\r\nexport const camelCase = (str: string): string => {\r\n const words = splitWordsForCase(str);\r\n if (!words.length) return '';\r\n return words[0].toLowerCase() + words.slice(1).map(capitalizeWord).join('');\r\n};\r\n\r\n/**\r\n * Capitalizes first character and lowercases the rest\r\n * @param str - String to capitalize\r\n * @returns Capitalized string. Returns empty string if input is empty.\r\n * @example\r\n * capitalize('hello') // 'Hello'\r\n * capitalize('HELLO') // 'Hello'\r\n */\r\nexport const capitalize = (str: string): string =>\r\n str ? str.charAt(0).toUpperCase() + str.slice(1).toLowerCase() : str;\r\n\r\n/**\r\n * Converts string to CONSTANT_CASE (UPPERCASE_WITH_UNDERSCORES)\r\n * @param str - String to convert\r\n * @returns CONSTANT_CASE string. Returns empty string if input contains no words.\r\n * @example\r\n * constantCase('hello world') // 'HELLO_WORLD'\r\n */\r\nexport const constantCase = (str: string): string =>\r\n splitWordsForCase(str)\r\n .map((w) => w.toUpperCase())\r\n .join('_');\r\n\r\n/**\r\n * Converts string to kebab-case (lowercase-with-hyphens)\r\n * @param str - String to convert\r\n * @returns kebab-case string. Returns empty string if input contains no words.\r\n * @example\r\n * kebabCase('Hello World') // 'hello-world'\r\n */\r\nexport const kebabCase = (str: string): string =>\r\n splitWordsForCase(str)\r\n .map((w) => w.toLowerCase())\r\n .join('-');\r\n\r\n/**\r\n * Converts string to lowercase with spaces\r\n * @param str - String to convert\r\n * @returns Lowercase string with words separated by spaces. Returns empty string if input contains no words.\r\n * @example\r\n * lowerCase('HelloWorld') // 'hello world'\r\n */\r\nexport const lowerCase = (str: string): string =>\r\n splitWordsForCase(str)\r\n .map((w) => w.toLowerCase())\r\n .join(' ');\r\n\r\n/**\r\n * Converts first character to lowercase\r\n * @param str - String to convert\r\n * @returns String with first character lowercased. Returns empty string if input is empty.\r\n * @example\r\n * lowerFirst('Hello') // 'hello'\r\n * lowerFirst('HELLO') // 'hELLO'\r\n */\r\nexport const lowerFirst = (str: string): string =>\r\n str ? str.charAt(0).toLowerCase() + str.slice(1) : str;\r\n\r\n/**\r\n * Converts string to PascalCase (capitalizes first letter of each word)\r\n * @param str - String to convert\r\n * @returns PascalCase string. Returns empty string if input contains no words.\r\n * @example\r\n * pascalCase('hello world') // 'HelloWorld'\r\n */\r\nexport const pascalCase = (str: string): string =>\r\n splitWordsForCase(str).map(capitalizeWord).join('');\r\n\r\n/**\r\n * Converts string to snake_case (lowercase_with_underscores)\r\n * @param str - String to convert\r\n * @returns snake_case string. Returns empty string if input contains no words.\r\n * @example\r\n * snakeCase('Hello World') // 'hello_world'\r\n */\r\nexport const snakeCase = (str: string): string =>\r\n splitWordsForCase(str)\r\n .map((w) => w.toLowerCase())\r\n .join('_');\r\n\r\n/**\r\n * Converts string to UPPERCASE WITH SPACES\r\n * @param str - String to convert\r\n * @returns Uppercase string with words separated by spaces. Returns empty string if input contains no words.\r\n * @example\r\n * upperCase('hello-world') // 'HELLO WORLD'\r\n */\r\nexport const upperCase = (str: string): string =>\r\n splitWordsForCase(str)\r\n .map((w) => w.toUpperCase())\r\n .join(' ');\r\n\r\n/**\r\n * Converts first character to uppercase\r\n * @param str - String to convert\r\n * @returns String with first character uppercased. Returns empty string if input is empty.\r\n * @example\r\n * upperFirst('hello') // 'Hello'\r\n * upperFirst('hELLO') // 'HELLO'\r\n */\r\nexport const upperFirst = (str: string): string =>\r\n str ? str.charAt(0).toUpperCase() + str.slice(1) : str;\r\n\r\n// ------ 单词提取 ------\r\n\r\n/**\r\n * Extracts words from string using Unicode-aware regex (supports all languages)\r\n * @param str - String to extract words from\r\n * @returns Array of words (Unicode letters and numbers). Returns empty array if no words found.\r\n * @example\r\n * words('Hello world!') // ['Hello', 'world']\r\n * words('你好,世界!') // ['你好', '世界']\r\n * words('123 abc') // ['123', 'abc']\r\n */\r\nexport const words = (str: string): string[] =>\r\n str.match(UNICODE_WORD_REGEXP) || [];\r\n\r\n// ------ 随机字符串生成 ------\r\n\r\n/**\r\n * Generates a random string from the specified character set\r\n * @param length - Length of the string to generate. Must be a non-negative integer.\r\n * @param charset - Character set to use for generation. Defaults to alphanumeric (a-z, A-Z, 0-9).\r\n * @returns Randomly generated string\r\n * @throws ParameterError if length is negative or not an integer\r\n * @example\r\n * randomString(8) // 'aB3xK9pL'\r\n * randomString(6, '0123456789') // '384729'\r\n * randomString(10, 'abc') // 'abccabacba'\r\n */\r\nexport const randomString = (length: number, charset?: string): string => {\r\n if (!Number.isInteger(length) || length < 0)\r\n throw new ParameterError('Length must be a non-negative integer');\r\n\r\n const chars =\r\n charset ?? 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\r\n if (chars.length === 0) return '';\r\n\r\n let result = '';\r\n for (let i = 0; i < length; i++)\r\n result += chars.charAt(Math.floor(Math.random() * chars.length));\r\n\r\n return result;\r\n};\r\n\r\n\r\n\r\n// ------ 模板字符串 ------\r\n\r\n/**\r\n * Replaces placeholders in template string with values from data object\r\n * @template T - Type of data object\r\n * @param str - Template string with {{placeholder}} syntax\r\n * @param data - Object containing values to replace placeholders. Supports nested paths like {{user.name}}\r\n * @returns String with placeholders replaced by corresponding values. Undefined values are replaced with empty string.\r\n * @example\r\n * template('Hello {{name}}!', {name: 'Alice'}) // 'Hello Alice!'\r\n * template('Hello {{user.name}}!', {user: {name: 'Bob'}}) // 'Hello Bob!'\r\n * template('Welcome to {{company}}!', {company: 'Tech Corp'}) // 'Welcome to Tech Corp!'\r\n */\r\nexport const template = <T extends Record<string, unknown>>(\r\n str: string,\r\n data: T,\r\n): string => {\r\n return str.replace(/\\{\\{([^}]+)\\}\\}/g, (_, path: string) => {\r\n const trimmed_path = path.trim();\r\n const keys = trimmed_path.split('.');\r\n let current: unknown = data;\r\n\r\n for (const key of keys) {\r\n if (current === null || typeof current !== 'object') {\r\n current = undefined;\r\n break;\r\n }\r\n current = (current as Record<string, unknown>)[key];\r\n }\r\n\r\n if (current === undefined || current === null) return '';\r\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\r\n return String(current);\r\n });\r\n};\r\n"],"names":["HTML_ESCAPE_MAP","HTML_UNESCAPE_MAP","HTML_ESCAPE_REGEXP","HTML_UNESCAPE_REGEXP","WORD_SPLIT_REGEXP","UNICODE_WORD_REGEXP","TRIM_START_REGEXP","TRIM_END_REGEXP","trim","str","chars","safeChars","escapeRegExp","trimStart","trimEnd","pad","length","ParameterError","strLen","totalPad","leftPad","rightPad","repeatLeft","repeatRight","deburr","escape","match","unescape","reverseString","splitWordsForCase","capitalizeWord","word","startCase","_","p1","p2","p3","p4","camelCase","words","capitalize","constantCase","w","kebabCase","lowerCase","lowerFirst","pascalCase","snakeCase","upperCase","upperFirst","randomString","charset","result","i","template","data","path","keys","current","key"],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../chunks/types-B7X_LBjM.cjs"),c=require("../chunks/Errors-BWEYu-AB.cjs"),t=Symbol("Data"),a=Symbol("Cleanup");class l{[t];[a];constructor(s,o){this[t]=s,this[a]=o}static open(s,o){return new l(s,o)}[Symbol.dispose](){this[t]!==r.NONE&&(this[a]&&this[a](this[t]),this[t]=r.NONE)}}function p(e,s){if(e[t]===r.NONE)throw new c.UseAfterFreeError("Resource already disposed.");return s(e[t])}function d(e,s){if(e[t]===r.NONE)throw new c.UseAfterFreeError("Resource already disposed.");return s(e[t]),e}function f(e){return e[Symbol.dispose](),e}function h(e,s){if(e[t]===r.NONE)throw new c.UseAfterFreeError("Resource already disposed.");try{s(e[t])}finally{e[Symbol.dispose]()}return e}function w(e,s,o){const i=e;return i[t]=s,i[a]=o,i}const n=Symbol("Data"),y=Symbol("Cleanup");class u{[n];[y];constructor(s,o){this[n]=s,this[y]=o}static open(s,o){return new u(s,o)}async[Symbol.asyncDispose](){this[n]!==r.NONE&&(this[y]&&await this[y](this[n]),this[n]=r.NONE)}}async function N(e,s){if(e[n]===r.NONE)throw new c.UseAfterFreeError("Resource already disposed.");return await s(e[n])}async function A(e,s){if(e[n]===r.NONE)throw new c.UseAfterFreeError("Resource already disposed.");return await s(e[n]),e}async function E(e){return await e[Symbol.asyncDispose](),e}async function S(e,s){if(e[n]===r.NONE)throw new c.UseAfterFreeError("Resource already disposed.");try{await s(e[n])}finally{await e[Symbol.asyncDispose]()}return e}function b(e,s,o){const i=e;return i[n]=s,i[y]=o,i}const _=Object.freeze(Object.defineProperty({__proto__:null,Resource:l,ResourceAsync:u,close:f,closeAsync:E,dispose:h,disposeAsync:S,exec:d,execAsync:A,reopen:w,reopenAsync:b,use:p,useAsync:N},Symbol.toStringTag,{value:"Module"}));exports.Resource=l;exports.ResourceAsync=u;exports.__exportTxScope__=_;exports.close=f;exports.closeAsync=E;exports.dispose=h;exports.disposeAsync=S;exports.exec=d;exports.execAsync=A;exports.reopen=w;exports.reopenAsync=b;exports.use=p;exports.useAsync=N;
2
+ //# sourceMappingURL=TxScope.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TxScope.cjs","sources":["../../src/Resource/resource.ts","../../src/Resource/resource-async.ts"],"sourcesContent":["// ========================================\r\n// ./src/Resource/resource.ts\r\n// ========================================\r\n/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */\r\n\r\nimport {\r\n type StateOpened,\r\n type StateClosed,\r\n type NoneType,\r\n type Cleaner,\r\n NONE,\r\n} from './types';\r\nimport {UseAfterFreeError} from '../Errors';\r\n\r\n// ------ 私有符号定义 ------\r\nconst _data = Symbol('Data');\r\nconst _cleanup = Symbol('Cleanup');\r\n\r\n/**\r\n * Synchronous resource management class.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam S - The state type (opened or closed)\r\n */\r\nexport class Resource<T, S extends StateOpened | StateClosed> {\r\n declare private state: S;\r\n public [_data]: T | NoneType;\r\n public [_cleanup]: Cleaner<T> | undefined;\r\n\r\n // ------ 构造函数 ------\r\n private constructor(data: T, cleanup_fn?: Cleaner<T>) {\r\n this[_data] = data;\r\n this[_cleanup] = cleanup_fn;\r\n }\r\n\r\n /**\r\n * Creates a new opened synchronous resource.\r\n * @typeParam D - The type of the resource data\r\n * @param data - The resource data\r\n * @param cleaner - Optional synchronous cleanup function\r\n * @returns A new opened synchronous resource\r\n */\r\n static open<D>(data: D, cleaner?: Cleaner<D>): Resource<D, StateOpened> {\r\n return new Resource(data, cleaner);\r\n }\r\n\r\n /**\r\n * Synchronously disposes the resource (cleanup).\r\n */\r\n [Symbol.dispose](this: Resource<T, StateOpened>): void {\r\n if (this[_data] === NONE) {\r\n // 让清理具备幂等性,不会双重释放。这是为了避免被using修饰的资源被手动close之后资源被using再次尝试清理 -> 触发双重释放\r\n return;\r\n }\r\n if (this[_cleanup]) {\r\n this[_cleanup](this[_data] as T);\r\n }\r\n this[_data] = NONE;\r\n }\r\n}\r\n\r\n/**\r\n * Union type for synchronous resource states.\r\n * @typeParam T - The type of the resource data\r\n */\r\nexport type ResType<T> = Resource<T, StateOpened> | Resource<T, StateClosed>;\r\n\r\n/**\r\n * Uses a synchronous resource with a callback function.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the callback\r\n * @param resource - The opened synchronous resource\r\n * @param fn - Function to process the resource data\r\n * @returns The result of the callback\r\n * @throws Error if resource is already disposed\r\n */\r\nexport function use<T, R>(\r\n resource: Resource<T, StateOpened>,\r\n fn: (data: T) => R,\r\n): R {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n return fn(resource[_data] as T);\r\n}\r\n\r\n/**\r\n * Performs a side effect on a synchronous resource and returns the resource.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the side effect function\r\n * @param resource - The opened synchronous resource\r\n * @param fn - Side effect function to execute\r\n * @returns The same resource after executing the side effect\r\n * @throws Error if resource is already disposed\r\n */\r\nexport function exec<T, R>(\r\n resource: Resource<T, StateOpened>,\r\n fn: (data: T) => R,\r\n): Resource<T, StateOpened> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n fn(resource[_data] as T);\r\n return resource;\r\n}\r\n\r\n/**\r\n * Closes a synchronous resource (disposes it).\r\n * @typeParam T - The type of the resource data\r\n * @param resource - The opened synchronous resource to close\r\n * @returns The closed synchronous resource\r\n */\r\nexport function close<T>(\r\n resource: Resource<T, StateOpened>,\r\n): Resource<T, StateClosed> {\r\n resource[Symbol.dispose]();\r\n return resource as unknown as Resource<T, StateClosed>;\r\n}\r\n\r\n/**\r\n * Executes a function on the resource and then closes it,\r\n * guaranteeing cleanup even if the function throws.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the function\r\n * @param resource - The opened synchronous resource\r\n * @param fn - Function to execute before closing\r\n * @returns The closed synchronous resource\r\n */\r\nexport function dispose<T, R>(\r\n resource: Resource<T, StateOpened>,\r\n fn: (data: T) => R,\r\n): Resource<T, StateClosed> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n try {\r\n fn(resource[_data] as T);\r\n } finally {\r\n resource[Symbol.dispose]();\r\n }\r\n return resource as unknown as Resource<T, StateClosed>;\r\n}\r\n\r\n/**\r\n * Reopens a closed synchronous resource with new data.\r\n * @typeParam T - The type of the resource data\r\n * @param resource - The closed synchronous resource\r\n * @param data - New data for the resource\r\n * @param cleaner - Optional new cleanup function\r\n * @returns The reopened synchronous resource\r\n */\r\nexport function reopen<T>(\r\n resource: Resource<T, StateClosed>,\r\n data: T,\r\n cleaner?: Cleaner<T>,\r\n): Resource<T, StateOpened> {\r\n const r = resource as unknown as Resource<T, StateOpened>;\r\n r[_data] = data;\r\n r[_cleanup] = cleaner;\r\n return r;\r\n}\r\n","// ========================================\r\n// ./src/Resource/resource-async.ts\r\n// ========================================\r\n/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */\r\n\r\nimport {\r\n type StateOpened,\r\n type StateClosed,\r\n type AnyCleaner,\r\n type NoneType,\r\n NONE,\r\n} from './types';\r\nimport {UseAfterFreeError} from '../Errors';\r\n\r\n// ------ 私有符号定义 ------\r\nconst _data = Symbol('Data');\r\nconst _cleanup = Symbol('Cleanup');\r\n\r\n/**\r\n * Asynchronous resource management class.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam S - The state type (opened or closed)\r\n */\r\nexport class ResourceAsync<T, S extends StateOpened | StateClosed> {\r\n declare private state: S;\r\n public [_data]: T | NoneType;\r\n public [_cleanup]: AnyCleaner<T> | undefined;\r\n\r\n // ------ 构造函数 ------\r\n private constructor(data: T, async_cleanup_fn?: AnyCleaner<T>) {\r\n this[_data] = data;\r\n this[_cleanup] = async_cleanup_fn;\r\n }\r\n\r\n /**\r\n * Creates a new opened asynchronous resource.\r\n * @typeParam D - The type of the resource data\r\n * @param data - The resource data\r\n * @param cleaner - Optional asynchronous cleanup function\r\n * @returns A new opened asynchronous resource\r\n */\r\n static open<D>(\r\n data: D,\r\n cleaner?: AnyCleaner<D>,\r\n ): ResourceAsync<D, StateOpened> {\r\n return new ResourceAsync(data, cleaner);\r\n }\r\n\r\n /**\r\n * Asynchronously disposes the resource (cleanup).\r\n * @returns Promise that resolves when disposal is complete\r\n */\r\n async [Symbol.asyncDispose](\r\n this: ResourceAsync<T, StateOpened>,\r\n ): Promise<void> {\r\n if (this[_data] === NONE) {\r\n return;\r\n }\r\n if (this[_cleanup]) {\r\n await this[_cleanup](this[_data] as T);\r\n }\r\n this[_data] = NONE;\r\n }\r\n}\r\n\r\n/**\r\n * Union type for asynchronous resource states.\r\n * @typeParam T - The type of the resource data\r\n */\r\nexport type ResAsyncType<T> =\r\n | ResourceAsync<T, StateOpened>\r\n | ResourceAsync<T, StateClosed>;\r\n\r\n/**\r\n * Uses an asynchronous resource with a callback function.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the callback\r\n * @param resource - The opened asynchronous resource\r\n * @param callback - Function to process the resource data\r\n * @returns Promise with the result of the callback\r\n * @throws Error if resource is already disposed\r\n */\r\nexport async function useAsync<T, R>(\r\n resource: ResourceAsync<T, StateOpened>,\r\n callback: (data: T) => Promise<R> | R,\r\n): Promise<R> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n return await callback(resource[_data] as T);\r\n}\r\n\r\n/**\r\n * Performs a side effect on an asynchronous resource and returns the resource.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the side effect function\r\n * @param resource - The opened asynchronous resource\r\n * @param fn - Side effect function to execute\r\n * @returns The same resource after executing the side effect\r\n * @throws Error if resource is already disposed\r\n */\r\nexport async function execAsync<T, R>(\r\n resource: ResourceAsync<T, StateOpened>,\r\n fn: (data: T) => Promise<R> | R,\r\n): Promise<ResourceAsync<T, StateOpened>> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n await fn(resource[_data] as T);\r\n return resource;\r\n}\r\n\r\n/**\r\n * Closes an asynchronous resource (disposes it).\r\n * @typeParam T - The type of the resource data\r\n * @param resource - The opened asynchronous resource to close\r\n * @returns The closed asynchronous resource\r\n */\r\nexport async function closeAsync<T>(\r\n resource: ResourceAsync<T, StateOpened>,\r\n): Promise<ResourceAsync<T, StateClosed>> {\r\n await resource[Symbol.asyncDispose]();\r\n return resource as unknown as ResourceAsync<T, StateClosed>;\r\n}\r\n\r\n/**\r\n * Executes an asynchronous or synchronous function on the resource and then closes it,\r\n * guaranteeing asynchronous cleanup even if the function throws.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the function\r\n * @param resource - The opened asynchronous resource\r\n * @param fn - Asynchronous or synchronous function to execute before closing\r\n * @returns A promise that resolves to the closed asynchronous resource\r\n */\r\nexport async function disposeAsync<T, R>(\r\n resource: ResourceAsync<T, StateOpened>,\r\n fn: (data: T) => Promise<R> | R,\r\n): Promise<ResourceAsync<T, StateClosed>> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n try {\r\n await fn(resource[_data] as T);\r\n } finally {\r\n await resource[Symbol.asyncDispose]();\r\n }\r\n return resource as unknown as ResourceAsync<T, StateClosed>;\r\n}\r\n\r\n/**\r\n * Reopens a closed asynchronous resource with new data.\r\n * @typeParam T - The type of the resource data\r\n * @param resource - The closed asynchronous resource\r\n * @param data - New data for the resource\r\n * @param cleaner - Optional new cleanup function\r\n * @returns The reopened asynchronous resource\r\n */\r\nexport function reopenAsync<T>(\r\n resource: ResourceAsync<T, StateClosed>,\r\n data: T,\r\n cleaner?: AnyCleaner<T>,\r\n): ResourceAsync<T, StateOpened> {\r\n const r = resource as unknown as ResourceAsync<T, StateOpened>;\r\n r[_data] = data;\r\n r[_cleanup] = cleaner;\r\n return r;\r\n}\r\n"],"names":["_data","_cleanup","Resource","data","cleanup_fn","cleaner","NONE","use","resource","fn","UseAfterFreeError","exec","close","dispose","reopen","r","ResourceAsync","async_cleanup_fn","useAsync","callback","execAsync","closeAsync","disposeAsync","reopenAsync"],"mappings":"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"}
@@ -0,0 +1,138 @@
1
+ import { N as e } from "../chunks/types-DE2SnSbz.mjs";
2
+ import { U as r } from "../chunks/Errors-DwUAvFIF.mjs";
3
+ const s = Symbol("Data"), c = Symbol("Cleanup");
4
+ class l {
5
+ [s];
6
+ [c];
7
+ // ------ 构造函数 ------
8
+ constructor(n, i) {
9
+ this[s] = n, this[c] = i;
10
+ }
11
+ /**
12
+ * Creates a new opened synchronous resource.
13
+ * @typeParam D - The type of the resource data
14
+ * @param data - The resource data
15
+ * @param cleaner - Optional synchronous cleanup function
16
+ * @returns A new opened synchronous resource
17
+ */
18
+ static open(n, i) {
19
+ return new l(n, i);
20
+ }
21
+ /**
22
+ * Synchronously disposes the resource (cleanup).
23
+ */
24
+ [Symbol.dispose]() {
25
+ this[s] !== e && (this[c] && this[c](this[s]), this[s] = e);
26
+ }
27
+ }
28
+ function d(t, n) {
29
+ if (t[s] === e)
30
+ throw new r("Resource already disposed.");
31
+ return n(t[s]);
32
+ }
33
+ function f(t, n) {
34
+ if (t[s] === e)
35
+ throw new r("Resource already disposed.");
36
+ return n(t[s]), t;
37
+ }
38
+ function u(t) {
39
+ return t[Symbol.dispose](), t;
40
+ }
41
+ function h(t, n) {
42
+ if (t[s] === e)
43
+ throw new r("Resource already disposed.");
44
+ try {
45
+ n(t[s]);
46
+ } finally {
47
+ t[Symbol.dispose]();
48
+ }
49
+ return t;
50
+ }
51
+ function w(t, n, i) {
52
+ const a = t;
53
+ return a[s] = n, a[c] = i, a;
54
+ }
55
+ const o = Symbol("Data"), y = Symbol("Cleanup");
56
+ class p {
57
+ [o];
58
+ [y];
59
+ // ------ 构造函数 ------
60
+ constructor(n, i) {
61
+ this[o] = n, this[y] = i;
62
+ }
63
+ /**
64
+ * Creates a new opened asynchronous resource.
65
+ * @typeParam D - The type of the resource data
66
+ * @param data - The resource data
67
+ * @param cleaner - Optional asynchronous cleanup function
68
+ * @returns A new opened asynchronous resource
69
+ */
70
+ static open(n, i) {
71
+ return new p(n, i);
72
+ }
73
+ /**
74
+ * Asynchronously disposes the resource (cleanup).
75
+ * @returns Promise that resolves when disposal is complete
76
+ */
77
+ async [Symbol.asyncDispose]() {
78
+ this[o] !== e && (this[y] && await this[y](this[o]), this[o] = e);
79
+ }
80
+ }
81
+ async function m(t, n) {
82
+ if (t[o] === e)
83
+ throw new r("Resource already disposed.");
84
+ return await n(t[o]);
85
+ }
86
+ async function b(t, n) {
87
+ if (t[o] === e)
88
+ throw new r("Resource already disposed.");
89
+ return await n(t[o]), t;
90
+ }
91
+ async function S(t) {
92
+ return await t[Symbol.asyncDispose](), t;
93
+ }
94
+ async function _(t, n) {
95
+ if (t[o] === e)
96
+ throw new r("Resource already disposed.");
97
+ try {
98
+ await n(t[o]);
99
+ } finally {
100
+ await t[Symbol.asyncDispose]();
101
+ }
102
+ return t;
103
+ }
104
+ function A(t, n, i) {
105
+ const a = t;
106
+ return a[o] = n, a[y] = i, a;
107
+ }
108
+ const D = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
109
+ __proto__: null,
110
+ Resource: l,
111
+ ResourceAsync: p,
112
+ close: u,
113
+ closeAsync: S,
114
+ dispose: h,
115
+ disposeAsync: _,
116
+ exec: f,
117
+ execAsync: b,
118
+ reopen: w,
119
+ reopenAsync: A,
120
+ use: d,
121
+ useAsync: m
122
+ }, Symbol.toStringTag, { value: "Module" }));
123
+ export {
124
+ l as Resource,
125
+ p as ResourceAsync,
126
+ D as _,
127
+ u as close,
128
+ S as closeAsync,
129
+ h as dispose,
130
+ _ as disposeAsync,
131
+ f as exec,
132
+ b as execAsync,
133
+ w as reopen,
134
+ A as reopenAsync,
135
+ d as use,
136
+ m as useAsync
137
+ };
138
+ //# sourceMappingURL=TxScope.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TxScope.mjs","sources":["../../src/Resource/resource.ts","../../src/Resource/resource-async.ts"],"sourcesContent":["// ========================================\r\n// ./src/Resource/resource.ts\r\n// ========================================\r\n/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */\r\n\r\nimport {\r\n type StateOpened,\r\n type StateClosed,\r\n type NoneType,\r\n type Cleaner,\r\n NONE,\r\n} from './types';\r\nimport {UseAfterFreeError} from '../Errors';\r\n\r\n// ------ 私有符号定义 ------\r\nconst _data = Symbol('Data');\r\nconst _cleanup = Symbol('Cleanup');\r\n\r\n/**\r\n * Synchronous resource management class.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam S - The state type (opened or closed)\r\n */\r\nexport class Resource<T, S extends StateOpened | StateClosed> {\r\n declare private state: S;\r\n public [_data]: T | NoneType;\r\n public [_cleanup]: Cleaner<T> | undefined;\r\n\r\n // ------ 构造函数 ------\r\n private constructor(data: T, cleanup_fn?: Cleaner<T>) {\r\n this[_data] = data;\r\n this[_cleanup] = cleanup_fn;\r\n }\r\n\r\n /**\r\n * Creates a new opened synchronous resource.\r\n * @typeParam D - The type of the resource data\r\n * @param data - The resource data\r\n * @param cleaner - Optional synchronous cleanup function\r\n * @returns A new opened synchronous resource\r\n */\r\n static open<D>(data: D, cleaner?: Cleaner<D>): Resource<D, StateOpened> {\r\n return new Resource(data, cleaner);\r\n }\r\n\r\n /**\r\n * Synchronously disposes the resource (cleanup).\r\n */\r\n [Symbol.dispose](this: Resource<T, StateOpened>): void {\r\n if (this[_data] === NONE) {\r\n // 让清理具备幂等性,不会双重释放。这是为了避免被using修饰的资源被手动close之后资源被using再次尝试清理 -> 触发双重释放\r\n return;\r\n }\r\n if (this[_cleanup]) {\r\n this[_cleanup](this[_data] as T);\r\n }\r\n this[_data] = NONE;\r\n }\r\n}\r\n\r\n/**\r\n * Union type for synchronous resource states.\r\n * @typeParam T - The type of the resource data\r\n */\r\nexport type ResType<T> = Resource<T, StateOpened> | Resource<T, StateClosed>;\r\n\r\n/**\r\n * Uses a synchronous resource with a callback function.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the callback\r\n * @param resource - The opened synchronous resource\r\n * @param fn - Function to process the resource data\r\n * @returns The result of the callback\r\n * @throws Error if resource is already disposed\r\n */\r\nexport function use<T, R>(\r\n resource: Resource<T, StateOpened>,\r\n fn: (data: T) => R,\r\n): R {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n return fn(resource[_data] as T);\r\n}\r\n\r\n/**\r\n * Performs a side effect on a synchronous resource and returns the resource.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the side effect function\r\n * @param resource - The opened synchronous resource\r\n * @param fn - Side effect function to execute\r\n * @returns The same resource after executing the side effect\r\n * @throws Error if resource is already disposed\r\n */\r\nexport function exec<T, R>(\r\n resource: Resource<T, StateOpened>,\r\n fn: (data: T) => R,\r\n): Resource<T, StateOpened> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n fn(resource[_data] as T);\r\n return resource;\r\n}\r\n\r\n/**\r\n * Closes a synchronous resource (disposes it).\r\n * @typeParam T - The type of the resource data\r\n * @param resource - The opened synchronous resource to close\r\n * @returns The closed synchronous resource\r\n */\r\nexport function close<T>(\r\n resource: Resource<T, StateOpened>,\r\n): Resource<T, StateClosed> {\r\n resource[Symbol.dispose]();\r\n return resource as unknown as Resource<T, StateClosed>;\r\n}\r\n\r\n/**\r\n * Executes a function on the resource and then closes it,\r\n * guaranteeing cleanup even if the function throws.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the function\r\n * @param resource - The opened synchronous resource\r\n * @param fn - Function to execute before closing\r\n * @returns The closed synchronous resource\r\n */\r\nexport function dispose<T, R>(\r\n resource: Resource<T, StateOpened>,\r\n fn: (data: T) => R,\r\n): Resource<T, StateClosed> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n try {\r\n fn(resource[_data] as T);\r\n } finally {\r\n resource[Symbol.dispose]();\r\n }\r\n return resource as unknown as Resource<T, StateClosed>;\r\n}\r\n\r\n/**\r\n * Reopens a closed synchronous resource with new data.\r\n * @typeParam T - The type of the resource data\r\n * @param resource - The closed synchronous resource\r\n * @param data - New data for the resource\r\n * @param cleaner - Optional new cleanup function\r\n * @returns The reopened synchronous resource\r\n */\r\nexport function reopen<T>(\r\n resource: Resource<T, StateClosed>,\r\n data: T,\r\n cleaner?: Cleaner<T>,\r\n): Resource<T, StateOpened> {\r\n const r = resource as unknown as Resource<T, StateOpened>;\r\n r[_data] = data;\r\n r[_cleanup] = cleaner;\r\n return r;\r\n}\r\n","// ========================================\r\n// ./src/Resource/resource-async.ts\r\n// ========================================\r\n/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */\r\n\r\nimport {\r\n type StateOpened,\r\n type StateClosed,\r\n type AnyCleaner,\r\n type NoneType,\r\n NONE,\r\n} from './types';\r\nimport {UseAfterFreeError} from '../Errors';\r\n\r\n// ------ 私有符号定义 ------\r\nconst _data = Symbol('Data');\r\nconst _cleanup = Symbol('Cleanup');\r\n\r\n/**\r\n * Asynchronous resource management class.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam S - The state type (opened or closed)\r\n */\r\nexport class ResourceAsync<T, S extends StateOpened | StateClosed> {\r\n declare private state: S;\r\n public [_data]: T | NoneType;\r\n public [_cleanup]: AnyCleaner<T> | undefined;\r\n\r\n // ------ 构造函数 ------\r\n private constructor(data: T, async_cleanup_fn?: AnyCleaner<T>) {\r\n this[_data] = data;\r\n this[_cleanup] = async_cleanup_fn;\r\n }\r\n\r\n /**\r\n * Creates a new opened asynchronous resource.\r\n * @typeParam D - The type of the resource data\r\n * @param data - The resource data\r\n * @param cleaner - Optional asynchronous cleanup function\r\n * @returns A new opened asynchronous resource\r\n */\r\n static open<D>(\r\n data: D,\r\n cleaner?: AnyCleaner<D>,\r\n ): ResourceAsync<D, StateOpened> {\r\n return new ResourceAsync(data, cleaner);\r\n }\r\n\r\n /**\r\n * Asynchronously disposes the resource (cleanup).\r\n * @returns Promise that resolves when disposal is complete\r\n */\r\n async [Symbol.asyncDispose](\r\n this: ResourceAsync<T, StateOpened>,\r\n ): Promise<void> {\r\n if (this[_data] === NONE) {\r\n return;\r\n }\r\n if (this[_cleanup]) {\r\n await this[_cleanup](this[_data] as T);\r\n }\r\n this[_data] = NONE;\r\n }\r\n}\r\n\r\n/**\r\n * Union type for asynchronous resource states.\r\n * @typeParam T - The type of the resource data\r\n */\r\nexport type ResAsyncType<T> =\r\n | ResourceAsync<T, StateOpened>\r\n | ResourceAsync<T, StateClosed>;\r\n\r\n/**\r\n * Uses an asynchronous resource with a callback function.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the callback\r\n * @param resource - The opened asynchronous resource\r\n * @param callback - Function to process the resource data\r\n * @returns Promise with the result of the callback\r\n * @throws Error if resource is already disposed\r\n */\r\nexport async function useAsync<T, R>(\r\n resource: ResourceAsync<T, StateOpened>,\r\n callback: (data: T) => Promise<R> | R,\r\n): Promise<R> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n return await callback(resource[_data] as T);\r\n}\r\n\r\n/**\r\n * Performs a side effect on an asynchronous resource and returns the resource.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the side effect function\r\n * @param resource - The opened asynchronous resource\r\n * @param fn - Side effect function to execute\r\n * @returns The same resource after executing the side effect\r\n * @throws Error if resource is already disposed\r\n */\r\nexport async function execAsync<T, R>(\r\n resource: ResourceAsync<T, StateOpened>,\r\n fn: (data: T) => Promise<R> | R,\r\n): Promise<ResourceAsync<T, StateOpened>> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n await fn(resource[_data] as T);\r\n return resource;\r\n}\r\n\r\n/**\r\n * Closes an asynchronous resource (disposes it).\r\n * @typeParam T - The type of the resource data\r\n * @param resource - The opened asynchronous resource to close\r\n * @returns The closed asynchronous resource\r\n */\r\nexport async function closeAsync<T>(\r\n resource: ResourceAsync<T, StateOpened>,\r\n): Promise<ResourceAsync<T, StateClosed>> {\r\n await resource[Symbol.asyncDispose]();\r\n return resource as unknown as ResourceAsync<T, StateClosed>;\r\n}\r\n\r\n/**\r\n * Executes an asynchronous or synchronous function on the resource and then closes it,\r\n * guaranteeing asynchronous cleanup even if the function throws.\r\n * @typeParam T - The type of the resource data\r\n * @typeParam R - The return type of the function\r\n * @param resource - The opened asynchronous resource\r\n * @param fn - Asynchronous or synchronous function to execute before closing\r\n * @returns A promise that resolves to the closed asynchronous resource\r\n */\r\nexport async function disposeAsync<T, R>(\r\n resource: ResourceAsync<T, StateOpened>,\r\n fn: (data: T) => Promise<R> | R,\r\n): Promise<ResourceAsync<T, StateClosed>> {\r\n if (resource[_data] === NONE) {\r\n throw new UseAfterFreeError('Resource already disposed.');\r\n }\r\n try {\r\n await fn(resource[_data] as T);\r\n } finally {\r\n await resource[Symbol.asyncDispose]();\r\n }\r\n return resource as unknown as ResourceAsync<T, StateClosed>;\r\n}\r\n\r\n/**\r\n * Reopens a closed asynchronous resource with new data.\r\n * @typeParam T - The type of the resource data\r\n * @param resource - The closed asynchronous resource\r\n * @param data - New data for the resource\r\n * @param cleaner - Optional new cleanup function\r\n * @returns The reopened asynchronous resource\r\n */\r\nexport function reopenAsync<T>(\r\n resource: ResourceAsync<T, StateClosed>,\r\n data: T,\r\n cleaner?: AnyCleaner<T>,\r\n): ResourceAsync<T, StateOpened> {\r\n const r = resource as unknown as ResourceAsync<T, StateOpened>;\r\n r[_data] = data;\r\n r[_cleanup] = cleaner;\r\n return r;\r\n}\r\n"],"names":["_data","_cleanup","Resource","data","cleanup_fn","cleaner","NONE","use","resource","fn","UseAfterFreeError","exec","close","dispose","reopen","r","ResourceAsync","async_cleanup_fn","useAsync","callback","execAsync","closeAsync","disposeAsync","reopenAsync"],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=e=>e,c=e=>{},s=()=>e=>{};exports.castErr=t;exports.expectAssignable=c;exports.expectIdentical=s;
2
+ //# sourceMappingURL=TypeTool.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeTool.cjs","sources":["../../src/Utils/type-tool.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* v8 ignore file -- @preserve */\n\n/**\n * Represents a value that can be either a plain value or a Promise-like object.\n * @template T - The type of the value or Promise-like object.\n */\nexport type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * Creates a deeply partial type where all properties become optional recursively.\n * @template T - The source type\n * @remarks Functions are left untouched (preserved as-is).\n */\nexport type PartialDeep<T> = T extends (...args: any[]) => any\n ? T\n : T extends object\n ? {[K in keyof T]?: PartialDeep<T[K]>}\n : T;\n\n/**\n * Creates a deeply required type where all properties become non-optional recursively.\n * @template T - The source type\n * @remarks Functions are left untouched (preserved as-is).\n */\nexport type RequiredDeep<T> = T extends (...args: any[]) => any\n ? T\n : T extends object\n ? {[K in keyof T]-?: RequiredDeep<T[K]>}\n : T;\n\n/**\n * Creates a deeply readonly type where all properties become immutable recursively.\n * @template T - The source type\n * @remarks Functions are left untouched (preserved as-is).\n */\nexport type ReadonlyDeep<T> = T extends (...args: any[]) => any\n ? T\n : T extends object\n ? {readonly [K in keyof T]: ReadonlyDeep<T[K]>}\n : T;\n\n/**\n * Removes readonly modifiers from all properties at the first level only.\n * @template T - The source type\n */\nexport type Mutable<T> = {-readonly [P in keyof T]: T[P]};\n\n/**\n * Removes readonly modifiers from all properties recursively.\n * @template T - The source type\n * @remarks This affects nested objects as well.\n */\nexport type MutableDeep<T> = {\n -readonly [K in keyof T]: T[K] extends object ? MutableDeep<T[K]> : T[K];\n};\n\n/**\n * Makes specific properties required while keeping others unchanged.\n * @template T - The source type\n * @template K - Keys of properties to make required\n */\nexport type SetRequired<T, K extends keyof T> = {\n [P in keyof T as P extends K ? never : P]: T[P];\n} & {\n [P in K]-?: T[P];\n} extends infer O\n ? {[P in keyof O]: O[P]}\n : never;\n\n/**\n * Makes specific properties optional while keeping others unchanged.\n * @template T - The source type\n * @template K - Keys of properties to make optional\n */\nexport type SetOptional<T, K extends keyof T> = {\n [P in keyof T as P extends K ? never : P]: T[P];\n} & {\n [P in K]?: T[P];\n} extends infer O\n ? {[P in keyof O]: O[P]}\n : never;\n\n/**\n * Creates a union type that includes literal values plus a base type.\n * @template Literal - The literal type(s) to include\n * @template Base - The base string or number type\n * @remarks Useful for allowing string literals while also accepting any string.\n */\nexport type LiteralUnion<Literal, Base extends string | number> =\n | Literal\n | (Base & Record<never, never>);\n\n/**\n * Flattens type intersections for better IntelliSense display.\n * @template T - The type to prettify\n * @remarks This doesn't change the type, only its display in IDEs.\n */\nexport type Prettify<T> = {[K in keyof T]: T[K]} & {};\n\n/**\n * Extracts the resolved return type of an async function.\n * @template T - The async function type\n * @remarks Unwraps Promise to get the actual return type.\n */\nexport type AsyncReturnType<T extends (...args: any) => any> = Awaited<\n ReturnType<T>\n>;\n\n/**\n * Checks if a type is the `any` type.\n * @template T - The type to check\n * @returns `true` if T is `any`, otherwise `false`\n */\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Checks if a type is exactly `undefined`.\n * @template T - The type to check\n * @returns `true` if T is `undefined`, otherwise `false`\n * @remarks Note: This distinguishes `undefined` from optional properties.\n */\nexport type IsUndefined<T> = [T] extends [undefined] ? true : false;\n\n/**\n * Checks if a type is the `never` type.\n * @template T - The type to check\n * @returns `true` if T is `never`, otherwise `false`\n */\nexport type IsNever<T> = [T] extends [never] ? true : false;\n\n/**\n * Checks if a type is the `unknown` type.\n * @template T - The type to check\n * @returns `true` if T is `unknown`, otherwise `false`\n * @remarks Note: Returns `false` for `any` type.\n */\nexport type IsUnknown<T> = unknown extends T\n ? IsAny<T> extends true\n ? false\n : true\n : false;\n\n/**\n * Transforms a union type into an intersection type.\n * @template U - The union type to transform\n * @example UnionToIntersection<{a:1}|{b:2}> becomes {a:1}&{b:2}\n */\nexport type UnionToIntersection<U> = (\n U extends any ? (k: U) => void : never\n) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * Represents valid JSON value types.\n * @remarks This is a recursive definition allowing nested structures.\n */\nexport type JSONValue =\n | string\n | number\n | boolean\n | null\n | {[key: string]: JSONValue}\n | JSONValue[];\n\n/**\n * Casts an unknown value to Error type.\n * @param e - The value to cast\n * @returns The casted Error value\n */\nexport const castErr = (e: unknown) => e as Error;\n\n/**\n * Asserts that one type is assignable to another.\n * @template T - The source type\n * @template U - The target type\n * @param _value - The value to use for type inference\n * @returns A function that expects a value assignable to T\n */\nexport const expectAssignable = <T>(_: T): void => {};\n\n/**\n * Asserts that one type is identical to another.\n * @template T - The source type\n * @template U - The target type\n * @param _value - The value to use for type inference\n * @returns A function that expects a value identical to T\n */\nexport type Equals<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2\n ? true\n : false;\n\n/**\n * Asserts that one type is identical to another.\n * @template T - The source type\n * @template U - The target type\n * @param _value - The value to use for type inference\n * @returns A function that expects a value identical to T\n *\n * @example\n * ```ts\n * type A = { x: number };\n * type B = { x: number };\n * type C = { x: string };\n *\n * expectIdentical<A>()({} as B); // OK: A and B are identical\n * expectIdentical<A>()({} as C); // Error: C is not assignable to never\n * ```\n */\nexport const expectIdentical =\n <T>() =>\n <U extends T>(_value: Equals<T, U> extends true ? U : never): void => {};\n"],"names":["castErr","expectAssignable","_","expectIdentical","_value"],"mappings":"gFA2KO,MAAMA,EAAW,GAAe,EAS1BC,EAAuBC,GAAe,CAAC,EA+BvCC,EACX,IACcC,GAAwD,CAAC"}
@@ -0,0 +1,9 @@
1
+ const t = (e) => e, c = (e) => {
2
+ }, s = () => (e) => {
3
+ };
4
+ export {
5
+ t as castErr,
6
+ c as expectAssignable,
7
+ s as expectIdentical
8
+ };
9
+ //# sourceMappingURL=TypeTool.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeTool.mjs","sources":["../../src/Utils/type-tool.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* v8 ignore file -- @preserve */\n\n/**\n * Represents a value that can be either a plain value or a Promise-like object.\n * @template T - The type of the value or Promise-like object.\n */\nexport type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * Creates a deeply partial type where all properties become optional recursively.\n * @template T - The source type\n * @remarks Functions are left untouched (preserved as-is).\n */\nexport type PartialDeep<T> = T extends (...args: any[]) => any\n ? T\n : T extends object\n ? {[K in keyof T]?: PartialDeep<T[K]>}\n : T;\n\n/**\n * Creates a deeply required type where all properties become non-optional recursively.\n * @template T - The source type\n * @remarks Functions are left untouched (preserved as-is).\n */\nexport type RequiredDeep<T> = T extends (...args: any[]) => any\n ? T\n : T extends object\n ? {[K in keyof T]-?: RequiredDeep<T[K]>}\n : T;\n\n/**\n * Creates a deeply readonly type where all properties become immutable recursively.\n * @template T - The source type\n * @remarks Functions are left untouched (preserved as-is).\n */\nexport type ReadonlyDeep<T> = T extends (...args: any[]) => any\n ? T\n : T extends object\n ? {readonly [K in keyof T]: ReadonlyDeep<T[K]>}\n : T;\n\n/**\n * Removes readonly modifiers from all properties at the first level only.\n * @template T - The source type\n */\nexport type Mutable<T> = {-readonly [P in keyof T]: T[P]};\n\n/**\n * Removes readonly modifiers from all properties recursively.\n * @template T - The source type\n * @remarks This affects nested objects as well.\n */\nexport type MutableDeep<T> = {\n -readonly [K in keyof T]: T[K] extends object ? MutableDeep<T[K]> : T[K];\n};\n\n/**\n * Makes specific properties required while keeping others unchanged.\n * @template T - The source type\n * @template K - Keys of properties to make required\n */\nexport type SetRequired<T, K extends keyof T> = {\n [P in keyof T as P extends K ? never : P]: T[P];\n} & {\n [P in K]-?: T[P];\n} extends infer O\n ? {[P in keyof O]: O[P]}\n : never;\n\n/**\n * Makes specific properties optional while keeping others unchanged.\n * @template T - The source type\n * @template K - Keys of properties to make optional\n */\nexport type SetOptional<T, K extends keyof T> = {\n [P in keyof T as P extends K ? never : P]: T[P];\n} & {\n [P in K]?: T[P];\n} extends infer O\n ? {[P in keyof O]: O[P]}\n : never;\n\n/**\n * Creates a union type that includes literal values plus a base type.\n * @template Literal - The literal type(s) to include\n * @template Base - The base string or number type\n * @remarks Useful for allowing string literals while also accepting any string.\n */\nexport type LiteralUnion<Literal, Base extends string | number> =\n | Literal\n | (Base & Record<never, never>);\n\n/**\n * Flattens type intersections for better IntelliSense display.\n * @template T - The type to prettify\n * @remarks This doesn't change the type, only its display in IDEs.\n */\nexport type Prettify<T> = {[K in keyof T]: T[K]} & {};\n\n/**\n * Extracts the resolved return type of an async function.\n * @template T - The async function type\n * @remarks Unwraps Promise to get the actual return type.\n */\nexport type AsyncReturnType<T extends (...args: any) => any> = Awaited<\n ReturnType<T>\n>;\n\n/**\n * Checks if a type is the `any` type.\n * @template T - The type to check\n * @returns `true` if T is `any`, otherwise `false`\n */\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Checks if a type is exactly `undefined`.\n * @template T - The type to check\n * @returns `true` if T is `undefined`, otherwise `false`\n * @remarks Note: This distinguishes `undefined` from optional properties.\n */\nexport type IsUndefined<T> = [T] extends [undefined] ? true : false;\n\n/**\n * Checks if a type is the `never` type.\n * @template T - The type to check\n * @returns `true` if T is `never`, otherwise `false`\n */\nexport type IsNever<T> = [T] extends [never] ? true : false;\n\n/**\n * Checks if a type is the `unknown` type.\n * @template T - The type to check\n * @returns `true` if T is `unknown`, otherwise `false`\n * @remarks Note: Returns `false` for `any` type.\n */\nexport type IsUnknown<T> = unknown extends T\n ? IsAny<T> extends true\n ? false\n : true\n : false;\n\n/**\n * Transforms a union type into an intersection type.\n * @template U - The union type to transform\n * @example UnionToIntersection<{a:1}|{b:2}> becomes {a:1}&{b:2}\n */\nexport type UnionToIntersection<U> = (\n U extends any ? (k: U) => void : never\n) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * Represents valid JSON value types.\n * @remarks This is a recursive definition allowing nested structures.\n */\nexport type JSONValue =\n | string\n | number\n | boolean\n | null\n | {[key: string]: JSONValue}\n | JSONValue[];\n\n/**\n * Casts an unknown value to Error type.\n * @param e - The value to cast\n * @returns The casted Error value\n */\nexport const castErr = (e: unknown) => e as Error;\n\n/**\n * Asserts that one type is assignable to another.\n * @template T - The source type\n * @template U - The target type\n * @param _value - The value to use for type inference\n * @returns A function that expects a value assignable to T\n */\nexport const expectAssignable = <T>(_: T): void => {};\n\n/**\n * Asserts that one type is identical to another.\n * @template T - The source type\n * @template U - The target type\n * @param _value - The value to use for type inference\n * @returns A function that expects a value identical to T\n */\nexport type Equals<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2\n ? true\n : false;\n\n/**\n * Asserts that one type is identical to another.\n * @template T - The source type\n * @template U - The target type\n * @param _value - The value to use for type inference\n * @returns A function that expects a value identical to T\n *\n * @example\n * ```ts\n * type A = { x: number };\n * type B = { x: number };\n * type C = { x: string };\n *\n * expectIdentical<A>()({} as B); // OK: A and B are identical\n * expectIdentical<A>()({} as C); // Error: C is not assignable to never\n * ```\n */\nexport const expectIdentical =\n <T>() =>\n <U extends T>(_value: Equals<T, U> extends true ? U : never): void => {};\n"],"names":["castErr","expectAssignable","_","expectIdentical","_value"],"mappings":"AA2KO,MAAMA,IAAU,CAAC,MAAe,GAS1BC,IAAmB,CAAIC,MAAe;AAAC,GA+BvCC,IACX,MACA,CAAcC,MAAwD;AAAC;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const tt=require("./Arr.cjs"),L=require("./Str.cjs"),et=require("./Sets.cjs"),rt=require("./Maps.cjs"),p=require("../chunks/Math-CWZVxSF-.cjs"),A=require("../chunks/helper-tsqZMRHW.cjs"),m=require("../chunks/base-r6kn0B0D.cjs"),S=require("../chunks/Errors-BWEYu-AB.cjs");function x(t,e){let r=t;for(const n of e)r=n(r);return r}function F(t,e){let r=t;for(let n=0;n<e.length;n++)if(r=e[n](r),A.isPromiseLike(r))return(async()=>{let o=await r;for(let i=n+1;i<e.length;i++)o=e[i](o),A.isPromiseLike(o)&&(o=await o);return o})();return r}function nt(t,...e){return x(t,e)}function st(...t){return t.length===0?m.identity:(...e)=>{const r=t[0](...e),n=t.slice(1);return x(r,n)}}function it(t,...e){return F(t,e)}function ot(...t){return t.length===0?m.identity:(...e)=>{const r=t[0](...e),n=t.slice(1);return A.isPromiseLike(r)?(async()=>{const o=await r;return F(o,n)})():F(r,n)}}const O=Symbol("Curry placeholder");function ct(t,e){if(e<=0||!Number.isInteger(e))throw new S.ParameterError(`Invalid length: Expected a positive integer, but received ${e}.`);const r=(n,o)=>(...i)=>{const a=[...n];let[l,c]=[0,o];for(let s=0;s<a.length&&l<i.length;s++)a[s]===O&&i[l]!==O?(a[s]=i[l++],c--):a[s]===O&&i[l]===O&&l++;for(;l<i.length;){const s=i[l++];a.push(s),s===O&&c++}return a.length-c>=e?t(...a.map(s=>s===O?void 0:s).slice(0,e)):r(a,c)};return r([],0)}const k=Symbol("skipped"),b=Symbol("requestAnimationFrame");class j{constructor(e,r,n=!1,o=!0,i){if(this.wait=r,this.leading=n,this.trailing=o,this.max_wait=i,r===b&&typeof requestAnimationFrame!="function")throw new S.ParameterError("Error: wait = useRAF, But the environment does not support requestAnimationFrame.");if(r===b&&i!=null)throw new S.ParameterError("Error: maxWait cannot be used when wait is set to useRAF.");if(r!==b&&(r<0||!Number.isFinite(r)))throw new S.ParameterError(`Error: wait = ${r} < 0 or is not a finite number.`);if(i!=null&&(!Number.isFinite(i)||i<=0||r!==b&&i<r))throw new S.ParameterError(`Error: maxWait (${i}) must be positive and at least the value of wait (${String(r)}).`);if(!n&&!o)throw new S.ParameterError("Error: Both leading and trailing are false, which is meaningless.");this.fn=e}fn;last_args=null;last_this=null;result_=k;timer_id=null;last_call_time=0;last_invoke_time=0;static getTime=typeof performance<"u"?performance.now.bind(performance):Date.now;get result(){return this.result_}get pending(){return this.timer_id!==null}invokeFunc(e){const r=this.last_args;if(r===null){this.result_=k;return}const n=this.last_this;this.clearTimers(),this.last_args=this.last_this=null,this.last_invoke_time=e,this.result_=this.fn.call(n,...r)}shouldInvoke(e){if(this.last_call_time===0)return!0;if(this.wait===b)return this.timer_id===null;const r=e-this.last_call_time;return!!(r>=this.wait||this.max_wait&&e-this.last_invoke_time>=this.max_wait||r<0)}remainingWait(e){if(this.wait===b)return 0;const r=e-this.last_call_time,n=this.wait-r;if(!this.max_wait)return n;const o=e-this.last_invoke_time,i=this.max_wait-o;return Math.min(n,i)}static Task(e){const r=j.getTime();e.wait===b||e.shouldInvoke(r)?e.invokeFunc(r):e.refreshTimer(e.remainingWait(r))}refreshTimer(e){this.clearTimers(),this.wait===b?this.timer_id=requestAnimationFrame(()=>j.Task(this)):this.timer_id=setTimeout(j.Task,e,this)}clearTimers(){this.timer_id!==null&&(this.wait===b?cancelAnimationFrame(this.timer_id):clearTimeout(this.timer_id),this.timer_id=null)}call(e,...r){const n=j.getTime(),o=this.shouldInvoke(n);return this.last_args=r,this.last_this=e,this.last_call_time=n,this.last_invoke_time===0&&(this.last_invoke_time=n),this.result_=k,o&&this.leading&&this.invokeFunc(n),this.trailing&&this.refreshTimer(this.remainingWait(n)),this.result_}cancel(){this.clearTimers(),this.last_invoke_time=this.last_call_time=0,this.last_args=this.last_this=null,this.result_=k}flush(){if(this.timer_id===null)return this.result_;if(this.trailing&&this.last_args!==null)this.invokeFunc(j.getTime());else return this.clearTimers(),k;return this.result_}[Symbol.dispose](){this.cancel(),this.fn=null,this.last_args=null,this.last_this=null}}function at(t,e,r={leading:!1,trailing:!0}){const{leading:n=!1,trailing:o=!0,maxWait:i,useRAF:a}=r,l=a?b:e,c=new j(t,l,n,o,i),s=function(...u){return c.call(this,...u)};s.cancel=()=>c.cancel(),s.flush=()=>c.flush(),s.pending=()=>c.pending,s.result=()=>c.result;const f=()=>{c[Symbol.dispose]()};return s[Symbol.dispose]=f,s}function lt(t,e,r={leading:!0,trailing:!0}){const{leading:n=!0,trailing:o=!0,useRAF:i}=r,a=i?b:e,l=new j(t,a,n,o,i?void 0:e),c=function(...f){return l.call(this,...f)};c.cancel=()=>l.cancel(),c.flush=()=>l.flush(),c.pending=()=>l.pending,c.result=()=>l.result;const s=()=>{l[Symbol.dispose]()};return c[Symbol.dispose]=s,c}const M=Symbol("No Error"),ut=async t=>{const e=[],r=a=>void e.push(a);let n,o=M;const i=[];try{n=await A.dynamicAwait(t(r))}catch(a){o=a}finally{for(let a=e.length-1;a>=0;a--)try{await e[a](o)}catch(l){i.push(l)}}if(o!==M){if(i.length>0){const a=[o,...i];throw new AggregateError(a,"defer: task and callbacks failed")}throw o}if(i.length>0)throw new AggregateError(i,"defer: callbacks failed");return n},h=t=>t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t),E=t=>typeof t=="string"||h(t)==="[object String]",N=t=>typeof t=="number"||h(t)==="[object Number]",ft=t=>N(t)&&globalThis.isFinite(t),pt=t=>typeof t=="boolean"||h(t)==="[object Boolean]",K=t=>typeof t=="symbol"||h(t)==="[object Symbol]",yt=t=>t===null,ht=t=>t===void 0,P=t=>t==null,mt=t=>!P(t),bt=t=>!P(t),C=t=>{if(t===null)return!0;const e=typeof t;return e!=="object"&&e!=="function"},B=t=>typeof t=="function"||typeof t=="object"&&t!==null,gt=t=>typeof t=="function",D=t=>Array.isArray(t),d=t=>{if(h(t)!=="[object Object]")return!1;const e=Object.getPrototypeOf(t);return e===null?!0:e===Object.prototype||e.constructor===Object},dt=t=>N(t)&&Number.isInteger(t),_t=t=>N(t)&&Number.isSafeInteger(t),jt=t=>typeof t=="number"&&t>-1&&t%1===0&&t<=Number.MAX_SAFE_INTEGER,Ot=t=>h(t)==="[object Date]",wt=t=>h(t)==="[object RegExp]",Et=t=>{const e=h(t);return e==="[object Error]"||e==="[object DOMException]"},V=t=>h(t)==="[object Map]",$=t=>h(t)==="[object Set]",St=t=>h(t)==="[object WeakMap]",kt=t=>h(t)==="[object WeakSet]",At=t=>h(t)==="[object ArrayBuffer]",Nt=/^\[object (?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)Array\]$/,Pt=t=>B(t)&&Nt.test(h(t)),Rt=()=>typeof window<"u"&&typeof document<"u"&&window.document===document,It=()=>typeof window<"u"||typeof self<"u",Tt=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null,Bt=t=>{try{if(t!=null&&t.constructor&&typeof t.constructor.isBuffer=="function")return t.constructor.isBuffer(t)}catch{return!1}return!1},Dt=t=>h(t)==="[object Blob]",Ft=t=>h(t)==="[object File]",Mt=t=>!P(t)&&typeof t[Symbol.iterator]=="function",Wt=t=>B(t)&&Symbol.asyncIterator in t,Lt=t=>t instanceof Promise||h(t)==="[object Promise]"||A.isPromiseLike(t),Ct=(t,e)=>B(t)&&t instanceof e,Ut=t=>E(t)||N(t)||K(t),qt=t=>P(t)?!0:D(t)||E(t)?t.length===0:V(t)||$(t)?t.size===0:d(t)?Object.keys(t).length===0:!1,xt=t=>d(t)&&Object.keys(t).length===0,W=t=>t===void 0||typeof t=="symbol"||typeof t=="function"?!1:C(t)?!0:D(t)?t.every(W):d(t)?Object.values(t).every(W):!1,U=t=>t===void 0||typeof t=="symbol"?!1:C(t)||J(t)||G(t),J=t=>d(t)?Object.entries(t).every(([r,n])=>U(n)):!1,G=t=>D(t)?t.every(U):!1,Kt=t=>{if(!E(t))return!1;const e=t.trim();if(e.length===0)return!1;if(e==="null"||e==="true"||e==="false")return!0;if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]"))try{return JSON.parse(e),!0}catch{return!1}try{return JSON.parse(e),!0}catch{return!1}},Vt=t=>E(t)&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t),$t=t=>{if(!E(t))return!1;try{return new URL(t),!0}catch{return!1}},Jt=t=>E(t)?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t):!1,Y=(t,e,r)=>{const n=new WeakMap,o=(i,a)=>{if(r){const s=r(i,a);if(s!==void 0)return s}if(i===a||typeof i=="number"&&typeof a=="number"&&isNaN(i)&&isNaN(a))return!0;if(i==null||a==null)return!1;const l=h(i),c=h(a);if(l!==c)return!1;if(typeof i=="object"||typeof i=="function"){const s=n.get(i);if(s?.has(a))return!0;s?s.add(a):n.set(i,new Set([a]))}switch(l){case"[object Date]":case"[object Number]":return+i==+a;case"[object RegExp]":case"[object String]":return String(i)===String(a);case"[object Array]":{const s=i,f=a;return s.length!==f.length?!1:s.every((u,y)=>o(u,f[y]))}case"[object Object]":{if(!d(i)||!d(a))return!1;const s=Object.keys(i),f=Object.keys(a);return s.length!==f.length?!1:s.every(u=>Object.prototype.hasOwnProperty.call(a,u)?o(i[u],a[u]):!1)}case"[object Map]":{const s=i,f=a;if(s.size!==f.size)return!1;for(const[u,y]of s)if(!f.has(u)||!o(y,f.get(u)))return!1;return!0}case"[object Set]":{const s=i,f=a;if(s.size!==f.size)return!1;const u=Array.from(f);for(const y of s){const _=u.findIndex(R=>o(y,R));if(_===-1)return!1;u.splice(_,1)}return!0}case"[object ArrayBuffer]":{const s=new Uint8Array(i),f=new Uint8Array(a);if(s.length!==f.length)return!1;for(let u=0;u<s.length;u++)if(s[u]!==f[u])return!1;return!0}default:return!1}};return o(t,e)},Gt=(t,e)=>Y(t,e),Yt=(t,e)=>Object.fromEntries(Object.entries(t).map(([r,n])=>[e(n,r),n])),Ht=(t,e)=>Object.fromEntries(Object.entries(t).map(([r,n])=>[r,e(n,r)])),Xt=t=>Object.fromEntries(Object.entries(t).map(([e,r])=>[r,e])),Qt=(t,e)=>{const r={};for(const n of e)n in t&&(r[n]=t[n]);return r},Zt=(t,e)=>Object.fromEntries(Object.entries(t).filter(([r,n])=>e(n,r))),zt=(t,e)=>{const r={},n=new Set(e);for(const o of Object.keys(t))n.has(o)||(r[o]=t[o]);return r},vt=(t,e)=>Object.fromEntries(Object.entries(t).filter(([r,n])=>!e(n,r))),te=(t,e)=>{for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&e(t[r],r))return r},H=Symbol("Merge skip"),X=Symbol("Merge default"),q=(t,e,...r)=>{if(!r.length)return t;for(const n of r){const o=[[t,n]];for(;o.length>0;){const[i,a]=o.pop();for(const l in a)if(Object.prototype.hasOwnProperty.call(a,l)){const c=a[l],s=i[l],f=c;if(e){const u=e(s,c,l,i,a);if(u!==X){u!==H&&(i[l]=u);continue}}d(f)?(d(s)||(i[l]={}),o.push([i[l],f])):i[l]=f}}}return t},ee=(t,...e)=>q(structuredClone(t),void 0,...e),re=(t,e,...r)=>q(structuredClone(t),e,...r),ne=(t,e=".")=>{const r={},n=[[t,""]];for(;n.length>0;){const[o,i]=n.pop();for(const a in o)if(Object.prototype.hasOwnProperty.call(o,a)){const l=o[a],c=i?`${i}${e}${a}`:a;d(l)&&Object.keys(l).length>0?n.push([l,c]):r[c]=l}}return r},T=(t,e)=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(n=>T(n,e));const r=Object.getPrototypeOf(t);return r!==Object.prototype&&r!==null?t:Object.fromEntries(Object.entries(t).map(([n,o])=>[e(n),T(o,e)]))},se=t=>T(t,L.camelCase),ie=t=>T(t,L.snakeCase),w=Symbol("Clone filter"),Q=Symbol("Clone default"),Z=Symbol("Clone hole"),oe=t=>t===null||typeof t!="object"?t:Array.isArray(t)?[...t]:t instanceof Date?new Date(t.getTime()):t instanceof RegExp?new RegExp(t.source,t.flags):{...t},z=(t,e=0)=>typeof t!="symbol"?(e=Number(t),e>>>0===e&&e!==4294967295&&String(e)===t):!1,ce=/^\[object (?:Int8|Uint8|Uint8Clamped|Int16|Uint16|Int32|Uint32|Float32|Float64|BigInt64|BigUint64)Array\]$/;function g(t,e,r,n,o=void 0,i=void 0,a=[]){if(n<=0)return t;if(e){const s=e(t,o,i,r);if(s!==Q)return s}if(t===null||typeof t!="object")return t;if(r.has(t))return r.get(t);const l=h(t);if(l==="[object Promise]"||l==="[object Function]"||typeof t=="function")return t;let c;switch(l){case"[object ArrayBuffer]":return c=t.slice(0),r.set(t,c),c;case"[object WeakMap]":return c=new WeakMap,r.set(t,c),c;case"[object WeakSet]":return c=new WeakSet,r.set(t,c),c;case"[object Date]":{c=new Date(t.getTime());break}case"[object RegExp]":{const s=t;c=new RegExp(s.source,s.flags),c.lastIndex=s.lastIndex;break}case"[object Error]":{const s=t;c=Object.create(Object.getPrototypeOf(s));const f=Object.getOwnPropertyDescriptors(s);Object.defineProperties(c,f);break}case"[object Array]":{c=[];break}case"[object Map]":{c=new Map;break}case"[object Set]":{c=new Set;break}case"[object DataView]":{const s=t,f=g(s.buffer,e,r,n-1,"buffer",s,a);c=new DataView(f,s.byteOffset,s.byteLength);break}default:{if(ce.test(l)){const s=t,f=g(s.buffer,e,r,n-1,"buffer",s,a);c=new s.constructor(f,s.byteOffset,s.length)}else c=Object.create(Object.getPrototypeOf(t));break}}return r.set(t,c),a.push({source:t,target:c,tag:l,depth:n-1}),c}function I(t,e,r,n,o,i){const a=Array.isArray(t),l=Object.keys(t),c=l.length;for(let u=0;u<c;u++){const y=l[u];if(a&&z(y))continue;const _=g(t[y],n,o,r,y,t,i);_!==w&&(e[y]=_)}const s=Object.getOwnPropertySymbols(t),f=s.length;for(let u=0;u<f;u++){const y=s[u];if(Object.getOwnPropertyDescriptor(t,y)?.enumerable){const R=g(t[y],n,o,r,y,t,i);R!==w&&(e[y]=R)}}}function v(t,e,r){for(;t.length>0;){const n=t.pop(),{source:o,target:i,tag:a,depth:l}=n;switch(a){case"[object Array]":{const c=o,s=i,f=c.length;s.length=0;for(let u=0;u<f;u++){if(!(u in c)){s.length++;continue}const y=g(c[u],e,r,l,u,c,t);y!==w&&(y===Z?s.length++:s.push(y))}I(o,i,l,e,r,t);break}case"[object Map]":{const c=o,s=i;c.forEach((f,u)=>{const y=g(u,e,r,l,u,c,t);if(y!==w){const _=g(f,e,r,l,u,c,t);_!==w&&s.set(y,_)}}),I(o,i,l,e,r,t);break}case"[object Set]":{const c=o,s=i;c.forEach(f=>{const u=g(f,e,r,l,f,c,t);u!==w&&s.add(u)}),I(o,i,l,e,r,t);break}default:{I(o,i,l,e,r,t);break}}}}const ae=(t,e=1/0)=>{const r=[],n=new WeakMap,o=g(t,void 0,n,e,void 0,void 0,r);return v(r,void 0,n),o},le=(t,e,r=1/0)=>{const n=[],o=new WeakMap,i=g(t,e,o,r,void 0,void 0,n);return v(n,e,o),i};exports.Arr=tt.__export__;exports.Str=L.String;exports.Sets=et.Set;exports.Maps=rt.Map;exports.angleDist=p.angleDist;exports.approxEqual=p.approxEqual;exports.bezier2=p.bezier2;exports.clamp=p.clamp;exports.gcd=p.gcd;exports.getDistance=p.getDistance;exports.getDistanceSq=p.getDistanceSq;exports.inRange=p.inRange;exports.isEven=p.isEven;exports.isOdd=p.isOdd;exports.lcm=p.lcm;exports.lerp=p.lerp;exports.mapRange=p.mapRange;exports.mean=p.mean;exports.meanBy=p.meanBy;exports.median=p.median;exports.medianBy=p.medianBy;exports.normalize=p.normalize;exports.random=p.random;exports.randomInt=p.randomInt;exports.range=p.range;exports.rangeRight=p.rangeRight;exports.round=p.round;exports.stdDev=p.stdDev;exports.sum=p.sum;exports.sumBy=p.sumBy;exports.toDegrees=p.toDegrees;exports.toRadians=p.toRadians;exports.wrapAngle=p.wrapAngle;exports.isPromiseLike=A.isPromiseLike;exports.after=m.after;exports.ary=m.ary;exports.asyncNoop=m.asyncNoop;exports.attempt=m.attempt;exports.before=m.before;exports.identity=m.identity;exports.memoize=m.memoize;exports.negate=m.negate;exports.noop=m.noop;exports.once=m.once;exports.partial=m.partial;exports.partialRight=m.partialRight;exports.rest=m.rest;exports.spread=m.spread;exports.unary=m.unary;exports.CLONE_DEFAULT=Q;exports.CLONE_FILTER=w;exports.CLONE_HOLE=Z;exports.Debounced=j;exports.MERGE_DEFAULT=X;exports.MERGE_SKIP=H;exports.NO_ERROR=M;exports.SKIPPED=k;exports.__=O;exports.clone=oe;exports.cloneDeep=ae;exports.cloneDeepWith=le;exports.createDebounce=at;exports.createThrottle=lt;exports.curry=ct;exports.defer=ut;exports.findKey=te;exports.flattenObject=ne;exports.getTag=h;exports.internalMerge=q;exports.invert=Xt;exports.isArray=D;exports.isArrayBuffer=At;exports.isArrayIndex=z;exports.isAsyncIterable=Wt;exports.isBlob=Dt;exports.isBoolean=pt;exports.isBrowser=Rt;exports.isBuffer=Bt;exports.isClient=It;exports.isDate=Ot;exports.isEmail=Vt;exports.isEmpty=qt;exports.isEmptyObject=xt;exports.isEqual=Gt;exports.isEqualWith=Y;exports.isError=Et;exports.isFile=Ft;exports.isFinite=ft;exports.isFunction=gt;exports.isInstanceOf=Ct;exports.isInteger=dt;exports.isIterable=Mt;exports.isJSON=Kt;exports.isJSONArray=G;exports.isJSONObject=J;exports.isJSONValue=U;exports.isLength=jt;exports.isMap=V;exports.isNil=P;exports.isNode=Tt;exports.isNotNil=mt;exports.isNotNullish=bt;exports.isNull=yt;exports.isNumber=N;exports.isObject=B;exports.isPlainObject=d;exports.isPrimitive=C;exports.isPromise=Lt;exports.isPropertyKey=Ut;exports.isRegExp=wt;exports.isSafeInteger=_t;exports.isSerializable=W;exports.isSet=$;exports.isString=E;exports.isSymbol=K;exports.isTypedArray=Pt;exports.isUUID=Jt;exports.isUndefined=ht;exports.isUrl=$t;exports.isWeakMap=St;exports.isWeakSet=kt;exports.mapKeys=Yt;exports.mapValues=Ht;exports.merge=ee;exports.mergeWith=re;exports.omit=zt;exports.omitBy=vt;exports.pick=Qt;exports.pickBy=Zt;exports.pipe=st;exports.pipeAsync=ot;exports.run=nt;exports.runAsync=it;exports.toCamelCaseKeys=se;exports.toSnakeCaseKeys=ie;exports.useRAF=b;
2
+ //# sourceMappingURL=Utils.cjs.map