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
@@ -1,144 +1,20 @@
1
1
  /**
2
- * Applies a function to a value if the value is not `null` or `undefined`.
3
- * If the value is `null` or `undefined`, it returns `undefined`.
2
+ * Applies a function to a value if the value is not `null` or `undefined`. If
3
+ * the value is `null` or `undefined`, it returns `undefined`.
4
4
  *
5
- * This function provides a safe way to transform nullable values without explicit null checks.
6
- * It's similar to Optional.map() but works directly with TypeScript's nullable types.
7
- * Supports both regular and curried usage for functional composition.
5
+ * This function provides a safe way to transform nullable values without
6
+ * explicit null checks. It's similar to Optional.map() but works directly with
7
+ * TypeScript's nullable types. Supports both regular and curried usage for
8
+ * functional composition.
8
9
  *
9
10
  * @template A - The type of the input value (excluding null/undefined)
10
11
  * @template B - The type of the value returned by the mapping function
11
- * @param value - The value to potentially transform (can be `A`, `null`, or `undefined`)
12
- * @param mapFn - A function that transforms a non-nullable value of type `A` to type `B`
13
- * @returns The result of applying `mapFn` to `value` if value is not null/undefined; otherwise `undefined`
14
- *
15
- * @example Basic usage with nullable values
16
- * ```typescript
17
- * // Safe string transformation
18
- * mapNullable("hello", s => s.toUpperCase()); // "HELLO"
19
- * mapNullable(null, s => s.toUpperCase()); // undefined
20
- * mapNullable(undefined, s => s.toUpperCase()); // undefined
21
- *
22
- * // Number operations
23
- * mapNullable(5, n => n * 2); // 10
24
- * mapNullable(0, n => n * 2); // 0 (note: 0 is not null/undefined)
25
- * mapNullable(null as number | null, n => n * 2); // undefined
26
- * ```
27
- *
28
- * @example Working with optional object properties
29
- * ```typescript
30
- * interface User {
31
- * id: number;
32
- * name?: string;
33
- * email?: string;
34
- * }
35
- *
36
- * function formatUserDisplay(user: User): string {
37
- * const displayName = mapNullable(user.name, name => name.toUpperCase()) ?? 'Anonymous';
38
- * const emailDomain = mapNullable(user.email, email => email.split('@')[1]);
39
- *
40
- * return `${displayName} ${emailDomain ? `(${emailDomain})` : ''}`;
41
- * }
42
- *
43
- * formatUserDisplay({ id: 1, name: 'John', email: 'john@example.com' }); // "JOHN (example.com)"
44
- * formatUserDisplay({ id: 2 }); // "Anonymous "
45
- * ```
46
- *
47
- * @example Curried usage for functional composition
48
- * ```typescript
49
- * // Create reusable transformers
50
- * const toUpperCase = mapNullable((s: string) => s.toUpperCase());
51
- * const addPrefix = mapNullable((s: string) => `PREFIX_${s}`);
52
- * const parseNumber = mapNullable((s: string) => parseInt(s, 10));
53
- *
54
- * // Use in different contexts
55
- * toUpperCase("hello"); // "HELLO"
56
- * toUpperCase(null); // undefined
57
- *
58
- * // Compose transformations
59
- * const processString = (s: string | null) => {
60
- * const upper = toUpperCase(s);
61
- * return addPrefix(upper);
62
- * };
63
- *
64
- * processString("test"); // "PREFIX_TEST"
65
- * processString(null); // undefined
66
- * ```
67
- *
68
- * @example Chaining nullable operations
69
- * ```typescript
70
- * // API response handling
71
- * interface ApiResponse {
72
- * data?: {
73
- * user?: {
74
- * profile?: {
75
- * displayName?: string;
76
- * };
77
- * };
78
- * };
79
- * }
80
- *
81
- * function getDisplayName(response: ApiResponse): string | undefined {
82
- * return mapNullable(
83
- * response.data?.user?.profile?.displayName,
84
- * name => name.trim().toUpperCase()
85
- * );
86
- * }
87
- *
88
- * // Chain multiple transformations
89
- * function processNullableChain(value: string | null): string | undefined {
90
- * const step1 = mapNullable(value, v => v.trim());
91
- * const step2 = mapNullable(step1, v => v.length > 0 ? v : null);
92
- * const step3 = mapNullable(step2, v => v.toUpperCase());
93
- * return step3;
94
- * }
95
- * ```
96
- *
97
- * @example Integration with array methods
98
- * ```typescript
99
- * const nullableNumbers: (number | null | undefined)[] = [1, null, 3, undefined, 5];
100
- *
101
- * // Transform and filter in one step
102
- * const doubled = nullableNumbers
103
- * .map(n => mapNullable(n, x => x * 2))
104
- * .filter((n): n is number => n !== undefined);
105
- * // Result: [2, 6, 10]
106
- *
107
- * // Process optional array elements
108
- * const users: Array<{ name?: string }> = [
109
- * { name: 'Alice' },
110
- * { name: undefined },
111
- * { name: 'Bob' }
112
- * ];
113
- *
114
- * const upperNames = users
115
- * .map(u => mapNullable(u.name, n => n.toUpperCase()))
116
- * .filter((n): n is string => n !== undefined);
117
- * // Result: ['ALICE', 'BOB']
118
- * ```
119
- *
120
- * @example Error handling patterns
121
- * ```typescript
122
- * // Safe JSON parsing
123
- * function parseJsonSafe<T>(json: string | null): T | undefined {
124
- * return mapNullable(json, j => {
125
- * try {
126
- * return JSON.parse(j) as T;
127
- * } catch {
128
- * return null;
129
- * }
130
- * }) ?? undefined;
131
- * }
132
- *
133
- * // Safe property access with computation
134
- * function calculateAge(birthYear: number | null): string | undefined {
135
- * return mapNullable(birthYear, year => {
136
- * const age = new Date().getFullYear() - year;
137
- * return age >= 0 ? `${age} years old` : null;
138
- * }) ?? undefined;
139
- * }
140
- * ```
141
- *
12
+ * @param value - The value to potentially transform (can be `A`, `null`, or
13
+ * `undefined`)
14
+ * @param mapFn - A function that transforms a non-nullable value of type `A` to
15
+ * type `B`
16
+ * @returns The result of applying `mapFn` to `value` if value is not
17
+ * null/undefined; otherwise `undefined`
142
18
  * @see Optional - For more complex optional value handling
143
19
  * @see Result - For error handling with detailed error information
144
20
  */
