ts-data-forge 3.3.0 → 3.3.1

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 (424) hide show
  1. package/README.md +37 -13
  2. package/dist/array/impl/array-utils-creation.d.mts +116 -0
  3. package/dist/array/impl/array-utils-creation.d.mts.map +1 -0
  4. package/dist/array/impl/array-utils-creation.mjs +110 -0
  5. package/dist/array/impl/array-utils-creation.mjs.map +1 -0
  6. package/dist/array/impl/array-utils-element-access.d.mts +61 -0
  7. package/dist/array/impl/array-utils-element-access.d.mts.map +1 -0
  8. package/dist/array/impl/array-utils-element-access.mjs +66 -0
  9. package/dist/array/impl/array-utils-element-access.mjs.map +1 -0
  10. package/dist/array/impl/array-utils-iterators.d.mts +59 -0
  11. package/dist/array/impl/array-utils-iterators.d.mts.map +1 -0
  12. package/dist/array/impl/array-utils-iterators.mjs +104 -0
  13. package/dist/array/impl/array-utils-iterators.mjs.map +1 -0
  14. package/dist/array/impl/array-utils-modification.d.mts +154 -0
  15. package/dist/array/impl/array-utils-modification.d.mts.map +1 -0
  16. package/dist/array/impl/array-utils-modification.mjs +139 -0
  17. package/dist/array/impl/array-utils-modification.mjs.map +1 -0
  18. package/dist/array/impl/array-utils-reducing-value.d.mts +214 -0
  19. package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -0
  20. package/dist/array/impl/array-utils-reducing-value.mjs +160 -0
  21. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -0
  22. package/dist/array/impl/array-utils-search.d.mts +179 -0
  23. package/dist/array/impl/array-utils-search.d.mts.map +1 -0
  24. package/dist/array/impl/array-utils-search.mjs +153 -0
  25. package/dist/array/impl/array-utils-search.mjs.map +1 -0
  26. package/dist/array/impl/array-utils-set-op.d.mts +100 -0
  27. package/dist/array/impl/array-utils-set-op.d.mts.map +1 -0
  28. package/dist/array/impl/array-utils-set-op.mjs +137 -0
  29. package/dist/array/impl/array-utils-set-op.mjs.map +1 -0
  30. package/dist/array/impl/array-utils-size.d.mts +24 -0
  31. package/dist/array/impl/array-utils-size.d.mts.map +1 -0
  32. package/dist/array/impl/array-utils-size.mjs +28 -0
  33. package/dist/array/impl/array-utils-size.mjs.map +1 -0
  34. package/dist/array/impl/array-utils-slice-clamped.d.mts +18 -0
  35. package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -0
  36. package/dist/array/impl/array-utils-slice-clamped.mjs +49 -0
  37. package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -0
  38. package/dist/array/impl/array-utils-slicing.d.mts +120 -0
  39. package/dist/array/impl/array-utils-slicing.d.mts.map +1 -0
  40. package/dist/array/impl/array-utils-slicing.mjs +140 -0
  41. package/dist/array/impl/array-utils-slicing.mjs.map +1 -0
  42. package/dist/array/impl/array-utils-transformation.d.mts +348 -0
  43. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -0
  44. package/dist/array/impl/array-utils-transformation.mjs +331 -0
  45. package/dist/array/impl/array-utils-transformation.mjs.map +1 -0
  46. package/dist/array/impl/array-utils-validation.d.mts +149 -0
  47. package/dist/array/impl/array-utils-validation.d.mts.map +1 -0
  48. package/dist/array/impl/array-utils-validation.mjs +166 -0
  49. package/dist/array/impl/array-utils-validation.mjs.map +1 -0
  50. package/dist/array/impl/index.d.mts +13 -0
  51. package/dist/array/impl/index.d.mts.map +1 -0
  52. package/dist/array/impl/index.mjs +13 -0
  53. package/dist/array/impl/index.mjs.map +1 -0
  54. package/dist/array/index.d.mts +1 -1
  55. package/dist/array/index.d.mts.map +1 -1
  56. package/dist/array/index.mjs +2 -1
  57. package/dist/array/index.mjs.map +1 -1
  58. package/dist/collections/imap-mapped.d.mts +83 -253
  59. package/dist/collections/imap-mapped.d.mts.map +1 -1
  60. package/dist/collections/imap-mapped.mjs +33 -164
  61. package/dist/collections/imap-mapped.mjs.map +1 -1
  62. package/dist/collections/imap.d.mts +436 -163
  63. package/dist/collections/imap.d.mts.map +1 -1
  64. package/dist/collections/imap.mjs +74 -94
  65. package/dist/collections/imap.mjs.map +1 -1
  66. package/dist/collections/iset-mapped.d.mts +828 -345
  67. package/dist/collections/iset-mapped.d.mts.map +1 -1
  68. package/dist/collections/iset-mapped.mjs +200 -242
  69. package/dist/collections/iset-mapped.mjs.map +1 -1
  70. package/dist/collections/iset.d.mts +397 -205
  71. package/dist/collections/iset.d.mts.map +1 -1
  72. package/dist/collections/iset.mjs +102 -184
  73. package/dist/collections/iset.mjs.map +1 -1
  74. package/dist/collections/queue.d.mts +155 -135
  75. package/dist/collections/queue.d.mts.map +1 -1
  76. package/dist/collections/queue.mjs +55 -156
  77. package/dist/collections/queue.mjs.map +1 -1
  78. package/dist/collections/stack.d.mts +154 -154
  79. package/dist/collections/stack.d.mts.map +1 -1
  80. package/dist/collections/stack.mjs +54 -203
  81. package/dist/collections/stack.mjs.map +1 -1
  82. package/dist/entry-point.d.mts +1 -0
  83. package/dist/entry-point.d.mts.map +1 -1
  84. package/dist/entry-point.mjs +2 -1
  85. package/dist/entry-point.mjs.map +1 -1
  86. package/dist/expect-type.d.mts +43 -172
  87. package/dist/expect-type.d.mts.map +1 -1
  88. package/dist/expect-type.mjs +43 -172
  89. package/dist/expect-type.mjs.map +1 -1
  90. package/dist/functional/match.d.mts +35 -140
  91. package/dist/functional/match.d.mts.map +1 -1
  92. package/dist/functional/match.mjs.map +1 -1
  93. package/dist/functional/optional.d.mts +282 -160
  94. package/dist/functional/optional.d.mts.map +1 -1
  95. package/dist/functional/optional.mjs +131 -71
  96. package/dist/functional/optional.mjs.map +1 -1
  97. package/dist/functional/pipe.d.mts +59 -113
  98. package/dist/functional/pipe.d.mts.map +1 -1
  99. package/dist/functional/pipe.mjs.map +1 -1
  100. package/dist/functional/result.d.mts +433 -332
  101. package/dist/functional/result.d.mts.map +1 -1
  102. package/dist/functional/result.mjs +233 -239
  103. package/dist/functional/result.mjs.map +1 -1
  104. package/dist/globals.d.mts +12 -5
  105. package/dist/guard/has-key.d.mts +23 -74
  106. package/dist/guard/has-key.d.mts.map +1 -1
  107. package/dist/guard/has-key.mjs +23 -74
  108. package/dist/guard/has-key.mjs.map +1 -1
  109. package/dist/guard/is-non-empty-string.d.mts +20 -87
  110. package/dist/guard/is-non-empty-string.d.mts.map +1 -1
  111. package/dist/guard/is-non-empty-string.mjs +20 -87
  112. package/dist/guard/is-non-empty-string.mjs.map +1 -1
  113. package/dist/guard/is-non-null-object.d.mts +14 -84
  114. package/dist/guard/is-non-null-object.d.mts.map +1 -1
  115. package/dist/guard/is-non-null-object.mjs +14 -84
  116. package/dist/guard/is-non-null-object.mjs.map +1 -1
  117. package/dist/guard/is-primitive.d.mts +13 -126
  118. package/dist/guard/is-primitive.d.mts.map +1 -1
  119. package/dist/guard/is-primitive.mjs +13 -126
  120. package/dist/guard/is-primitive.mjs.map +1 -1
  121. package/dist/guard/is-record.d.mts +21 -132
  122. package/dist/guard/is-record.d.mts.map +1 -1
  123. package/dist/guard/is-record.mjs +21 -132
  124. package/dist/guard/is-record.mjs.map +1 -1
  125. package/dist/guard/is-type.d.mts +201 -238
  126. package/dist/guard/is-type.d.mts.map +1 -1
  127. package/dist/guard/is-type.mjs +201 -238
  128. package/dist/guard/is-type.mjs.map +1 -1
  129. package/dist/guard/key-is-in.d.mts +22 -139
  130. package/dist/guard/key-is-in.d.mts.map +1 -1
  131. package/dist/guard/key-is-in.mjs +22 -139
  132. package/dist/guard/key-is-in.mjs.map +1 -1
  133. package/dist/index.d.mts +0 -1
  134. package/dist/index.d.mts.map +1 -1
  135. package/dist/index.mjs +0 -1
  136. package/dist/index.mjs.map +1 -1
  137. package/dist/iterator/range.d.mts +29 -62
  138. package/dist/iterator/range.d.mts.map +1 -1
  139. package/dist/iterator/range.mjs.map +1 -1
  140. package/dist/json/json.d.mts +191 -121
  141. package/dist/json/json.d.mts.map +1 -1
  142. package/dist/json/json.mjs +238 -136
  143. package/dist/json/json.mjs.map +1 -1
  144. package/dist/number/branded-types/finite-number.d.mts +24 -156
  145. package/dist/number/branded-types/finite-number.d.mts.map +1 -1
  146. package/dist/number/branded-types/finite-number.mjs +27 -159
  147. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  148. package/dist/number/branded-types/int.d.mts +122 -120
  149. package/dist/number/branded-types/int.d.mts.map +1 -1
  150. package/dist/number/branded-types/int.mjs +122 -120
  151. package/dist/number/branded-types/int.mjs.map +1 -1
  152. package/dist/number/branded-types/int16.d.mts +22 -30
  153. package/dist/number/branded-types/int16.d.mts.map +1 -1
  154. package/dist/number/branded-types/int16.mjs +22 -30
  155. package/dist/number/branded-types/int16.mjs.map +1 -1
  156. package/dist/number/branded-types/int32.d.mts +22 -31
  157. package/dist/number/branded-types/int32.d.mts.map +1 -1
  158. package/dist/number/branded-types/int32.mjs +22 -31
  159. package/dist/number/branded-types/int32.mjs.map +1 -1
  160. package/dist/number/branded-types/non-negative-finite-number.d.mts +28 -36
  161. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  162. package/dist/number/branded-types/non-negative-finite-number.mjs +31 -39
  163. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  164. package/dist/number/branded-types/non-negative-int16.d.mts +24 -34
  165. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  166. package/dist/number/branded-types/non-negative-int16.mjs +24 -34
  167. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  168. package/dist/number/branded-types/non-negative-int32.d.mts +26 -35
  169. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  170. package/dist/number/branded-types/non-negative-int32.mjs +26 -35
  171. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  172. package/dist/number/branded-types/non-zero-finite-number.d.mts +22 -37
  173. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
  174. package/dist/number/branded-types/non-zero-finite-number.mjs +25 -40
  175. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  176. package/dist/number/branded-types/non-zero-int.d.mts +15 -30
  177. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
  178. package/dist/number/branded-types/non-zero-int.mjs +15 -30
  179. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  180. package/dist/number/branded-types/non-zero-int16.d.mts +27 -35
  181. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  182. package/dist/number/branded-types/non-zero-int16.mjs +27 -35
  183. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  184. package/dist/number/branded-types/non-zero-int32.d.mts +29 -36
  185. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  186. package/dist/number/branded-types/non-zero-int32.mjs +29 -36
  187. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  188. package/dist/number/branded-types/non-zero-safe-int.d.mts +37 -38
  189. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  190. package/dist/number/branded-types/non-zero-safe-int.mjs +39 -40
  191. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  192. package/dist/number/branded-types/non-zero-uint16.d.mts +24 -35
  193. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  194. package/dist/number/branded-types/non-zero-uint16.mjs +24 -35
  195. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  196. package/dist/number/branded-types/non-zero-uint32.d.mts +24 -35
  197. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  198. package/dist/number/branded-types/non-zero-uint32.mjs +24 -35
  199. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  200. package/dist/number/branded-types/positive-finite-number.d.mts +26 -40
  201. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  202. package/dist/number/branded-types/positive-finite-number.mjs +29 -43
  203. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  204. package/dist/number/branded-types/positive-int.d.mts +133 -123
  205. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  206. package/dist/number/branded-types/positive-int.mjs +133 -123
  207. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  208. package/dist/number/branded-types/positive-int16.d.mts +24 -35
  209. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  210. package/dist/number/branded-types/positive-int16.mjs +24 -35
  211. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  212. package/dist/number/branded-types/positive-int32.d.mts +24 -35
  213. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  214. package/dist/number/branded-types/positive-int32.mjs +24 -35
  215. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  216. package/dist/number/branded-types/positive-safe-int.d.mts +159 -33
  217. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  218. package/dist/number/branded-types/positive-safe-int.mjs +160 -34
  219. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  220. package/dist/number/branded-types/positive-uint16.d.mts +24 -35
  221. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  222. package/dist/number/branded-types/positive-uint16.mjs +24 -35
  223. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  224. package/dist/number/branded-types/positive-uint32.d.mts +26 -36
  225. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  226. package/dist/number/branded-types/positive-uint32.mjs +26 -36
  227. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  228. package/dist/number/branded-types/safe-int.d.mts +140 -99
  229. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  230. package/dist/number/branded-types/safe-int.mjs +142 -101
  231. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  232. package/dist/number/branded-types/safe-uint.d.mts +24 -33
  233. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  234. package/dist/number/branded-types/safe-uint.mjs +25 -34
  235. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  236. package/dist/number/branded-types/uint.d.mts +121 -30
  237. package/dist/number/branded-types/uint.d.mts.map +1 -1
  238. package/dist/number/branded-types/uint.mjs +121 -30
  239. package/dist/number/branded-types/uint.mjs.map +1 -1
  240. package/dist/number/branded-types/uint16.d.mts +26 -34
  241. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  242. package/dist/number/branded-types/uint16.mjs +26 -34
  243. package/dist/number/branded-types/uint16.mjs.map +1 -1
  244. package/dist/number/branded-types/uint32.d.mts +26 -68
  245. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  246. package/dist/number/branded-types/uint32.mjs +26 -68
  247. package/dist/number/branded-types/uint32.mjs.map +1 -1
  248. package/dist/number/enum/int8.d.mts +37 -101
  249. package/dist/number/enum/int8.d.mts.map +1 -1
  250. package/dist/number/enum/int8.mjs +39 -170
  251. package/dist/number/enum/int8.mjs.map +1 -1
  252. package/dist/number/enum/uint8.d.mts +45 -55
  253. package/dist/number/enum/uint8.d.mts.map +1 -1
  254. package/dist/number/enum/uint8.mjs +46 -155
  255. package/dist/number/enum/uint8.mjs.map +1 -1
  256. package/dist/number/num.d.mts +145 -206
  257. package/dist/number/num.d.mts.map +1 -1
  258. package/dist/number/num.mjs +143 -199
  259. package/dist/number/num.mjs.map +1 -1
  260. package/dist/number/refined-number-utils.d.mts +97 -21
  261. package/dist/number/refined-number-utils.d.mts.map +1 -1
  262. package/dist/number/refined-number-utils.mjs +91 -20
  263. package/dist/number/refined-number-utils.mjs.map +1 -1
  264. package/dist/object/object.d.mts +126 -208
  265. package/dist/object/object.d.mts.map +1 -1
  266. package/dist/object/object.mjs +68 -102
  267. package/dist/object/object.mjs.map +1 -1
  268. package/dist/others/cast-mutable.d.mts +12 -88
  269. package/dist/others/cast-mutable.d.mts.map +1 -1
  270. package/dist/others/cast-mutable.mjs +13 -89
  271. package/dist/others/cast-mutable.mjs.map +1 -1
  272. package/dist/others/cast-readonly.d.mts +12 -168
  273. package/dist/others/cast-readonly.d.mts.map +1 -1
  274. package/dist/others/cast-readonly.mjs +13 -169
  275. package/dist/others/cast-readonly.mjs.map +1 -1
  276. package/dist/others/if-then.d.mts +6 -83
  277. package/dist/others/if-then.d.mts.map +1 -1
  278. package/dist/others/if-then.mjs +6 -83
  279. package/dist/others/if-then.mjs.map +1 -1
  280. package/dist/others/map-nullable.d.mts +12 -136
  281. package/dist/others/map-nullable.d.mts.map +1 -1
  282. package/dist/others/map-nullable.mjs.map +1 -1
  283. package/dist/others/memoize-function.d.mts +14 -157
  284. package/dist/others/memoize-function.d.mts.map +1 -1
  285. package/dist/others/memoize-function.mjs +14 -157
  286. package/dist/others/memoize-function.mjs.map +1 -1
  287. package/dist/others/tuple.d.mts +33 -151
  288. package/dist/others/tuple.d.mts.map +1 -1
  289. package/dist/others/tuple.mjs +33 -151
  290. package/dist/others/tuple.mjs.map +1 -1
  291. package/dist/others/unknown-to-string.d.mts +11 -125
  292. package/dist/others/unknown-to-string.d.mts.map +1 -1
  293. package/dist/others/unknown-to-string.mjs +12 -126
  294. package/dist/others/unknown-to-string.mjs.map +1 -1
  295. package/dist/promise/promise.d.mts +33 -20
  296. package/dist/promise/promise.d.mts.map +1 -1
  297. package/dist/promise/promise.mjs +34 -21
  298. package/dist/promise/promise.mjs.map +1 -1
  299. package/package.json +47 -39
  300. package/src/array/impl/array-utils-creation.mts +192 -0
  301. package/src/array/{array-utils-creation.test.mts → impl/array-utils-creation.test.mts} +121 -72
  302. package/src/array/impl/array-utils-element-access.mts +115 -0
  303. package/src/array/impl/array-utils-element-access.test.mts +151 -0
  304. package/src/array/impl/array-utils-iterators.mts +79 -0
  305. package/src/array/impl/array-utils-iterators.test.mts +98 -0
  306. package/src/array/impl/array-utils-modification.mts +434 -0
  307. package/src/array/{array-utils-modification.test.mts → impl/array-utils-modification.test.mts} +41 -28
  308. package/src/array/{array-utils-overload-type-error.test.mts → impl/array-utils-overload-type-error.test.mts} +33 -33
  309. package/src/array/impl/array-utils-reducing-value.mts +551 -0
  310. package/src/array/{array-utils-reducing-value.test.mts → impl/array-utils-reducing-value.test.mts} +45 -50
  311. package/src/array/impl/array-utils-search.mts +509 -0
  312. package/src/array/impl/array-utils-search.test.mts +346 -0
  313. package/src/array/impl/array-utils-set-op.mts +166 -0
  314. package/src/array/{array-utils-set-op.test.mts → impl/array-utils-set-op.test.mts} +42 -35
  315. package/src/array/impl/array-utils-size.mts +30 -0
  316. package/src/array/impl/array-utils-size.test.mts +9 -0
  317. package/src/array/impl/array-utils-slice-clamped.mts +51 -0
  318. package/src/array/{array-utils-slice-clamped.test.mts → impl/array-utils-slice-clamped.test.mts} +12 -12
  319. package/src/array/impl/array-utils-slicing.mts +275 -0
  320. package/src/array/impl/array-utils-slicing.test.mts +158 -0
  321. package/src/array/impl/array-utils-transformation.mts +746 -0
  322. package/src/array/{array-utils-transformation.test.mts → impl/array-utils-transformation.test.mts} +662 -889
  323. package/src/array/impl/array-utils-validation.mts +241 -0
  324. package/src/array/{array-utils-validation.test.mts → impl/array-utils-validation.test.mts} +194 -107
  325. package/src/array/{array.test.mts → impl/array.test.mts} +2 -2
  326. package/src/array/impl/index.mts +12 -0
  327. package/src/array/index.mts +1 -1
  328. package/src/collections/imap-mapped.mts +99 -265
  329. package/src/collections/imap.mts +477 -174
  330. package/src/collections/imap.test.mts +12 -19
  331. package/src/collections/iset-mapped.mts +892 -358
  332. package/src/collections/iset.mts +429 -213
  333. package/src/collections/queue.mts +174 -200
  334. package/src/collections/stack.mts +172 -245
  335. package/src/collections/stack.test.mts +9 -1
  336. package/src/entry-point.mts +1 -0
  337. package/src/expect-type.mts +43 -172
  338. package/src/functional/match.mts +35 -145
  339. package/src/functional/optional.mts +285 -163
  340. package/src/functional/optional.test.mts +4 -1
  341. package/src/functional/pipe.mts +60 -113
  342. package/src/functional/result.mts +452 -351
  343. package/src/functional/result.test.mts +9 -2
  344. package/src/globals.d.mts +12 -5
  345. package/src/guard/has-key.mts +23 -74
  346. package/src/guard/is-non-empty-string.mts +20 -87
  347. package/src/guard/is-non-null-object.mts +14 -84
  348. package/src/guard/is-non-null-object.test.mts +1 -1
  349. package/src/guard/is-primitive.mts +13 -126
  350. package/src/guard/is-primitive.test.mts +1 -1
  351. package/src/guard/is-record.mts +21 -132
  352. package/src/guard/is-type.mts +201 -238
  353. package/src/guard/is-type.test.mts +7 -7
  354. package/src/guard/key-is-in.mts +22 -139
  355. package/src/index.mts +0 -1
  356. package/src/iterator/range.mts +29 -62
  357. package/src/json/json.mts +202 -134
  358. package/src/json/json.test.mts +1 -3
  359. package/src/number/branded-types/finite-number.mts +27 -159
  360. package/src/number/branded-types/int.mts +122 -120
  361. package/src/number/branded-types/int16.mts +22 -30
  362. package/src/number/branded-types/int16.test.mts +24 -24
  363. package/src/number/branded-types/int32.mts +22 -31
  364. package/src/number/branded-types/int32.test.mts +39 -39
  365. package/src/number/branded-types/non-negative-finite-number.mts +31 -39
  366. package/src/number/branded-types/non-negative-int16.mts +24 -34
  367. package/src/number/branded-types/non-negative-int16.test.mts +16 -16
  368. package/src/number/branded-types/non-negative-int32.mts +26 -35
  369. package/src/number/branded-types/non-negative-int32.test.mts +30 -30
  370. package/src/number/branded-types/non-zero-finite-number.mts +25 -40
  371. package/src/number/branded-types/non-zero-int.mts +15 -30
  372. package/src/number/branded-types/non-zero-int16.mts +27 -35
  373. package/src/number/branded-types/non-zero-int16.test.mts +26 -26
  374. package/src/number/branded-types/non-zero-int32.mts +29 -36
  375. package/src/number/branded-types/non-zero-int32.test.mts +45 -42
  376. package/src/number/branded-types/non-zero-safe-int.mts +39 -40
  377. package/src/number/branded-types/non-zero-uint16.mts +24 -35
  378. package/src/number/branded-types/non-zero-uint16.test.mts +16 -16
  379. package/src/number/branded-types/non-zero-uint32.mts +24 -35
  380. package/src/number/branded-types/non-zero-uint32.test.mts +28 -28
  381. package/src/number/branded-types/positive-finite-number.mts +29 -43
  382. package/src/number/branded-types/positive-int.mts +134 -124
  383. package/src/number/branded-types/positive-int16.mts +24 -35
  384. package/src/number/branded-types/positive-int16.test.mts +14 -14
  385. package/src/number/branded-types/positive-int32.mts +24 -35
  386. package/src/number/branded-types/positive-int32.test.mts +26 -26
  387. package/src/number/branded-types/positive-safe-int.mts +160 -34
  388. package/src/number/branded-types/positive-uint16.mts +24 -35
  389. package/src/number/branded-types/positive-uint16.test.mts +16 -16
  390. package/src/number/branded-types/positive-uint32.mts +26 -36
  391. package/src/number/branded-types/positive-uint32.test.mts +31 -28
  392. package/src/number/branded-types/safe-int.mts +142 -101
  393. package/src/number/branded-types/safe-uint.mts +25 -34
  394. package/src/number/branded-types/uint.mts +121 -30
  395. package/src/number/branded-types/uint16.mts +26 -34
  396. package/src/number/branded-types/uint16.test.mts +16 -16
  397. package/src/number/branded-types/uint32.mts +26 -68
  398. package/src/number/branded-types/uint32.test.mts +28 -28
  399. package/src/number/enum/int8.mts +39 -170
  400. package/src/number/enum/uint8.mts +46 -155
  401. package/src/number/num.mts +157 -212
  402. package/src/number/num.test.mts +4 -4
  403. package/src/number/refined-number-utils.mts +109 -26
  404. package/src/object/object.mts +130 -212
  405. package/src/object/object.test.mts +29 -0
  406. package/src/others/cast-mutable.mts +13 -89
  407. package/src/others/cast-mutable.test.mts +80 -0
  408. package/src/others/cast-readonly.mts +13 -169
  409. package/src/others/if-then.mts +6 -83
  410. package/src/others/map-nullable.mts +12 -136
  411. package/src/others/map-nullable.test.mts +6 -6
  412. package/src/others/memoize-function.mts +14 -157
  413. package/src/others/tuple.mts +33 -151
  414. package/src/others/unknown-to-string.mts +12 -126
  415. package/src/others/unknown-to-string.test.mts +13 -1
  416. package/src/promise/promise.mts +34 -21
  417. package/src/promise/promise.test.mts +43 -0
  418. package/dist/array/array-utils.d.mts +0 -2956
  419. package/dist/array/array-utils.d.mts.map +0 -1
  420. package/dist/array/array-utils.mjs +0 -1838
  421. package/dist/array/array-utils.mjs.map +0 -1
  422. package/src/array/array-utils-search.test.mts +0 -169
  423. package/src/array/array-utils-slicing.test.mts +0 -274
  424. package/src/array/array-utils.mts +0 -4834
