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,44 @@
1
+ /**
2
+ * Groups array items by a computed key. Keys are converted to strings -
3
+ * distinct original keys that stringify to the same value will merge groups.
4
+ * @param list Array to group
5
+ * @param keyGetter Function extracting grouping key from each item
6
+ * @returns Object with stringified keys mapping to arrays of grouped items
7
+ */
8
+ export declare const groupBy: <T, K extends string | number | boolean>(list: readonly T[], keyGetter: (item: T) => K) => Record<string | number, T[]>;
9
+ /**
10
+ * Creates object lookup by computed key. Last item wins for duplicate keys
11
+ * after string conversion. Returns empty object for empty array.
12
+ * @param list Array to index
13
+ * @param keyGetter Function extracting key from each item
14
+ * @returns Object with stringified keys mapping to the last corresponding item
15
+ */
16
+ export declare const keyBy: <T, K extends string | number | boolean>(list: readonly T[], keyGetter: (item: T) => K) => Record<string | number, T>;
17
+ /**
18
+ * Splits array into two groups based on predicate. Always returns tuple of
19
+ * two arrays (truthy group first). Both arrays are empty for empty input.
20
+ * @param list Array to partition
21
+ * @param predicate Filtering function
22
+ * @returns Tuple where first array contains items satisfying predicate
23
+ */
24
+ export declare const partition: <T>(list: readonly T[], predicate: (item: T) => boolean) => [T[], T[]];
25
+ /**
26
+ * Splits an array into chunks of the specified size. Returns an empty array
27
+ * if the input array is empty or chunk size is zero. Negative sizes are
28
+ * treated as zero. The final chunk may be smaller than the specified size.
29
+ *
30
+ * @param array - The array to process
31
+ * @param size - The length of each chunk (default: 1)
32
+ * @returns A new array of chunks
33
+ */
34
+ export declare const chunk: <T>(array: readonly T[], size?: number) => T[][];
35
+ /**
36
+ * Creates an object composed of keys generated from iteratee results,
37
+ * with corresponding values counting their occurrences in the array.
38
+ * String and number keys are supported; other types will be coerced to strings.
39
+ *
40
+ * @param array - The array to iterate over
41
+ * @param iteratee - The function to generate keys from elements
42
+ * @returns An object with keys and their counts
43
+ */
44
+ export declare const countBy: <T>(array: readonly T[], iteratee: (value: T) => string | number) => Record<string, number>;
@@ -0,0 +1,86 @@
1
+ import { MaybePromise } from '../type-tool';
2
+ /**
3
+ * Iterates over array elements from right to left (last to first).
4
+ * Executes the iteratee function for each element.
5
+ *
6
+ * @param array - The array to iterate over
7
+ * @param iteratee - Function invoked per iteration with (value, index, collection)
8
+ * @returns void
9
+ *
10
+ * @remarks
11
+ * - For empty arrays, no iterations occur
12
+ * - Iteration order is reversed: array[length-1] to array[0]
13
+ * - Original array modifications during iteration affect the iteration
14
+ */
15
+ export declare const forEachRight: <T>(array: T[], iteratee: (value: T, index: number, collection: T[]) => void) => void;
16
+ /**
17
+ * Asynchronously iterates over array elements with controlled concurrency.
18
+ * Executes callbacks concurrently up to the concurrency limit.
19
+ *
20
+ * @param array - The array to iterate over
21
+ * @param callback - Async function invoked per element with (value, index, array)
22
+ * @param concurrency - Maximum number of concurrent executions (default: Infinity)
23
+ * @returns Promise that resolves when all callbacks complete
24
+ *
25
+ * @remarks
26
+ * - Empty arrays resolve immediately
27
+ * - Concurrency values < 1 behave as concurrency=Infinity
28
+ * - If concurrency >= array.length, uses Promise.all for optimization
29
+ * - Callback exceptions cause immediate rejection; pending callbacks continue
30
+ * - Execution order starts from index 0, but completion order varies
31
+ */
32
+ export declare const forEachAsync: <T>(array: T[], callback: (value: T, index: number, array: T[]) => Promise<void>, concurrency?: number) => Promise<void>;
33
+ /**
34
+ * Asynchronously maps array elements with controlled concurrency.
35
+ * Returns new array with mapped values in original indices.
36
+ *
37
+ * @template T - Input array element type
38
+ * @template U - Output array element type
39
+ * @param array - Source array to map
40
+ * @param callback - Async mapping function with (value, index, array)
41
+ * @param concurrency - Maximum concurrent executions (default: Infinity)
42
+ * @returns Promise resolving to new array of mapped values
43
+ *
44
+ * @remarks
45
+ * - Empty arrays resolve to empty array
46
+ * - Concurrency behavior matches forEachAsync
47
+ * - Output array length equals input array length
48
+ * - Original indices are preserved regardless of execution timing
49
+ * - Any rejection immediately rejects the entire operation
50
+ */
51
+ export declare const mapAsync: <T, U>(array: T[], callback: (value: T, index: number, array: T[]) => MaybePromise<U>, concurrency?: number) => Promise<U[]>;
52
+ /**
53
+ * Asynchronously filters array elements with controlled concurrency.
54
+ * Returns new array containing elements where predicate returns truthy.
55
+ *
56
+ * @param array - Array to filter
57
+ * @param predicate - Async function returning truthy/falsy with (value, index, array)
58
+ * @param concurrency - Maximum concurrent executions (default: Infinity)
59
+ * @returns Promise resolving to filtered array
60
+ *
61
+ * @remarks
62
+ * - Empty arrays resolve to empty array
63
+ * - Concurrency behavior matches mapAsync
64
+ * - Output array order preserves original relative order
65
+ * - Predicate is called for every element (no short-circuiting)
66
+ * - All predicates execute before filtering occurs
67
+ */
68
+ export declare const filterAsync: <T>(array: T[], predicate: (value: T, index: number, array: T[]) => MaybePromise<boolean>, concurrency?: number) => Promise<T[]>;
69
+ /**
70
+ * Asynchronously reduces array to single value using callback.
71
+ * Executes callbacks sequentially from left to right.
72
+ *
73
+ * @template T - Array element type
74
+ * @template U - Accumulator type
75
+ * @param array - Array to reduce
76
+ * @param callback - Async reducer with (accumulator, value, index, array)
77
+ * @param initial_value - Initial accumulator value
78
+ * @returns Promise resolving to final accumulator value
79
+ *
80
+ * @remarks
81
+ * - Empty arrays with initial_value return initial_value
82
+ * - Execution is strictly sequential (no concurrency)
83
+ * - Reduction order: array[0] to array[length-1]
84
+ * - Callback awaited before processing next element
85
+ */
86
+ export declare const reduceAsync: <T, U>(array: T[], callback: (accumulator: U, value: T, index: number, array: T[]) => MaybePromise<U>, initial_value: U) => Promise<U>;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Maps array in-place within specified range. Clamps indices to valid array bounds.
3
+ * Negative start/end count from array end. Returns modified original array.
4
+ * @param array - Array to modify (mutated)
5
+ * @param transform - Mapping function receiving current index
6
+ * @param start - Start index (clamped, negative counts from end)
7
+ * @param end - End index (clamped, negative counts from end)
8
+ * @returns Mutated original array with mixed types
9
+ */
10
+ export declare const mapInPlace: <T, R>(array: readonly T[], transform: (index: number) => R, start?: number, end?: number) => readonly (T | R)[];
11
+ /**
12
+ * Creates new array mapped within specified range. Clamps indices to valid bounds.
13
+ * Negative start/end count from array end. Original array remains unchanged.
14
+ * @param array - Source array (not mutated)
15
+ * @param transform - Mapping function receiving current index
16
+ * @param start - Start index (clamped, negative counts from end)
17
+ * @param end - End index (clamped, negative counts from end)
18
+ * @returns New array with mixed types
19
+ */
20
+ export declare const mapToNewArray: <T, R>(array: readonly T[], transform: (index: number) => R, start?: number, end?: number) => readonly (T | R)[];
21
+ /**
22
+ * Returns all arrays with minimum length. Empty arrays included in comparison.
23
+ * Returns single array if unique minimum, multiple arrays if tie.
24
+ * Returns empty array if no input arrays provided.
25
+ * @param arrays - Arrays to compare
26
+ * @returns Array of shortest arrays
27
+ */
28
+ export declare const shortest: <T>(...arrays: readonly T[][]) => readonly T[][];
29
+ /**
30
+ * Moves element between positions using circular indexing. Returns original array.
31
+ * No-op for single-element arrays or identical source/destination.
32
+ * Uses copyWithin for optimal performance. Handles both forward and backward moves.
33
+ * @param array - Array to modify (mutated)
34
+ * @param from - Source index (wraps circularly)
35
+ * @param to - Destination index (wraps circularly)
36
+ * @returns Mutated original array
37
+ */
38
+ export declare const move: <T>(array: T[], from: number, to: number) => T[];
39
+ /**
40
+ * Finds the element with maximum value according to the iteratee function
41
+ *
42
+ * @template T - The type of elements in the array
43
+ * @param array - The array to search (readonly, accepts sparse arrays)
44
+ * @param iteratee - Function that returns a numeric value for each element
45
+ * @returns The element with maximum iteratee value, or undefined for empty array
46
+ * @remarks - Returns undefined for empty arrays. Handles sparse arrays by skipping missing indices.
47
+ * - If multiple elements have the same maximum value, returns the first found.
48
+ * - Iteratee is called only for existing elements in sparse arrays.
49
+ */
50
+ export declare const maxBy: <T>(array: readonly T[], iteratee: (value: T) => number) => T | undefined;
51
+ /**
52
+ * Finds the element with minimum value according to the iteratee function
53
+ *
54
+ * @template T - The type of elements in the array
55
+ * @param array - The array to search (readonly, accepts sparse arrays)
56
+ * @param iteratee - Function that returns a numeric value for each element
57
+ * @returns The element with minimum iteratee value, or undefined for empty array
58
+ * @remarks - Returns undefined for empty arrays. Handles sparse arrays by skipping missing indices.
59
+ * - If multiple elements have the same minimum value, returns the first found.
60
+ * - Iteratee is called only for existing elements in sparse arrays.
61
+ */
62
+ export declare const minBy: <T>(array: readonly T[], iteratee: (value: T) => number) => T | undefined;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Returns a new array with elements randomly shuffled using Fisher-Yates algorithm
3
+ * @template T - Array element type
4
+ * @param {T[]} array - Input array to shuffle (will not be modified)
5
+ * @returns {T[]} New shuffled array. Empty array returns empty array.
6
+ */
7
+ export declare const shuffle: <T>(array: T[]) => T[];
8
+ /**
9
+ * Xorshift32 Pseudo-random number generator
10
+ * A small, fast PRNG that provides deterministic sequences based on a seed.
11
+ */
12
+ export declare class Xorshift32 {
13
+ private seed_state;
14
+ /**
15
+ * @param {number} seed - Initial seed (must be a non-zero 32-bit integer)
16
+ */
17
+ constructor(seed: number);
18
+ /**
19
+ * Generates the next raw 32-bit unsigned integer
20
+ * @returns {number} 32-bit unsigned integer
21
+ */
22
+ nextUint32(): number;
23
+ /**
24
+ * Returns a random float between [0, 1)
25
+ * @returns {number}
26
+ */
27
+ nextFloat(): number;
28
+ }
29
+ /**
30
+ * Shuffles array in-place using Fisher-Yates algorithm
31
+ * @template T - Array element type
32
+ * @param {T[]} array - Array to shuffle (will be modified)
33
+ * @returns {T[]} The same array reference, now shuffled. Empty array returns same empty array.
34
+ */
35
+ export declare const shuffleInplace: <T>(array: T[]) => T[];
36
+ /**
37
+ * Returns a random element from array
38
+ * @template T - Array element type
39
+ * @param {T[]} collection - Input array
40
+ * @returns {T | undefined} Random element, or undefined if array is empty
41
+ */
42
+ export declare const sample: <T>(collection: T[]) => T | undefined;
43
+ /**
44
+ * Returns n random unique elements from array
45
+ * @template T - Array element type
46
+ * @param {T[]} collection - Input array (will not be modified)
47
+ * @param {number} n - Number of elements to sample
48
+ * @returns {T[]} Array of n random unique elements. Returns empty array if:
49
+ * - Input array is empty
50
+ * - n ≤ 0
51
+ * - n > collection.length: returns shuffled copy of entire array
52
+ */
53
+ export declare const sampleSize: <T>(collection: T[], n: number) => T[];
54
+ /**
55
+ * Returns n random elements with replacement (duplicates possible)
56
+ * @template T - Array element type
57
+ * @param {T[]} collection - Input array
58
+ * @param {number} n - Number of elements to pick
59
+ * @returns {T[]} Array of n random elements. Returns empty array if:
60
+ * - Input array is empty
61
+ * - n ≤ 0
62
+ */
63
+ export declare const choices: <T>(collection: T[], n: number) => T[];
64
+ /**
65
+ * Returns n random elements based on weights
66
+ * @template T - Array element type
67
+ * @param {T[]} collection - Input array
68
+ * @param {number[]} weights - Corresponding weights for each element
69
+ * @param {number} n - Number of elements to pick
70
+ * @returns {T[]} Array of n random weighted elements. Returns empty array if:
71
+ * - Input array is empty
72
+ * - Weights array length doesn't match collection length
73
+ * - n ≤ 0
74
+ * @throws No explicit error, but will return empty array for invalid inputs
75
+ */
76
+ export declare const weightedChoices: <T>(collection: T[], weights: number[], n: number) => T[];
@@ -0,0 +1,108 @@
1
+ type Comparator<T> = (a: T, b: T) => boolean;
2
+ type Iteratee<T, V> = (value: T) => V;
3
+ /**
4
+ * Returns the difference between two arrays (elements in array1 but not in array2)
5
+ * @param array - The source array
6
+ * @param values - Arrays to exclude values from
7
+ * @returns Array containing elements present only in the first array
8
+ */
9
+ export declare const difference: <T>(array: readonly T[], ...values: (readonly T[])[]) => T[];
10
+ /**
11
+ * Returns the difference between arrays using an iteratee function
12
+ * @param array - The source array
13
+ * @param values - Array to exclude values from
14
+ * @param iteratee - Function to transform values before comparison
15
+ * @returns Array containing elements with unique transformed values
16
+ */
17
+ export declare const differenceBy: <T, V>(array: readonly T[], values: readonly T[], iteratee: Iteratee<T, V>) => T[];
18
+ /**
19
+ * Returns the difference between arrays using a comparator function
20
+ * @param array - The source array
21
+ * @param values - Array to exclude values from
22
+ * @param comparator - Function to compare two elements
23
+ * @returns Array containing elements not matching any in values
24
+ */
25
+ export declare const differenceWith: <T>(array: readonly T[], values: readonly T[], comparator: Comparator<T>) => T[];
26
+ /**
27
+ * Returns the intersection of multiple arrays
28
+ * @param arrays - Arrays to find common elements from
29
+ * @returns Array containing elements present in all arrays
30
+ */
31
+ export declare const intersection: <T>(...arrays: (readonly T[])[]) => T[];
32
+ /**
33
+ * Returns the intersection of two arrays using an iteratee function
34
+ * @param array1 - First array
35
+ * @param array2 - Second array
36
+ * @param iteratee - Function to transform values before comparison
37
+ * @returns Array containing elements with matching transformed values
38
+ */
39
+ export declare const intersectionBy: <T, V>(array1: readonly T[], array2: readonly T[], iteratee: Iteratee<T, V>) => T[];
40
+ /**
41
+ * Returns the intersection of two arrays using a comparator function
42
+ * @param array1 - First array
43
+ * @param array2 - Second array
44
+ * @param comparator - Function to compare two elements
45
+ * @returns Array containing elements matching at least one in both arrays
46
+ */
47
+ export declare const intersectionWith: <T>(array1: readonly T[], array2: readonly T[], comparator: Comparator<T>) => T[];
48
+ /**
49
+ * Returns the union of multiple arrays
50
+ * @param arrays - Arrays to combine
51
+ * @returns Array containing unique elements from all arrays
52
+ */
53
+ export declare const union: <T>(...arrays: (readonly T[])[]) => T[];
54
+ /**
55
+ * Returns the union of two arrays using an iteratee function
56
+ * @param array1 - First array
57
+ * @param array2 - Second array
58
+ * @param iteratee - Function to transform values before deduplication
59
+ * @returns Array containing unique elements based on transformed values
60
+ */
61
+ export declare const unionBy: <T, V>(array1: readonly T[], array2: readonly T[], iteratee: Iteratee<T, V>) => T[];
62
+ /**
63
+ * Returns the union of two arrays using a comparator function
64
+ * @param array1 - First array
65
+ * @param array2 - Second array
66
+ * @param comparator - Function to determine equality between elements
67
+ * @returns Array containing elements considered unique by the comparator
68
+ */
69
+ export declare const unionWith: <T>(array1: readonly T[], array2: readonly T[], comparator: Comparator<T>) => T[];
70
+ /**
71
+ * Returns the symmetric difference between two arrays
72
+ * @param array1 - First array
73
+ * @param array2 - Second array
74
+ * @returns Array containing elements present in only one of the arrays
75
+ */
76
+ export declare const xor: <T>(array1: readonly T[], array2: readonly T[]) => T[];
77
+ /**
78
+ * Returns the symmetric difference using an iteratee function
79
+ * @param array1 - First array
80
+ * @param array2 - Second array
81
+ * @param iteratee - Function to transform values before comparison
82
+ * @returns Array containing elements with unique transformed values
83
+ */
84
+ export declare const xorBy: <T, V>(array1: readonly T[], array2: readonly T[], iteratee: Iteratee<T, V>) => T[];
85
+ /**
86
+ * Returns the symmetric difference using a comparator function
87
+ * @param array1 - First array
88
+ * @param array2 - Second array
89
+ * @param comparator - Function to compare two elements
90
+ * @returns Array containing elements not matching any in the other array
91
+ */
92
+ export declare const xorWith: <T>(array1: readonly T[], array2: readonly T[], comparator: Comparator<T>) => T[];
93
+ /**
94
+ * Checks if one array is a subset of another
95
+ * @param subset - Array to check as subset
96
+ * @param superset - Array to check as superset
97
+ * @returns True if all elements of subset exist in superset
98
+ */
99
+ export declare const isSubset: <T>(subset: readonly T[], superset: readonly T[]) => boolean;
100
+ /**
101
+ * Checks if one array is a subset of another using a comparator
102
+ * @param subset - Array to check as subset
103
+ * @param superset - Array to check as superset
104
+ * @param comparator - Function to compare two elements
105
+ * @returns True if all elements of subset have matches in superset
106
+ */
107
+ export declare const isSubsetWith: <T>(subset: readonly T[], superset: readonly T[], comparator: Comparator<T>) => boolean;
108
+ export {};
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Gets the first element of an array.
3
+ * @param array - The array to query.
4
+ * @returns The first element, or undefined if array is empty.
5
+ * @example
6
+ * head([1, 2, 3]) // => 1
7
+ * head([]) // => undefined
8
+ */
9
+ export declare const head: <T>(array: readonly T[]) => T;
10
+ /**
11
+ * Gets the last element of an array.
12
+ * @param array - The array to query.
13
+ * @returns The last element, or undefined if array is empty.
14
+ * @example
15
+ * last([1, 2, 3]) // => 3
16
+ * last([]) // => undefined
17
+ */
18
+ export declare const last: <T>(array: readonly T[]) => T | undefined;
19
+ /**
20
+ * Gets all but the last element of an array.
21
+ * @param array - The array to query.
22
+ * @returns A new array excluding the last element.
23
+ * @remarks
24
+ * - Returns empty array if input array has 0 or 1 elements
25
+ * - Non-integer array length is handled by slice()
26
+ * @example
27
+ * initial([1, 2, 3]) // => [1, 2]
28
+ * initial([1]) // => []
29
+ * initial([]) // => []
30
+ */
31
+ export declare const initial: <T>(array: readonly T[]) => T[];
32
+ /**
33
+ * Gets all but the first element of an array.
34
+ * @param array - The array to query.
35
+ * @returns A new array excluding the first element.
36
+ * @remarks
37
+ * - Returns empty array if input array has 0 or 1 elements
38
+ * - Non-integer array length is handled by slice()
39
+ * @example
40
+ * tail([1, 2, 3]) // => [2, 3]
41
+ * tail([1]) // => []
42
+ * tail([]) // => []
43
+ */
44
+ export declare const tail: <T>(array: readonly T[]) => T[];
45
+ /**
46
+ * Takes n elements from the beginning.
47
+ * @param array - The array to query.
48
+ * @param n - Number of elements to take (default: 1).
49
+ * @returns A new array of taken elements.
50
+ * @remarks
51
+ * - n <= 0: returns empty array
52
+ * - n is not an integer: converted to integer via slice()
53
+ * - n > array.length: returns entire array copy
54
+ * - NaN or Infinity n: behavior depends on slice() conversion
55
+ * @example
56
+ * take([1, 2, 3], 2) // => [1, 2]
57
+ * take([1, 2, 3], 0) // => []
58
+ * take([1, 2, 3], -1) // => []
59
+ * take([1, 2, 3], 5) // => [1, 2, 3]
60
+ */
61
+ export declare const take: <T>(array: readonly T[], n?: number) => T[];
62
+ /**
63
+ * Takes n elements from the end.
64
+ * @param array - The array to query.
65
+ * @param n - Number of elements to take (default: 1).
66
+ * @returns A new array of taken elements.
67
+ * @remarks
68
+ * - n <= 0: returns empty array
69
+ * - n is not an integer: converted to integer via slice()
70
+ * - n > array.length: returns entire array copy
71
+ * - NaN or Infinity n: behavior depends on slice() conversion
72
+ * @example
73
+ * takeRight([1, 2, 3], 2) // => [2, 3]
74
+ * takeRight([1, 2, 3], 0) // => []
75
+ * takeRight([1, 2, 3], -1) // => []
76
+ */
77
+ export declare const takeRight: <T>(array: readonly T[], n?: number) => T[];
78
+ /**
79
+ * Drops n elements from the beginning.
80
+ * @param array - The array to query.
81
+ * @param n - Number of elements to drop (default: 1).
82
+ * @returns A new array of remaining elements.
83
+ * @remarks
84
+ * - n <= 0: returns full array copy
85
+ * - n is not an integer: converted to integer via slice()
86
+ * - n >= array.length: returns empty array
87
+ * - NaN or Infinity n: behavior depends on slice() conversion
88
+ * @example
89
+ * drop([1, 2, 3], 2) // => [3]
90
+ * drop([1, 2, 3], 0) // => [1, 2, 3]
91
+ * drop([1, 2, 3], 5) // => []
92
+ */
93
+ export declare const drop: <T>(array: readonly T[], n?: number) => T[];
94
+ /**
95
+ * Drops n elements from the end.
96
+ * @param array - The array to query.
97
+ * @param n - Number of elements to drop (default: 1).
98
+ * @returns A new array of remaining elements.
99
+ * @remarks
100
+ * - n <= 0: returns full array copy
101
+ * - n is not an integer: converted to integer via slice()
102
+ * - n >= array.length: returns empty array
103
+ * - NaN or Infinity n: behavior depends on slice() conversion
104
+ * @example
105
+ * dropRight([1, 2, 3], 2) // => [1]
106
+ * dropRight([1, 2, 3], 0) // => [1, 2, 3]
107
+ * dropRight([1, 2, 3], 5) // => []
108
+ */
109
+ export declare const dropRight: <T>(array: readonly T[], n?: number) => T[];
110
+ type Predicate<T> = (value: T) => boolean;
111
+ /**
112
+ * Takes elements from the beginning while predicate returns true.
113
+ * @param array - The array to query.
114
+ * @param predicate - The function invoked per iteration.
115
+ * @returns A new array of taken elements.
116
+ * @remarks
117
+ * - Empty array: returns empty array
118
+ * - All elements satisfy predicate: returns full array copy
119
+ * - No elements satisfy predicate: returns empty array
120
+ * - Predicate throws: iteration stops at exception
121
+ * @example
122
+ * takeWhile([1, 2, 3, 4], x => x < 3) // => [1, 2]
123
+ * takeWhile([], x => x < 3) // => []
124
+ * takeWhile([1, 2, 3], x => x < 5) // => [1, 2, 3]
125
+ */
126
+ export declare const takeWhile: <T>(array: readonly T[], predicate: Predicate<T>) => T[];
127
+ /**
128
+ * Takes elements from the end while predicate returns true.
129
+ * @param array - The array to query.
130
+ * @param predicate - The function invoked per iteration.
131
+ * @returns A new array of taken elements.
132
+ * @remarks
133
+ * - Empty array: returns empty array
134
+ * - All elements satisfy predicate: returns full array copy
135
+ * - No elements satisfy predicate: returns empty array
136
+ * - Iterates from end; predicate called for each element until false
137
+ * @example
138
+ * takeRightWhile([1, 2, 3, 4], x => x > 2) // => [3, 4]
139
+ * takeRightWhile([], x => x > 2) // => []
140
+ */
141
+ export declare const takeRightWhile: <T>(array: readonly T[], predicate: Predicate<T>) => T[];
142
+ /**
143
+ * Drops elements from the beginning while predicate returns true.
144
+ * @param array - The array to query.
145
+ * @param predicate - The function invoked per iteration.
146
+ * @returns A new array of remaining elements.
147
+ * @remarks
148
+ * - Empty array: returns empty array
149
+ * - All elements satisfy predicate: returns empty array
150
+ * - No elements satisfy predicate: returns full array copy
151
+ * @example
152
+ * dropWhile([1, 2, 3, 4], x => x < 3) // => [3, 4]
153
+ * dropWhile([], x => x < 3) // => []
154
+ * dropWhile([1, 2, 3], x => x < 5) // => []
155
+ */
156
+ export declare const dropWhile: <T>(array: readonly T[], predicate: Predicate<T>) => T[];
157
+ /**
158
+ * Drops elements from the end while predicate returns true.
159
+ * @param array - The array to query.
160
+ * @param predicate - The function invoked per iteration.
161
+ * @returns A new array of remaining elements.
162
+ * @remarks
163
+ * - Empty array: returns empty array
164
+ * - All elements satisfy predicate: returns empty array
165
+ * - No elements satisfy predicate: returns full array copy
166
+ * - Iterates from end; predicate called for each element until false
167
+ * @example
168
+ * dropRightWhile([1, 2, 3, 4], x => x > 2) // => [1, 2]
169
+ * dropRightWhile([], x => x > 2) // => []
170
+ */
171
+ export declare const dropRightWhile: <T>(array: readonly T[], predicate: Predicate<T>) => T[];
172
+ /**
173
+ * Collects elements at specified indices. Returns empty array if either array or indices are empty.
174
+ * When circular is true, indices wrap around array bounds using modulo arithmetic.
175
+ * @param array - Source array
176
+ * @param indices - Target indices to collect
177
+ * @param circular - Enable circular indexing (default: false)
178
+ * @returns Array of collected elements, undefined for out-of-bounds non-circular indices
179
+ */
180
+ export declare const collectAt: <T>(array: T[], indices: number[], circular?: boolean) => (T | undefined)[];
181
+ /**
182
+ * Gets element at circular index. Returns undefined for empty array.
183
+ * Implements modulo arithmetic: negative indices wrap from end, positive from start.
184
+ * @param array - Source array
185
+ * @param index - Target index (wraps circularly)
186
+ * @returns Element at circular index or undefined if array empty
187
+ */
188
+ export declare const circularAt: <T>(array: T[], index: number) => T | undefined;
189
+ export {};
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Extracts a comparable value from an item for sorting
3
+ * @template T - The type of items being sorted
4
+ */
5
+ export type Iteratee<T> = (item: T) => string | number | boolean | Date;
6
+ /**
7
+ * Sort order direction
8
+ */
9
+ export type Order = 'asc' | 'desc';
10
+ /**
11
+ * Core sorting function with full configuration
12
+ * @template T - Array element type
13
+ * @param array - Source array to sort
14
+ * @param iteratees - Functions to extract sort values
15
+ * @param orders - Sort directions for each iteratee
16
+ * @param inplace - Modify original array if true
17
+ * @returns Sorted array (original if inplace)
18
+ */
19
+ export declare const coreSort: <T>(array: T[], iteratees: Array<Iteratee<T>>, orders: Array<Order>, inplace: boolean) => T[];
20
+ /**
21
+ * Returns a new sorted array by multiple criteria
22
+ * @template T - Array element type
23
+ * @param array - Source array
24
+ * @param iteratees - Value extraction functions
25
+ * @param orders - Sort directions
26
+ * @returns New sorted array
27
+ */
28
+ export declare const orderBy: <T>(array: T[], iteratees: Array<Iteratee<T>>, orders: Array<Order>) => T[];
29
+ /**
30
+ * Sorts array in-place by multiple criteria
31
+ * @template T - Array element type
32
+ * @param array - Array to sort (modified)
33
+ * @param iteratees - Value extraction functions
34
+ * @param orders - Sort directions
35
+ * @returns Original sorted array
36
+ */
37
+ export declare const orderByInplace: <T>(array: T[], iteratees: Array<Iteratee<T>>, orders: Array<Order>) => T[];
38
+ /**
39
+ * Returns new array sorted by single criterion
40
+ * @template T - Array element type
41
+ * @param array - Source array
42
+ * @param iteratee - Value extraction function
43
+ * @param order - Sort direction (defaults to 'asc')
44
+ * @returns New sorted array
45
+ */
46
+ export declare const sortBy: <T>(array: T[], iteratee: Iteratee<T>, order?: Order) => T[];
47
+ /**
48
+ * Sorts array in-place by single criterion
49
+ * @template T - Array element type
50
+ * @param array - Array to sort (modified)
51
+ * @param iteratee - Value extraction function
52
+ * @param order - Sort direction (defaults to 'asc')
53
+ * @returns Original sorted array
54
+ */
55
+ export declare const sortByInplace: <T>(array: T[], iteratee: Iteratee<T>, order?: Order) => T[];