@@ -1 +1 @@
1
- {"version":3,"file":"map-nullable.d.mts","sourceRoot":"","sources":["../../src/others/map-nullable.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+IG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAC1C,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3B,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACjB,CAAC,GAAG,SAAS,CAAC;AAGjB,wBAAgB,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAC1C,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACjB,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"map-nullable.d.mts","sourceRoot":"","sources":["../../src/others/map-nullable.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAC1C,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3B,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACjB,CAAC,GAAG,SAAS,CAAC;AAGjB,wBAAgB,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAC1C,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACjB,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"map-nullable.mjs","sources":["../../src/others/map-nullable.mts"],"sourcesContent":[null],"names":[],"mappings":"AA0JM,SAAU,WAAW,CACzB,GAAG,IAE8B,EAAA;AAEjC,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,IAAI;AAC3B,YAAA,OAAO,KAAK,IAAI,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;QACjD;QACA,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI;YACpB,OAAO,CAAC,KAA2B,KAAK,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC;QACnE;;AAEJ;;;;"}
1
+ {"version":3,"file":"map-nullable.mjs","sources":["../../src/others/map-nullable.mts"],"sourcesContent":[null],"names":[],"mappings":"AA8BM,SAAU,WAAW,CACzB,GAAG,IAE8B,EAAA;AAEjC,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,IAAI;AAC3B,YAAA,OAAO,KAAK,IAAI,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;QACjD;QACA,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI;YACpB,OAAO,CAAC,KAA2B,KAAK,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC;QACnE;;AAEJ;;;;"}
@@ -1,172 +1,29 @@
1
1
  /**
2
- * Creates a memoized version of a function that caches results based on input arguments.
2
+ * Creates a memoized version of a function that caches results based on input
3
+ * arguments.
3
4
  *
4
- * The memoized function stores results in an internal Map and returns cached values
5
- * for repeated calls with the same arguments. This can significantly improve performance
6
- * for expensive computations or I/O operations.
5
+ * The memoized function stores results in an internal Map and returns cached
6
+ * values for repeated calls with the same arguments. This can significantly
7
+ * improve performance for expensive computations or I/O operations.
7
8
  *
8
9
  * **Important considerations:**
9
- * - The cache grows unbounded - consider memory implications for long-running applications
10
- * - Cache keys must be primitives (string, number, boolean, symbol, null, undefined, bigint)
10
+ *
11
+ * - The cache grows unbounded - consider memory implications for long-running
12
+ * applications
13
+ * - Cache keys must be primitives (string, number, boolean, symbol, null,
14
+ * undefined, bigint)
11
15
  * - Object arguments require careful key generation to ensure uniqueness
12
16
  * - Pure functions only - memoizing functions with side effects can lead to bugs
13
17
  *
14
18
  * @template A - The tuple type of the function arguments
15
19
  * @template R - The return type of the function
16
- * @template K - The primitive type used as the cache key (must be valid Map key)
20
+ * @template K - The primitive type used as the cache key (must be valid Map
21
+ * key)
17
22
  * @param fn - The pure function to memoize
18
- * @param argsToCacheKey - Function that converts arguments to a unique cache key
23
+ * @param argsToCacheKey - Function that converts arguments to a unique cache
24
+ * key
19
25
  * @returns A memoized version of the input function with the same signature
20
26
  *
21
- * @example Basic memoization for expensive calculations
22
- * ```typescript
23
- * // Fibonacci calculation (exponential time complexity)
24
- * const fibonacci = (n: number): number => {
25
- * console.log(`Computing fib(${n})`);
26
- * if (n <= 1) return n;
27
- * return fibonacci(n - 1) + fibonacci(n - 2);
28
- * };
29
- *
30
- * const memoizedFib = memoizeFunction(
31
- * fibonacci,
32
- * (n) => n // Number itself as key
33
- * );
34
- *
35
- * memoizedFib(40); // Much faster than unmemoized version
36
- * memoizedFib(40); // Returns instantly from cache
37
- * ```
38
- *
39
- * @example Multi-argument functions with composite keys
40
- * ```typescript
41
- * // Grid calculation with x,y coordinates
42
- * const calculateGridValue = (x: number, y: number, scale: number): number => {
43
- * console.log(`Computing grid(${x},${y},${scale})`);
44
- * // Expensive computation...
45
- * return Math.sin(x * scale) * Math.cos(y * scale);
46
- * };
47
- *
48
- * const memoizedGrid = memoizeFunction(
49
- * calculateGridValue,
50
- * (x, y, scale) => `${x},${y},${scale}` // String concatenation for composite key
51
- * );
52
- *
53
- * // Alternative: Using bit manipulation for integer coordinates
54
- * const memoizedGrid2 = memoizeFunction(
55
- * calculateGridValue,
56
- * (x, y, scale) => (x << 20) | (y << 10) | scale // Assuming small positive integers
57
- * );
58
- * ```
59
- *
60
- * @example Object arguments with selective memoization
61
- * ```typescript
62
- * interface User {
63
- * id: number;
64
- * name: string;
65
- * email: string;
66
- * metadata?: Record<string, unknown>;
67
- * }
68
- *
69
- * const fetchUserPermissions = async (user: User): Promise<string[]> => {
70
- * console.log(`Fetching permissions for user ${user.id}`);
71
- * const response = await api.get(`/permissions/${user.id}`);
72
- * return response.data;
73
- * };
74
- *
75
- * // Memoize based only on user ID, ignoring other fields
76
- * const memoizedFetchPermissions = memoizeFunction(
77
- * fetchUserPermissions,
78
- * (user) => user.id // Only cache by ID
79
- * );
80
- *
81
- * // For multiple identifying fields
82
- * const processUserData = (user: User, orgId: number): ProcessedData => {
83
- * // Complex processing...
84
- * };
85
- *
86
- * const memoizedProcess = memoizeFunction(
87
- * processUserData,
88
- * (user, orgId) => `${user.id}:${orgId}` // Composite key with separator
89
- * );
90
- * ```
91
- *
92
- * @example Memoizing recursive functions
93
- * ```typescript
94
- * // Recursive path finding
95
- * const findPaths = (start: string, end: string, visited: Set<string> = new Set()): string[][] => {
96
- * if (start === end) return [[end]];
97
- * // ... complex recursive logic
98
- * };
99
- *
100
- * // Use sorted, serialized visited set for consistent keys
101
- * const memoizedFindPaths = memoizeFunction(
102
- * findPaths,
103
- * (start, end, visited = new Set()) =>
104
- * `${start}->${end}:[${[...visited].toSorted().join(',')}]`
105
- * );
106
- * ```
107
- *
108
- * @example Cache key strategies
109
- * ```typescript
110
- * // 1. Simple primitive argument
111
- * memoizeFunction(fn, (x: number) => x);
112
- *
113
- * // 2. Multiple arguments with separator
114
- * memoizeFunction(fn, (a: string, b: number) => `${a}|${b}`);
115
- *
116
- * // 3. Object with specific fields
117
- * memoizeFunction(fn, (obj: { id: number; version: number }) =>
118
- * `${obj.id}:v${obj.version}`
119
- * );
120
- *
121
- * // 4. Array argument with JSON serialization
122
- * memoizeFunction(fn, (arr: number[]) => JSON.stringify(arr));
123
- *
124
- * // 5. Boolean flags as bit field
125
- * memoizeFunction(fn, (a: boolean, b: boolean, c: boolean) =>
126
- * (a ? 4 : 0) | (b ? 2 : 0) | (c ? 1 : 0)
127
- * );
128
- * ```
129
- *
130
- * @example Memory-conscious memoization with weak references
131
- * ```typescript
132
- * // For object keys, consider using WeakMap externally
133
- * const cache = new WeakMap<object, Result>();
134
- *
135
- * function memoizeWithWeakMap<T extends object, R>(
136
- * fn: (obj: T) => R
137
- * ): (obj: T) => R {
138
- * return (obj: T): R => {
139
- * if (cache.has(obj)) {
140
- * return cache.get(obj)!;
141
- * }
142
- * const result = fn(obj);
143
- * cache.set(obj, result);
144
- * return result;
145
- * };
146
- * }
147
- * ```
148
- *
149
- * @example Anti-patterns to avoid
150
- * ```typescript
151
- * // ❌ Bad: Memoizing impure functions
152
- * const memoizedRandom = memoizeFunction(
153
- * () => Math.random(),
154
- * () => 'key' // Always returns cached random value!
155
- * );
156
- *
157
- * // ❌ Bad: Memoizing functions with side effects
158
- * const memoizedLog = memoizeFunction(
159
- * (msg: string) => { console.log(msg); return msg; },
160
- * (msg) => msg // Logs only on first call!
161
- * );
162
- *
163
- * // ❌ Bad: Non-unique cache keys
164
- * const memoizedProcess = memoizeFunction(
165
- * (user: User) => processUser(user),
166
- * (user) => user.name // Multiple users can have same name!
167
- * );
168
- * ```
169
- *
170
27
  * @see https://en.wikipedia.org/wiki/Memoization
171
28
  */
172
29
  export declare const memoizeFunction: <const A extends readonly unknown[], R, K extends Primitive>(fn: (...args: A) => R, argsToCacheKey: (...args: A) => K) => ((...args: A) => R);
@@ -1 +1 @@
1
- {"version":3,"file":"memoize-function.d.mts","sourceRoot":"","sources":["../../src/others/memoize-function.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0KG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAClC,CAAC,EACD,CAAC,SAAS,SAAS,EAEnB,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,EACrB,gBAAgB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,KAChC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAiBpB,CAAC"}
1
+ {"version":3,"file":"memoize-function.d.mts","sourceRoot":"","sources":["../../src/others/memoize-function.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAClC,CAAC,EACD,CAAC,SAAS,SAAS,EAEnB,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,EACrB,gBAAgB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,KAChC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAiBpB,CAAC"}
@@ -1,172 +1,29 @@
1
1
  /**
2
- * Creates a memoized version of a function that caches results based on input arguments.
2
+ * Creates a memoized version of a function that caches results based on input
3
+ * arguments.
3
4
  *
4
- * The memoized function stores results in an internal Map and returns cached values
5
- * for repeated calls with the same arguments. This can significantly improve performance
6
- * for expensive computations or I/O operations.
5
+ * The memoized function stores results in an internal Map and returns cached
6
+ * values for repeated calls with the same arguments. This can significantly
7
+ * improve performance for expensive computations or I/O operations.
7
8
  *
8
9
  * **Important considerations:**
9
- * - The cache grows unbounded - consider memory implications for long-running applications
10
- * - Cache keys must be primitives (string, number, boolean, symbol, null, undefined, bigint)
10
+ *
11
+ * - The cache grows unbounded - consider memory implications for long-running
12
+ * applications
13
+ * - Cache keys must be primitives (string, number, boolean, symbol, null,
14
+ * undefined, bigint)
11
15
  * - Object arguments require careful key generation to ensure uniqueness
12
16
  * - Pure functions only - memoizing functions with side effects can lead to bugs
13
17
  *
14
18
  * @template A - The tuple type of the function arguments
15
19
  * @template R - The return type of the function
16
- * @template K - The primitive type used as the cache key (must be valid Map key)
20
+ * @template K - The primitive type used as the cache key (must be valid Map
21
+ * key)
17
22
  * @param fn - The pure function to memoize
18
- * @param argsToCacheKey - Function that converts arguments to a unique cache key
23
+ * @param argsToCacheKey - Function that converts arguments to a unique cache
24
+ * key
19
25
  * @returns A memoized version of the input function with the same signature
20
26
  *
21
- * @example Basic memoization for expensive calculations
22
- * ```typescript
23
- * // Fibonacci calculation (exponential time complexity)
24
- * const fibonacci = (n: number): number => {
25
- * console.log(`Computing fib(${n})`);
26
- * if (n <= 1) return n;
27
- * return fibonacci(n - 1) + fibonacci(n - 2);
28
- * };
29
- *
30
- * const memoizedFib = memoizeFunction(
31
- * fibonacci,
32
- * (n) => n // Number itself as key
33
- * );
34
- *
35
- * memoizedFib(40); // Much faster than unmemoized version
36
- * memoizedFib(40); // Returns instantly from cache
37
- * ```
38
- *
39
- * @example Multi-argument functions with composite keys
40
- * ```typescript
41
- * // Grid calculation with x,y coordinates
42
- * const calculateGridValue = (x: number, y: number, scale: number): number => {
43
- * console.log(`Computing grid(${x},${y},${scale})`);
44
- * // Expensive computation...
45
- * return Math.sin(x * scale) * Math.cos(y * scale);
46
- * };
47
- *
48
- * const memoizedGrid = memoizeFunction(
49
- * calculateGridValue,
50
- * (x, y, scale) => `${x},${y},${scale}` // String concatenation for composite key
51
- * );
52
- *
53
- * // Alternative: Using bit manipulation for integer coordinates
54
- * const memoizedGrid2 = memoizeFunction(
55
- * calculateGridValue,
56
- * (x, y, scale) => (x << 20) | (y << 10) | scale // Assuming small positive integers
57
- * );
58
- * ```
59
- *
60
- * @example Object arguments with selective memoization
61
- * ```typescript
62
- * interface User {
63
- * id: number;
64
- * name: string;
65
- * email: string;
66
- * metadata?: Record<string, unknown>;
67
- * }
68
- *
69
- * const fetchUserPermissions = async (user: User): Promise<string[]> => {
70
- * console.log(`Fetching permissions for user ${user.id}`);
71
- * const response = await api.get(`/permissions/${user.id}`);
72
- * return response.data;
73
- * };
74
- *
75
- * // Memoize based only on user ID, ignoring other fields
76
- * const memoizedFetchPermissions = memoizeFunction(
77
- * fetchUserPermissions,
78
- * (user) => user.id // Only cache by ID
79
- * );
80
- *
81
- * // For multiple identifying fields
82
- * const processUserData = (user: User, orgId: number): ProcessedData => {
83
- * // Complex processing...
84
- * };
85
- *
86
- * const memoizedProcess = memoizeFunction(
87
- * processUserData,
88
- * (user, orgId) => `${user.id}:${orgId}` // Composite key with separator
89
- * );
90
- * ```
91
- *
92
- * @example Memoizing recursive functions
93
- * ```typescript
94
- * // Recursive path finding
95
- * const findPaths = (start: string, end: string, visited: Set<string> = new Set()): string[][] => {
96
- * if (start === end) return [[end]];
97
- * // ... complex recursive logic
98
- * };
99
- *
100
- * // Use sorted, serialized visited set for consistent keys
101
- * const memoizedFindPaths = memoizeFunction(
102
- * findPaths,
103
- * (start, end, visited = new Set()) =>
104
- * `${start}->${end}:[${[...visited].toSorted().join(',')}]`
105
- * );
106
- * ```
107
- *
108
- * @example Cache key strategies
109
- * ```typescript
110
- * // 1. Simple primitive argument
111
- * memoizeFunction(fn, (x: number) => x);
112
- *
113
- * // 2. Multiple arguments with separator
114
- * memoizeFunction(fn, (a: string, b: number) => `${a}|${b}`);
115
- *
116
- * // 3. Object with specific fields
117
- * memoizeFunction(fn, (obj: { id: number; version: number }) =>
118
- * `${obj.id}:v${obj.version}`
119
- * );
120
- *
121
- * // 4. Array argument with JSON serialization
122
- * memoizeFunction(fn, (arr: number[]) => JSON.stringify(arr));
123
- *
124
- * // 5. Boolean flags as bit field
125
- * memoizeFunction(fn, (a: boolean, b: boolean, c: boolean) =>
126
- * (a ? 4 : 0) | (b ? 2 : 0) | (c ? 1 : 0)
127
- * );
128
- * ```
129
- *
130
- * @example Memory-conscious memoization with weak references
131
- * ```typescript
132
- * // For object keys, consider using WeakMap externally
133
- * const cache = new WeakMap<object, Result>();
134
- *
135
- * function memoizeWithWeakMap<T extends object, R>(
136
- * fn: (obj: T) => R
137
- * ): (obj: T) => R {
138
- * return (obj: T): R => {
139
- * if (cache.has(obj)) {
140
- * return cache.get(obj)!;
141
- * }
142
- * const result = fn(obj);
143
- * cache.set(obj, result);
144
- * return result;
145
- * };
146
- * }
147
- * ```
148
- *
149
- * @example Anti-patterns to avoid
150
- * ```typescript
151
- * // ❌ Bad: Memoizing impure functions
152
- * const memoizedRandom = memoizeFunction(
153
- * () => Math.random(),
154
- * () => 'key' // Always returns cached random value!
155
- * );
156
- *
157
- * // ❌ Bad: Memoizing functions with side effects
158
- * const memoizedLog = memoizeFunction(
159
- * (msg: string) => { console.log(msg); return msg; },
160
- * (msg) => msg // Logs only on first call!
161
- * );
162
- *
163
- * // ❌ Bad: Non-unique cache keys
164
- * const memoizedProcess = memoizeFunction(
165
- * (user: User) => processUser(user),
166
- * (user) => user.name // Multiple users can have same name!
167
- * );
168
- * ```
169
- *
170
27
  * @see https://en.wikipedia.org/wiki/Memoization
171
28
  */
172
29
  const memoizeFunction = (fn, argsToCacheKey) => {
@@ -1 +1 @@
1
- {"version":3,"file":"memoize-function.mjs","sources":["../../src/others/memoize-function.mts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0KG;MACU,eAAe,GAAG,CAK7B,EAAqB,EACrB,cAAiC,KACV;AACvB,IAAA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAQ;AAEjC,IAAA,OAAO,CAAC,GAAG,IAAO,KAAO;AACvB,QAAA,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC;AAEnC,QAAA,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;;AAEtB,YAAA,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAE;QAC5B;aAAO;AACL,YAAA,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;AAE1B,YAAA,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC;AAE1B,YAAA,OAAO,MAAM;QACf;AACF,IAAA,CAAC;AACH;;;;"}
1
+ {"version":3,"file":"memoize-function.mjs","sources":["../../src/others/memoize-function.mts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;MACU,eAAe,GAAG,CAK7B,EAAqB,EACrB,cAAiC,KACV;AACvB,IAAA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAQ;AAEjC,IAAA,OAAO,CAAC,GAAG,IAAO,KAAO;AACvB,QAAA,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC;AAEnC,QAAA,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;;AAEtB,YAAA,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAE;QAC5B;aAAO;AACL,YAAA,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;AAE1B,YAAA,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC;AAE1B,YAAA,OAAO,MAAM;QACf;AACF,IAAA,CAAC;AACH;;;;"}