@@ -3,24 +3,29 @@ import { range } from '../iterator/index.mjs';
3
3
  import { asUint32, Uint32 } from '../number/index.mjs';
4
4
 
5
5
  /**
6
- * Interface for a high-performance stack with LIFO (Last-In, First-Out) behavior.
6
+ * Interface for a high-performance stack with LIFO (Last-In, First-Out)
7
+ * behavior.
7
8
  *
8
- * This interface defines a mutable stack data structure where elements are added to and removed
9
- * from the top, following the Last-In, First-Out principle. The implementation uses a dynamic
10
- * array for optimal performance, providing O(1) operations for both push and pop operations.
9
+ * This interface defines a mutable stack data structure where elements are
10
+ * added to and removed from the top, following the Last-In, First-Out
11
+ * principle. The implementation uses a dynamic array for optimal performance,
12
+ * providing O(1) operations for both push and pop operations.
11
13
  *
12
14
  * **LIFO Behavior:**
15
+ *
13
16
  * - **push**: Adds elements to the top of the stack
14
17
  * - **pop**: Removes and returns elements from the top of the stack
15
18
  * - The last element added is the first element to be removed
16
19
  *
17
20
  * **Performance Characteristics:**
18
- * - push: O(1) amortized (O(n) when buffer needs resizing)
19
- * - pop: O(1) always
20
- * - size/isEmpty: O(1) always
21
+ *
22
+ * - Push: O(1) amortized (O(n) when buffer needs resizing)
23
+ * - Pop: O(1) always
24
+ * - Size/isEmpty: O(1) always
21
25
  * - Memory efficient with automatic garbage collection of removed elements
22
26
  *
23
27
  * **Use Cases:**
28
+ *
24
29
  * - Function call management and recursion
25
30
  * - Undo/redo functionality
26
31
  * - Expression evaluation and parsing
@@ -29,66 +34,138 @@ import { asUint32, Uint32 } from '../number/index.mjs';
29
34
  * - Browser history management
30
35
  *
31
36
  * @template T The type of elements stored in the stack.
32
- *
33
- * @example
34
- * ```typescript
35
- * import { createStack, Stack } from './stack';
36
- *
37
- * // Example 1: Basic LIFO operations
38
- * const operationStack: Stack<string> = createStack<string>();
39
- *
40
- * operationStack.push("operation1"); // Add to top
41
- * operationStack.push("operation2"); // Add to top
42
- * operationStack.push("operation3"); // Add to top
43
- *
44
- * console.log(operationStack.size); // Output: 3
45
- *
46
- * // Process operations in LIFO order
47
- * console.log(operationStack.pop().unwrap()); // "operation3" (last in, first out)
48
- * console.log(operationStack.pop().unwrap()); // "operation2"
49
- * console.log(operationStack.size); // Output: 1
50
- *
51
- * // Example 2: Undo functionality
52
- * type Action = { type: string; data: any; timestamp: number };
53
- * const undoStack: Stack<Action> = createStack<Action>();
54
- *
55
- * undoStack.push({ type: "delete", data: { id: 123 }, timestamp: Date.now() });
56
- * undoStack.push({ type: "edit", data: { field: "name", oldValue: "old" }, timestamp: Date.now() });
57
- *
58
- * // Undo last action
59
- * if (!undoStack.isEmpty) {
60
- * const lastAction = undoStack.pop().unwrap();
61
- * console.log(`Undoing: ${lastAction.type}`);
62
- * }
63
- * ```
64
37
  */
