ts-data-forge 1.0.0 → 1.0.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 (292) hide show
  1. package/README.md +1 -1
  2. package/dist/array/array-utils.d.mts +2617 -0
  3. package/dist/array/array-utils.d.mts.map +1 -0
  4. package/dist/array/array-utils.mjs +2915 -0
  5. package/dist/array/array-utils.mjs.map +1 -0
  6. package/dist/array/index.d.mts +3 -0
  7. package/dist/array/index.d.mts.map +1 -0
  8. package/dist/array/index.mjs +3 -0
  9. package/dist/array/index.mjs.map +1 -0
  10. package/dist/array/tuple-utils.d.mts +421 -0
  11. package/dist/array/tuple-utils.d.mts.map +1 -0
  12. package/dist/array/tuple-utils.mjs +391 -0
  13. package/dist/array/tuple-utils.mjs.map +1 -0
  14. package/dist/collections/imap-mapped.d.mts +445 -0
  15. package/dist/collections/imap-mapped.d.mts.map +1 -0
  16. package/dist/collections/imap-mapped.mjs +424 -0
  17. package/dist/collections/imap-mapped.mjs.map +1 -0
  18. package/dist/collections/imap.d.mts +359 -0
  19. package/dist/collections/imap.d.mts.map +1 -0
  20. package/dist/collections/imap.mjs +338 -0
  21. package/dist/collections/imap.mjs.map +1 -0
  22. package/dist/collections/index.d.mts +7 -0
  23. package/dist/collections/index.d.mts.map +1 -0
  24. package/dist/collections/index.mjs +7 -0
  25. package/dist/collections/index.mjs.map +1 -0
  26. package/dist/collections/iset-mapped.d.mts +576 -0
  27. package/dist/collections/iset-mapped.d.mts.map +1 -0
  28. package/dist/collections/iset-mapped.mjs +522 -0
  29. package/dist/collections/iset-mapped.mjs.map +1 -0
  30. package/dist/collections/iset.d.mts +426 -0
  31. package/dist/collections/iset.d.mts.map +1 -0
  32. package/dist/collections/iset.mjs +437 -0
  33. package/dist/collections/iset.mjs.map +1 -0
  34. package/dist/collections/queue.d.mts +190 -0
  35. package/dist/collections/queue.d.mts.map +1 -0
  36. package/dist/collections/queue.mjs +317 -0
  37. package/dist/collections/queue.mjs.map +1 -0
  38. package/dist/collections/stack.d.mts +210 -0
  39. package/dist/collections/stack.d.mts.map +1 -0
  40. package/dist/collections/stack.mjs +353 -0
  41. package/dist/collections/stack.mjs.map +1 -0
  42. package/dist/expect-type.d.mts +199 -0
  43. package/dist/expect-type.d.mts.map +1 -0
  44. package/dist/expect-type.mjs +201 -0
  45. package/dist/expect-type.mjs.map +1 -0
  46. package/dist/functional/index.d.mts +5 -0
  47. package/dist/functional/index.d.mts.map +1 -0
  48. package/dist/functional/index.mjs +5 -0
  49. package/dist/functional/index.mjs.map +1 -0
  50. package/dist/functional/match.d.mts +215 -0
  51. package/dist/functional/match.d.mts.map +1 -0
  52. package/dist/functional/match.mjs +139 -0
  53. package/dist/functional/match.mjs.map +1 -0
  54. package/dist/functional/optional.d.mts +517 -0
  55. package/dist/functional/optional.d.mts.map +1 -0
  56. package/dist/functional/optional.mjs +532 -0
  57. package/dist/functional/optional.mjs.map +1 -0
  58. package/dist/functional/pipe.d.mts +185 -0
  59. package/dist/functional/pipe.d.mts.map +1 -0
  60. package/dist/functional/pipe.mjs +129 -0
  61. package/dist/functional/pipe.mjs.map +1 -0
  62. package/dist/functional/result.d.mts +796 -0
  63. package/dist/functional/result.d.mts.map +1 -0
  64. package/dist/functional/result.mjs +844 -0
  65. package/dist/functional/result.mjs.map +1 -0
  66. package/dist/globals.d.mts +38 -0
  67. package/dist/guard/has-key.d.mts +100 -0
  68. package/dist/guard/has-key.d.mts.map +1 -0
  69. package/dist/guard/has-key.mjs +94 -0
  70. package/dist/guard/has-key.mjs.map +1 -0
  71. package/dist/guard/index.d.mts +8 -0
  72. package/dist/guard/index.d.mts.map +1 -0
  73. package/dist/guard/index.mjs +8 -0
  74. package/dist/guard/index.mjs.map +1 -0
  75. package/dist/guard/is-non-empty-string.d.mts +106 -0
  76. package/dist/guard/is-non-empty-string.d.mts.map +1 -0
  77. package/dist/guard/is-non-empty-string.mjs +108 -0
  78. package/dist/guard/is-non-empty-string.mjs.map +1 -0
  79. package/dist/guard/is-non-null-object.d.mts +105 -0
  80. package/dist/guard/is-non-null-object.d.mts.map +1 -0
  81. package/dist/guard/is-non-null-object.mjs +108 -0
  82. package/dist/guard/is-non-null-object.mjs.map +1 -0
  83. package/dist/guard/is-primitive.d.mts +146 -0
  84. package/dist/guard/is-primitive.d.mts.map +1 -0
  85. package/dist/guard/is-primitive.mjs +161 -0
  86. package/dist/guard/is-primitive.mjs.map +1 -0
  87. package/dist/guard/is-record.d.mts +151 -0
  88. package/dist/guard/is-record.d.mts.map +1 -0
  89. package/dist/guard/is-record.mjs +155 -0
  90. package/dist/guard/is-record.mjs.map +1 -0
  91. package/dist/guard/is-type.d.mts +430 -0
  92. package/dist/guard/is-type.d.mts.map +1 -0
  93. package/dist/guard/is-type.mjs +432 -0
  94. package/dist/guard/is-type.mjs.map +1 -0
  95. package/dist/guard/key-is-in.d.mts +158 -0
  96. package/dist/guard/key-is-in.d.mts.map +1 -0
  97. package/dist/guard/key-is-in.mjs +160 -0
  98. package/dist/guard/key-is-in.mjs.map +1 -0
  99. package/dist/index.d.mts +11 -0
  100. package/dist/index.d.mts.map +1 -0
  101. package/dist/index.mjs +61 -0
  102. package/dist/index.mjs.map +1 -0
  103. package/dist/iterator/index.d.mts +2 -0
  104. package/dist/iterator/index.d.mts.map +1 -0
  105. package/dist/iterator/index.mjs +2 -0
  106. package/dist/iterator/index.mjs.map +1 -0
  107. package/dist/iterator/range.d.mts +97 -0
  108. package/dist/iterator/range.d.mts.map +1 -0
  109. package/dist/iterator/range.mjs +130 -0
  110. package/dist/iterator/range.mjs.map +1 -0
  111. package/dist/json/index.d.mts +2 -0
  112. package/dist/json/index.d.mts.map +1 -0
  113. package/dist/json/index.mjs +2 -0
  114. package/dist/json/index.mjs.map +1 -0
  115. package/dist/json/json.d.mts +597 -0
  116. package/dist/json/json.d.mts.map +1 -0
  117. package/dist/json/json.mjs +687 -0
  118. package/dist/json/json.mjs.map +1 -0
  119. package/dist/number/branded-types/finite-number.d.mts +291 -0
  120. package/dist/number/branded-types/finite-number.d.mts.map +1 -0
  121. package/dist/number/branded-types/finite-number.mjs +296 -0
  122. package/dist/number/branded-types/finite-number.mjs.map +1 -0
  123. package/dist/number/branded-types/index.d.mts +27 -0
  124. package/dist/number/branded-types/index.d.mts.map +1 -0
  125. package/dist/number/branded-types/index.mjs +27 -0
  126. package/dist/number/branded-types/index.mjs.map +1 -0
  127. package/dist/number/branded-types/int.d.mts +242 -0
  128. package/dist/number/branded-types/int.d.mts.map +1 -0
  129. package/dist/number/branded-types/int.mjs +239 -0
  130. package/dist/number/branded-types/int.mjs.map +1 -0
  131. package/dist/number/branded-types/int16.d.mts +162 -0
  132. package/dist/number/branded-types/int16.d.mts.map +1 -0
  133. package/dist/number/branded-types/int16.mjs +141 -0
  134. package/dist/number/branded-types/int16.mjs.map +1 -0
  135. package/dist/number/branded-types/int32.d.mts +155 -0
  136. package/dist/number/branded-types/int32.d.mts.map +1 -0
  137. package/dist/number/branded-types/int32.mjs +142 -0
  138. package/dist/number/branded-types/int32.mjs.map +1 -0
  139. package/dist/number/branded-types/non-negative-finite-number.d.mts +165 -0
  140. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -0
  141. package/dist/number/branded-types/non-negative-finite-number.mjs +160 -0
  142. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -0
  143. package/dist/number/branded-types/non-negative-int16.d.mts +160 -0
  144. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -0
  145. package/dist/number/branded-types/non-negative-int16.mjs +138 -0
  146. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -0
  147. package/dist/number/branded-types/non-negative-int32.d.mts +156 -0
  148. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -0
  149. package/dist/number/branded-types/non-negative-int32.mjs +138 -0
  150. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -0
  151. package/dist/number/branded-types/non-zero-finite-number.d.mts +154 -0
  152. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -0
  153. package/dist/number/branded-types/non-zero-finite-number.mjs +160 -0
  154. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -0
  155. package/dist/number/branded-types/non-zero-int.d.mts +131 -0
  156. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -0
  157. package/dist/number/branded-types/non-zero-int.mjs +128 -0
  158. package/dist/number/branded-types/non-zero-int.mjs.map +1 -0
  159. package/dist/number/branded-types/non-zero-int16.d.mts +166 -0
  160. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -0
  161. package/dist/number/branded-types/non-zero-int16.mjs +145 -0
  162. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -0
  163. package/dist/number/branded-types/non-zero-int32.d.mts +158 -0
  164. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -0
  165. package/dist/number/branded-types/non-zero-int32.mjs +145 -0
  166. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -0
  167. package/dist/number/branded-types/non-zero-safe-int.d.mts +148 -0
  168. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -0
  169. package/dist/number/branded-types/non-zero-safe-int.mjs +145 -0
  170. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -0
  171. package/dist/number/branded-types/non-zero-uint16.d.mts +160 -0
  172. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -0
  173. package/dist/number/branded-types/non-zero-uint16.mjs +140 -0
  174. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -0
  175. package/dist/number/branded-types/non-zero-uint32.d.mts +156 -0
  176. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -0
  177. package/dist/number/branded-types/non-zero-uint32.mjs +140 -0
  178. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -0
  179. package/dist/number/branded-types/positive-finite-number.d.mts +171 -0
  180. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -0
  181. package/dist/number/branded-types/positive-finite-number.mjs +165 -0
  182. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -0
  183. package/dist/number/branded-types/positive-int.d.mts +270 -0
  184. package/dist/number/branded-types/positive-int.d.mts.map +1 -0
  185. package/dist/number/branded-types/positive-int.mjs +257 -0
  186. package/dist/number/branded-types/positive-int.mjs.map +1 -0
  187. package/dist/number/branded-types/positive-int16.d.mts +162 -0
  188. package/dist/number/branded-types/positive-int16.d.mts.map +1 -0
  189. package/dist/number/branded-types/positive-int16.mjs +139 -0
  190. package/dist/number/branded-types/positive-int16.mjs.map +1 -0
  191. package/dist/number/branded-types/positive-int32.d.mts +158 -0
  192. package/dist/number/branded-types/positive-int32.d.mts.map +1 -0
  193. package/dist/number/branded-types/positive-int32.mjs +139 -0
  194. package/dist/number/branded-types/positive-int32.mjs.map +1 -0
  195. package/dist/number/branded-types/positive-safe-int.d.mts +152 -0
  196. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -0
  197. package/dist/number/branded-types/positive-safe-int.mjs +138 -0
  198. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -0
  199. package/dist/number/branded-types/positive-uint16.d.mts +160 -0
  200. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -0
  201. package/dist/number/branded-types/positive-uint16.mjs +139 -0
  202. package/dist/number/branded-types/positive-uint16.mjs.map +1 -0
  203. package/dist/number/branded-types/positive-uint32.d.mts +156 -0
  204. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -0
  205. package/dist/number/branded-types/positive-uint32.mjs +139 -0
  206. package/dist/number/branded-types/positive-uint32.mjs.map +1 -0
  207. package/dist/number/branded-types/safe-int.d.mts +243 -0
  208. package/dist/number/branded-types/safe-int.d.mts.map +1 -0
  209. package/dist/number/branded-types/safe-int.mjs +240 -0
  210. package/dist/number/branded-types/safe-int.mjs.map +1 -0
  211. package/dist/number/branded-types/safe-uint.d.mts +151 -0
  212. package/dist/number/branded-types/safe-uint.d.mts.map +1 -0
  213. package/dist/number/branded-types/safe-uint.mjs +138 -0
  214. package/dist/number/branded-types/safe-uint.mjs.map +1 -0
  215. package/dist/number/branded-types/uint.d.mts +144 -0
  216. package/dist/number/branded-types/uint.d.mts.map +1 -0
  217. package/dist/number/branded-types/uint.mjs +132 -0
  218. package/dist/number/branded-types/uint.mjs.map +1 -0
  219. package/dist/number/branded-types/uint16.d.mts +157 -0
  220. package/dist/number/branded-types/uint16.d.mts.map +1 -0
  221. package/dist/number/branded-types/uint16.mjs +137 -0
  222. package/dist/number/branded-types/uint16.mjs.map +1 -0
  223. package/dist/number/branded-types/uint32.d.mts +185 -0
  224. package/dist/number/branded-types/uint32.d.mts.map +1 -0
  225. package/dist/number/branded-types/uint32.mjs +169 -0
  226. package/dist/number/branded-types/uint32.mjs.map +1 -0
  227. package/dist/number/enum/index.d.mts +3 -0
  228. package/dist/number/enum/index.d.mts.map +1 -0
  229. package/dist/number/enum/index.mjs +3 -0
  230. package/dist/number/enum/index.mjs.map +1 -0
  231. package/dist/number/enum/int8.d.mts +202 -0
  232. package/dist/number/enum/int8.d.mts.map +1 -0
  233. package/dist/number/enum/int8.mjs +296 -0
  234. package/dist/number/enum/int8.mjs.map +1 -0
  235. package/dist/number/enum/uint8.d.mts +128 -0
  236. package/dist/number/enum/uint8.d.mts.map +1 -0
  237. package/dist/number/enum/uint8.mjs +251 -0
  238. package/dist/number/enum/uint8.mjs.map +1 -0
  239. package/dist/number/index.d.mts +5 -0
  240. package/dist/number/index.d.mts.map +1 -0
  241. package/dist/number/index.mjs +31 -0
  242. package/dist/number/index.mjs.map +1 -0
  243. package/dist/number/num.d.mts +515 -0
  244. package/dist/number/num.d.mts.map +1 -0
  245. package/dist/number/num.mjs +513 -0
  246. package/dist/number/num.mjs.map +1 -0
  247. package/dist/number/refined-number-utils.d.mts +191 -0
  248. package/dist/number/refined-number-utils.d.mts.map +1 -0
  249. package/dist/number/refined-number-utils.mjs +179 -0
  250. package/dist/number/refined-number-utils.mjs.map +1 -0
  251. package/dist/object/index.d.mts +2 -0
  252. package/dist/object/index.d.mts.map +1 -0
  253. package/dist/object/index.mjs +2 -0
  254. package/dist/object/index.mjs.map +1 -0
  255. package/dist/object/object.d.mts +296 -0
  256. package/dist/object/object.d.mts.map +1 -0
  257. package/dist/object/object.mjs +295 -0
  258. package/dist/object/object.mjs.map +1 -0
  259. package/dist/others/cast-mutable.d.mts +110 -0
  260. package/dist/others/cast-mutable.d.mts.map +1 -0
  261. package/dist/others/cast-mutable.mjs +114 -0
  262. package/dist/others/cast-mutable.mjs.map +1 -0
  263. package/dist/others/cast-readonly.d.mts +189 -0
  264. package/dist/others/cast-readonly.d.mts.map +1 -0
  265. package/dist/others/cast-readonly.mjs +193 -0
  266. package/dist/others/cast-readonly.mjs.map +1 -0
  267. package/dist/others/if-then.d.mts +98 -0
  268. package/dist/others/if-then.d.mts.map +1 -0
  269. package/dist/others/if-then.mjs +100 -0
  270. package/dist/others/if-then.mjs.map +1 -0
  271. package/dist/others/index.d.mts +8 -0
  272. package/dist/others/index.d.mts.map +1 -0
  273. package/dist/others/index.mjs +8 -0
  274. package/dist/others/index.mjs.map +1 -0
  275. package/dist/others/map-nullable.d.mts +151 -0
  276. package/dist/others/map-nullable.d.mts.map +1 -0
  277. package/dist/others/map-nullable.mjs +159 -0
  278. package/dist/others/map-nullable.mjs.map +1 -0
  279. package/dist/others/memoize-function.d.mts +173 -0
  280. package/dist/others/memoize-function.d.mts.map +1 -0
  281. package/dist/others/memoize-function.mjs +189 -0
  282. package/dist/others/memoize-function.mjs.map +1 -0
  283. package/dist/others/tuple.d.mts +159 -0
  284. package/dist/others/tuple.d.mts.map +1 -0
  285. package/dist/others/tuple.mjs +161 -0
  286. package/dist/others/tuple.mjs.map +1 -0
  287. package/dist/others/unknown-to-string.d.mts +180 -0
  288. package/dist/others/unknown-to-string.d.mts.map +1 -0
  289. package/dist/others/unknown-to-string.mjs +211 -0
  290. package/dist/others/unknown-to-string.mjs.map +1 -0
  291. package/dist/tsconfig.json +1 -0
  292. package/package.json +16 -14
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Implements the logical implication (if-then) operator.
3
+ *
4
+ * Returns `true` if the antecedent is `false` or the consequent is `true`.
5
+ * In logical terms: `antecedent → consequent` is equivalent to `¬antecedent ∨ consequent`.
6
+ *
7
+ * **Truth table:**
8
+ * - `true → true` = `true` (valid implication)
9
+ * - `true → false` = `false` (invalid implication)
10
+ * - `false → true` = `true` (vacuously true)
11
+ * - `false → false` = `true` (vacuously true)
12
+ *
13
+ * @param antecedent - The condition (if part)
14
+ * @param consequent - The result that should hold if the condition is true (then part)
15
+ * @returns `true` if the implication holds, `false` otherwise
16
+ *
17
+ * @example Basic truth table demonstration
18
+ * ```typescript
19
+ * ifThen(true, true); // true (if true then true = true)
20
+ * ifThen(true, false); // false (if true then false = false)
21
+ * ifThen(false, true); // true (if false then true = true - vacuously true)
22
+ * ifThen(false, false); // true (if false then false = true - vacuously true)
23
+ * ```
24
+ *
25
+ * @example Validation logic - "if required then must have value"
26
+ * ```typescript
27
+ * function validateField(value: string, isRequired: boolean): boolean {
28
+ * const hasValue = value.trim().length > 0;
29
+ * return ifThen(isRequired, hasValue);
30
+ * }
31
+ *
32
+ * validateField('hello', true); // true (required and has value)
33
+ * validateField('', true); // false (required but no value)
34
+ * validateField('', false); // true (not required, so valid)
35
+ * validateField('hello', false); // true (not required, but has value is fine)
36
+ * ```
37
+ *
38
+ * @example Access control - "if admin then has all permissions"
39
+ * ```typescript
40
+ * function checkPermission(user: User, permission: string): boolean {
41
+ * const isAdmin = user.role === 'admin';
42
+ * const hasPermission = user.permissions.includes(permission);
43
+ *
44
+ * // Admin must have all permissions
45
+ * return ifThen(isAdmin, hasPermission);
46
+ * }
47
+ *
48
+ * const adminUser = { role: 'admin', permissions: ['read', 'write'] };
49
+ * checkPermission(adminUser, 'delete'); // false (admin without delete permission = invalid)
50
+ *
51
+ * const regularUser = { role: 'user', permissions: ['read'] };
52
+ * checkPermission(regularUser, 'delete'); // true (non-admin without permission is valid)
53
+ * ```
54
+ *
55
+ * @example Contract validation - "if premium then features enabled"
56
+ * ```typescript
57
+ * interface Subscription {
58
+ * isPremium: boolean;
59
+ * features: {
60
+ * advancedAnalytics: boolean;
61
+ * unlimitedStorage: boolean;
62
+ * prioritySupport: boolean;
63
+ * };
64
+ * }
65
+ *
66
+ * function validateSubscription(sub: Subscription): boolean {
67
+ * // If premium, then all premium features must be enabled
68
+ * return ifThen(sub.isPremium,
69
+ * sub.features.advancedAnalytics &&
70
+ * sub.features.unlimitedStorage &&
71
+ * sub.features.prioritySupport
72
+ * );
73
+ * }
74
+ * ```
75
+ *
76
+ * @example Chaining multiple implications
77
+ * ```typescript
78
+ * // "If A then B" AND "If B then C"
79
+ * function validateChain(a: boolean, b: boolean, c: boolean): boolean {
80
+ * return ifThen(a, b) && ifThen(b, c);
81
+ * }
82
+ *
83
+ * validateChain(true, true, true); // true (valid chain)
84
+ * validateChain(true, false, true); // false (breaks at first implication)
85
+ * validateChain(false, false, false); // true (vacuously true chain)
86
+ * ```
87
+ *
88
+ * @example Negation patterns
89
+ * ```typescript
90
+ * // "If not expired then valid" is equivalent to "expired OR valid"
91
+ * const isExpired = Date.now() > expiryDate;
92
+ * const isValid = checkValidity();
93
+ * const result = ifThen(!isExpired, isValid);
94
+ * // Same as: isExpired || isValid
95
+ * ```
96
+ */
97
+ export declare const ifThen: (antecedent: boolean, consequent: boolean) => boolean;
98
+ //# sourceMappingURL=if-then.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if-then.d.mts","sourceRoot":"","sources":["../../src/others/if-then.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+FG;AACH,eAAO,MAAM,MAAM,GAAI,YAAY,OAAO,EAAE,YAAY,OAAO,KAAG,OACvC,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Implements the logical implication (if-then) operator.
3
+ *
4
+ * Returns `true` if the antecedent is `false` or the consequent is `true`.
5
+ * In logical terms: `antecedent → consequent` is equivalent to `¬antecedent ∨ consequent`.
6
+ *
7
+ * **Truth table:**
8
+ * - `true → true` = `true` (valid implication)
9
+ * - `true → false` = `false` (invalid implication)
10
+ * - `false → true` = `true` (vacuously true)
11
+ * - `false → false` = `true` (vacuously true)
12
+ *
13
+ * @param antecedent - The condition (if part)
14
+ * @param consequent - The result that should hold if the condition is true (then part)
15
+ * @returns `true` if the implication holds, `false` otherwise
16
+ *
17
+ * @example Basic truth table demonstration
18
+ * ```typescript
19
+ * ifThen(true, true); // true (if true then true = true)
20
+ * ifThen(true, false); // false (if true then false = false)
21
+ * ifThen(false, true); // true (if false then true = true - vacuously true)
22
+ * ifThen(false, false); // true (if false then false = true - vacuously true)
23
+ * ```
24
+ *
25
+ * @example Validation logic - "if required then must have value"
26
+ * ```typescript
27
+ * function validateField(value: string, isRequired: boolean): boolean {
28
+ * const hasValue = value.trim().length > 0;
29
+ * return ifThen(isRequired, hasValue);
30
+ * }
31
+ *
32
+ * validateField('hello', true); // true (required and has value)
33
+ * validateField('', true); // false (required but no value)
34
+ * validateField('', false); // true (not required, so valid)
35
+ * validateField('hello', false); // true (not required, but has value is fine)
36
+ * ```
37
+ *
38
+ * @example Access control - "if admin then has all permissions"
39
+ * ```typescript
40
+ * function checkPermission(user: User, permission: string): boolean {
41
+ * const isAdmin = user.role === 'admin';
42
+ * const hasPermission = user.permissions.includes(permission);
43
+ *
44
+ * // Admin must have all permissions
45
+ * return ifThen(isAdmin, hasPermission);
46
+ * }
47
+ *
48
+ * const adminUser = { role: 'admin', permissions: ['read', 'write'] };
49
+ * checkPermission(adminUser, 'delete'); // false (admin without delete permission = invalid)
50
+ *
51
+ * const regularUser = { role: 'user', permissions: ['read'] };
52
+ * checkPermission(regularUser, 'delete'); // true (non-admin without permission is valid)
53
+ * ```
54
+ *
55
+ * @example Contract validation - "if premium then features enabled"
56
+ * ```typescript
57
+ * interface Subscription {
58
+ * isPremium: boolean;
59
+ * features: {
60
+ * advancedAnalytics: boolean;
61
+ * unlimitedStorage: boolean;
62
+ * prioritySupport: boolean;
63
+ * };
64
+ * }
65
+ *
66
+ * function validateSubscription(sub: Subscription): boolean {
67
+ * // If premium, then all premium features must be enabled
68
+ * return ifThen(sub.isPremium,
69
+ * sub.features.advancedAnalytics &&
70
+ * sub.features.unlimitedStorage &&
71
+ * sub.features.prioritySupport
72
+ * );
73
+ * }
74
+ * ```
75
+ *
76
+ * @example Chaining multiple implications
77
+ * ```typescript
78
+ * // "If A then B" AND "If B then C"
79
+ * function validateChain(a: boolean, b: boolean, c: boolean): boolean {
80
+ * return ifThen(a, b) && ifThen(b, c);
81
+ * }
82
+ *
83
+ * validateChain(true, true, true); // true (valid chain)
84
+ * validateChain(true, false, true); // false (breaks at first implication)
85
+ * validateChain(false, false, false); // true (vacuously true chain)
86
+ * ```
87
+ *
88
+ * @example Negation patterns
89
+ * ```typescript
90
+ * // "If not expired then valid" is equivalent to "expired OR valid"
91
+ * const isExpired = Date.now() > expiryDate;
92
+ * const isValid = checkValidity();
93
+ * const result = ifThen(!isExpired, isValid);
94
+ * // Same as: isExpired || isValid
95
+ * ```
96
+ */
97
+ const ifThen = (antecedent, consequent) => !antecedent || consequent;
98
+
99
+ export { ifThen };
100
+ //# sourceMappingURL=if-then.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if-then.mjs","sources":["../../src/others/if-then.mts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FG;AACI,MAAM,MAAM,GAAG,CAAC,UAAmB,EAAE,UAAmB,KAC7D,CAAC,UAAU,IAAI;;;;"}
@@ -0,0 +1,8 @@
1
+ export * from './cast-mutable.mjs';
2
+ export * from './cast-readonly.mjs';
3
+ export * from './if-then.mjs';
4
+ export * from './map-nullable.mjs';
5
+ export * from './memoize-function.mjs';
6
+ export * from './tuple.mjs';
7
+ export * from './unknown-to-string.mjs';
8
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/others/index.mts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { castDeepMutable, castMutable } from './cast-mutable.mjs';
2
+ export { castDeepReadonly, castReadonly } from './cast-readonly.mjs';
3
+ export { ifThen } from './if-then.mjs';
4
+ export { mapNullable } from './map-nullable.mjs';
5
+ export { memoizeFunction } from './memoize-function.mjs';
6
+ export { tp } from './tuple.mjs';
7
+ export { unknownToString } from './unknown-to-string.mjs';
8
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,151 @@
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`.
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.
8
+ *
9
+ * @template A - The type of the input value (excluding null/undefined)
10
+ * @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
+ *
142
+ * @see Optional - For more complex optional value handling
143
+ * @see Result - For error handling with detailed error information
144
+ */
145
+ export declare const mapNullable: MapNullableFnOverload;
146
+ type MapNullableFnOverload = {
147
+ <const A, const B>(value: A | null | undefined, mapFn: (v: A) => B): B | undefined;
148
+ <const A, const B>(mapFn: (v: A) => B): (value: A | null | undefined) => B | undefined;
149
+ };
150
+ export {};
151
+ //# sourceMappingURL=map-nullable.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-nullable.d.mts","sourceRoot":"","sources":["../../src/others/map-nullable.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+IG;AACH,eAAO,MAAM,WAAW,EAAE,qBAeC,CAAC;AAE5B,KAAK,qBAAqB,GAAG;IAC3B,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EACf,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3B,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACjB,CAAC,GAAG,SAAS,CAAC;IAGjB,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EACf,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACjB,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS,CAAC;CACnD,CAAC"}
@@ -0,0 +1,159 @@
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`.
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.
8
+ *
9
+ * @template A - The type of the input value (excluding null/undefined)
10
+ * @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
+ *
142
+ * @see Optional - For more complex optional value handling
143
+ * @see Result - For error handling with detailed error information
144
+ */
145
+ const mapNullable = ((...args) => {
146
+ switch (args.length) {
147
+ case 2: {
148
+ const [value, mapFn] = args;
149
+ return value == null ? undefined : mapFn(value);
150
+ }
151
+ case 1: {
152
+ const [mapFn] = args;
153
+ return (value) => mapNullable(value, mapFn);
154
+ }
155
+ }
156
+ });
157
+
158
+ export { mapNullable };
159
+ //# sourceMappingURL=map-nullable.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-nullable.mjs","sources":["../../src/others/map-nullable.mts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+IG;MACU,WAAW,IAA2B,CACjD,GAAG,IAE8B,KACqC;AACtE,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;;QAEjD,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI;YACpB,OAAO,CAAC,KAA2B,KAAK,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC;;;AAGvE,CAAC;;;;"}