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,63 @@
1
+ class e extends Error {
2
+ /**
3
+ * Creates an instance of UseAfterFreeError.
4
+ * @param message - The error message. Defaults to 'Cannot access resource after it has been disposed.'
5
+ */
6
+ constructor(r) {
7
+ super(r), this.name = "UseAfterFreeError", typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, e);
8
+ }
9
+ }
10
+ class t extends Error {
11
+ /**
12
+ * Creates an instance of LockError.
13
+ * @param message - The error message describing the lock failure.
14
+ */
15
+ constructor(r) {
16
+ super(r), this.name = "LockError", typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, t);
17
+ }
18
+ }
19
+ class c extends t {
20
+ /**
21
+ * Creates an instance of MutexError.
22
+ * @param message - The error message describing the mutex failure.
23
+ */
24
+ constructor(r) {
25
+ super(r), this.name = "MutexError", typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, c);
26
+ }
27
+ }
28
+ class a extends t {
29
+ /**
30
+ * Creates an instance of RWLockError.
31
+ * @param message - The error message describing the read-write lock failure.
32
+ */
33
+ constructor(r) {
34
+ super(r), this.name = "RWLockError", typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, a);
35
+ }
36
+ }
37
+ class o extends Error {
38
+ /**
39
+ * Creates an instance of ParameterError.
40
+ * @param message - The error message describing the parameter validation failure.
41
+ */
42
+ constructor(r) {
43
+ super(r), this.name = "ParameterError", typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, o);
44
+ }
45
+ }
46
+ class s extends Error {
47
+ /**
48
+ * Creates an instance of FlowCompletionError.
49
+ * @param message - The error message. Defaults to 'Flow completed before run could finish'.
50
+ */
51
+ constructor(r = "Flow completed before run could finish") {
52
+ super(r), this.name = "FlowCompletionError", typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, s);
53
+ }
54
+ }
55
+ export {
56
+ s as F,
57
+ t as L,
58
+ c as M,
59
+ o as P,
60
+ a as R,
61
+ e as U
62
+ };
63
+ //# sourceMappingURL=Errors-DwUAvFIF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Errors-DwUAvFIF.mjs","sources":["../../src/Errors.ts"],"sourcesContent":["// ========================================\r\n// ./src/Errors.ts\r\n// ========================================\r\n/* v8 ignore file -- @preserve */\r\n\r\n/**\r\n * Error thrown when a resource is accessed after it has been disposed (Use After Free).\r\n */\r\nexport class UseAfterFreeError extends Error {\r\n /**\r\n * Creates an instance of UseAfterFreeError.\r\n * @param message - The error message. Defaults to 'Cannot access resource after it has been disposed.'\r\n */\r\n constructor(message: string) {\r\n super(message);\r\n this.name = 'UseAfterFreeError';\r\n if (typeof Error.captureStackTrace === 'function')\r\n Error.captureStackTrace(this, UseAfterFreeError);\r\n }\r\n}\r\n\r\n/**\r\n * Error thrown when a lock operation fails.\r\n * Base class for all lock-related errors.\r\n */\r\nexport class LockError extends Error {\r\n /**\r\n * Creates an instance of LockError.\r\n * @param message - The error message describing the lock failure.\r\n */\r\n constructor(message: string) {\r\n super(message);\r\n this.name = 'LockError';\r\n if (typeof Error.captureStackTrace === 'function')\r\n Error.captureStackTrace(this, LockError);\r\n }\r\n}\r\n\r\n/**\r\n * Error thrown when a mutex operation fails.\r\n * Used for mutual exclusion lock violations and failures.\r\n */\r\nexport class MutexError extends LockError {\r\n /**\r\n * Creates an instance of MutexError.\r\n * @param message - The error message describing the mutex failure.\r\n */\r\n constructor(message: string) {\r\n super(message);\r\n this.name = 'MutexError';\r\n if (typeof Error.captureStackTrace === 'function')\r\n Error.captureStackTrace(this, MutexError);\r\n }\r\n}\r\n\r\n/**\r\n * Error thrown when a read-write lock operation fails.\r\n * Used for reader-writer lock violations and failures.\r\n */\r\nexport class RWLockError extends LockError {\r\n /**\r\n * Creates an instance of RWLockError.\r\n * @param message - The error message describing the read-write lock failure.\r\n */\r\n constructor(message: string) {\r\n super(message);\r\n this.name = 'RWLockError';\r\n if (typeof Error.captureStackTrace === 'function')\r\n Error.captureStackTrace(this, RWLockError);\r\n }\r\n}\r\n\r\n/**\r\n * Error thrown when a function parameter is invalid.\r\n * Used for parameter validation failures.\r\n */\r\nexport class ParameterError extends Error {\r\n /**\r\n * Creates an instance of ParameterError.\r\n * @param message - The error message describing the parameter validation failure.\r\n */\r\n constructor(message: string) {\r\n super(message);\r\n this.name = 'ParameterError';\r\n if (typeof Error.captureStackTrace === 'function')\r\n Error.captureStackTrace(this, ParameterError);\r\n }\r\n}\r\n\r\n/**\r\n * Error thrown when a Flow completes before a run operation could finish.\r\n * This indicates that the Flow was completed or stopped while there were\r\n * still pending operations waiting for values.\r\n */\r\nexport class FlowCompletionError extends Error {\r\n /**\r\n * Creates an instance of FlowCompletionError.\r\n * @param message - The error message. Defaults to 'Flow completed before run could finish'.\r\n */\r\n constructor(message: string = 'Flow completed before run could finish') {\r\n super(message);\r\n this.name = 'FlowCompletionError';\r\n if (typeof Error.captureStackTrace === 'function')\r\n Error.captureStackTrace(this, FlowCompletionError);\r\n }\r\n}\r\n"],"names":["UseAfterFreeError","message","LockError","MutexError","RWLockError","ParameterError","FlowCompletionError"],"mappings":"AAQO,MAAMA,UAA0B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAK3C,YAAYC,GAAiB;AAC3B,UAAMA,CAAO,GACb,KAAK,OAAO,qBACR,OAAO,MAAM,qBAAsB,cACrC,MAAM,kBAAkB,MAAMD,CAAiB;AAAA,EACnD;AACF;AAMO,MAAME,UAAkB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAKnC,YAAYD,GAAiB;AAC3B,UAAMA,CAAO,GACb,KAAK,OAAO,aACR,OAAO,MAAM,qBAAsB,cACrC,MAAM,kBAAkB,MAAMC,CAAS;AAAA,EAC3C;AACF;AAMO,MAAMC,UAAmBD,EAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxC,YAAYD,GAAiB;AAC3B,UAAMA,CAAO,GACb,KAAK,OAAO,cACR,OAAO,MAAM,qBAAsB,cACrC,MAAM,kBAAkB,MAAME,CAAU;AAAA,EAC5C;AACF;AAMO,MAAMC,UAAoBF,EAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAKzC,YAAYD,GAAiB;AAC3B,UAAMA,CAAO,GACb,KAAK,OAAO,eACR,OAAO,MAAM,qBAAsB,cACrC,MAAM,kBAAkB,MAAMG,CAAW;AAAA,EAC7C;AACF;AAMO,MAAMC,UAAuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxC,YAAYJ,GAAiB;AAC3B,UAAMA,CAAO,GACb,KAAK,OAAO,kBACR,OAAO,MAAM,qBAAsB,cACrC,MAAM,kBAAkB,MAAMI,CAAc;AAAA,EAChD;AACF;AAOO,MAAMC,UAA4B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAK7C,YAAYL,IAAkB,0CAA0C;AACtE,UAAMA,CAAO,GACb,KAAK,OAAO,uBACR,OAAO,MAAM,qBAAsB,cACrC,MAAM,kBAAkB,MAAMK,CAAmB;AAAA,EACrD;AACF;"}
@@ -0,0 +1,68 @@
1
+ const g = (t, n, e) => Math.min(Math.max(t, n), e), l = (t, n = 0) => +(Math.round(+(t + "e" + n)) + "e-" + n), u = (t, n, e) => n === e ? 0 : (t - n) / (e - n), c = (t, n) => {
2
+ for (t = Math.abs(t), n = Math.abs(n); n !== 0; ) {
3
+ const e = n;
4
+ n = t % n, t = e;
5
+ }
6
+ return t;
7
+ }, m = (t, n) => t === 0 || n === 0 ? 0 : Math.abs(t / c(t, n) * n), d = (t, n, e) => Number.isFinite(t) && t >= n && t < e, M = (t, n, e = 1) => {
8
+ if (e === 0 || !Number.isFinite(t) || !Number.isFinite(n)) return [];
9
+ const s = Math.max(Math.ceil((n - t) / e), 0);
10
+ return Array.from({ length: s }, (a, r) => t + r * e);
11
+ }, f = (t, n, e = 1) => {
12
+ if (e === 0 || !Number.isFinite(t) || !Number.isFinite(n)) return [];
13
+ const s = Math.max(Math.ceil((n - t) / e), 0);
14
+ return Array.from({ length: s }, (a, r) => t + (s - 1 - r) * e);
15
+ }, y = (t, n, e, s, a) => !Number.isFinite(t) || n === e ? s : (t - n) * (a - s) / (e - n) + s, x = (t, n) => Math.random() * (n - t) + t, N = (t, n) => Math.floor(Math.random() * (n - t + 1)) + t, h = (t) => t.reduce((n, e) => n + e, 0), o = (t, n) => t.reduce((e, s) => e + n(s), 0), i = (t) => t.length === 0 ? 0 : h(t) / t.length, b = (t, n) => t.length ? o(t, n) / t.length : 0, v = (t) => {
16
+ const n = [...t].sort((s, a) => s - a), e = n.length >> 1;
17
+ return n.length % 2 ? n[e] : (n[e - 1] + n[e]) / 2;
18
+ }, F = (t, n) => {
19
+ if (t.length === 0)
20
+ return 0;
21
+ const e = t.map(n).sort((a, r) => a - r), s = e.length >> 1;
22
+ return e.length % 2 ? e[s] : (e[s - 1] + e[s]) / 2;
23
+ }, D = (t, n = !1) => {
24
+ if (t.length === 0 || n && t.length === 1) return 0;
25
+ const e = i(t), s = o(t, (a) => (a - e) ** 2) / (t.length - (n ? 1 : 0));
26
+ return Math.sqrt(s);
27
+ }, q = (t, n, e = 1e-10) => Math.abs(t - n) < e, A = (t) => (t & 1) === 0, B = (t) => (t & 1) !== 0, R = (t) => t * Math.PI / 180, w = (t) => t * 180 / Math.PI, z = (t) => (t % 360 + 360) % 360, I = (t, n) => {
28
+ const e = (n - t + 180) % 360;
29
+ return (e < 0 ? e + 360 : e) - 180;
30
+ }, p = (t, n, e, s) => Math.hypot(e - t, s - n), E = (t, n, e, s) => (e - t) ** 2 + (s - n) ** 2, P = (t, n, e) => t + e * (n - t), _ = (t, n, e, s) => {
31
+ const a = 1 - s;
32
+ return {
33
+ x: a * a * t.x + 2 * a * s * n.x + s * s * e.x,
34
+ y: a * a * t.y + 2 * a * s * n.y + s * s * e.y
35
+ };
36
+ };
37
+ export {
38
+ E as A,
39
+ P as B,
40
+ _ as C,
41
+ M as a,
42
+ f as b,
43
+ g as c,
44
+ x as d,
45
+ N as e,
46
+ o as f,
47
+ c as g,
48
+ i as h,
49
+ d as i,
50
+ b as j,
51
+ v as k,
52
+ m as l,
53
+ y as m,
54
+ u as n,
55
+ F as o,
56
+ D as p,
57
+ q,
58
+ l as r,
59
+ h as s,
60
+ A as t,
61
+ B as u,
62
+ R as v,
63
+ w,
64
+ z as x,
65
+ I as y,
66
+ p as z
67
+ };
68
+ //# sourceMappingURL=Math-CGEH1ClN.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Math-CGEH1ClN.mjs","sources":["../../src/Utils/Math.ts"],"sourcesContent":["// ========================================\r\n// ./src/Utils/Math.ts\r\n// ========================================\r\n\r\n// 1. Basic numeric utilities\r\n\r\n/**\r\n * Clamps a number between a minimum and maximum value.\r\n * @param n The number to clamp.\r\n * @param min The minimum allowed value.\r\n * @param max The maximum allowed value.\r\n * @returns The clamped number.\r\n */\r\nexport const clamp = (n: number, min: number, max: number): number =>\r\n Math.min(Math.max(n, min), max);\r\n\r\n/**\r\n * Rounds a number to a specified number of decimal places.\r\n * @param n The number to round.\r\n * @param precision The number of decimal places (default: 0).\r\n * @returns The rounded number.\r\n */\r\nexport const round = (n: number, precision = 0): number => {\r\n // 利用指数移动小数点,避免直接乘法带来的精度偏移\r\n return Number(Math.round(Number(n + 'e' + precision)) + 'e-' + precision);\r\n};\r\n/**\r\n * Normalizes a value from a given range to [0, 1].\r\n * @param n The value to normalize.\r\n * @param min The minimum of the original range.\r\n * @param max The maximum of the original range.\r\n * @returns The normalized value in [0, 1].\r\n */\r\nexport const normalize = (n: number, min: number, max: number): number =>\r\n min === max ? 0 : (n - min) / (max - min);\r\n\r\n/**\r\n * Computes the greatest common divisor (GCD) of two numbers.\r\n * @param a First number\r\n * @param b Second number\r\n * @returns The GCD (always non-negative)\r\n */\r\nexport const gcd = (a: number, b: number): number => {\r\n a = Math.abs(a);\r\n b = Math.abs(b);\r\n while (b !== 0) {\r\n const temp = b;\r\n b = a % b;\r\n a = temp;\r\n }\r\n return a;\r\n};\r\n\r\n/**\r\n * Computes the least common multiple (LCM) of two numbers.\r\n * Uses safe calculation to prevent integer overflow.\r\n * @param a First number\r\n * @param b Second number\r\n * @returns The LCM (always non-negative), 0 if either input is 0\r\n */\r\nexport const lcm = (a: number, b: number): number => {\r\n if (a === 0 || b === 0) return 0;\r\n\r\n // 先除后乘,避免 (a * b) 溢出\r\n return Math.abs((a / gcd(a, b)) * b);\r\n};\r\n\r\n// 2. Range and interval utilities\r\n\r\n/**\r\n * Checks if a number is within a specified range [min, max).\r\n * @param n The number to check.\r\n * @param min The inclusive lower bound.\r\n * @param max The exclusive upper bound.\r\n * @returns `true` if the number is in range.\r\n */\r\nexport const inRange = (n: number, min: number, max: number): boolean =>\r\n Number.isFinite(n) && n >= min && n < max;\r\n\r\n/**\r\n * Generates an array of numbers from `start` to `end` (exclusive), incremented by `step`.\r\n * @param start The start of the range.\r\n * @param end The end of the range (exclusive).\r\n * @param step The increment between numbers (default: 1).\r\n * @returns An array of numbers.\r\n */\r\nexport const range = (start: number, end: number, step = 1): number[] => {\r\n if (step === 0 || !Number.isFinite(start) || !Number.isFinite(end)) return [];\r\n const length = Math.max(Math.ceil((end - start) / step), 0);\r\n return Array.from({length}, (_, i) => start + i * step);\r\n};\r\n\r\n/**\r\n * Like `range`, but returns numbers in reverse order.\r\n * @param start The start of the range.\r\n * @param end The end of the range (exclusive).\r\n * @param step The increment between numbers (default: 1).\r\n * @returns A reversed array of numbers.\r\n */\r\nexport const rangeRight = (start: number, end: number, step = 1): number[] => {\r\n if (step === 0 || !Number.isFinite(start) || !Number.isFinite(end)) return [];\r\n const len = Math.max(Math.ceil((end - start) / step), 0);\r\n return Array.from({length: len}, (_, i) => start + (len - 1 - i) * step);\r\n};\r\n\r\n/**\r\n * Maps a number from one range to another linearly.\r\n * @param n The input value.\r\n * @param inMin Minimum of the input range.\r\n * @param inMax Maximum of the input range.\r\n * @param outMin Minimum of the output range.\r\n * @param outMax Maximum of the output range.\r\n * @returns The mapped value.\r\n */\r\nexport const mapRange = (\r\n n: number,\r\n inMin: number,\r\n inMax: number,\r\n outMin: number,\r\n outMax: number,\r\n): number => {\r\n if (!Number.isFinite(n) || inMin === inMax) return outMin;\r\n return ((n - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;\r\n};\r\n\r\n// Random number generation\r\n\r\n/**\r\n * Generates a random floating-point number between `min` (inclusive) and `max` (exclusive).\r\n * @param min The minimum value (inclusive).\r\n * @param max The maximum value (exclusive).\r\n * @returns A random number in [min, max).\r\n */\r\nexport const random = (min: number, max: number): number =>\r\n Math.random() * (max - min) + min;\r\n\r\n/**\r\n * Generates a random integer between `min` and `max` (both inclusive).\r\n * @param min The minimum integer (inclusive).\r\n * @param max The maximum integer (inclusive).\r\n * @returns A random integer in [min, max].\r\n */\r\nexport const randomInt = (min: number, max: number): number =>\r\n Math.floor(Math.random() * (max - min + 1)) + min;\r\n\r\n// Aggregation & statistics\r\n\r\n/**\r\n * Computes the sum of an array of numbers.\r\n * @param nums Array of numbers.\r\n * @returns The sum.\r\n */\r\nexport const sum = (nums: number[]): number => nums.reduce((a, b) => a + b, 0);\r\n\r\n/**\r\n * Computes the sum of values extracted from an array using a selector function.\r\n * @param arr The input array.\r\n * @param getValue A function to extract numeric values from items.\r\n * @returns The sum of extracted values.\r\n */\r\nexport const sumBy = <T>(arr: T[], getValue: (item: T) => number): number =>\r\n arr.reduce((sum, item) => sum + getValue(item), 0);\r\n\r\n/**\r\n * Computes the arithmetic mean (average) of an array of numbers.\r\n * @param nums Array of numbers.\r\n * @returns The mean, or 0 if the array is empty.\r\n */\r\nexport const mean = (nums: number[]): number =>\r\n nums.length === 0 ? 0 : sum(nums) / nums.length;\r\n\r\n/**\r\n * Computes the arithmetic mean of values extracted from an array.\r\n * @param arr The input array.\r\n * @param getValue A function to extract numeric values from items.\r\n * @returns The mean of extracted values, or 0 if empty.\r\n */\r\nexport const meanBy = <T>(arr: T[], getValue: (item: T) => number): number =>\r\n arr.length ? sumBy(arr, getValue) / arr.length : 0;\r\n\r\n/**\r\n * Computes the median of an array of numbers.\r\n * @param nums Array of numbers.\r\n * @returns The median value.\r\n */\r\nexport const median = (nums: number[]): number => {\r\n const s = [...nums].sort((a, b) => a - b),\r\n m = s.length >> 1;\r\n return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;\r\n};\r\n\r\n/**\r\n * Computes the median of values extracted from an array.\r\n * @param arr The input array.\r\n * @param getValue A function to extract numeric values from items.\r\n * @returns The median of extracted values.\r\n */\r\nexport const medianBy = <T>(\r\n arr: T[],\r\n getValue: (item: T) => number,\r\n): number => {\r\n if (arr.length === 0) {\r\n return 0;\r\n }\r\n const v = arr.map(getValue).sort((a, b) => a - b),\r\n m = v.length >> 1;\r\n return v.length % 2 ? v[m] : (v[m - 1] + v[m]) / 2;\r\n};\r\n\r\n/**\r\n * Computes the standard deviation of an array of numbers.\r\n * @param nums Array of numbers.\r\n * @param isSample If `true`, computes sample standard deviation (Bessel's correction).\r\n * @returns The standard deviation.\r\n */\r\nexport const stdDev = (nums: number[], isSample = false): number => {\r\n if (nums.length === 0) return 0;\r\n if (isSample && nums.length === 1) return 0;\r\n const avg = mean(nums);\r\n const variance =\r\n sumBy(nums, (n) => (n - avg) ** 2) / (nums.length - (isSample ? 1 : 0));\r\n return Math.sqrt(variance);\r\n};\r\n\r\n// Comparison & approximation\r\n\r\n/**\r\n * Checks if two numbers are approximately equal within a tolerance.\r\n * @param n1 First number.\r\n * @param n2 Second number.\r\n * @param epsilon Tolerance (default: 1e-10).\r\n * @returns `true` if |n1 - n2| < epsilon.\r\n */\r\nexport const approxEqual = (n1: number, n2: number, epsilon = 1e-10): boolean =>\r\n Math.abs(n1 - n2) < epsilon;\r\n\r\n/**\r\n * Checks if a number is even.\r\n * @param n The number to check.\r\n * @returns `true` if even.\r\n */\r\nexport const isEven = (n: number): boolean => (n & 1) === 0;\r\n\r\n/**\r\n * Checks if a number is odd.\r\n * @param n The number to check.\r\n * @returns `true` if odd.\r\n */\r\nexport const isOdd = (n: number): boolean => (n & 1) !== 0;\r\n\r\n// Angle utilities\r\n\r\n/**\r\n * Converts degrees to radians.\r\n * @param deg Angle in degrees.\r\n * @returns Angle in radians.\r\n */\r\nexport const toRadians = (deg: number): number => (deg * Math.PI) / 180;\r\n\r\n/**\r\n * Converts radians to degrees.\r\n * @param rad Angle in radians.\r\n * @returns Angle in degrees.\r\n */\r\nexport const toDegrees = (rad: number): number => (rad * 180) / Math.PI;\r\n\r\n/**\r\n * Wraps an angle in degrees to [0, 360).\r\n * @param deg Input angle in degrees.\r\n * @returns Wrapped angle in [0, 360).\r\n */\r\nexport const wrapAngle = (deg: number): number => ((deg % 360) + 360) % 360;\r\n\r\n/**\r\n * Computes the smallest signed difference between two angles (in degrees).\r\n * Result is in [-180, 180].\r\n * @param a First angle in degrees.\r\n * @param b Second angle in degrees.\r\n * @returns The angular difference.\r\n */\r\nexport const angleDist = (a: number, b: number): number => {\r\n const d = (b - a + 180) % 360;\r\n return (d < 0 ? d + 360 : d) - 180;\r\n};\r\n\r\n// Geometric distance\r\n\r\n/**\r\n * Computes the Euclidean distance between two 2D points.\r\n * @param x1 X-coordinate of the first point.\r\n * @param y1 Y-coordinate of the first point.\r\n * @param x2 X-coordinate of the second point.\r\n * @param y2 Y-coordinate of the second point.\r\n * @returns The distance.\r\n */\r\nexport const getDistance = (\r\n x1: number,\r\n y1: number,\r\n x2: number,\r\n y2: number,\r\n): number => Math.hypot(x2 - x1, y2 - y1);\r\n\r\n/**\r\n * Computes the squared Euclidean distance between two 2D points (faster, no sqrt).\r\n * @param x1 X-coordinate of the first point.\r\n * @param y1 Y-coordinate of the first point.\r\n * @param x2 X-coordinate of the second point.\r\n * @param y2 Y-coordinate of the second point.\r\n * @returns The squared distance.\r\n */\r\nexport const getDistanceSq = (\r\n x1: number,\r\n y1: number,\r\n x2: number,\r\n y2: number,\r\n): number => (x2 - x1) ** 2 + (y2 - y1) ** 2;\r\n\r\n// Linear interpolation\r\n\r\n/**\r\n * Linearly interpolates between `start` and `end` by factor `t`.\r\n * @param start Start value.\r\n * @param end End value.\r\n * @param t Interpolation factor (0 = start, 1 = end).\r\n * @returns The interpolated value.\r\n */\r\nexport const lerp = (start: number, end: number, t: number): number =>\r\n start + t * (end - start);\r\n\r\n/**\r\n * Computes a point on a quadratic Bezier curve.\r\n * @param p0 Start point {x, y}\r\n * @param p1 Control point {x, y}\r\n * @param p2 End point {x, y}\r\n * @param t Interpolation factor [0, 1]\r\n * @returns The interpolated point {x, y}\r\n */\r\nexport const bezier2 = (\r\n p0: {x: number; y: number},\r\n p1: {x: number; y: number},\r\n p2: {x: number; y: number},\r\n t: number,\r\n) => {\r\n const mt = 1 - t;\r\n return {\r\n x: mt * mt * p0.x + 2 * mt * t * p1.x + t * t * p2.x,\r\n y: mt * mt * p0.y + 2 * mt * t * p1.y + t * t * p2.y,\r\n };\r\n};\r\n"],"names":["clamp","n","min","max","round","precision","normalize","gcd","a","b","temp","lcm","inRange","range","start","end","step","length","_","i","rangeRight","len","mapRange","inMin","inMax","outMin","outMax","random","randomInt","sum","nums","sumBy","arr","getValue","item","mean","meanBy","median","s","m","medianBy","v","stdDev","isSample","avg","variance","approxEqual","n1","n2","epsilon","isEven","isOdd","toRadians","deg","toDegrees","rad","wrapAngle","angleDist","d","getDistance","x1","y1","x2","y2","getDistanceSq","lerp","t","bezier2","p0","p1","p2","mt"],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ "use strict";const h=(t,e,n)=>Math.min(Math.max(t,e),n),l=(t,e=0)=>+(Math.round(+(t+"e"+e))+"e-"+e),m=(t,e,n)=>e===n?0:(t-e)/(n-e),c=(t,e)=>{for(t=Math.abs(t),e=Math.abs(e);e!==0;){const n=e;e=t%e,t=n}return t},u=(t,e)=>t===0||e===0?0:Math.abs(t/c(t,e)*e),d=(t,e,n)=>Number.isFinite(t)&&t>=e&&t<n,y=(t,e,n=1)=>{if(n===0||!Number.isFinite(t)||!Number.isFinite(e))return[];const r=Math.max(Math.ceil((e-t)/n),0);return Array.from({length:r},(a,o)=>t+o*n)},M=(t,e,n=1)=>{if(n===0||!Number.isFinite(t)||!Number.isFinite(e))return[];const r=Math.max(Math.ceil((e-t)/n),0);return Array.from({length:r},(a,o)=>t+(r-1-o)*n)},f=(t,e,n,r,a)=>!Number.isFinite(t)||e===n?r:(t-e)*(a-r)/(n-e)+r,D=(t,e)=>Math.random()*(e-t)+t,N=(t,e)=>Math.floor(Math.random()*(e-t+1))+t,i=t=>t.reduce((e,n)=>e+n,0),s=(t,e)=>t.reduce((n,r)=>n+e(r),0),g=t=>t.length===0?0:i(t)/t.length,R=(t,e)=>t.length?s(t,e)/t.length:0,b=t=>{const e=[...t].sort((r,a)=>r-a),n=e.length>>1;return e.length%2?e[n]:(e[n-1]+e[n])/2},v=(t,e)=>{if(t.length===0)return 0;const n=t.map(e).sort((a,o)=>a-o),r=n.length>>1;return n.length%2?n[r]:(n[r-1]+n[r])/2},x=(t,e=!1)=>{if(t.length===0||e&&t.length===1)return 0;const n=g(t),r=s(t,a=>(a-n)**2)/(t.length-(e?1:0));return Math.sqrt(r)},p=(t,e,n=1e-10)=>Math.abs(t-e)<n,B=t=>(t&1)===0,F=t=>(t&1)!==0,q=t=>t*Math.PI/180,z=t=>t*180/Math.PI,A=t=>(t%360+360)%360,E=(t,e)=>{const n=(e-t+180)%360;return(n<0?n+360:n)-180},I=(t,e,n,r)=>Math.hypot(n-t,r-e),w=(t,e,n,r)=>(n-t)**2+(r-e)**2,O=(t,e,n)=>t+n*(e-t),P=(t,e,n,r)=>{const a=1-r;return{x:a*a*t.x+2*a*r*e.x+r*r*n.x,y:a*a*t.y+2*a*r*e.y+r*r*n.y}};exports.angleDist=E;exports.approxEqual=p;exports.bezier2=P;exports.clamp=h;exports.gcd=c;exports.getDistance=I;exports.getDistanceSq=w;exports.inRange=d;exports.isEven=B;exports.isOdd=F;exports.lcm=u;exports.lerp=O;exports.mapRange=f;exports.mean=g;exports.meanBy=R;exports.median=b;exports.medianBy=v;exports.normalize=m;exports.random=D;exports.randomInt=N;exports.range=y;exports.rangeRight=M;exports.round=l;exports.stdDev=x;exports.sum=i;exports.sumBy=s;exports.toDegrees=z;exports.toRadians=q;exports.wrapAngle=A;
2
+ //# sourceMappingURL=Math-CWZVxSF-.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Math-CWZVxSF-.cjs","sources":["../../src/Utils/Math.ts"],"sourcesContent":["// ========================================\r\n// ./src/Utils/Math.ts\r\n// ========================================\r\n\r\n// 1. Basic numeric utilities\r\n\r\n/**\r\n * Clamps a number between a minimum and maximum value.\r\n * @param n The number to clamp.\r\n * @param min The minimum allowed value.\r\n * @param max The maximum allowed value.\r\n * @returns The clamped number.\r\n */\r\nexport const clamp = (n: number, min: number, max: number): number =>\r\n Math.min(Math.max(n, min), max);\r\n\r\n/**\r\n * Rounds a number to a specified number of decimal places.\r\n * @param n The number to round.\r\n * @param precision The number of decimal places (default: 0).\r\n * @returns The rounded number.\r\n */\r\nexport const round = (n: number, precision = 0): number => {\r\n // 利用指数移动小数点,避免直接乘法带来的精度偏移\r\n return Number(Math.round(Number(n + 'e' + precision)) + 'e-' + precision);\r\n};\r\n/**\r\n * Normalizes a value from a given range to [0, 1].\r\n * @param n The value to normalize.\r\n * @param min The minimum of the original range.\r\n * @param max The maximum of the original range.\r\n * @returns The normalized value in [0, 1].\r\n */\r\nexport const normalize = (n: number, min: number, max: number): number =>\r\n min === max ? 0 : (n - min) / (max - min);\r\n\r\n/**\r\n * Computes the greatest common divisor (GCD) of two numbers.\r\n * @param a First number\r\n * @param b Second number\r\n * @returns The GCD (always non-negative)\r\n */\r\nexport const gcd = (a: number, b: number): number => {\r\n a = Math.abs(a);\r\n b = Math.abs(b);\r\n while (b !== 0) {\r\n const temp = b;\r\n b = a % b;\r\n a = temp;\r\n }\r\n return a;\r\n};\r\n\r\n/**\r\n * Computes the least common multiple (LCM) of two numbers.\r\n * Uses safe calculation to prevent integer overflow.\r\n * @param a First number\r\n * @param b Second number\r\n * @returns The LCM (always non-negative), 0 if either input is 0\r\n */\r\nexport const lcm = (a: number, b: number): number => {\r\n if (a === 0 || b === 0) return 0;\r\n\r\n // 先除后乘,避免 (a * b) 溢出\r\n return Math.abs((a / gcd(a, b)) * b);\r\n};\r\n\r\n// 2. Range and interval utilities\r\n\r\n/**\r\n * Checks if a number is within a specified range [min, max).\r\n * @param n The number to check.\r\n * @param min The inclusive lower bound.\r\n * @param max The exclusive upper bound.\r\n * @returns `true` if the number is in range.\r\n */\r\nexport const inRange = (n: number, min: number, max: number): boolean =>\r\n Number.isFinite(n) && n >= min && n < max;\r\n\r\n/**\r\n * Generates an array of numbers from `start` to `end` (exclusive), incremented by `step`.\r\n * @param start The start of the range.\r\n * @param end The end of the range (exclusive).\r\n * @param step The increment between numbers (default: 1).\r\n * @returns An array of numbers.\r\n */\r\nexport const range = (start: number, end: number, step = 1): number[] => {\r\n if (step === 0 || !Number.isFinite(start) || !Number.isFinite(end)) return [];\r\n const length = Math.max(Math.ceil((end - start) / step), 0);\r\n return Array.from({length}, (_, i) => start + i * step);\r\n};\r\n\r\n/**\r\n * Like `range`, but returns numbers in reverse order.\r\n * @param start The start of the range.\r\n * @param end The end of the range (exclusive).\r\n * @param step The increment between numbers (default: 1).\r\n * @returns A reversed array of numbers.\r\n */\r\nexport const rangeRight = (start: number, end: number, step = 1): number[] => {\r\n if (step === 0 || !Number.isFinite(start) || !Number.isFinite(end)) return [];\r\n const len = Math.max(Math.ceil((end - start) / step), 0);\r\n return Array.from({length: len}, (_, i) => start + (len - 1 - i) * step);\r\n};\r\n\r\n/**\r\n * Maps a number from one range to another linearly.\r\n * @param n The input value.\r\n * @param inMin Minimum of the input range.\r\n * @param inMax Maximum of the input range.\r\n * @param outMin Minimum of the output range.\r\n * @param outMax Maximum of the output range.\r\n * @returns The mapped value.\r\n */\r\nexport const mapRange = (\r\n n: number,\r\n inMin: number,\r\n inMax: number,\r\n outMin: number,\r\n outMax: number,\r\n): number => {\r\n if (!Number.isFinite(n) || inMin === inMax) return outMin;\r\n return ((n - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;\r\n};\r\n\r\n// Random number generation\r\n\r\n/**\r\n * Generates a random floating-point number between `min` (inclusive) and `max` (exclusive).\r\n * @param min The minimum value (inclusive).\r\n * @param max The maximum value (exclusive).\r\n * @returns A random number in [min, max).\r\n */\r\nexport const random = (min: number, max: number): number =>\r\n Math.random() * (max - min) + min;\r\n\r\n/**\r\n * Generates a random integer between `min` and `max` (both inclusive).\r\n * @param min The minimum integer (inclusive).\r\n * @param max The maximum integer (inclusive).\r\n * @returns A random integer in [min, max].\r\n */\r\nexport const randomInt = (min: number, max: number): number =>\r\n Math.floor(Math.random() * (max - min + 1)) + min;\r\n\r\n// Aggregation & statistics\r\n\r\n/**\r\n * Computes the sum of an array of numbers.\r\n * @param nums Array of numbers.\r\n * @returns The sum.\r\n */\r\nexport const sum = (nums: number[]): number => nums.reduce((a, b) => a + b, 0);\r\n\r\n/**\r\n * Computes the sum of values extracted from an array using a selector function.\r\n * @param arr The input array.\r\n * @param getValue A function to extract numeric values from items.\r\n * @returns The sum of extracted values.\r\n */\r\nexport const sumBy = <T>(arr: T[], getValue: (item: T) => number): number =>\r\n arr.reduce((sum, item) => sum + getValue(item), 0);\r\n\r\n/**\r\n * Computes the arithmetic mean (average) of an array of numbers.\r\n * @param nums Array of numbers.\r\n * @returns The mean, or 0 if the array is empty.\r\n */\r\nexport const mean = (nums: number[]): number =>\r\n nums.length === 0 ? 0 : sum(nums) / nums.length;\r\n\r\n/**\r\n * Computes the arithmetic mean of values extracted from an array.\r\n * @param arr The input array.\r\n * @param getValue A function to extract numeric values from items.\r\n * @returns The mean of extracted values, or 0 if empty.\r\n */\r\nexport const meanBy = <T>(arr: T[], getValue: (item: T) => number): number =>\r\n arr.length ? sumBy(arr, getValue) / arr.length : 0;\r\n\r\n/**\r\n * Computes the median of an array of numbers.\r\n * @param nums Array of numbers.\r\n * @returns The median value.\r\n */\r\nexport const median = (nums: number[]): number => {\r\n const s = [...nums].sort((a, b) => a - b),\r\n m = s.length >> 1;\r\n return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;\r\n};\r\n\r\n/**\r\n * Computes the median of values extracted from an array.\r\n * @param arr The input array.\r\n * @param getValue A function to extract numeric values from items.\r\n * @returns The median of extracted values.\r\n */\r\nexport const medianBy = <T>(\r\n arr: T[],\r\n getValue: (item: T) => number,\r\n): number => {\r\n if (arr.length === 0) {\r\n return 0;\r\n }\r\n const v = arr.map(getValue).sort((a, b) => a - b),\r\n m = v.length >> 1;\r\n return v.length % 2 ? v[m] : (v[m - 1] + v[m]) / 2;\r\n};\r\n\r\n/**\r\n * Computes the standard deviation of an array of numbers.\r\n * @param nums Array of numbers.\r\n * @param isSample If `true`, computes sample standard deviation (Bessel's correction).\r\n * @returns The standard deviation.\r\n */\r\nexport const stdDev = (nums: number[], isSample = false): number => {\r\n if (nums.length === 0) return 0;\r\n if (isSample && nums.length === 1) return 0;\r\n const avg = mean(nums);\r\n const variance =\r\n sumBy(nums, (n) => (n - avg) ** 2) / (nums.length - (isSample ? 1 : 0));\r\n return Math.sqrt(variance);\r\n};\r\n\r\n// Comparison & approximation\r\n\r\n/**\r\n * Checks if two numbers are approximately equal within a tolerance.\r\n * @param n1 First number.\r\n * @param n2 Second number.\r\n * @param epsilon Tolerance (default: 1e-10).\r\n * @returns `true` if |n1 - n2| < epsilon.\r\n */\r\nexport const approxEqual = (n1: number, n2: number, epsilon = 1e-10): boolean =>\r\n Math.abs(n1 - n2) < epsilon;\r\n\r\n/**\r\n * Checks if a number is even.\r\n * @param n The number to check.\r\n * @returns `true` if even.\r\n */\r\nexport const isEven = (n: number): boolean => (n & 1) === 0;\r\n\r\n/**\r\n * Checks if a number is odd.\r\n * @param n The number to check.\r\n * @returns `true` if odd.\r\n */\r\nexport const isOdd = (n: number): boolean => (n & 1) !== 0;\r\n\r\n// Angle utilities\r\n\r\n/**\r\n * Converts degrees to radians.\r\n * @param deg Angle in degrees.\r\n * @returns Angle in radians.\r\n */\r\nexport const toRadians = (deg: number): number => (deg * Math.PI) / 180;\r\n\r\n/**\r\n * Converts radians to degrees.\r\n * @param rad Angle in radians.\r\n * @returns Angle in degrees.\r\n */\r\nexport const toDegrees = (rad: number): number => (rad * 180) / Math.PI;\r\n\r\n/**\r\n * Wraps an angle in degrees to [0, 360).\r\n * @param deg Input angle in degrees.\r\n * @returns Wrapped angle in [0, 360).\r\n */\r\nexport const wrapAngle = (deg: number): number => ((deg % 360) + 360) % 360;\r\n\r\n/**\r\n * Computes the smallest signed difference between two angles (in degrees).\r\n * Result is in [-180, 180].\r\n * @param a First angle in degrees.\r\n * @param b Second angle in degrees.\r\n * @returns The angular difference.\r\n */\r\nexport const angleDist = (a: number, b: number): number => {\r\n const d = (b - a + 180) % 360;\r\n return (d < 0 ? d + 360 : d) - 180;\r\n};\r\n\r\n// Geometric distance\r\n\r\n/**\r\n * Computes the Euclidean distance between two 2D points.\r\n * @param x1 X-coordinate of the first point.\r\n * @param y1 Y-coordinate of the first point.\r\n * @param x2 X-coordinate of the second point.\r\n * @param y2 Y-coordinate of the second point.\r\n * @returns The distance.\r\n */\r\nexport const getDistance = (\r\n x1: number,\r\n y1: number,\r\n x2: number,\r\n y2: number,\r\n): number => Math.hypot(x2 - x1, y2 - y1);\r\n\r\n/**\r\n * Computes the squared Euclidean distance between two 2D points (faster, no sqrt).\r\n * @param x1 X-coordinate of the first point.\r\n * @param y1 Y-coordinate of the first point.\r\n * @param x2 X-coordinate of the second point.\r\n * @param y2 Y-coordinate of the second point.\r\n * @returns The squared distance.\r\n */\r\nexport const getDistanceSq = (\r\n x1: number,\r\n y1: number,\r\n x2: number,\r\n y2: number,\r\n): number => (x2 - x1) ** 2 + (y2 - y1) ** 2;\r\n\r\n// Linear interpolation\r\n\r\n/**\r\n * Linearly interpolates between `start` and `end` by factor `t`.\r\n * @param start Start value.\r\n * @param end End value.\r\n * @param t Interpolation factor (0 = start, 1 = end).\r\n * @returns The interpolated value.\r\n */\r\nexport const lerp = (start: number, end: number, t: number): number =>\r\n start + t * (end - start);\r\n\r\n/**\r\n * Computes a point on a quadratic Bezier curve.\r\n * @param p0 Start point {x, y}\r\n * @param p1 Control point {x, y}\r\n * @param p2 End point {x, y}\r\n * @param t Interpolation factor [0, 1]\r\n * @returns The interpolated point {x, y}\r\n */\r\nexport const bezier2 = (\r\n p0: {x: number; y: number},\r\n p1: {x: number; y: number},\r\n p2: {x: number; y: number},\r\n t: number,\r\n) => {\r\n const mt = 1 - t;\r\n return {\r\n x: mt * mt * p0.x + 2 * mt * t * p1.x + t * t * p2.x,\r\n y: mt * mt * p0.y + 2 * mt * t * p1.y + t * t * p2.y,\r\n };\r\n};\r\n"],"names":["clamp","n","min","max","round","precision","normalize","gcd","a","b","temp","lcm","inRange","range","start","end","step","length","_","i","rangeRight","len","mapRange","inMin","inMax","outMin","outMax","random","randomInt","sum","nums","sumBy","arr","getValue","item","mean","meanBy","median","s","m","medianBy","v","stdDev","isSample","avg","variance","approxEqual","n1","n2","epsilon","isEven","isOdd","toRadians","deg","toDegrees","rad","wrapAngle","angleDist","d","getDistance","x1","y1","x2","y2","getDistanceSq","lerp","t","bezier2","p0","p1","p2","mt"],"mappings":"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"}
@@ -0,0 +1,56 @@
1
+ import { i as c } from "./helper-BVabbpmX.mjs";
2
+ const u = (t) => t, i = () => {
3
+ }, l = async () => {
4
+ }, f = (t) => (r) => t(r), p = (t) => (...r) => !t(...r), d = (t) => {
5
+ let r = !1, e;
6
+ return (...n) => (r || (r = !0, e = t(...n)), e);
7
+ }, h = (t, r) => (...e) => t(...e.slice(0, r)), y = (t) => (...r) => {
8
+ const e = t.length > 0 ? t.length - 1 : 0, n = r.slice(0, e), s = r.slice(e);
9
+ return t(n, s);
10
+ }, m = (t) => (r) => t(...r), g = (t, ...r) => (...e) => t(...r, ...e), v = (t, ...r) => (...e) => t(...e, ...r), x = (t, r) => {
11
+ let e = 0;
12
+ return (...n) => {
13
+ if (e++, e >= t)
14
+ return r(...n);
15
+ };
16
+ }, b = (t, r) => {
17
+ let e = 0, n;
18
+ return (...s) => (e < t && (e++, n = r(...s)), n);
19
+ }, k = (t, r) => {
20
+ const e = /* @__PURE__ */ new Map();
21
+ return (...n) => {
22
+ const s = r ? r(...n) : JSON.stringify(n);
23
+ if (e.has(s))
24
+ return e.get(s);
25
+ const o = t(...n);
26
+ return e.set(s, o), o;
27
+ };
28
+ }, L = (t) => function(...r) {
29
+ try {
30
+ const e = t.apply(this, r);
31
+ return c(e) ? e.then(
32
+ (n) => [void 0, n],
33
+ (n) => [n, void 0]
34
+ ) : [void 0, e];
35
+ } catch (e) {
36
+ return [e, void 0];
37
+ }
38
+ };
39
+ export {
40
+ l as a,
41
+ p as b,
42
+ h as c,
43
+ v as d,
44
+ x as e,
45
+ b as f,
46
+ L as g,
47
+ u as i,
48
+ k as m,
49
+ i as n,
50
+ d as o,
51
+ g as p,
52
+ y as r,
53
+ m as s,
54
+ f as u
55
+ };
56
+ //# sourceMappingURL=base-B9k8Lqvf.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-B9k8Lqvf.mjs","sources":["../../src/Utils/Functions/base.ts"],"sourcesContent":["// ========================================\r\n// ./src/Utils/Functions/base.ts\r\n// ========================================\r\n/* eslint-disable @typescript-eslint/no-unsafe-return */\r\n/* eslint-disable @typescript-eslint/no-explicit-any */\r\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\r\n\r\nimport {isPromiseLike} from 'src/helper';\r\n\r\n/**\r\n * Generic type for an identity function.\r\n * @template T - The type of the input and output value.\r\n */\r\nexport type IdentityFn = <T>(x: T) => T;\r\n\r\n/**\r\n * A function that returns the same value passed to it.\r\n * @template T\r\n * @param x - The value to return\r\n * @returns The input value `x`\r\n * @satisfies {IdentityFn}\r\n */\r\nexport const identity: IdentityFn = (x) => x;\r\n\r\nexport const noop = (): void => {};\r\nexport const asyncNoop = async (): Promise<void> => {};\r\n\r\n/**\r\n * Creates a function that accepts up to one argument, ignoring any additional arguments.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to cap arguments for.\r\n * @returns The new function.\r\n */\r\nexport const unary = <T, Ret>(\r\n fn: (arg: T, ...rest: unknown[]) => Ret,\r\n): ((arg: T) => Ret) => {\r\n return (arg) => fn(arg);\r\n};\r\n\r\n/**\r\n * Creates a function that negates the result of the predicate `fn`.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @param predicate - The predicate to negate.\r\n * @returns The new negated function.\r\n */\r\nexport const negate = <Args extends unknown[]>(\r\n predicate: (...args: Args) => boolean,\r\n): ((...args: Args) => boolean) => {\r\n return (...args) => !predicate(...args);\r\n};\r\n\r\n/**\r\n * Creates a function that is restricted to invoking `fn` once.\r\n * Repeat calls to the function return the value of the first invocation.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to restrict.\r\n * @returns The new restricted function.\r\n */\r\nexport const once = <Args extends unknown[], Ret>(\r\n fn: (...args: Args) => Ret,\r\n): ((...args: Args) => Ret) => {\r\n let done = false;\r\n let result: Ret;\r\n\r\n return (...args) => {\r\n if (!done) {\r\n done = true;\r\n result = fn(...args);\r\n }\r\n return result;\r\n };\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with only the first `n` arguments provided.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to cap arguments for.\r\n * @param n - The number of arguments to accept.\r\n * @returns The new function.\r\n */\r\nexport const ary = <Args extends unknown[], Ret>(\r\n fn: (...args: Args) => Ret,\r\n n: number,\r\n): ((...args: Args) => Ret) => {\r\n return (...args) => fn(...(args.slice(0, n) as Args));\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with arguments transformed.\r\n * The implementation splits arguments based on `fn.length`, expecting `fn` to take two arguments:\r\n * 1. A tuple of the first `fn.length - 1` arguments.\r\n * 2. A tuple of the remaining arguments.\r\n *\r\n * Note: Based on the implementation `fn.length - 1`, `FixedArgs` is strictly a single-element tuple.\r\n *\r\n * @template FixedArgs - The fixed arguments tuple (must be length 1).\r\n * @template RestArgs - The rest arguments tuple.\r\n * @template Ret - The return type.\r\n * @param fn - The function to transform arguments for.\r\n * @returns The new function.\r\n */\r\nexport const rest = <\r\n FixedArgs extends [unknown],\r\n RestArgs extends unknown[],\r\n Ret,\r\n>(\r\n fn: (fixed: FixedArgs, rest: RestArgs) => Ret,\r\n): ((...args: [...FixedArgs, ...RestArgs]) => Ret) => {\r\n return (...args) => {\r\n const fixedLength = fn.length > 0 ? fn.length - 1 : 0;\r\n const fixed = args.slice(0, fixedLength) as FixedArgs;\r\n const restParts = args.slice(fixedLength) as RestArgs;\r\n return fn(fixed, restParts);\r\n };\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with the `args` spread as an array.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to spread arguments for.\r\n * @returns The new function.\r\n */\r\nexport const spread = <Args extends unknown[], Ret>(\r\n fn: (...args: Args) => Ret,\r\n): ((args: Args) => Ret) => {\r\n return (args) => fn(...args);\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with `partial` arguments prepended to those provided to the new function.\r\n *\r\n * @template Fixed - The fixed arguments type.\r\n * @template Rest - The remaining arguments type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to partially apply arguments to.\r\n * @param fixedArgs - The arguments to prepend.\r\n * @returns The new partially applied function.\r\n */\r\nexport const partial = <Fixed extends unknown[], Rest extends unknown[], Ret>(\r\n fn: (...args: [...Fixed, ...Rest]) => Ret,\r\n ...fixedArgs: Fixed\r\n): ((...rest: Rest) => Ret) => {\r\n return (...restArgs) => fn(...fixedArgs, ...restArgs);\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with `partial` arguments appended to those provided to the new function.\r\n *\r\n * @template Fixed - The fixed arguments type (appended).\r\n * @template Rest - The remaining arguments type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to partially apply arguments to.\r\n * @param fixedArgs - The arguments to append.\r\n * @returns The new partially applied function.\r\n */\r\nexport const partialRight = <\r\n T extends (...args: any[]) => any,\r\n Fixed extends any[],\r\n>(\r\n fn: T,\r\n ...fixedArgs: Fixed\r\n): ((\r\n ...rest: T extends (...args: [...infer Rest, ...Fixed]) => any ? Rest : never\r\n) => ReturnType<T>) => {\r\n return (...restArgs: any[]) => fn(...restArgs, ...fixedArgs);\r\n};\r\n/**\r\n * Creates a function that invokes `fn` only after being called `n` times.\r\n *\r\n * @template Args - The arguments type.\r\n * @template Ret - The return type.\r\n * @param n - The number of calls before the function is invoked.\r\n * @param fn - The function to restrict.\r\n * @returns The new restricted function.\r\n */\r\nexport const after = <Args extends unknown[], Ret>(\r\n n: number,\r\n fn: (...args: Args) => Ret,\r\n): ((...args: Args) => Ret | undefined) => {\r\n let count = 0;\r\n return (...args) => {\r\n count++;\r\n if (count >= n) {\r\n return fn(...args);\r\n }\r\n return undefined;\r\n };\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` while it's called less than `n` times.\r\n *\r\n * @template Args - The arguments type.\r\n * @template Ret - The return type.\r\n * @param n - The number of calls before the function stops being invoked.\r\n * @param fn - The function to restrict.\r\n * @returns The new restricted function.\r\n */\r\nexport const before = <Args extends unknown[], Ret>(\r\n n: number,\r\n fn: (...args: Args) => Ret,\r\n): ((...args: Args) => Ret | undefined) => {\r\n let count = 0;\r\n let lastResult: Ret | undefined;\r\n return (...args) => {\r\n if (count < n) {\r\n count++;\r\n lastResult = fn(...args);\r\n }\r\n return lastResult;\r\n };\r\n};\r\n\r\n/**\r\n * Creates a function that memoizes the result of `fn`.\r\n * If `resolver` is provided, it determines the cache key for storing the result based on the arguments provided.\r\n *\r\n * @template Args - The arguments type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to memoize.\r\n * @param resolver - The function to resolve the cache key.\r\n * @returns The new memoized function.\r\n */\r\nexport const memoize = <Args extends unknown[], Ret>(\r\n fn: (...args: Args) => Ret,\r\n resolver?: (...args: Args) => unknown,\r\n): ((...args: Args) => Ret) => {\r\n const cache = new Map<unknown, Ret>();\r\n return (...args) => {\r\n const key = resolver ? resolver(...args) : JSON.stringify(args);\r\n\r\n if (cache.has(key)) {\r\n return cache.get(key) as Ret;\r\n }\r\n const result = fn(...args);\r\n cache.set(key, result);\r\n return result;\r\n };\r\n};\r\n\r\ntype AttemptResult<T> =\r\n T extends PromiseLike<infer R>\r\n ? Promise<[undefined, R] | [unknown, undefined]>\r\n : [undefined, T] | [unknown, undefined];\r\n\r\n/**\r\n *\r\n * Wraps any function – synchronous or asynchronous – and returns a tuple `[error, result]` instead of throwing.\r\n * It catches **everything**: thrown exceptions and rejected promises alike, turning them into a consistent error-first return.\r\n * Eliminates try-catch blocks and makes error handling explicit and type‑safe.\r\n *\r\n * @template Args - The arguments tuple type of the wrapped function\r\n * @template R - The return type of the wrapped function\r\n * @param fn - The function to wrap\r\n * @returns A function that returns `[undefined, result]` on success, or `[error, undefined]` on failure\r\n *\r\n * @example\r\n * ```typescript\r\n * const [err, data] = attempt(JSON.parse)('{\"a\":1}');\r\n * if (err) console.error('Parse failed:', err);\r\n * else console.log('Parsed:', data);\r\n * ```\r\n *\r\n * @example\r\n * ```typescript\r\n * // Works seamlessly with async functions\r\n * const fetchData = async (url: string) => ({ data: 'response' });\r\n * const [err, data] = await attempt(fetchData)('https://api.example.com');\r\n * ```\r\n */\r\nexport const attempt = <Args extends unknown[], R>(\r\n fn: (...args: Args) => R,\r\n): ((\r\n this: ThisParameterType<typeof fn>,\r\n ...args: Args\r\n) => AttemptResult<R>) => {\r\n return function (\r\n this: ThisParameterType<typeof fn>,\r\n ...args: Args\r\n ): AttemptResult<R> {\r\n try {\r\n const result = fn.apply(this, args);\r\n\r\n // 处理异步函数\r\n if (isPromiseLike(result))\r\n return (result as PromiseLike<R>).then(\r\n (value) => [undefined, value],\r\n (err: unknown) => [err, undefined],\r\n ) as AttemptResult<R>;\r\n\r\n // 处理同步函数\r\n return [undefined, result] as AttemptResult<R>;\r\n } catch (err) {\r\n return [err, undefined] as AttemptResult<R>;\r\n }\r\n };\r\n};\r\n"],"names":["identity","x","noop","asyncNoop","unary","fn","arg","negate","predicate","args","once","done","result","ary","n","rest","fixedLength","fixed","restParts","spread","partial","fixedArgs","restArgs","partialRight","after","count","before","lastResult","memoize","resolver","cache","key","attempt","isPromiseLike","value","err"],"mappings":";AAsBO,MAAMA,IAAuB,CAACC,MAAMA,GAE9BC,IAAO,MAAY;AAAC,GACpBC,IAAY,YAA2B;AAAC,GAUxCC,IAAQ,CACnBC,MAEO,CAACC,MAAQD,EAAGC,CAAG,GAUXC,IAAS,CACpBC,MAEO,IAAIC,MAAS,CAACD,EAAU,GAAGC,CAAI,GAY3BC,IAAO,CAClBL,MAC6B;AAC7B,MAAIM,IAAO,IACPC;AAEJ,SAAO,IAAIH,OACJE,MACHA,IAAO,IACPC,IAASP,EAAG,GAAGI,CAAI,IAEdG;AAEX,GAWaC,IAAM,CACjBR,GACAS,MAEO,IAAIL,MAASJ,EAAG,GAAII,EAAK,MAAM,GAAGK,CAAC,CAAU,GAiBzCC,IAAO,CAKlBV,MAEO,IAAII,MAAS;AAClB,QAAMO,IAAcX,EAAG,SAAS,IAAIA,EAAG,SAAS,IAAI,GAC9CY,IAAQR,EAAK,MAAM,GAAGO,CAAW,GACjCE,IAAYT,EAAK,MAAMO,CAAW;AACxC,SAAOX,EAAGY,GAAOC,CAAS;AAC5B,GAWWC,IAAS,CACpBd,MAEO,CAACI,MAASJ,EAAG,GAAGI,CAAI,GAahBW,IAAU,CACrBf,MACGgB,MAEI,IAAIC,MAAajB,EAAG,GAAGgB,GAAW,GAAGC,CAAQ,GAazCC,IAAe,CAI1BlB,MACGgB,MAII,IAAIC,MAAoBjB,EAAG,GAAGiB,GAAU,GAAGD,CAAS,GAWhDG,IAAQ,CACnBV,GACAT,MACyC;AACzC,MAAIoB,IAAQ;AACZ,SAAO,IAAIhB,MAAS;AAElB,QADAgB,KACIA,KAASX;AACX,aAAOT,EAAG,GAAGI,CAAI;AAAA,EAGrB;AACF,GAWaiB,IAAS,CACpBZ,GACAT,MACyC;AACzC,MAAIoB,IAAQ,GACRE;AACJ,SAAO,IAAIlB,OACLgB,IAAQX,MACVW,KACAE,IAAatB,EAAG,GAAGI,CAAI,IAElBkB;AAEX,GAYaC,IAAU,CACrBvB,GACAwB,MAC6B;AAC7B,QAAMC,wBAAY,IAAA;AAClB,SAAO,IAAIrB,MAAS;AAClB,UAAMsB,IAAMF,IAAWA,EAAS,GAAGpB,CAAI,IAAI,KAAK,UAAUA,CAAI;AAE9D,QAAIqB,EAAM,IAAIC,CAAG;AACf,aAAOD,EAAM,IAAIC,CAAG;AAEtB,UAAMnB,IAASP,EAAG,GAAGI,CAAI;AACzB,WAAAqB,EAAM,IAAIC,GAAKnB,CAAM,GACdA;AAAA,EACT;AACF,GAgCaoB,IAAU,CACrB3B,MAKO,YAEFI,GACe;AAClB,MAAI;AACF,UAAMG,IAASP,EAAG,MAAM,MAAMI,CAAI;AAGlC,WAAIwB,EAAcrB,CAAM,IACdA,EAA0B;AAAA,MAChC,CAACsB,MAAU,CAAC,QAAWA,CAAK;AAAA,MAC5B,CAACC,MAAiB,CAACA,GAAK,MAAS;AAAA,IAAA,IAI9B,CAAC,QAAWvB,CAAM;AAAA,EAC3B,SAASuB,GAAK;AACZ,WAAO,CAACA,GAAK,MAAS;AAAA,EACxB;AACF;"}
@@ -0,0 +1,2 @@
1
+ "use strict";const s=require("./helper-tsqZMRHW.cjs"),c=r=>({ok:!0,value:r}),n=r=>({ok:!1,error:r}),i=r=>r.ok,u=r=>!r.ok,a=(r,o)=>r.ok&&o(r.value),k=(r,o)=>!r.ok&&o(r.error);function f(r,o,t){try{const e=r();return c(e)}catch(e){return t&&t(e)?n(e):n(s.UnknownError.from(e,o))}}async function m(r,o,t){try{const e=await r();return c(e)}catch(e){return t&&t(e)?n(e):n(s.UnknownError.from(e,o))}}const E=r=>r.ok?Promise.resolve(r.value):Promise.reject(s.ensureError(r.error)),w=r=>r.then(c).catch(o=>n(s.UnknownError.from(o))),y=async r=>{if(!s.isPromiseLike(r))return r;try{return await r}catch(o){return n(s.wrapError(o))}};exports.Err=n;exports.Ok=c;exports.fromPromise=w;exports.isErr=u;exports.isErrAnd=k;exports.isOk=i;exports.isOkAnd=a;exports.normalizeToResult=y;exports.safeExecute=f;exports.safeExecuteAsync=m;exports.toPromise=E;
2
+ //# sourceMappingURL=base-BTXL1y_I.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-BTXL1y_I.cjs","sources":["../../src/Result/base.ts"],"sourcesContent":["// ========================================\r\n// ./src/Result/base.ts\r\n// ========================================\r\nimport type {Result, Success, Failure, AsyncResult, AnyResult} from './types';\r\nimport {UnknownError, ensureError} from '../unknown-error';\r\nimport {isPromiseLike, wrapError} from '../helper';\r\n\r\n/**\r\n * Constructs a successful Result instance.\r\n * @typeParam T - The type of the successful value\r\n * @param value - The value upon success\r\n * @returns A successful Result\r\n */\r\nexport const Ok = <T, E = never>(value: T): Result<T, E> =>\r\n ({\r\n ok: true,\r\n value,\r\n }) as const;\r\n\r\n/**\r\n * Get the value of Result<T, never>\r\n * @typeParam T - The type of the error\r\n * @param error - The error upon failure\r\n * @returns A failed Result\r\n */\r\nexport const Err = <T = never, E = unknown>(error: E): Result<T, E> =>\r\n ({\r\n ok: false,\r\n error,\r\n }) as const;\r\n\r\n/**\r\n * Checks if the Result is in the Success (Ok) state.\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result instance to check\r\n * @returns Returns true if the Result is Success\r\n */\r\nexport const isOk = <T, E>(result: Result<T, E>): result is Success<T> =>\r\n result.ok;\r\n\r\n/**\r\n * Checks if the Result is in the Failure (Err) state.\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result instance to check\r\n * @returns Returns true if the Result is Failure\r\n */\r\nexport const isErr = <T, E>(result: Result<T, E>): result is Failure<E> =>\r\n !result.ok;\r\n\r\n/**\r\n * Checks if the Result is Success AND its value satisfies the given predicate.\r\n * @typeParam T - The type of the success valueexport function isPromiseLike<T>(value: unknown): value is PromiseLike<T> {\r\n return value !== null && typeof value === 'object' && 'then' in value;\r\n }\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result instance to check\r\n * @param fn - The predicate function to check the success value\r\n * @returns Returns true if the Result is Success and the condition is met\r\n */\r\nexport const isOkAnd = <T, E>(\r\n result: Result<T, E>,\r\n fn: (value: T) => boolean,\r\n): boolean => result.ok && fn(result.value);\r\n\r\n/**\r\n * Checks if the Result is Failure AND its error satisfies the given predicate.\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result instance to check\r\n * @param fn - The predicate function to check the error value\r\n * @returns Returns true if the Result is Failure and the condition is met\r\n */\r\nexport const isErrAnd = <T, E>(\r\n result: Result<T, E>,\r\n fn: (error: E) => boolean,\r\n): boolean => !result.ok && fn(result.error);\r\n\r\n// ============================================\r\n// 异常安全执行器\r\n// ============================================\r\n\r\n/**\r\n * Safely executes a synchronous function, catching any thrown exception and wrapping it as an UnknownError.\r\n * @typeParam T - The success value type\r\n * @param fn - The synchronous function that might throw an exception\r\n * @param message - The error message to be used as the primary message for the UnknownError if an exception is thrown\r\n * @returns Returns Ok(T) on success, or Err(UnknownError) on failure\r\n */\r\nexport function safeExecute<T>(\r\n fn: () => T,\r\n message?: string,\r\n): Result<T, UnknownError>;\r\n\r\n/**\r\n * Safely executes a synchronous function, catching any thrown exception. If the exception is of the declared type E,\r\n * it returns Err(E); otherwise, it is wrapped as an UnknownError.\r\n * @typeParam T - The success value type\r\n * @typeParam E - The declared expected error type\r\n * @param fn - The synchronous function that might throw an exception\r\n * @param message - The error message to be used as the primary message for the UnknownError if an unknown exception is thrown\r\n * @param isExpectedError - A type guard function to determine if the caught error is of type E\r\n * @returns Returns Ok(T) on success, or Err(E | UnknownError) on failure\r\n */\r\nexport function safeExecute<T, E>(\r\n fn: () => T,\r\n message: string | undefined,\r\n isExpectedError: (error: unknown) => error is E,\r\n): Result<T, E | UnknownError>;\r\n\r\nexport function safeExecute<T, E = never>(\r\n fn: () => T,\r\n message?: string,\r\n isExpectedError?: (error: unknown) => error is E,\r\n): Result<T, E | UnknownError> {\r\n try {\r\n const value = fn();\r\n return Ok(value);\r\n } catch (raw_error) {\r\n if (isExpectedError && isExpectedError(raw_error)) {\r\n return Err(raw_error);\r\n }\r\n\r\n return Err(UnknownError.from(raw_error, message));\r\n }\r\n}\r\n\r\n/**\r\n * Safely executes an asynchronous function, catching its rejection or thrown exception and wrapping it as an UnknownError.\r\n * @typeParam T - The success value type\r\n * @param async_fn - The asynchronous function that might throw or reject\r\n * @param message - The error message to be used as the primary message for the UnknownError\r\n * @returns Returns Promise<Ok(T)> on success, or Promise<Err(UnknownError)> on failure\r\n */\r\nexport async function safeExecuteAsync<T>(\r\n async_fn: () => Promise<T>,\r\n message?: string,\r\n): AsyncResult<T, UnknownError>;\r\n\r\n/**\r\n * Safely executes an asynchronous function, catching its rejection or thrown exception. If the exception is of the declared type E,\r\n * it returns Err(E); otherwise, it is wrapped as an UnknownError.\r\n * @typeParam T - The success value type\r\n * @typeParam E - The declared expected error type\r\n * @param async_fn - The asynchronous function that might throw or reject\r\n * @param message - The error message to be used as the primary message for the UnknownError if an unknown exception is thrown\r\n * @param isExpectedError - A type guard function to determine if the caught error is of type E\r\n * @returns Returns Promise<Ok(T)> on success, or Promise<Err(E | UnknownError)> on failure\r\n */\r\nexport async function safeExecuteAsync<T, E>(\r\n async_fn: () => Promise<T>,\r\n message: string | undefined,\r\n isExpectedError: (error: unknown) => error is E,\r\n): AsyncResult<T, E | UnknownError>;\r\nexport async function safeExecuteAsync<T, E = never>(\r\n async_fn: () => Promise<T>,\r\n message?: string,\r\n isExpectedError?: (error: unknown) => error is E,\r\n): AsyncResult<T, E | UnknownError> {\r\n try {\r\n const value = await async_fn();\r\n return Ok(value);\r\n } catch (raw_error) {\r\n if (isExpectedError && isExpectedError(raw_error)) {\r\n return Err(raw_error);\r\n }\r\n return Err(UnknownError.from(raw_error, message));\r\n }\r\n}\r\n\r\n// ========================================\r\n// 互相转换\r\n// ========================================\r\n\r\n/**\r\n * Converts a Result into a Promise. Success resolves, Failure rejects.\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result to convert\r\n * @returns The resulting Promise\r\n * @throws If the Result is Failure, it rejects with the error wrapped by `ensureError`\r\n */\r\nexport const toPromise = <T, E>(result: Result<T, E>): Promise<T> =>\r\n result.ok\r\n ? Promise.resolve(result.value)\r\n : Promise.reject(ensureError(result.error));\r\n\r\n/**\r\n * Converts a Promise into an AsyncResult. Resolution becomes Ok, and rejection becomes Err(UnknownError).\r\n * @typeParam T - The type of the success value\r\n * @param promise - The Promise to convert\r\n * @returns The resulting AsyncResult\r\n */\r\nexport const fromPromise = <T>(\r\n promise: Promise<T>,\r\n): AsyncResult<T, UnknownError> =>\r\n promise.then(Ok).catch((e) => Err(UnknownError.from(e)));\r\n\r\n/**\r\n * Safely normalizes an AnyResult (synchronous Result or asynchronous AsyncResult/Thenable) into a Promise<Result>.\r\n * It handles the Promise resolve/reject paths, ensuring rejection is always encapsulated as Err(UnknownError).\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param awaitable - The value to normalize, which can be a Result, Promise<Result>, or a Thenable object\r\n * @returns The normalized Promise<Result>\r\n */\r\nexport const normalizeToResult = async <T, E>(\r\n awaitable: AnyResult<T, E>,\r\n): Promise<Result<T, E | UnknownError | DOMException>> => {\r\n // 同步 Result 快速路径\r\n if (!isPromiseLike(awaitable)) return awaitable;\r\n\r\n // 统一处理所有异步情况 (Promise & Thenable)\r\n try {\r\n return await awaitable;\r\n } catch (raw_error) {\r\n return Err(wrapError(raw_error));\r\n }\r\n};\r\n"],"names":["Ok","value","Err","error","isOk","result","isErr","isOkAnd","fn","isErrAnd","safeExecute","message","isExpectedError","raw_error","UnknownError","safeExecuteAsync","async_fn","toPromise","ensureError","fromPromise","promise","e","normalizeToResult","awaitable","isPromiseLike","wrapError"],"mappings":"sDAaaA,EAAoBC,IAC9B,CACC,GAAI,GACJ,MAAAA,CACF,GAQWC,EAA+BC,IACzC,CACC,GAAI,GACJ,MAAAA,CACF,GASWC,EAAcC,GACzBA,EAAO,GASIC,EAAeD,GAC1B,CAACA,EAAO,GAYGE,EAAU,CACrBF,EACAG,IACYH,EAAO,IAAMG,EAAGH,EAAO,KAAK,EAU7BI,EAAW,CACtBJ,EACAG,IACY,CAACH,EAAO,IAAMG,EAAGH,EAAO,KAAK,EAkCpC,SAASK,EACdF,EACAG,EACAC,EAC6B,CAC7B,GAAI,CACF,MAAMX,EAAQO,EAAA,EACd,OAAOR,EAAGC,CAAK,CACjB,OAASY,EAAW,CAClB,OAAID,GAAmBA,EAAgBC,CAAS,EACvCX,EAAIW,CAAS,EAGfX,EAAIY,EAAAA,aAAa,KAAKD,EAAWF,CAAO,CAAC,CAClD,CACF,CA6BA,eAAsBI,EACpBC,EACAL,EACAC,EACkC,CAClC,GAAI,CACF,MAAMX,EAAQ,MAAMe,EAAA,EACpB,OAAOhB,EAAGC,CAAK,CACjB,OAASY,EAAW,CAClB,OAAID,GAAmBA,EAAgBC,CAAS,EACvCX,EAAIW,CAAS,EAEfX,EAAIY,EAAAA,aAAa,KAAKD,EAAWF,CAAO,CAAC,CAClD,CACF,CAcO,MAAMM,EAAmBZ,GAC9BA,EAAO,GACH,QAAQ,QAAQA,EAAO,KAAK,EAC5B,QAAQ,OAAOa,EAAAA,YAAYb,EAAO,KAAK,CAAC,EAQjCc,EACXC,GAEAA,EAAQ,KAAKpB,CAAE,EAAE,MAAOqB,GAAMnB,EAAIY,EAAAA,aAAa,KAAKO,CAAC,CAAC,CAAC,EAU5CC,EAAoB,MAC/BC,GACwD,CAExD,GAAI,CAACC,EAAAA,cAAcD,CAAS,EAAG,OAAOA,EAGtC,GAAI,CACF,OAAO,MAAMA,CACf,OAASV,EAAW,CAClB,OAAOX,EAAIuB,YAAUZ,CAAS,CAAC,CACjC,CACF"}
@@ -0,0 +1,19 @@
1
+ import { O as c, E as r } from "./base-K-RHLZ-S.mjs";
2
+ const n = (s) => s, t = () => {
3
+ }, o = (s) => s != null, l = (s) => s == null, e = (s) => l(s) ? t() : n(s), u = (s) => s ? n(s) : t(), f = (s) => o(s) ? s : null, N = (s, a) => o(s) ? c(s) : r(a()), d = (s) => o(s) ? [s] : [];
4
+ async function p(s) {
5
+ return o(s) ? await s : t();
6
+ }
7
+ export {
8
+ t as N,
9
+ n as S,
10
+ l as a,
11
+ e as b,
12
+ f as c,
13
+ N as d,
14
+ p as e,
15
+ u as f,
16
+ o as i,
17
+ d as t
18
+ };
19
+ //# sourceMappingURL=base-BpECeKwU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-BpECeKwU.mjs","sources":["../../src/Maybe/base.ts"],"sourcesContent":["// ========================================\r\n// ./src/Maybe/base.ts\r\n// ========================================\r\nimport type {Result} from 'src/Result/types';\r\nimport {type AsyncMaybe, type Maybe} from './types';\r\nimport {Err, Ok} from 'src/Result/base';\r\n\r\n/**\r\n * Constructs a `Some` value containing a non-null, non-undefined value.\r\n * @param value - The value to wrap in a Maybe.\r\n * @returns A Maybe containing the value.\r\n */\r\nexport const Some = <T>(value: T): Maybe<T> => value;\r\n\r\n/**\r\n * Constructs a `None` value representing absence of a value.\r\n * @returns An empty Maybe (undefined).\r\n */\r\nexport const None = (): Maybe<never> => undefined;\r\n\r\n/**\r\n * Type guard checking if a Maybe contains a value (`Some`).\r\n * @param m - The Maybe to inspect.\r\n * @returns True if the Maybe contains a value.\r\n */\r\nexport const isSome = <T>(m: Maybe<T>): m is T => m !== null && m !== undefined;\r\n\r\n/**\r\n * Type guard checking if a Maybe is empty (`None`).\r\n * @param m - The Maybe to inspect.\r\n * @returns True if the Maybe is null or undefined.\r\n */\r\nexport const isNone = (m: Maybe<unknown>): m is null | undefined =>\r\n m === null || m === undefined;\r\n\r\n/**\r\n * Converts nullable value to a Maybe.\r\n * @param value - Possibly null/undefined value.\r\n * @returns Some(value) if value exists, None otherwise.\r\n */\r\nexport const fromNullable = <T>(value: T | null | undefined): Maybe<T> =>\r\n isNone(value) ? None() : Some(value);\r\n\r\n/**\r\n * Converts falsy value to a Maybe.\r\n * @param value - Possibly falsy value.\r\n * @returns Some(value) if truthy, None otherwise.\r\n */\r\nexport const fromFalsy = <T>(\r\n value: T | null | undefined | false | 0 | '',\r\n): Maybe<T> => (!value ? None() : Some(value as T));\r\n\r\n/**\r\n * Converts Maybe to nullable value.\r\n * @param maybe - Maybe value.\r\n * @returns The value if Some, null if None.\r\n */\r\nexport const toNullable = <T>(maybe: Maybe<T>): T | null =>\r\n isSome(maybe) ? maybe : null;\r\n\r\n/**\r\n * Converts Maybe to Result type.\r\n * @param maybe - Maybe value.\r\n * @param errorFn - Error generator for None case.\r\n * @returns Ok(value) if Some, Err(errorFn()) if None.\r\n */\r\nexport const toResult = <T, E>(\r\n maybe: Maybe<T>,\r\n errorFn: () => E,\r\n): Result<T, E> => (isSome(maybe) ? Ok(maybe) : Err(errorFn()));\r\n\r\n/**\r\n * Converts Maybe to array representation.\r\n * @param val - Maybe value.\r\n * @returns Singleton array if Some, empty array if None.\r\n */\r\nexport const toArray = <T>(val: Maybe<T>): T[] => (isSome(val) ? [val] : []);\r\n\r\n/**\r\n * Transposes a Maybe containing a Promise to an AsyncMaybe.\r\n * @param val - Maybe wrapping a Promise.\r\n * @returns Promise resolving to Some(value) if input was Some, None otherwise.\r\n */\r\nexport async function transpose<T>(val: Maybe<Promise<T>>): AsyncMaybe<T> {\r\n return isSome(val) ? await val : None();\r\n}\r\n"],"names":["Some","value","None","isSome","m","isNone","fromNullable","fromFalsy","toNullable","maybe","toResult","errorFn","Ok","Err","toArray","val","transpose"],"mappings":";AAYO,MAAMA,IAAO,CAAIC,MAAuBA,GAMlCC,IAAO,MAAA;AAAA,GAOPC,IAAS,CAAIC,MAAwBA,KAAM,MAO3CC,IAAS,CAACD,MACrBA,KAAM,MAOKE,IAAe,CAAIL,MAC9BI,EAAOJ,CAAK,IAAIC,EAAA,IAASF,EAAKC,CAAK,GAOxBM,IAAY,CACvBN,MACeA,IAAiBD,EAAKC,CAAU,IAAxBC,EAAA,GAOZM,IAAa,CAAIC,MAC5BN,EAAOM,CAAK,IAAIA,IAAQ,MAQbC,IAAW,CACtBD,GACAE,MACkBR,EAAOM,CAAK,IAAIG,EAAGH,CAAK,IAAII,EAAIF,EAAA,CAAS,GAOhDG,IAAU,CAAIC,MAAwBZ,EAAOY,CAAG,IAAI,CAACA,CAAG,IAAI,CAAA;AAOzE,eAAsBC,EAAaD,GAAuC;AACxE,SAAOZ,EAAOY,CAAG,IAAI,MAAMA,IAAMb,EAAA;AACnC;"}
@@ -0,0 +1,2 @@
1
+ "use strict";const l=require("./base-BTXL1y_I.cjs"),n=o=>o,t=()=>{},s=o=>o!=null,e=o=>o==null,c=o=>e(o)?t():n(o),i=o=>o?n(o):t(),u=o=>s(o)?o:null,a=(o,r)=>s(o)?l.Ok(o):l.Err(r()),N=o=>s(o)?[o]:[];async function f(o){return s(o)?await o:t()}exports.None=t;exports.Some=n;exports.fromFalsy=i;exports.fromNullable=c;exports.isNone=e;exports.isSome=s;exports.toArray=N;exports.toNullable=u;exports.toResult=a;exports.transpose=f;
2
+ //# sourceMappingURL=base-BvHqpP_s.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-BvHqpP_s.cjs","sources":["../../src/Maybe/base.ts"],"sourcesContent":["// ========================================\r\n// ./src/Maybe/base.ts\r\n// ========================================\r\nimport type {Result} from 'src/Result/types';\r\nimport {type AsyncMaybe, type Maybe} from './types';\r\nimport {Err, Ok} from 'src/Result/base';\r\n\r\n/**\r\n * Constructs a `Some` value containing a non-null, non-undefined value.\r\n * @param value - The value to wrap in a Maybe.\r\n * @returns A Maybe containing the value.\r\n */\r\nexport const Some = <T>(value: T): Maybe<T> => value;\r\n\r\n/**\r\n * Constructs a `None` value representing absence of a value.\r\n * @returns An empty Maybe (undefined).\r\n */\r\nexport const None = (): Maybe<never> => undefined;\r\n\r\n/**\r\n * Type guard checking if a Maybe contains a value (`Some`).\r\n * @param m - The Maybe to inspect.\r\n * @returns True if the Maybe contains a value.\r\n */\r\nexport const isSome = <T>(m: Maybe<T>): m is T => m !== null && m !== undefined;\r\n\r\n/**\r\n * Type guard checking if a Maybe is empty (`None`).\r\n * @param m - The Maybe to inspect.\r\n * @returns True if the Maybe is null or undefined.\r\n */\r\nexport const isNone = (m: Maybe<unknown>): m is null | undefined =>\r\n m === null || m === undefined;\r\n\r\n/**\r\n * Converts nullable value to a Maybe.\r\n * @param value - Possibly null/undefined value.\r\n * @returns Some(value) if value exists, None otherwise.\r\n */\r\nexport const fromNullable = <T>(value: T | null | undefined): Maybe<T> =>\r\n isNone(value) ? None() : Some(value);\r\n\r\n/**\r\n * Converts falsy value to a Maybe.\r\n * @param value - Possibly falsy value.\r\n * @returns Some(value) if truthy, None otherwise.\r\n */\r\nexport const fromFalsy = <T>(\r\n value: T | null | undefined | false | 0 | '',\r\n): Maybe<T> => (!value ? None() : Some(value as T));\r\n\r\n/**\r\n * Converts Maybe to nullable value.\r\n * @param maybe - Maybe value.\r\n * @returns The value if Some, null if None.\r\n */\r\nexport const toNullable = <T>(maybe: Maybe<T>): T | null =>\r\n isSome(maybe) ? maybe : null;\r\n\r\n/**\r\n * Converts Maybe to Result type.\r\n * @param maybe - Maybe value.\r\n * @param errorFn - Error generator for None case.\r\n * @returns Ok(value) if Some, Err(errorFn()) if None.\r\n */\r\nexport const toResult = <T, E>(\r\n maybe: Maybe<T>,\r\n errorFn: () => E,\r\n): Result<T, E> => (isSome(maybe) ? Ok(maybe) : Err(errorFn()));\r\n\r\n/**\r\n * Converts Maybe to array representation.\r\n * @param val - Maybe value.\r\n * @returns Singleton array if Some, empty array if None.\r\n */\r\nexport const toArray = <T>(val: Maybe<T>): T[] => (isSome(val) ? [val] : []);\r\n\r\n/**\r\n * Transposes a Maybe containing a Promise to an AsyncMaybe.\r\n * @param val - Maybe wrapping a Promise.\r\n * @returns Promise resolving to Some(value) if input was Some, None otherwise.\r\n */\r\nexport async function transpose<T>(val: Maybe<Promise<T>>): AsyncMaybe<T> {\r\n return isSome(val) ? await val : None();\r\n}\r\n"],"names":["Some","value","None","isSome","m","isNone","fromNullable","fromFalsy","toNullable","maybe","toResult","errorFn","Ok","Err","toArray","val","transpose"],"mappings":"oDAYaA,EAAWC,GAAuBA,EAMlCC,EAAO,IAAA,GAOPC,EAAaC,GAAwBA,GAAM,KAO3CC,EAAUD,GACrBA,GAAM,KAOKE,EAAmBL,GAC9BI,EAAOJ,CAAK,EAAIC,EAAA,EAASF,EAAKC,CAAK,EAOxBM,EACXN,GACeA,EAAiBD,EAAKC,CAAU,EAAxBC,EAAA,EAOZM,EAAiBC,GAC5BN,EAAOM,CAAK,EAAIA,EAAQ,KAQbC,EAAW,CACtBD,EACAE,IACkBR,EAAOM,CAAK,EAAIG,EAAAA,GAAGH,CAAK,EAAII,EAAAA,IAAIF,EAAA,CAAS,EAOhDG,EAAcC,GAAwBZ,EAAOY,CAAG,EAAI,CAACA,CAAG,EAAI,CAAA,EAOzE,eAAsBC,EAAaD,EAAuC,CACxE,OAAOZ,EAAOY,CAAG,EAAI,MAAMA,EAAMb,EAAA,CACnC"}
@@ -0,0 +1,46 @@
1
+ import { U as t, e as c, i, w as u } from "./helper-BVabbpmX.mjs";
2
+ const a = (r) => ({
3
+ ok: !0,
4
+ value: r
5
+ }), n = (r) => ({
6
+ ok: !1,
7
+ error: r
8
+ }), k = (r) => r.ok, m = (r) => !r.ok, w = (r, o) => r.ok && o(r.value), y = (r, o) => !r.ok && o(r.error);
9
+ function h(r, o, e) {
10
+ try {
11
+ const s = r();
12
+ return a(s);
13
+ } catch (s) {
14
+ return e && e(s) ? n(s) : n(t.from(s, o));
15
+ }
16
+ }
17
+ async function v(r, o, e) {
18
+ try {
19
+ const s = await r();
20
+ return a(s);
21
+ } catch (s) {
22
+ return e && e(s) ? n(s) : n(t.from(s, o));
23
+ }
24
+ }
25
+ const E = (r) => r.ok ? Promise.resolve(r.value) : Promise.reject(c(r.error)), P = (r) => r.then(a).catch((o) => n(t.from(o))), O = async (r) => {
26
+ if (!i(r)) return r;
27
+ try {
28
+ return await r;
29
+ } catch (o) {
30
+ return n(u(o));
31
+ }
32
+ };
33
+ export {
34
+ n as E,
35
+ a as O,
36
+ k as a,
37
+ y as b,
38
+ w as c,
39
+ v as d,
40
+ P as f,
41
+ m as i,
42
+ O as n,
43
+ h as s,
44
+ E as t
45
+ };
46
+ //# sourceMappingURL=base-K-RHLZ-S.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-K-RHLZ-S.mjs","sources":["../../src/Result/base.ts"],"sourcesContent":["// ========================================\r\n// ./src/Result/base.ts\r\n// ========================================\r\nimport type {Result, Success, Failure, AsyncResult, AnyResult} from './types';\r\nimport {UnknownError, ensureError} from '../unknown-error';\r\nimport {isPromiseLike, wrapError} from '../helper';\r\n\r\n/**\r\n * Constructs a successful Result instance.\r\n * @typeParam T - The type of the successful value\r\n * @param value - The value upon success\r\n * @returns A successful Result\r\n */\r\nexport const Ok = <T, E = never>(value: T): Result<T, E> =>\r\n ({\r\n ok: true,\r\n value,\r\n }) as const;\r\n\r\n/**\r\n * Get the value of Result<T, never>\r\n * @typeParam T - The type of the error\r\n * @param error - The error upon failure\r\n * @returns A failed Result\r\n */\r\nexport const Err = <T = never, E = unknown>(error: E): Result<T, E> =>\r\n ({\r\n ok: false,\r\n error,\r\n }) as const;\r\n\r\n/**\r\n * Checks if the Result is in the Success (Ok) state.\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result instance to check\r\n * @returns Returns true if the Result is Success\r\n */\r\nexport const isOk = <T, E>(result: Result<T, E>): result is Success<T> =>\r\n result.ok;\r\n\r\n/**\r\n * Checks if the Result is in the Failure (Err) state.\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result instance to check\r\n * @returns Returns true if the Result is Failure\r\n */\r\nexport const isErr = <T, E>(result: Result<T, E>): result is Failure<E> =>\r\n !result.ok;\r\n\r\n/**\r\n * Checks if the Result is Success AND its value satisfies the given predicate.\r\n * @typeParam T - The type of the success valueexport function isPromiseLike<T>(value: unknown): value is PromiseLike<T> {\r\n return value !== null && typeof value === 'object' && 'then' in value;\r\n }\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result instance to check\r\n * @param fn - The predicate function to check the success value\r\n * @returns Returns true if the Result is Success and the condition is met\r\n */\r\nexport const isOkAnd = <T, E>(\r\n result: Result<T, E>,\r\n fn: (value: T) => boolean,\r\n): boolean => result.ok && fn(result.value);\r\n\r\n/**\r\n * Checks if the Result is Failure AND its error satisfies the given predicate.\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result instance to check\r\n * @param fn - The predicate function to check the error value\r\n * @returns Returns true if the Result is Failure and the condition is met\r\n */\r\nexport const isErrAnd = <T, E>(\r\n result: Result<T, E>,\r\n fn: (error: E) => boolean,\r\n): boolean => !result.ok && fn(result.error);\r\n\r\n// ============================================\r\n// 异常安全执行器\r\n// ============================================\r\n\r\n/**\r\n * Safely executes a synchronous function, catching any thrown exception and wrapping it as an UnknownError.\r\n * @typeParam T - The success value type\r\n * @param fn - The synchronous function that might throw an exception\r\n * @param message - The error message to be used as the primary message for the UnknownError if an exception is thrown\r\n * @returns Returns Ok(T) on success, or Err(UnknownError) on failure\r\n */\r\nexport function safeExecute<T>(\r\n fn: () => T,\r\n message?: string,\r\n): Result<T, UnknownError>;\r\n\r\n/**\r\n * Safely executes a synchronous function, catching any thrown exception. If the exception is of the declared type E,\r\n * it returns Err(E); otherwise, it is wrapped as an UnknownError.\r\n * @typeParam T - The success value type\r\n * @typeParam E - The declared expected error type\r\n * @param fn - The synchronous function that might throw an exception\r\n * @param message - The error message to be used as the primary message for the UnknownError if an unknown exception is thrown\r\n * @param isExpectedError - A type guard function to determine if the caught error is of type E\r\n * @returns Returns Ok(T) on success, or Err(E | UnknownError) on failure\r\n */\r\nexport function safeExecute<T, E>(\r\n fn: () => T,\r\n message: string | undefined,\r\n isExpectedError: (error: unknown) => error is E,\r\n): Result<T, E | UnknownError>;\r\n\r\nexport function safeExecute<T, E = never>(\r\n fn: () => T,\r\n message?: string,\r\n isExpectedError?: (error: unknown) => error is E,\r\n): Result<T, E | UnknownError> {\r\n try {\r\n const value = fn();\r\n return Ok(value);\r\n } catch (raw_error) {\r\n if (isExpectedError && isExpectedError(raw_error)) {\r\n return Err(raw_error);\r\n }\r\n\r\n return Err(UnknownError.from(raw_error, message));\r\n }\r\n}\r\n\r\n/**\r\n * Safely executes an asynchronous function, catching its rejection or thrown exception and wrapping it as an UnknownError.\r\n * @typeParam T - The success value type\r\n * @param async_fn - The asynchronous function that might throw or reject\r\n * @param message - The error message to be used as the primary message for the UnknownError\r\n * @returns Returns Promise<Ok(T)> on success, or Promise<Err(UnknownError)> on failure\r\n */\r\nexport async function safeExecuteAsync<T>(\r\n async_fn: () => Promise<T>,\r\n message?: string,\r\n): AsyncResult<T, UnknownError>;\r\n\r\n/**\r\n * Safely executes an asynchronous function, catching its rejection or thrown exception. If the exception is of the declared type E,\r\n * it returns Err(E); otherwise, it is wrapped as an UnknownError.\r\n * @typeParam T - The success value type\r\n * @typeParam E - The declared expected error type\r\n * @param async_fn - The asynchronous function that might throw or reject\r\n * @param message - The error message to be used as the primary message for the UnknownError if an unknown exception is thrown\r\n * @param isExpectedError - A type guard function to determine if the caught error is of type E\r\n * @returns Returns Promise<Ok(T)> on success, or Promise<Err(E | UnknownError)> on failure\r\n */\r\nexport async function safeExecuteAsync<T, E>(\r\n async_fn: () => Promise<T>,\r\n message: string | undefined,\r\n isExpectedError: (error: unknown) => error is E,\r\n): AsyncResult<T, E | UnknownError>;\r\nexport async function safeExecuteAsync<T, E = never>(\r\n async_fn: () => Promise<T>,\r\n message?: string,\r\n isExpectedError?: (error: unknown) => error is E,\r\n): AsyncResult<T, E | UnknownError> {\r\n try {\r\n const value = await async_fn();\r\n return Ok(value);\r\n } catch (raw_error) {\r\n if (isExpectedError && isExpectedError(raw_error)) {\r\n return Err(raw_error);\r\n }\r\n return Err(UnknownError.from(raw_error, message));\r\n }\r\n}\r\n\r\n// ========================================\r\n// 互相转换\r\n// ========================================\r\n\r\n/**\r\n * Converts a Result into a Promise. Success resolves, Failure rejects.\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param result - The Result to convert\r\n * @returns The resulting Promise\r\n * @throws If the Result is Failure, it rejects with the error wrapped by `ensureError`\r\n */\r\nexport const toPromise = <T, E>(result: Result<T, E>): Promise<T> =>\r\n result.ok\r\n ? Promise.resolve(result.value)\r\n : Promise.reject(ensureError(result.error));\r\n\r\n/**\r\n * Converts a Promise into an AsyncResult. Resolution becomes Ok, and rejection becomes Err(UnknownError).\r\n * @typeParam T - The type of the success value\r\n * @param promise - The Promise to convert\r\n * @returns The resulting AsyncResult\r\n */\r\nexport const fromPromise = <T>(\r\n promise: Promise<T>,\r\n): AsyncResult<T, UnknownError> =>\r\n promise.then(Ok).catch((e) => Err(UnknownError.from(e)));\r\n\r\n/**\r\n * Safely normalizes an AnyResult (synchronous Result or asynchronous AsyncResult/Thenable) into a Promise<Result>.\r\n * It handles the Promise resolve/reject paths, ensuring rejection is always encapsulated as Err(UnknownError).\r\n * @typeParam T - The type of the success value\r\n * @typeParam E - The type of the error value\r\n * @param awaitable - The value to normalize, which can be a Result, Promise<Result>, or a Thenable object\r\n * @returns The normalized Promise<Result>\r\n */\r\nexport const normalizeToResult = async <T, E>(\r\n awaitable: AnyResult<T, E>,\r\n): Promise<Result<T, E | UnknownError | DOMException>> => {\r\n // 同步 Result 快速路径\r\n if (!isPromiseLike(awaitable)) return awaitable;\r\n\r\n // 统一处理所有异步情况 (Promise & Thenable)\r\n try {\r\n return await awaitable;\r\n } catch (raw_error) {\r\n return Err(wrapError(raw_error));\r\n }\r\n};\r\n"],"names":["Ok","value","Err","error","isOk","result","isErr","isOkAnd","fn","isErrAnd","safeExecute","message","isExpectedError","raw_error","UnknownError","safeExecuteAsync","async_fn","toPromise","ensureError","fromPromise","promise","e","normalizeToResult","awaitable","isPromiseLike","wrapError"],"mappings":";AAaO,MAAMA,IAAK,CAAeC,OAC9B;AAAA,EACC,IAAI;AAAA,EACJ,OAAAA;AACF,IAQWC,IAAM,CAAyBC,OACzC;AAAA,EACC,IAAI;AAAA,EACJ,OAAAA;AACF,IASWC,IAAO,CAAOC,MACzBA,EAAO,IASIC,IAAQ,CAAOD,MAC1B,CAACA,EAAO,IAYGE,IAAU,CACrBF,GACAG,MACYH,EAAO,MAAMG,EAAGH,EAAO,KAAK,GAU7BI,IAAW,CACtBJ,GACAG,MACY,CAACH,EAAO,MAAMG,EAAGH,EAAO,KAAK;AAkCpC,SAASK,EACdF,GACAG,GACAC,GAC6B;AAC7B,MAAI;AACF,UAAMX,IAAQO,EAAA;AACd,WAAOR,EAAGC,CAAK;AAAA,EACjB,SAASY,GAAW;AAClB,WAAID,KAAmBA,EAAgBC,CAAS,IACvCX,EAAIW,CAAS,IAGfX,EAAIY,EAAa,KAAKD,GAAWF,CAAO,CAAC;AAAA,EAClD;AACF;AA6BA,eAAsBI,EACpBC,GACAL,GACAC,GACkC;AAClC,MAAI;AACF,UAAMX,IAAQ,MAAMe,EAAA;AACpB,WAAOhB,EAAGC,CAAK;AAAA,EACjB,SAASY,GAAW;AAClB,WAAID,KAAmBA,EAAgBC,CAAS,IACvCX,EAAIW,CAAS,IAEfX,EAAIY,EAAa,KAAKD,GAAWF,CAAO,CAAC;AAAA,EAClD;AACF;AAcO,MAAMM,IAAY,CAAOZ,MAC9BA,EAAO,KACH,QAAQ,QAAQA,EAAO,KAAK,IAC5B,QAAQ,OAAOa,EAAYb,EAAO,KAAK,CAAC,GAQjCc,IAAc,CACzBC,MAEAA,EAAQ,KAAKpB,CAAE,EAAE,MAAM,CAACqB,MAAMnB,EAAIY,EAAa,KAAKO,CAAC,CAAC,CAAC,GAU5CC,IAAoB,OAC/BC,MACwD;AAExD,MAAI,CAACC,EAAcD,CAAS,EAAG,QAAOA;AAGtC,MAAI;AACF,WAAO,MAAMA;AAAA,EACf,SAASV,GAAW;AAClB,WAAOX,EAAIuB,EAAUZ,CAAS,CAAC;AAAA,EACjC;AACF;"}
@@ -0,0 +1,2 @@
1
+ "use strict";const c=require("./helper-tsqZMRHW.cjs"),i=t=>t,u=()=>{},a=async()=>{},l=t=>r=>t(r),p=t=>(...r)=>!t(...r),y=t=>{let r=!1,e;return(...n)=>(r||(r=!0,e=t(...n)),e)},d=(t,r)=>(...e)=>t(...e.slice(0,r)),f=t=>(...r)=>{const e=t.length>0?t.length-1:0,n=r.slice(0,e),o=r.slice(e);return t(n,o)},h=t=>r=>t(...r),m=(t,...r)=>(...e)=>t(...r,...e),g=(t,...r)=>(...e)=>t(...e,...r),v=(t,r)=>{let e=0;return(...n)=>{if(e++,e>=t)return r(...n)}},N=(t,r)=>{let e=0,n;return(...o)=>(e<t&&(e++,n=r(...o)),n)},R=(t,r)=>{const e=new Map;return(...n)=>{const o=r?r(...n):JSON.stringify(n);if(e.has(o))return e.get(o);const s=t(...n);return e.set(o,s),s}},b=t=>function(...r){try{const e=t.apply(this,r);return c.isPromiseLike(e)?e.then(n=>[void 0,n],n=>[n,void 0]):[void 0,e]}catch(e){return[e,void 0]}};exports.after=v;exports.ary=d;exports.asyncNoop=a;exports.attempt=b;exports.before=N;exports.identity=i;exports.memoize=R;exports.negate=p;exports.noop=u;exports.once=y;exports.partial=m;exports.partialRight=g;exports.rest=f;exports.spread=h;exports.unary=l;
2
+ //# sourceMappingURL=base-r6kn0B0D.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-r6kn0B0D.cjs","sources":["../../src/Utils/Functions/base.ts"],"sourcesContent":["// ========================================\r\n// ./src/Utils/Functions/base.ts\r\n// ========================================\r\n/* eslint-disable @typescript-eslint/no-unsafe-return */\r\n/* eslint-disable @typescript-eslint/no-explicit-any */\r\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\r\n\r\nimport {isPromiseLike} from 'src/helper';\r\n\r\n/**\r\n * Generic type for an identity function.\r\n * @template T - The type of the input and output value.\r\n */\r\nexport type IdentityFn = <T>(x: T) => T;\r\n\r\n/**\r\n * A function that returns the same value passed to it.\r\n * @template T\r\n * @param x - The value to return\r\n * @returns The input value `x`\r\n * @satisfies {IdentityFn}\r\n */\r\nexport const identity: IdentityFn = (x) => x;\r\n\r\nexport const noop = (): void => {};\r\nexport const asyncNoop = async (): Promise<void> => {};\r\n\r\n/**\r\n * Creates a function that accepts up to one argument, ignoring any additional arguments.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to cap arguments for.\r\n * @returns The new function.\r\n */\r\nexport const unary = <T, Ret>(\r\n fn: (arg: T, ...rest: unknown[]) => Ret,\r\n): ((arg: T) => Ret) => {\r\n return (arg) => fn(arg);\r\n};\r\n\r\n/**\r\n * Creates a function that negates the result of the predicate `fn`.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @param predicate - The predicate to negate.\r\n * @returns The new negated function.\r\n */\r\nexport const negate = <Args extends unknown[]>(\r\n predicate: (...args: Args) => boolean,\r\n): ((...args: Args) => boolean) => {\r\n return (...args) => !predicate(...args);\r\n};\r\n\r\n/**\r\n * Creates a function that is restricted to invoking `fn` once.\r\n * Repeat calls to the function return the value of the first invocation.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to restrict.\r\n * @returns The new restricted function.\r\n */\r\nexport const once = <Args extends unknown[], Ret>(\r\n fn: (...args: Args) => Ret,\r\n): ((...args: Args) => Ret) => {\r\n let done = false;\r\n let result: Ret;\r\n\r\n return (...args) => {\r\n if (!done) {\r\n done = true;\r\n result = fn(...args);\r\n }\r\n return result;\r\n };\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with only the first `n` arguments provided.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to cap arguments for.\r\n * @param n - The number of arguments to accept.\r\n * @returns The new function.\r\n */\r\nexport const ary = <Args extends unknown[], Ret>(\r\n fn: (...args: Args) => Ret,\r\n n: number,\r\n): ((...args: Args) => Ret) => {\r\n return (...args) => fn(...(args.slice(0, n) as Args));\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with arguments transformed.\r\n * The implementation splits arguments based on `fn.length`, expecting `fn` to take two arguments:\r\n * 1. A tuple of the first `fn.length - 1` arguments.\r\n * 2. A tuple of the remaining arguments.\r\n *\r\n * Note: Based on the implementation `fn.length - 1`, `FixedArgs` is strictly a single-element tuple.\r\n *\r\n * @template FixedArgs - The fixed arguments tuple (must be length 1).\r\n * @template RestArgs - The rest arguments tuple.\r\n * @template Ret - The return type.\r\n * @param fn - The function to transform arguments for.\r\n * @returns The new function.\r\n */\r\nexport const rest = <\r\n FixedArgs extends [unknown],\r\n RestArgs extends unknown[],\r\n Ret,\r\n>(\r\n fn: (fixed: FixedArgs, rest: RestArgs) => Ret,\r\n): ((...args: [...FixedArgs, ...RestArgs]) => Ret) => {\r\n return (...args) => {\r\n const fixedLength = fn.length > 0 ? fn.length - 1 : 0;\r\n const fixed = args.slice(0, fixedLength) as FixedArgs;\r\n const restParts = args.slice(fixedLength) as RestArgs;\r\n return fn(fixed, restParts);\r\n };\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with the `args` spread as an array.\r\n *\r\n * @template Args - The arguments tuple type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to spread arguments for.\r\n * @returns The new function.\r\n */\r\nexport const spread = <Args extends unknown[], Ret>(\r\n fn: (...args: Args) => Ret,\r\n): ((args: Args) => Ret) => {\r\n return (args) => fn(...args);\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with `partial` arguments prepended to those provided to the new function.\r\n *\r\n * @template Fixed - The fixed arguments type.\r\n * @template Rest - The remaining arguments type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to partially apply arguments to.\r\n * @param fixedArgs - The arguments to prepend.\r\n * @returns The new partially applied function.\r\n */\r\nexport const partial = <Fixed extends unknown[], Rest extends unknown[], Ret>(\r\n fn: (...args: [...Fixed, ...Rest]) => Ret,\r\n ...fixedArgs: Fixed\r\n): ((...rest: Rest) => Ret) => {\r\n return (...restArgs) => fn(...fixedArgs, ...restArgs);\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` with `partial` arguments appended to those provided to the new function.\r\n *\r\n * @template Fixed - The fixed arguments type (appended).\r\n * @template Rest - The remaining arguments type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to partially apply arguments to.\r\n * @param fixedArgs - The arguments to append.\r\n * @returns The new partially applied function.\r\n */\r\nexport const partialRight = <\r\n T extends (...args: any[]) => any,\r\n Fixed extends any[],\r\n>(\r\n fn: T,\r\n ...fixedArgs: Fixed\r\n): ((\r\n ...rest: T extends (...args: [...infer Rest, ...Fixed]) => any ? Rest : never\r\n) => ReturnType<T>) => {\r\n return (...restArgs: any[]) => fn(...restArgs, ...fixedArgs);\r\n};\r\n/**\r\n * Creates a function that invokes `fn` only after being called `n` times.\r\n *\r\n * @template Args - The arguments type.\r\n * @template Ret - The return type.\r\n * @param n - The number of calls before the function is invoked.\r\n * @param fn - The function to restrict.\r\n * @returns The new restricted function.\r\n */\r\nexport const after = <Args extends unknown[], Ret>(\r\n n: number,\r\n fn: (...args: Args) => Ret,\r\n): ((...args: Args) => Ret | undefined) => {\r\n let count = 0;\r\n return (...args) => {\r\n count++;\r\n if (count >= n) {\r\n return fn(...args);\r\n }\r\n return undefined;\r\n };\r\n};\r\n\r\n/**\r\n * Creates a function that invokes `fn` while it's called less than `n` times.\r\n *\r\n * @template Args - The arguments type.\r\n * @template Ret - The return type.\r\n * @param n - The number of calls before the function stops being invoked.\r\n * @param fn - The function to restrict.\r\n * @returns The new restricted function.\r\n */\r\nexport const before = <Args extends unknown[], Ret>(\r\n n: number,\r\n fn: (...args: Args) => Ret,\r\n): ((...args: Args) => Ret | undefined) => {\r\n let count = 0;\r\n let lastResult: Ret | undefined;\r\n return (...args) => {\r\n if (count < n) {\r\n count++;\r\n lastResult = fn(...args);\r\n }\r\n return lastResult;\r\n };\r\n};\r\n\r\n/**\r\n * Creates a function that memoizes the result of `fn`.\r\n * If `resolver` is provided, it determines the cache key for storing the result based on the arguments provided.\r\n *\r\n * @template Args - The arguments type.\r\n * @template Ret - The return type.\r\n * @param fn - The function to memoize.\r\n * @param resolver - The function to resolve the cache key.\r\n * @returns The new memoized function.\r\n */\r\nexport const memoize = <Args extends unknown[], Ret>(\r\n fn: (...args: Args) => Ret,\r\n resolver?: (...args: Args) => unknown,\r\n): ((...args: Args) => Ret) => {\r\n const cache = new Map<unknown, Ret>();\r\n return (...args) => {\r\n const key = resolver ? resolver(...args) : JSON.stringify(args);\r\n\r\n if (cache.has(key)) {\r\n return cache.get(key) as Ret;\r\n }\r\n const result = fn(...args);\r\n cache.set(key, result);\r\n return result;\r\n };\r\n};\r\n\r\ntype AttemptResult<T> =\r\n T extends PromiseLike<infer R>\r\n ? Promise<[undefined, R] | [unknown, undefined]>\r\n : [undefined, T] | [unknown, undefined];\r\n\r\n/**\r\n *\r\n * Wraps any function – synchronous or asynchronous – and returns a tuple `[error, result]` instead of throwing.\r\n * It catches **everything**: thrown exceptions and rejected promises alike, turning them into a consistent error-first return.\r\n * Eliminates try-catch blocks and makes error handling explicit and type‑safe.\r\n *\r\n * @template Args - The arguments tuple type of the wrapped function\r\n * @template R - The return type of the wrapped function\r\n * @param fn - The function to wrap\r\n * @returns A function that returns `[undefined, result]` on success, or `[error, undefined]` on failure\r\n *\r\n * @example\r\n * ```typescript\r\n * const [err, data] = attempt(JSON.parse)('{\"a\":1}');\r\n * if (err) console.error('Parse failed:', err);\r\n * else console.log('Parsed:', data);\r\n * ```\r\n *\r\n * @example\r\n * ```typescript\r\n * // Works seamlessly with async functions\r\n * const fetchData = async (url: string) => ({ data: 'response' });\r\n * const [err, data] = await attempt(fetchData)('https://api.example.com');\r\n * ```\r\n */\r\nexport const attempt = <Args extends unknown[], R>(\r\n fn: (...args: Args) => R,\r\n): ((\r\n this: ThisParameterType<typeof fn>,\r\n ...args: Args\r\n) => AttemptResult<R>) => {\r\n return function (\r\n this: ThisParameterType<typeof fn>,\r\n ...args: Args\r\n ): AttemptResult<R> {\r\n try {\r\n const result = fn.apply(this, args);\r\n\r\n // 处理异步函数\r\n if (isPromiseLike(result))\r\n return (result as PromiseLike<R>).then(\r\n (value) => [undefined, value],\r\n (err: unknown) => [err, undefined],\r\n ) as AttemptResult<R>;\r\n\r\n // 处理同步函数\r\n return [undefined, result] as AttemptResult<R>;\r\n } catch (err) {\r\n return [err, undefined] as AttemptResult<R>;\r\n }\r\n };\r\n};\r\n"],"names":["identity","x","noop","asyncNoop","unary","fn","arg","negate","predicate","args","once","done","result","ary","n","rest","fixedLength","fixed","restParts","spread","partial","fixedArgs","restArgs","partialRight","after","count","before","lastResult","memoize","resolver","cache","key","attempt","isPromiseLike","value","err"],"mappings":"sDAsBaA,EAAwBC,GAAMA,EAE9BC,EAAO,IAAY,CAAC,EACpBC,EAAY,SAA2B,CAAC,EAUxCC,EACXC,GAEQC,GAAQD,EAAGC,CAAG,EAUXC,EACXC,GAEO,IAAIC,IAAS,CAACD,EAAU,GAAGC,CAAI,EAY3BC,EACXL,GAC6B,CAC7B,IAAIM,EAAO,GACPC,EAEJ,MAAO,IAAIH,KACJE,IACHA,EAAO,GACPC,EAASP,EAAG,GAAGI,CAAI,GAEdG,EAEX,EAWaC,EAAM,CACjBR,EACAS,IAEO,IAAIL,IAASJ,EAAG,GAAII,EAAK,MAAM,EAAGK,CAAC,CAAU,EAiBzCC,EAKXV,GAEO,IAAII,IAAS,CAClB,MAAMO,EAAcX,EAAG,OAAS,EAAIA,EAAG,OAAS,EAAI,EAC9CY,EAAQR,EAAK,MAAM,EAAGO,CAAW,EACjCE,EAAYT,EAAK,MAAMO,CAAW,EACxC,OAAOX,EAAGY,EAAOC,CAAS,CAC5B,EAWWC,EACXd,GAEQI,GAASJ,EAAG,GAAGI,CAAI,EAahBW,EAAU,CACrBf,KACGgB,IAEI,IAAIC,IAAajB,EAAG,GAAGgB,EAAW,GAAGC,CAAQ,EAazCC,EAAe,CAI1BlB,KACGgB,IAII,IAAIC,IAAoBjB,EAAG,GAAGiB,EAAU,GAAGD,CAAS,EAWhDG,EAAQ,CACnBV,EACAT,IACyC,CACzC,IAAIoB,EAAQ,EACZ,MAAO,IAAIhB,IAAS,CAElB,GADAgB,IACIA,GAASX,EACX,OAAOT,EAAG,GAAGI,CAAI,CAGrB,CACF,EAWaiB,EAAS,CACpBZ,EACAT,IACyC,CACzC,IAAIoB,EAAQ,EACRE,EACJ,MAAO,IAAIlB,KACLgB,EAAQX,IACVW,IACAE,EAAatB,EAAG,GAAGI,CAAI,GAElBkB,EAEX,EAYaC,EAAU,CACrBvB,EACAwB,IAC6B,CAC7B,MAAMC,MAAY,IAClB,MAAO,IAAIrB,IAAS,CAClB,MAAMsB,EAAMF,EAAWA,EAAS,GAAGpB,CAAI,EAAI,KAAK,UAAUA,CAAI,EAE9D,GAAIqB,EAAM,IAAIC,CAAG,EACf,OAAOD,EAAM,IAAIC,CAAG,EAEtB,MAAMnB,EAASP,EAAG,GAAGI,CAAI,EACzB,OAAAqB,EAAM,IAAIC,EAAKnB,CAAM,EACdA,CACT,CACF,EAgCaoB,EACX3B,GAKO,YAEFI,EACe,CAClB,GAAI,CACF,MAAMG,EAASP,EAAG,MAAM,KAAMI,CAAI,EAGlC,OAAIwB,EAAAA,cAAcrB,CAAM,EACdA,EAA0B,KAC/BsB,GAAU,CAAC,OAAWA,CAAK,EAC3BC,GAAiB,CAACA,EAAK,MAAS,CAAA,EAI9B,CAAC,OAAWvB,CAAM,CAC3B,OAASuB,EAAK,CACZ,MAAO,CAACA,EAAK,MAAS,CACxB,CACF"}
@@ -0,0 +1,2 @@
1
+ "use strict";const r=require("./base-BTXL1y_I.cjs"),u=require("./helper-tsqZMRHW.cjs"),E=(n,o,e)=>n.ok?o(n.value):e(n.error);function m(n,o,e){return n.ok?o(n.value):e?.(n.error)}function k(n,o,e){return n.ok?e?.(n.value):o(n.error)}const O=(n,o,e)=>n.ok?e(n.value):o(n.error),w=(n,o)=>E(n,e=>r.Ok(o(e)),e=>r.Err(e)),d=(n,o)=>E(n,e=>r.Ok(e),e=>r.Err(o(e))),A=(n,o,e)=>E(n,t=>r.Ok(o(t)),t=>r.Err(e(t))),f=(n,o)=>n.ok?o(n.value):n,p=(n,o)=>n.ok?n:o(n.error),v=(n,o)=>p(n,o);function b(n,o,e){return f(n,t=>o(t)?r.Ok(t):r.Err(e(t)))}function h(n,o){if(!n.ok)return n;if(!o.ok)return o;const e=n.value,t=o.value;return r.Ok(e(t))}function l(n,o){return n.ok?o.ok?r.Ok([n.value,o.value]):o:n}function y(n){const o=[];for(const e of n){if(!e.ok)return r.Err(e.error);o.push(e.value)}return r.Ok(o)}function z(n,o){const e=[];for(let t=0;t<n.length;t++){const a=o(n[t],t);if(!a.ok)return r.Err(a.error);e.push(a.value)}return r.Ok(e)}const x=(n,o)=>n.ok?o:n,D=(n,o)=>n.ok?n:o;async function M(n,o,e){if(e?.aborted)return r.Err(u.ensureDOMException(e.reason));const t=await r.normalizeToResult(n);if(!t.ok)return r.Err(t.error);try{const a=await u.dynamicAwait(o(t.value,e));return e?.aborted?r.Err(u.ensureDOMException(e.reason)):r.Ok(a)}catch(a){return r.Err(u.wrapError(a))}}async function T(n,o,e){if(e?.aborted)return r.Err(u.ensureDOMException(e.reason));const t=await r.normalizeToResult(n);if(t.ok)return r.Ok(t.value);try{const a=await u.dynamicAwait(o(t.error,e));return e?.aborted?r.Err(u.ensureDOMException(e.reason)):r.Err(a)}catch(a){return r.Err(u.wrapError(a))}}async function R(n,o,e,t){if(t?.aborted)return r.Err(u.ensureDOMException(t.reason));const a=await r.normalizeToResult(n);if(a.ok)try{const c=await u.dynamicAwait(o(a.value,t));return t?.aborted?r.Err(u.ensureDOMException(t.reason)):r.Ok(c)}catch(c){return r.Err(u.wrapError(c))}try{const c=await u.dynamicAwait(e(a.error,t));return t?.aborted?r.Err(u.ensureDOMException(t.reason)):r.Err(c)}catch(c){return r.Err(u.wrapError(c))}}async function q(n,o,e){if(e?.aborted)return r.Err(u.ensureDOMException(e.reason));const t=await r.normalizeToResult(n);if(!t.ok)return r.Err(t.error);try{const a=o(t.value,e),c=await r.normalizeToResult(a);return e?.aborted?r.Err(u.ensureDOMException(e.reason)):c}catch(a){return r.Err(u.wrapError(a))}}async function B(n,o,e){if(e?.aborted)return r.Err(u.ensureDOMException(e.reason));const t=await r.normalizeToResult(n);if(t.ok)return r.Ok(t.value);try{const a=await r.normalizeToResult(o(t.error,e));return e?.aborted?r.Err(u.ensureDOMException(e.reason)):a}catch(a){return r.Err(u.wrapError(a))}}async function P(n,o,e){if(e?.aborted)return r.Err(u.ensureDOMException(e.reason));const t=await r.normalizeToResult(n);if(t.ok)return r.Ok(t.value);try{const a=await r.normalizeToResult(o(t.error,e));return e?.aborted?r.Err(u.ensureDOMException(e.reason)):a}catch(a){return r.Err(u.wrapError(a))}}async function _(n,o,e,t){if(t?.aborted)return r.Err(u.ensureDOMException(t.reason));const a=await r.normalizeToResult(n);if(!a.ok)return a;const c=a.value;try{if(await u.dynamicAwait(o(c,t)))return t?.aborted?r.Err(u.ensureDOMException(t.reason)):r.Ok(c);{const s=await u.dynamicAwait(e(c,t));return t?.aborted?r.Err(u.ensureDOMException(t.reason)):r.Err(s)}}catch(i){return r.Err(u.wrapError(i))}}async function V(n,o,e){if(e?.aborted)return r.Err(u.ensureDOMException(e.reason));const[t,a]=await Promise.all([r.normalizeToResult(n),r.normalizeToResult(o)]);if(!t.ok)return r.Err(t.error);if(!a.ok)return r.Err(a.error);const c=t.value,i=a.value;try{const s=r.Ok(await c(i,e));return e?.aborted?r.Err(u.ensureDOMException(e.reason)):s}catch(s){return r.Err(u.wrapError(s))}}async function j(n,o,e){if(e?.aborted)return r.Err(u.ensureDOMException(e.reason));const[t,a]=await Promise.all([r.normalizeToResult(n),r.normalizeToResult(o)]);return l(t,a)}async function C(n,o){if(o?.aborted)return r.Err(u.ensureDOMException(o.reason));if(n.length===0)return r.Ok([]);const e=n.map(a=>r.normalizeToResult(a)),t=await Promise.all(e);return y(t)}async function F(n,o){if(o?.aborted)return r.Err(u.ensureDOMException(o.reason));const e=[];for(let t=0;t<n.length;t++){const a=n[t],c=await r.normalizeToResult(a);if(o?.aborted)return r.Err(u.ensureDOMException(o.reason));if(!c.ok)return r.Err(c.error);e.push(c.value)}return r.Ok(e)}async function G(n,o,e){if(e?.aborted)return r.Err(u.ensureDOMException(e.reason));const t=await r.normalizeToResult(n);return t.ok?r.normalizeToResult(o):r.Err(t.error)}async function H(n,o,e){if(e?.aborted)return r.Err(u.ensureDOMException(e.reason));const t=await r.normalizeToResult(n);return t.ok?r.Ok(t.value):r.normalizeToResult(o)}exports.all=y;exports.allAsync=C;exports.and=x;exports.andAsync=G;exports.andThen=f;exports.andThenAsync=q;exports.ap=h;exports.apAsync=V;exports.filter=b;exports.filterAsync=_;exports.ifErr=k;exports.ifOk=m;exports.map=w;exports.mapAll=z;exports.mapAsync=M;exports.mapBoth=A;exports.mapBothAsync=R;exports.mapErr=d;exports.mapErrAsync=T;exports.mapOrElse=O;exports.match=E;exports.or=D;exports.orAsync=H;exports.orElse=v;exports.orElseAsync=P;exports.recover=p;exports.recoverAsync=B;exports.sequenceAsync=F;exports.zip=l;exports.zipAsync=j;
2
+ //# sourceMappingURL=combine-async-DcG-3p8i.cjs.map