65
38
  export type Stack<T> = Readonly<{
66
- /** Checks if the stack is empty. */
39
+ /**
40
+ * Checks if the stack is empty.
41
+ *
42
+ * @example
43
+ *
44
+ * ```ts
45
+ * const stack = createStack<string>();
46
+ *
47
+ * assert.ok(stack.isEmpty);
48
+ * assert(stack.size === 0);
49
+ *
50
+ * stack.push('first');
51
+ * // eslint-disable-next-line unicorn/prefer-single-call
52
+ * stack.push('second');
53
+ *
54
+ * assert.notOk(stack.isEmpty);
55
+ * assert(stack.size === 2);
56
+ * assert.deepStrictEqual(stack.pop(), Optional.some('second'));
57
+ * assert.deepStrictEqual(stack.pop(), Optional.some('first'));
58
+ * assert.deepStrictEqual(stack.pop(), Optional.none);
59
+ *
60
+ * const seededStack = createStack([10, 20, 30]);
61
+ *
62
+ * assert(seededStack.size === 3);
63
+ * assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
64
+ * ```
65
+ */
67
66
  isEmpty: boolean;
68
67
 
69
- /** The number of elements in the stack. */
68
+ /**
69
+ * The number of elements in the stack.
70
+ *
71
+ * @example
72
+ *
73
+ * ```ts
74
+ * const stack = createStack<string>();
75
+ *
76
+ * assert.ok(stack.isEmpty);
77
+ * assert(stack.size === 0);
78
+ *
79
+ * stack.push('first');
80
+ * // eslint-disable-next-line unicorn/prefer-single-call
81
+ * stack.push('second');
82
+ *
83
+ * assert.notOk(stack.isEmpty);
84
+ * assert(stack.size === 2);
85
+ * assert.deepStrictEqual(stack.pop(), Optional.some('second'));
86
+ * assert.deepStrictEqual(stack.pop(), Optional.some('first'));
87
+ * assert.deepStrictEqual(stack.pop(), Optional.none);
88
+ *
89
+ * const seededStack = createStack([10, 20, 30]);
90
+ *
91
+ * assert(seededStack.size === 3);
92
+ * assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
93
+ * ```
94
+ */
70
95
  size: SizeType.Arr;
71
96
 
72
97
  /**
73
98
  * Removes and returns the element at the top of the stack.
74
- * @returns The element at the top of the stack, or `Optional.none` if the stack is empty.
99
+ *
100
+ * @example
101
+ *
102
+ * ```ts
103
+ * const stack = createStack<string>();
104
+ *
105
+ * assert.ok(stack.isEmpty);
106
+ * assert(stack.size === 0);
107
+ *
108
+ * stack.push('first');
109
+ * // eslint-disable-next-line unicorn/prefer-single-call
110
+ * stack.push('second');
111
+ *
112
+ * assert.notOk(stack.isEmpty);
113
+ * assert(stack.size === 2);
114
+ * assert.deepStrictEqual(stack.pop(), Optional.some('second'));
115
+ * assert.deepStrictEqual(stack.pop(), Optional.some('first'));
116
+ * assert.deepStrictEqual(stack.pop(), Optional.none);
117
+ *
118
+ * const seededStack = createStack([10, 20, 30]);
119
+ *
120
+ * assert(seededStack.size === 3);
121
+ * assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
122
+ * ```
123
+ *
124
+ * @returns The element at the top of the stack, or `Optional.none` if the
125
+ * stack is empty.
75
126
  */
76
127
  pop: () => Optional<T>;
77
128
 
78
129
  /**
79
130
  * Adds an element to the top of the stack.
131
+ *
132
+ * @example
133
+ *
134
+ * ```ts
135
+ * const stack = createStack<string>();
136
+ *
137
+ * assert.ok(stack.isEmpty);
138
+ * assert(stack.size === 0);
139
+ *
140
+ * stack.push('first');
141
+ * // eslint-disable-next-line unicorn/prefer-single-call
142
+ * stack.push('second');
143
+ *
144
+ * assert.notOk(stack.isEmpty);
145
+ * assert(stack.size === 2);
146
+ * assert.deepStrictEqual(stack.pop(), Optional.some('second'));
147
+ * assert.deepStrictEqual(stack.pop(), Optional.some('first'));
148
+ * assert.deepStrictEqual(stack.pop(), Optional.none);
149
+ *
150
+ * const seededStack = createStack([10, 20, 30]);
151
+ *
152
+ * assert(seededStack.size === 3);
153
+ * assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
154
+ * ```
155
+ *
80
156
  * @param value The element to add.
81
157
  */
82
158
  push: (value: T) => void;
83
159
  }>;
84
160
 
85
161
  /**
86
- * Class implementation for a stack with LIFO (Last-In, First-Out) behavior using a dynamic array.
87
- * This implementation provides O(1) amortized push and O(1) pop operations by using a resizable buffer
88
- * that grows as needed.
162
+ * Class implementation for a stack with LIFO (Last-In, First-Out) behavior
163
+ * using a dynamic array. This implementation provides O(1) amortized push and
164
+ * O(1) pop operations by using a resizable buffer that grows as needed.
89
165
  *
90
- * The underlying array automatically resizes when it becomes full, ensuring that the stack
91
- * can grow to accommodate any number of elements while maintaining efficient operations.
166
+ * The underlying array automatically resizes when it becomes full, ensuring
167
+ * that the stack can grow to accommodate any number of elements while
168
+ * maintaining efficient operations.
92
169
  *
93
170
  * @template T The type of elements in the stack.
94
171
  * @implements Stack
@@ -108,6 +185,7 @@ class StackClass<T> implements Stack<T> {
108
185
 
109
186
  /**
110
187
  * Constructs a new StackClass instance.
188
+ *
111
189
  * @param initialValues Optional initial values to populate the stack.
112
190
  */
113
191
  constructor(initialValues: readonly T[] = []) {
@@ -141,50 +219,16 @@ class StackClass<T> implements Stack<T> {
141
219
  /**
142
220
  * Removes and returns the element at the top of the stack (LIFO).
143
221
  *
144
- * This operation removes the element that was added most recently (last-in) and returns it.
145
- * If the stack is empty, returns `Optional.none`. The operation is guaranteed to be O(1)
146
- * and does not require any array resizing or memory reallocation.
147
- *
148
- * **Time Complexity:** O(1) - constant time operation
149
- * **Space Complexity:** O(1) - no additional memory allocation
222
+ * This operation removes the element that was added most recently (last-in)
223
+ * and returns it. If the stack is empty, returns `Optional.none`. The
224
+ * operation is guaranteed to be O(1) and does not require any array resizing
225
+ * or memory reallocation.
150
226
  *
151
- * @returns An Optional containing the removed element, or `Optional.none` if the stack is empty.
227
+ * **Time Complexity:** O(1) - constant time operation **Space Complexity:**
228
+ * O(1) - no additional memory allocation
152
229
  *
153
- * @example
154
- * ```typescript
155
- * const stack = createStack<string>();
156
- *
157
- * // Add some elements
158
- * stack.push("bottom");
159
- * stack.push("middle");
160
- * stack.push("top");
161
- *
162
- * // Remove elements in LIFO order
163
- * const top = stack.pop();
164
- * if (top.isSome) {
165
- * console.log(top.value); // "top" (last pushed, first popped)
166
- * }
167
- *
168
- * const middle = stack.pop().unwrap(); // "middle"
169
- * console.log(stack.size); // 1
170
- *
171
- * // Safe handling of empty stack
172
- * const emptyStack = createStack<number>();
173
- * const result = emptyStack.pop();
174
- * if (result.isNone) {
175
- * console.log("Stack is empty");
176
- * }
177
- *
178
- * // Typical usage in algorithms
179
- * const pathStack = createStack<string>();
180
- * pathStack.push("/home");
181
- * pathStack.push("/users");
182
- * pathStack.push("/documents");
183
- *
184
- * // Backtrack one level
185
- * const currentDir = pathStack.pop().unwrap(); // "/documents"
186
- * const parentDir = pathStack.pop().unwrap(); // "/users"
187
- * ```
230
+ * @returns An Optional containing the removed element, or `Optional.none` if
231
+ * the stack is empty.
188
232
  */
189
233
  pop(): Optional<T> {
190
234
  if (this.isEmpty) {
@@ -202,60 +246,19 @@ class StackClass<T> implements Stack<T> {
202
246
  /**
203
247
  * Adds an element to the top of the stack (LIFO).
204
248
  *
205
- * This operation adds the element to the top of the stack, where it will be the first
206
- * to be popped (last-in, first-out ordering). The operation is amortized O(1),
207
- * meaning it's O(1) for most operations with occasional O(n) when the buffer needs resizing.
249
+ * This operation adds the element to the top of the stack, where it will be
250
+ * the first to be popped (last-in, first-out ordering). The operation is
251
+ * amortized O(1), meaning it's O(1) for most operations with occasional O(n)
252
+ * when the buffer needs resizing.
208
253
  *
209
- * **Time Complexity:** O(1) amortized - O(n) only when buffer resize is needed
210
- * **Space Complexity:** O(1) - constant additional memory per element
254
+ * **Time Complexity:** O(1) amortized - O(n) only when buffer resize is
255
+ * needed **Space Complexity:** O(1) - constant additional memory per element
211
256
  *
212
- * **Buffer Resizing:** When the internal buffer becomes full, it automatically doubles
213
- * in size and copies existing elements to maintain the stack structure.
257
+ * **Buffer Resizing:** When the internal buffer becomes full, it
258
+ * automatically doubles in size and copies existing elements to maintain the
259
+ * stack structure.
214
260
  *
215
261
  * @param value The element to add to the top of the stack.
216
- *
217
- * @example
218
- * ```typescript
219
- * const actionStack = createStack<string>();
220
- *
221
- * // Add actions in chronological order
222
- * actionStack.push("open file"); // O(1)
223
- * actionStack.push("edit content"); // O(1)
224
- * actionStack.push("save file"); // O(1)
225
- *
226
- * console.log(actionStack.size); // 3
227
- *
228
- * // Actions will be undone in reverse order (LIFO)
229
- * while (!actionStack.isEmpty) {
230
- * const action = actionStack.pop().unwrap();
231
- * console.log(`Undoing: ${action}`);
232
- * }
233
- * // Output:
234
- * // Undoing: save file
235
- * // Undoing: edit content
236
- * // Undoing: open file
237
- *
238
- * // High-volume pushing (demonstrates amortized O(1) performance)
239
- * const dataStack = createStack<number>();
240
- *
241
- * for (const i of range(1000000)) {
242
- * dataStack.push(i); // Each operation is O(1) amortized
243
- * }
244
- *
245
- * console.log(dataStack.size); // 1000000
246
- *
247
- * // Function call stack simulation
248
- * type StackFrame = { function: string; variables: Record<string, any> };
249
- * const callStack = createStack<StackFrame>();
250
- *
251
- * callStack.push({ function: "main", variables: { argc: 1, argv: ["program"] } });
252
- * callStack.push({ function: "process", variables: { data: [1, 2, 3] } });
253
- * callStack.push({ function: "validate", variables: { input: "test" } });
254
- *
255
- * // Current function context is at the top
256
- * const currentFrame = callStack.pop().unwrap();
257
- * console.log(`Current function: ${currentFrame.function}`);
258
- * ```
259
262
  */
260
263
  push(value: T): void {
261
264
  // Resize if buffer is full
@@ -290,13 +293,16 @@ class StackClass<T> implements Stack<T> {
290
293
  }
291
294
 
292
295
  /**
293
- * Creates a new Stack instance with LIFO (Last-In, First-Out) behavior using a high-performance dynamic array.
296
+ * Creates a new Stack instance with LIFO (Last-In, First-Out) behavior using a
297
+ * high-performance dynamic array.
294
298
  *
295
- * This factory function creates an optimized stack implementation that maintains excellent performance
296
- * characteristics for both push and pop operations. The underlying dynamic array automatically
297
- * resizes to accommodate growing workloads while providing predictable O(1) operations.
299
+ * This factory function creates an optimized stack implementation that
300
+ * maintains excellent performance characteristics for both push and pop
301
+ * operations. The underlying dynamic array automatically resizes to accommodate
302
+ * growing workloads while providing predictable O(1) operations.
298
303
  *
299
304
  * **Implementation Features:**
305
+ *
300
306
  * - **O(1) push operations** (amortized - occasionally O(n) when resizing)
301
307
  * - **O(1) pop operations** (always)
302
308
  * - **Automatic buffer resizing** - starts at 8 elements, doubles when full
@@ -304,121 +310,42 @@ class StackClass<T> implements Stack<T> {
304
310
  * - **Dynamic array design** - eliminates need for complex memory management
305
311
  *
306
312
  * **Performance Benefits:**
313
+ *
307
314
  * - No array shifting required for stack operations
308
315
  * - Minimal memory allocation overhead
309
316
  * - Predictable performance under high load
310
317
  * - Efficient memory usage with automatic cleanup
311
318
  *
312
- * @template T The type of elements stored in the stack.
313
- * @param initialValues Optional array of initial elements to populate the stack.
314
- * Elements will be popped in reverse order of how they appear in the array
315
- * (last array element will be popped first).
316
- * If provided, the initial buffer capacity will be at least twice the array length.
317
- * @returns A new Stack instance optimized for high-performance LIFO operations.
318
- *
319
319
  * @example
320
- * ```typescript
321
- * import { createStack } from './stack';
322
- *
323
- * // Example 1: Function call simulation
324
- * type FunctionCall = { name: string; args: any[]; context: any };
325
- * const callStack = createStack<FunctionCall>();
326
- *
327
- * // Simulate function calls (push onto stack)
328
- * callStack.push({ name: "main", args: [], context: {} }); // O(1)
329
- * callStack.push({ name: "processData", args: [data], context: {} }); // O(1)
330
- * callStack.push({ name: "validateInput", args: [input], context: {} }); // O(1)
331
- *
332
- * // Simulate function returns (pop from stack)
333
- * while (!callStack.isEmpty) {
334
- * const call = callStack.pop().unwrap(); // O(1)
335
- * console.log(`Returning from: ${call.name}`);
336
- * }
337
- * // Output:
338
- * // Returning from: validateInput
339
- * // Returning from: processData
340
- * // Returning from: main
341
- *
342
- * // Example 2: Expression evaluation with operator precedence
343
- * const operatorStack = createStack<string>();
344
- * const operandStack = createStack<number>();
345
320
  *
346
- * // Simulate parsing "3 + 4 * 2"
347
- * operandStack.push(3);
348
- * operatorStack.push("+");
349
- * operandStack.push(4);
350
- * operatorStack.push("*"); // Higher precedence
351
- * operandStack.push(2);
321
+ * ```ts
322
+ * const stack = createStack<string>();
352
323
  *
353
- * // Process higher precedence first (LIFO)
354
- * const op = operatorStack.pop().unwrap(); // "*"
355
- * const b = operandStack.pop().unwrap(); // 2
356
- * const a = operandStack.pop().unwrap(); // 4
357
- * operandStack.push(a * b); // Push result: 8
324
+ * assert.ok(stack.isEmpty);
325
+ * assert(stack.size === 0);
358
326
  *
359
- * // Example 3: Undo/Redo functionality
360
- * type EditAction = {
361
- * type: 'insert' | 'delete' | 'modify';
362
- * position: number;
363
- * oldValue: string;
364
- * newValue: string;
365
- * };
327
+ * stack.push('first');
328
+ * // eslint-disable-next-line unicorn/prefer-single-call
329
+ * stack.push('second');
366
330
  *
367
- * const undoStack = createStack<EditAction>();
368
- * const redoStack = createStack<EditAction>();
331
+ * assert.notOk(stack.isEmpty);
332
+ * assert(stack.size === 2);
333
+ * assert.deepStrictEqual(stack.pop(), Optional.some('second'));
334
+ * assert.deepStrictEqual(stack.pop(), Optional.some('first'));
335
+ * assert.deepStrictEqual(stack.pop(), Optional.none);
369
336
  *
370
- * // Perform edits (push to undo stack)
371
- * const edit1: EditAction = { type: 'insert', position: 0, oldValue: '', newValue: 'Hello' };
372
- * const edit2: EditAction = { type: 'insert', position: 5, oldValue: '', newValue: ' World' };
337
+ * const seededStack = createStack([10, 20, 30]);
373
338
  *
374
- * undoStack.push(edit1);
375
- * undoStack.push(edit2);
376
- *
377
- * // Undo last edit
378
- * if (!undoStack.isEmpty) {
379
- * const lastEdit = undoStack.pop().unwrap();
380
- * redoStack.push(lastEdit);
381
- * console.log(`Undid: ${lastEdit.type} at position ${lastEdit.position}`);
382
- * }
383
- *
384
- * // Example 4: High-throughput data processing
385
- * const processingStack = createStack<number>();
386
- *
387
- * // Add large amount of data (demonstrates amortized O(1) performance)
388
- * for (const i of range(100000)) {
389
- * processingStack.push(i); // Each push is O(1) amortized
390
- * }
391
- *
392
- * // Process data in LIFO order
393
- * let processedCount = 0;
394
- * while (!processingStack.isEmpty) {
395
- * const value = processingStack.pop().unwrap(); // O(1)
396
- * // Process value...
397
- * processedCount++;
398
- * }
399
- * console.log(`Processed ${processedCount} items`); // 100000
400
- *
401
- * // Example 5: Stack with pre-populated data
402
- * const historyStack = createStack<string>([
403
- * "page1.html",
404
- * "page2.html",
405
- * "page3.html",
406
- * "page4.html"
407
- * ]);
408
- *
409
- * console.log(historyStack.size); // Output: 4
410
- *
411
- * // Navigate back through history (LIFO order)
412
- * while (!historyStack.isEmpty) {
413
- * const page = historyStack.pop().unwrap();
414
- * console.log(`Going back to: ${page}`);
415
- * }
416
- * // Output:
417
- * // Going back to: page4.html (last added, first removed)
418
- * // Going back to: page3.html
419
- * // Going back to: page2.html
420
- * // Going back to: page1.html
339
+ * assert(seededStack.size === 3);
340
+ * assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
421
341
  * ```
342
+ *
343
+ * @template T The type of elements stored in the stack.
344
+ * @param initialValues Optional array of initial elements to populate the
345
+ * stack. Elements will be popped in reverse order of how they appear in the
346
+ * array (last array element will be popped first). If provided, the initial
347
+ * buffer capacity will be at least twice the array length.
348
+ * @returns A new Stack instance optimized for high-performance LIFO operations.
422
349
  */
423
350
  export const createStack = <T,>(initialValues?: readonly T[]): Stack<T> =>
424
351
  new StackClass<T>(initialValues);
@@ -45,7 +45,9 @@ describe('Stack', () => {
45
45
  const stack = createStack<string>();
46
46
 
47
47
  stack.push('first');
48
+ // eslint-disable-next-line unicorn/prefer-single-call
48
49
  stack.push('second');
50
+ // eslint-disable-next-line unicorn/prefer-single-call
49
51
  stack.push('third');
50
52
 
51
53
  expect(stack.size).toBe(3);
@@ -98,10 +100,12 @@ describe('Stack', () => {
98
100
  const stack = createStack<string>();
99
101
 
100
102
  stack.push('a');
103
+ // eslint-disable-next-line unicorn/prefer-single-call
101
104
  stack.push('b');
102
105
  expect(Optional.unwrap(stack.pop())).toBe('b');
103
106
 
104
107
  stack.push('c');
108
+ // eslint-disable-next-line unicorn/prefer-single-call
105
109
  stack.push('d');
106
110
  expect(Optional.unwrap(stack.pop())).toBe('d');
107
111
  expect(Optional.unwrap(stack.pop())).toBe('c');
@@ -118,6 +122,7 @@ describe('Stack', () => {
118
122
  const item2: Item = { id: 2, name: 'second' };
119
123
 
120
124
  stack.push(item1);
125
+ // eslint-disable-next-line unicorn/prefer-single-call
121
126
  stack.push(item2);
122
127
 
123
128
  expect(Optional.unwrap(stack.pop())).toStrictEqual(item2);
@@ -127,7 +132,7 @@ describe('Stack', () => {
127
132
 
128
133
  test('should handle large number of operations efficiently', () => {
129
134
  const stack = createStack<number>();
130
- const n = asPositiveSafeInt(10000);
135
+ const n = asPositiveSafeInt(10_000);
131
136
 
132
137
  // Push many elements
133
138
  for (const i of range(n)) {
@@ -167,8 +172,11 @@ describe('Stack', () => {
167
172
  const stack = createStack<string | null | undefined>();
168
173
 
169
174
  stack.push('value');
175
+ // eslint-disable-next-line unicorn/prefer-single-call
170
176
  stack.push(null);
177
+ // eslint-disable-next-line unicorn/prefer-single-call
171
178
  stack.push(undefined);
179
+ // eslint-disable-next-line unicorn/prefer-single-call
172
180
  stack.push('another');
173
181
 
174
182
  expect(Optional.unwrap(stack.pop())).toBe('another');
@@ -1 +1,2 @@
1
+ export * from './array/index.mjs';
1
2
  export * from './index.mjs';