ts-data-forge 10.0.0 → 11.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 (249) hide show
  1. package/dist/array/impl/array-utils-creation.d.mts +3 -3
  2. package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
  3. package/dist/array/impl/array-utils-creation.mjs.map +1 -1
  4. package/dist/array/impl/array-utils-element-access.d.mts +4 -4
  5. package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
  6. package/dist/{guard/as-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-cast.d.mts} +9 -9
  7. package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -0
  8. package/dist/{guard/as-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-cast.mjs} +2 -2
  9. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -0
  10. package/dist/{guard/is-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-guard.d.mts} +13 -13
  11. package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -0
  12. package/dist/{guard/is-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-guard.mjs} +1 -1
  13. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -0
  14. package/dist/array/impl/array-utils-modification.d.mts +9 -9
  15. package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
  16. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  17. package/dist/array/impl/array-utils-reducing-value.d.mts +9 -9
  18. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  19. package/dist/array/impl/array-utils-size.d.mts +3 -3
  20. package/dist/array/impl/array-utils-size.mjs.map +1 -1
  21. package/dist/array/impl/array-utils-slicing.d.mts +9 -9
  22. package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
  23. package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
  24. package/dist/array/impl/array-utils-transformation.d.mts +16 -10
  25. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  26. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  27. package/dist/array/impl/index.d.mts +2 -0
  28. package/dist/array/impl/index.d.mts.map +1 -1
  29. package/dist/array/impl/index.mjs +2 -0
  30. package/dist/array/impl/index.mjs.map +1 -1
  31. package/dist/entry-point.mjs +1 -3
  32. package/dist/entry-point.mjs.map +1 -1
  33. package/dist/guard/index.d.mts +0 -3
  34. package/dist/guard/index.d.mts.map +1 -1
  35. package/dist/guard/index.mjs +0 -3
  36. package/dist/guard/index.mjs.map +1 -1
  37. package/dist/index.d.mts +1 -0
  38. package/dist/index.d.mts.map +1 -1
  39. package/dist/index.mjs +1 -3
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/number/branded-types/finite-number.d.mts +47 -61
  42. package/dist/number/branded-types/finite-number.d.mts.map +1 -1
  43. package/dist/number/branded-types/finite-number.mjs +37 -41
  44. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  45. package/dist/number/branded-types/int.d.mts +40 -46
  46. package/dist/number/branded-types/int.d.mts.map +1 -1
  47. package/dist/number/branded-types/int.mjs +29 -31
  48. package/dist/number/branded-types/int.mjs.map +1 -1
  49. package/dist/number/branded-types/int16.d.mts +65 -58
  50. package/dist/number/branded-types/int16.d.mts.map +1 -1
  51. package/dist/number/branded-types/int16.mjs +49 -45
  52. package/dist/number/branded-types/int16.mjs.map +1 -1
  53. package/dist/number/branded-types/int32.d.mts +65 -58
  54. package/dist/number/branded-types/int32.d.mts.map +1 -1
  55. package/dist/number/branded-types/int32.mjs +49 -45
  56. package/dist/number/branded-types/int32.mjs.map +1 -1
  57. package/dist/number/branded-types/negative-finite-number.d.mts +68 -59
  58. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  59. package/dist/number/branded-types/negative-finite-number.mjs +52 -46
  60. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  61. package/dist/number/branded-types/negative-int.d.mts +60 -48
  62. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  63. package/dist/number/branded-types/negative-int.mjs +40 -36
  64. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  65. package/dist/number/branded-types/negative-safe-int.d.mts +57 -56
  66. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  67. package/dist/number/branded-types/negative-safe-int.mjs +40 -41
  68. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  69. package/dist/number/branded-types/non-negative-finite-number.d.mts +74 -64
  70. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  71. package/dist/number/branded-types/non-negative-finite-number.mjs +58 -51
  72. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  73. package/dist/number/branded-types/non-negative-int16.d.mts +64 -57
  74. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  75. package/dist/number/branded-types/non-negative-int16.mjs +47 -43
  76. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  77. package/dist/number/branded-types/non-negative-int32.d.mts +64 -58
  78. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  79. package/dist/number/branded-types/non-negative-int32.mjs +47 -44
  80. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  81. package/dist/number/branded-types/non-positive-finite-number.d.mts +64 -54
  82. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  83. package/dist/number/branded-types/non-positive-finite-number.mjs +48 -41
  84. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  85. package/dist/number/branded-types/non-positive-int.d.mts +41 -146
  86. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  87. package/dist/number/branded-types/non-positive-int.mjs +27 -107
  88. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  89. package/dist/number/branded-types/non-positive-safe-int.d.mts +54 -53
  90. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  91. package/dist/number/branded-types/non-positive-safe-int.mjs +37 -39
  92. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  93. package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
  94. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
  95. package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
  96. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  97. package/dist/number/branded-types/non-zero-int.d.mts +51 -38
  98. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
  99. package/dist/number/branded-types/non-zero-int.mjs +31 -27
  100. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  101. package/dist/number/branded-types/non-zero-int16.d.mts +52 -53
  102. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  103. package/dist/number/branded-types/non-zero-int16.mjs +36 -39
  104. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  105. package/dist/number/branded-types/non-zero-int32.d.mts +52 -54
  106. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  107. package/dist/number/branded-types/non-zero-int32.mjs +36 -40
  108. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  109. package/dist/number/branded-types/non-zero-safe-int.d.mts +53 -54
  110. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  111. package/dist/number/branded-types/non-zero-safe-int.mjs +36 -40
  112. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  113. package/dist/number/branded-types/non-zero-uint16.d.mts +52 -53
  114. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  115. package/dist/number/branded-types/non-zero-uint16.mjs +35 -39
  116. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  117. package/dist/number/branded-types/non-zero-uint32.d.mts +52 -53
  118. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  119. package/dist/number/branded-types/non-zero-uint32.mjs +35 -39
  120. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  121. package/dist/number/branded-types/positive-finite-number.d.mts +74 -63
  122. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  123. package/dist/number/branded-types/positive-finite-number.mjs +58 -50
  124. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  125. package/dist/number/branded-types/positive-int.d.mts +46 -68
  126. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  127. package/dist/number/branded-types/positive-int.mjs +34 -49
  128. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  129. package/dist/number/branded-types/positive-int16.d.mts +61 -57
  130. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  131. package/dist/number/branded-types/positive-int16.mjs +44 -43
  132. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  133. package/dist/number/branded-types/positive-int32.d.mts +61 -57
  134. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  135. package/dist/number/branded-types/positive-int32.mjs +44 -43
  136. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  137. package/dist/number/branded-types/positive-safe-int.d.mts +62 -57
  138. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  139. package/dist/number/branded-types/positive-safe-int.mjs +45 -43
  140. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  141. package/dist/number/branded-types/positive-uint16.d.mts +61 -57
  142. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  143. package/dist/number/branded-types/positive-uint16.mjs +44 -43
  144. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  145. package/dist/number/branded-types/positive-uint32.d.mts +61 -58
  146. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  147. package/dist/number/branded-types/positive-uint32.mjs +44 -44
  148. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  149. package/dist/number/branded-types/safe-int.d.mts +43 -62
  150. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  151. package/dist/number/branded-types/safe-int.mjs +35 -42
  152. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  153. package/dist/number/branded-types/safe-uint.d.mts +62 -57
  154. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  155. package/dist/number/branded-types/safe-uint.mjs +46 -44
  156. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  157. package/dist/number/branded-types/uint.d.mts +63 -50
  158. package/dist/number/branded-types/uint.d.mts.map +1 -1
  159. package/dist/number/branded-types/uint.mjs +42 -39
  160. package/dist/number/branded-types/uint.mjs.map +1 -1
  161. package/dist/number/branded-types/uint16.d.mts +60 -58
  162. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  163. package/dist/number/branded-types/uint16.mjs +44 -43
  164. package/dist/number/branded-types/uint16.mjs.map +1 -1
  165. package/dist/number/branded-types/uint32.d.mts +59 -55
  166. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  167. package/dist/number/branded-types/uint32.mjs +42 -42
  168. package/dist/number/branded-types/uint32.mjs.map +1 -1
  169. package/dist/number/enum/int8.d.mts +56 -65
  170. package/dist/number/enum/int8.d.mts.map +1 -1
  171. package/dist/number/enum/int8.mjs +44 -43
  172. package/dist/number/enum/int8.mjs.map +1 -1
  173. package/dist/number/enum/uint8.d.mts +60 -58
  174. package/dist/number/enum/uint8.d.mts.map +1 -1
  175. package/dist/number/enum/uint8.mjs +44 -43
  176. package/dist/number/enum/uint8.mjs.map +1 -1
  177. package/dist/string/index.d.mts +2 -0
  178. package/dist/string/index.d.mts.map +1 -0
  179. package/dist/string/index.mjs +2 -0
  180. package/dist/string/index.mjs.map +1 -0
  181. package/dist/string/str.d.mts +273 -0
  182. package/dist/string/str.d.mts.map +1 -0
  183. package/dist/string/str.mjs +42 -0
  184. package/dist/string/str.mjs.map +1 -0
  185. package/package.json +31 -92
  186. package/src/array/impl/array-utils-creation.mts +2 -1
  187. package/src/array/impl/array-utils-element-access.mts +3 -3
  188. package/src/array/impl/array-utils-element-access.test.mts +3 -3
  189. package/src/{guard/as-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-cast.mts} +9 -9
  190. package/src/{guard/as-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-cast.test.mts} +2 -2
  191. package/src/{guard/is-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-guard.mts} +12 -12
  192. package/src/{guard/is-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-guard.test.mts} +2 -2
  193. package/src/array/impl/array-utils-modification.mts +9 -8
  194. package/src/array/impl/array-utils-modification.test.mts +6 -1
  195. package/src/array/impl/array-utils-reducing-value.mts +9 -9
  196. package/src/array/impl/array-utils-size.mts +2 -2
  197. package/src/array/impl/array-utils-slicing.mts +24 -13
  198. package/src/array/impl/array-utils-transformation.mts +18 -12
  199. package/src/array/impl/array-utils-transformation.test.mts +12 -12
  200. package/src/array/impl/index.mts +2 -0
  201. package/src/guard/index.mts +0 -3
  202. package/src/index.mts +1 -0
  203. package/src/number/branded-types/finite-number.mts +47 -61
  204. package/src/number/branded-types/int.mts +40 -46
  205. package/src/number/branded-types/int16.mts +65 -58
  206. package/src/number/branded-types/int32.mts +65 -58
  207. package/src/number/branded-types/negative-finite-number.mts +68 -68
  208. package/src/number/branded-types/negative-int.mts +60 -57
  209. package/src/number/branded-types/negative-safe-int.mts +57 -65
  210. package/src/number/branded-types/non-negative-finite-number.mts +74 -64
  211. package/src/number/branded-types/non-negative-int16.mts +64 -57
  212. package/src/number/branded-types/non-negative-int32.mts +64 -58
  213. package/src/number/branded-types/non-positive-finite-number.mts +64 -54
  214. package/src/number/branded-types/non-positive-int.mts +41 -146
  215. package/src/number/branded-types/non-positive-safe-int.mts +54 -53
  216. package/src/number/branded-types/non-zero-finite-number.mts +62 -51
  217. package/src/number/branded-types/non-zero-int.mts +51 -38
  218. package/src/number/branded-types/non-zero-int16.mts +52 -53
  219. package/src/number/branded-types/non-zero-int32.mts +52 -54
  220. package/src/number/branded-types/non-zero-safe-int.mts +53 -54
  221. package/src/number/branded-types/non-zero-uint16.mts +52 -53
  222. package/src/number/branded-types/non-zero-uint32.mts +52 -53
  223. package/src/number/branded-types/positive-finite-number.mts +74 -63
  224. package/src/number/branded-types/positive-int.mts +46 -68
  225. package/src/number/branded-types/positive-int16.mts +61 -57
  226. package/src/number/branded-types/positive-int32.mts +61 -57
  227. package/src/number/branded-types/positive-safe-int.mts +62 -57
  228. package/src/number/branded-types/positive-uint16.mts +61 -57
  229. package/src/number/branded-types/positive-uint32.mts +61 -58
  230. package/src/number/branded-types/safe-int.mts +43 -62
  231. package/src/number/branded-types/safe-uint.mts +62 -57
  232. package/src/number/branded-types/uint.mts +63 -50
  233. package/src/number/branded-types/uint16.mts +60 -58
  234. package/src/number/branded-types/uint32.mts +59 -55
  235. package/src/number/enum/int8.mts +56 -65
  236. package/src/number/enum/uint8.mts +60 -58
  237. package/src/string/index.mts +1 -0
  238. package/src/string/str.mts +371 -0
  239. package/src/string/str.test.mts +215 -0
  240. package/dist/guard/as-length-bounded-array.d.mts.map +0 -1
  241. package/dist/guard/as-length-bounded-array.mjs.map +0 -1
  242. package/dist/guard/is-length-bounded-array.d.mts.map +0 -1
  243. package/dist/guard/is-length-bounded-array.mjs.map +0 -1
  244. package/dist/guard/is-length-bounded-string.d.mts +0 -163
  245. package/dist/guard/is-length-bounded-string.d.mts.map +0 -1
  246. package/dist/guard/is-length-bounded-string.mjs +0 -7
  247. package/dist/guard/is-length-bounded-string.mjs.map +0 -1
  248. package/src/guard/is-length-bounded-string.mts +0 -199
  249. package/src/guard/is-length-bounded-string.test.mts +0 -170
@@ -24,151 +24,71 @@ const NonPositiveInt = {
24
24
  /**
25
25
  * Type guard that checks if a value is a non-positive integer.
26
26
  *
27
- * @example
28
- *
29
- * ```ts
30
- * const value: number = -42;
31
- *
32
- * if (NonPositiveInt.is(value)) {
33
- * // value is now typed as NonPositiveInt
34
- * const debt = value;
35
- * }
36
- * ```
37
- *
38
27
  * @param value - The value to check
39
28
  * @returns `true` if the value is a non-positive integer, `false` otherwise
29
+ * @see {@link isNonPositiveInt} for usage examples
40
30
  */
41
31
  is,
42
32
  /**
43
- * The maximum value for a non-positive integer.
44
- *
45
- * @readonly
33
+ * The largest value representable as `NonPositiveInt`.
46
34
  */
47
35
  MAX_VALUE,
48
36
  /**
49
- * Returns the smaller of two non-positive integers.
50
- *
51
- * Since non-positive integers range from negative infinity to 0, the smaller
52
- * value is the one further from zero (more negative).
37
+ * Returns the smallest of the given non-positive integers.
53
38
  *
54
- * @example
55
- *
56
- * ```ts
57
- * const result = NonPositiveInt.min(-5, -10);
58
- *
59
- * assert.strictEqual(result, -10);
60
- * ```
61
- *
62
- * @param a - The first non-positive integer
63
- * @param b - The second non-positive integer
64
- * @returns The minimum value as a non-positive integer
39
+ * @param values - The non-positive integers to compare (at least one required)
40
+ * @returns The smallest value as a `NonPositiveInt`
65
41
  */
66
42
  min: min_,
67
43
  /**
68
- * Returns the larger of two non-positive integers.
69
- *
70
- * Since non-positive integers range from negative infinity to 0, the larger
71
- * value is the one closer to zero (less negative).
72
- *
73
- * @example
74
- *
75
- * ```ts
76
- * const result = NonPositiveInt.max(-5, -10);
77
- *
78
- * assert.strictEqual(result, -5);
79
- * ```
44
+ * Returns the largest of the given non-positive integers.
80
45
  *
81
- * @param a - The first non-positive integer
82
- * @param b - The second non-positive integer
83
- * @returns The maximum value as a non-positive integer
46
+ * @param values - The non-positive integers to compare (at least one required)
47
+ * @returns The largest value as a `NonPositiveInt`
84
48
  */
85
49
  max: max_,
86
50
  /**
87
- * Clamps a number to the non-positive integer range.
88
- *
89
- * Any positive value is clamped to 0 (the maximum non-positive integer).
90
- * Negative values are preserved as long as they are valid integers.
91
- *
92
- * @example
51
+ * Clamps a `number` into the `NonPositiveInt` range, rounding to the nearest
52
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
93
53
  *
94
- * ```ts
95
- * assert.strictEqual(NonPositiveInt.clamp(5), 0);
96
- *
97
- * assert.strictEqual(NonPositiveInt.clamp(-5), -5);
98
- *
99
- * assert.strictEqual(NonPositiveInt.clamp(0), 0);
100
- * ```
101
- *
102
- * @param value - The number to clamp
103
- * @returns The value clamped to the non-positive integer range
54
+ * @param value - The value to clamp
55
+ * @returns The clamped value as a `NonPositiveInt`
104
56
  */
105
57
  clamp,
106
58
  /**
107
- * Generates a random non-positive integer value.
108
- *
109
- * @example
110
- *
111
- * ```ts
112
- * const randomValue = NonPositiveInt.random();
59
+ * Generates a random `NonPositiveInt` within the given range.
113
60
  *
114
- * assert.isTrue(NonPositiveInt.is(randomValue));
115
- * ```
61
+ * The range is inclusive on both ends.
116
62
  *
117
- * @returns A random non-positive integer
63
+ * @param min - The minimum value (inclusive)
64
+ * @param max - The maximum value (inclusive)
65
+ * @returns A random `NonPositiveInt` in `[min, max]`
118
66
  */
119
67
  random,
120
68
  /**
121
- * Raises a non-positive integer to the power of another non-positive integer.
122
- *
123
- * The result is clamped to the non-positive integer range.
124
- *
125
- * @example
126
- *
127
- * ```ts
128
- * const result = NonPositiveInt.pow(-2, -1);
129
- * ```
69
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveInt`
70
+ * (floored to an integer).
130
71
  *
131
72
  * @param a - The base non-positive integer
132
73
  * @param b - The exponent non-positive integer
133
- * @returns `a ** b` clamped to the non-positive integer range
74
+ * @returns `a ** b` as a `NonPositiveInt`
134
75
  */
135
76
  pow,
136
77
  /**
137
- * Adds two non-positive integers.
138
- *
139
- * The result is clamped to the non-positive integer range. If the sum is
140
- * positive, it is clamped to 0.
141
- *
142
- * @example
143
- *
144
- * ```ts
145
- * assert.strictEqual(NonPositiveInt.add(-5, -3), -8);
146
- *
147
- * assert.strictEqual(NonPositiveInt.add(-5, 10), 0);
148
- * ```
78
+ * Adds two non-positive integers, returning `a + b` as a `NonPositiveInt`.
149
79
  *
150
80
  * @param a - The first non-positive integer
151
81
  * @param b - The second non-positive integer
152
- * @returns `a + b` clamped to the non-positive integer range
82
+ * @returns The sum of `a` and `b` as a `NonPositiveInt`
153
83
  */
154
84
  add,
155
85
  /**
156
- * Subtracts one non-positive integer from another.
157
- *
158
- * The result is clamped to the non-positive integer range. If the result is
159
- * positive, it is clamped to 0.
160
- *
161
- * @example
86
+ * Subtracts two non-positive integers, returning `a - b` as a
87
+ * `NonPositiveInt`.
162
88
  *
163
- * ```ts
164
- * assert.strictEqual(NonPositiveInt.sub(-10, -3), -7);
165
- *
166
- * assert.strictEqual(NonPositiveInt.sub(-10, 5), 0);
167
- * ```
168
- *
169
- * @param a - The minuend non-positive integer
170
- * @param b - The subtrahend non-positive integer
171
- * @returns `a - b` clamped to the non-positive integer range
89
+ * @param a - The first non-positive integer
90
+ * @param b - The second non-positive integer
91
+ * @returns The difference of `a` and `b` as a `NonPositiveInt`
172
92
  */
173
93
  sub
174
94
  };
@@ -1 +1 @@
1
- {"version":3,"file":"non-positive-int.mjs","sources":["../../../src/number/branded-types/non-positive-int.mts"],"sourcesContent":["import { type NonPositiveInt as TtfImported_NonPositiveInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveInt = TtfImported_NonPositiveInt;\n\ntype ElementType = NonPositiveInt;\n\nconst typeNameInMessage = 'a non-positive integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n 0\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-positive integer.\n *\n * A non-positive integer is any integer less than or equal to zero (<= 0).\n * This includes zero and all negative integers, but excludes positive numbers\n * and non-integers.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isNonPositiveInt(0));\n *\n * assert.isTrue(isNonPositiveInt(-5));\n *\n * assert.isFalse(isNonPositiveInt(1));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive integer, `false` otherwise\n */\nexport const isNonPositiveInt = is;\n\n/**\n * Casts a number to a NonPositiveInt branded type.\n *\n * This function validates that the input is a non-positive integer (<= 0) and\n * returns it with the NonPositiveInt brand. This ensures type safety for\n * operations that require non-positive integer values.\n *\n * @example\n *\n * ```ts\n * const branded = asNonPositiveInt(-7);\n *\n * assert.isTrue(branded === -7);\n *\n * assert.isTrue(NonPositiveInt.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as a NonPositiveInt branded type\n * @throws {TypeError} If the value is not a non-positive integer\n */\nexport const asNonPositiveInt = castType;\n\n/**\n * Namespace providing type-safe operations for NonPositiveInt branded types.\n *\n * NonPositiveInt represents integers that are less than or equal to zero (<= 0).\n * All operations automatically clamp results to maintain the non-positive\n * constraint, ensuring that arithmetic operations never produce positive values.\n *\n * This type is essential for:\n *\n * - Debts and negative balances\n * - Penalties and reductions\n * - Offsets and adjustments (downward)\n * - Negative counts or differences\n * - Depth or altitude below a reference point\n */\nexport const NonPositiveInt = {\n /**\n * Type guard that checks if a value is a non-positive integer.\n *\n * @example\n *\n * ```ts\n * const value: number = -42;\n *\n * if (NonPositiveInt.is(value)) {\n * // value is now typed as NonPositiveInt\n * const debt = value;\n * }\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive integer, `false` otherwise\n */\n is,\n\n /**\n * The maximum value for a non-positive integer.\n *\n * @readonly\n */\n MAX_VALUE,\n\n /**\n * Returns the smaller of two non-positive integers.\n *\n * Since non-positive integers range from negative infinity to 0, the smaller\n * value is the one further from zero (more negative).\n *\n * @example\n *\n * ```ts\n * const result = NonPositiveInt.min(-5, -10);\n *\n * assert.strictEqual(result, -10);\n * ```\n *\n * @param a - The first non-positive integer\n * @param b - The second non-positive integer\n * @returns The minimum value as a non-positive integer\n */\n min: min_,\n\n /**\n * Returns the larger of two non-positive integers.\n *\n * Since non-positive integers range from negative infinity to 0, the larger\n * value is the one closer to zero (less negative).\n *\n * @example\n *\n * ```ts\n * const result = NonPositiveInt.max(-5, -10);\n *\n * assert.strictEqual(result, -5);\n * ```\n *\n * @param a - The first non-positive integer\n * @param b - The second non-positive integer\n * @returns The maximum value as a non-positive integer\n */\n max: max_,\n\n /**\n * Clamps a number to the non-positive integer range.\n *\n * Any positive value is clamped to 0 (the maximum non-positive integer).\n * Negative values are preserved as long as they are valid integers.\n *\n * @example\n *\n * ```ts\n * assert.strictEqual(NonPositiveInt.clamp(5), 0);\n *\n * assert.strictEqual(NonPositiveInt.clamp(-5), -5);\n *\n * assert.strictEqual(NonPositiveInt.clamp(0), 0);\n * ```\n *\n * @param value - The number to clamp\n * @returns The value clamped to the non-positive integer range\n */\n clamp,\n\n /**\n * Generates a random non-positive integer value.\n *\n * @example\n *\n * ```ts\n * const randomValue = NonPositiveInt.random();\n *\n * assert.isTrue(NonPositiveInt.is(randomValue));\n * ```\n *\n * @returns A random non-positive integer\n */\n random,\n\n /**\n * Raises a non-positive integer to the power of another non-positive integer.\n *\n * The result is clamped to the non-positive integer range.\n *\n * @example\n *\n * ```ts\n * const result = NonPositiveInt.pow(-2, -1);\n * ```\n *\n * @param a - The base non-positive integer\n * @param b - The exponent non-positive integer\n * @returns `a ** b` clamped to the non-positive integer range\n */\n pow,\n\n /**\n * Adds two non-positive integers.\n *\n * The result is clamped to the non-positive integer range. If the sum is\n * positive, it is clamped to 0.\n *\n * @example\n *\n * ```ts\n * assert.strictEqual(NonPositiveInt.add(-5, -3), -8);\n *\n * assert.strictEqual(NonPositiveInt.add(-5, 10), 0);\n * ```\n *\n * @param a - The first non-positive integer\n * @param b - The second non-positive integer\n * @returns `a + b` clamped to the non-positive integer range\n */\n add,\n\n /**\n * Subtracts one non-positive integer from another.\n *\n * The result is clamped to the non-positive integer range. If the result is\n * positive, it is clamped to 0.\n *\n * @example\n *\n * ```ts\n * assert.strictEqual(NonPositiveInt.sub(-10, -3), -7);\n *\n * assert.strictEqual(NonPositiveInt.sub(-10, 5), 0);\n * ```\n *\n * @param a - The minuend non-positive integer\n * @param b - The subtrahend non-positive integer\n * @returns `a - b` clamped to the non-positive integer range\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;AAOA,MAAM,iBAAA,GAAoB,wBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,CAAA;AAAA,EACX;AACF,CAAU,CAAA;AAsBH,MAAM,gBAAA,GAAmB;AAuBzB,MAAM,gBAAA,GAAmB;AAiBzB,MAAM,cAAA,GAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkB5B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA;AACF;;;;"}
1
+ {"version":3,"file":"non-positive-int.mjs","sources":["../../../src/number/branded-types/non-positive-int.mts"],"sourcesContent":["import { type NonPositiveInt as TtfImported_NonPositiveInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveInt = TtfImported_NonPositiveInt;\n\ntype ElementType = NonPositiveInt;\n\nconst typeNameInMessage = 'a non-positive integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n 0\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-positive integer.\n *\n * Returns `true` for a non-positive integer — a value with no fractional\n * component, including values outside the safe integer range (unlike\n * `SafeInt`).\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive integer, `false` otherwise\n */\nexport const isNonPositiveInt = is;\n\n/**\n * Casts a `number` to the `NonPositiveInt` branded type.\n *\n * Validates that the value is a non-positive integer and returns it with the\n * `NonPositiveInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NonPositiveInt`\n * @throws {TypeError} If the value is not a non-positive integer\n */\nexport const asNonPositiveInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NonPositiveInt` branded\n * type.\n *\n * The `NonPositiveInt` type represents a non-positive integer. Division (`div`)\n * uses floor division.\n *\n * Unlike `SafeInt`, `NonPositiveInt` allows values outside the safe integer\n * range (±2^53 − 1), so very large magnitudes may lose precision in\n * JavaScript's `number` type.\n */\nexport const NonPositiveInt = {\n /**\n * Type guard that checks if a value is a non-positive integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive integer, `false` otherwise\n * @see {@link isNonPositiveInt} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NonPositiveInt`.\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-positive integers.\n *\n * @param values - The non-positive integers to compare (at least one required)\n * @returns The smallest value as a `NonPositiveInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-positive integers.\n *\n * @param values - The non-positive integers to compare (at least one required)\n * @returns The largest value as a `NonPositiveInt`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `NonPositiveInt` range, rounding to the nearest\n * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `NonPositiveInt`\n */\n clamp,\n\n /**\n * Generates a random `NonPositiveInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `NonPositiveInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveInt`\n * (floored to an integer).\n *\n * @param a - The base non-positive integer\n * @param b - The exponent non-positive integer\n * @returns `a ** b` as a `NonPositiveInt`\n */\n pow,\n\n /**\n * Adds two non-positive integers, returning `a + b` as a `NonPositiveInt`.\n *\n * @param a - The first non-positive integer\n * @param b - The second non-positive integer\n * @returns The sum of `a` and `b` as a `NonPositiveInt`\n */\n add,\n\n /**\n * Subtracts two non-positive integers, returning `a - b` as a\n * `NonPositiveInt`.\n *\n * @param a - The first non-positive integer\n * @param b - The second non-positive integer\n * @returns The difference of `a` and `b` as a `NonPositiveInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;AAOA,MAAM,iBAAA,GAAoB,wBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,CAAA;AAAA,EACX;AACF,CAAU,CAAA;AAYH,MAAM,gBAAA,GAAmB;AAYzB,MAAM,gBAAA,GAAmB;AAazB,MAAM,cAAA,GAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
@@ -1,19 +1,24 @@
1
1
  import { type NonPositiveSafeInt as TtfImported_NonPositiveSafeInt } from 'ts-type-forge';
2
2
  export type NonPositiveSafeInt = TtfImported_NonPositiveSafeInt;
3
3
  /**
4
- * Checks if a number is a NonPositiveSafeInt (non-positive safe integer in the
5
- * range [Number.MIN_SAFE_INTEGER, 0]).
4
+ * Type guard that checks if a value is a non-positive safe integer.
6
5
  *
7
- * @param value The value to check.
8
- * @returns `true` if the value is a NonPositiveSafeInt, `false` otherwise.
6
+ * Returns `true` for a non-positive safe integer — a value with no fractional
7
+ * component.
8
+ *
9
+ * @param value - The value to check
10
+ * @returns `true` if the value is a non-positive safe integer, `false` otherwise
9
11
  */
10
12
  export declare const isNonPositiveSafeInt: (a: number) => a is TtfImported_NonPositiveSafeInt;
11
13
  /**
12
- * Casts a number to a NonPositiveSafeInt type.
14
+ * Casts a `number` to the `NonPositiveSafeInt` branded type.
15
+ *
16
+ * Validates that the value is a non-positive safe integer and returns it with
17
+ * the `NonPositiveSafeInt` brand. Throws a `TypeError` otherwise.
13
18
  *
14
- * @param value The value to cast.
15
- * @returns The value as a NonPositiveSafeInt type.
16
- * @throws {TypeError} If the value is not a non-positive safe integer.
19
+ * @param value - The value to cast
20
+ * @returns The value as a `NonPositiveSafeInt`
21
+ * @throws {TypeError} If the value is not a non-positive safe integer
17
22
  */
18
23
  export declare const asNonPositiveSafeInt: <N extends number>(x: N) => number & {
19
24
  readonly "< 2^15": true;
@@ -29,90 +34,86 @@ export declare const asNonPositiveSafeInt: <N extends number>(x: N) => number &
29
34
  'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
30
35
  }> & N;
31
36
  /**
32
- * Namespace providing type-safe arithmetic operations for non-positive
33
- * safe integers.
37
+ * Namespace providing type-safe operations for the `NonPositiveSafeInt` branded
38
+ * type.
34
39
  *
35
- * All operations automatically clamp results to the valid NonPositiveSafeInt
36
- * range [Number.MIN_SAFE_INTEGER, 0]. This ensures that all arithmetic
37
- * maintains the non-positive safe integer constraint, with positive results
38
- * clamped to 0 and underflow results clamped to MIN_VALUE.
40
+ * The `NonPositiveSafeInt` type represents a non-positive safe integer.
41
+ * Division (`div`) uses floor division.
39
42
  */
40
43
  export declare const NonPositiveSafeInt: {
41
44
  /**
42
- * Type guard to check if a value is a NonPositiveSafeInt.
45
+ * Type guard that checks if a value is a non-positive safe integer.
43
46
  *
44
- * @param value The value to check.
45
- * @returns `true` if the value is a non-positive safe integer, `false`
46
- * otherwise.
47
+ * @param value - The value to check
48
+ * @returns `true` if the value is a non-positive safe integer, `false` otherwise
49
+ * @see {@link isNonPositiveSafeInt} for usage examples
47
50
  */
48
51
  readonly is: (a: number) => a is TtfImported_NonPositiveSafeInt;
49
52
  /**
50
- * The minimum value for a non-positive safe integer.
51
- *
52
- * @readonly
53
+ * The smallest value representable as `NonPositiveSafeInt`.
53
54
  */
54
55
  readonly MIN_VALUE: number;
55
56
  /**
56
- * The maximum value for a non-positive safe integer.
57
- *
58
- * @readonly
57
+ * The largest value representable as `NonPositiveSafeInt`.
59
58
  */
60
59
  readonly MAX_VALUE: 0;
61
60
  /**
62
- * Returns the smaller of two NonPositiveSafeInt values.
61
+ * Returns the smallest of the given non-positive safe integers.
63
62
  *
64
- * @param a The first NonPositiveSafeInt.
65
- * @param b The second NonPositiveSafeInt.
66
- * @returns The minimum value as a NonPositiveSafeInt.
63
+ * @param values - The non-positive safe integers to compare (at least one required)
64
+ * @returns The smallest value as a `NonPositiveSafeInt`
67
65
  */
68
66
  readonly min: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>[]) => TtfImported_NonPositiveSafeInt;
69
67
  /**
70
- * Returns the larger of two NonPositiveSafeInt values.
68
+ * Returns the largest of the given non-positive safe integers.
71
69
  *
72
- * @param a The first NonPositiveSafeInt.
73
- * @param b The second NonPositiveSafeInt.
74
- * @returns The maximum value as a NonPositiveSafeInt.
70
+ * @param values - The non-positive safe integers to compare (at least one required)
71
+ * @returns The largest value as a `NonPositiveSafeInt`
75
72
  */
76
73
  readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>[]) => TtfImported_NonPositiveSafeInt;
77
74
  /**
78
- * Clamps a number to the NonPositiveSafeInt range.
75
+ * Clamps a `number` into the `NonPositiveSafeInt` range, rounding to the
76
+ * nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
79
77
  *
80
- * @param value The number to clamp.
81
- * @returns The value clamped to [Number.MIN_SAFE_INTEGER, 0] as a
82
- * NonPositiveSafeInt.
78
+ * @param value - The value to clamp
79
+ * @returns The clamped value as a `NonPositiveSafeInt`
83
80
  */
84
81
  readonly clamp: (x: number) => TtfImported_NonPositiveSafeInt;
85
82
  /**
86
- * Generates a random NonPositiveSafeInt value within the valid range.
83
+ * Generates a random `NonPositiveSafeInt` within the given range.
84
+ *
85
+ * The range is inclusive on both ends.
87
86
  *
88
- * @returns A random NonPositiveSafeInt between Number.MIN_SAFE_INTEGER and 0.
87
+ * @param min - The minimum value (inclusive)
88
+ * @param max - The maximum value (inclusive)
89
+ * @returns A random `NonPositiveSafeInt` in `[min, max]`
89
90
  */
90
91
  readonly random: (min?: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt> | undefined, max?: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt> | undefined) => TtfImported_NonPositiveSafeInt;
91
92
  /**
92
- * Raises a NonPositiveSafeInt to the power of another NonPositiveSafeInt.
93
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveSafeInt`
94
+ * (floored to an integer).
93
95
  *
94
- * @param a The base NonPositiveSafeInt.
95
- * @param b The exponent NonPositiveSafeInt.
96
- * @returns `a ** b` clamped to [Number.MIN_SAFE_INTEGER, 0] as a
97
- * NonPositiveSafeInt.
96
+ * @param a - The base non-positive safe integer
97
+ * @param b - The exponent non-positive safe integer
98
+ * @returns `a ** b` as a `NonPositiveSafeInt`
98
99
  */
99
100
  readonly pow: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>) => TtfImported_NonPositiveSafeInt;
100
101
  /**
101
- * Adds two NonPositiveSafeInt values.
102
+ * Adds two non-positive safe integers, returning `a + b` as a
103
+ * `NonPositiveSafeInt`.
102
104
  *
103
- * @param a The first NonPositiveSafeInt.
104
- * @param b The second NonPositiveSafeInt.
105
- * @returns `a + b` clamped to [Number.MIN_SAFE_INTEGER, 0] as a
106
- * NonPositiveSafeInt.
105
+ * @param a - The first non-positive safe integer
106
+ * @param b - The second non-positive safe integer
107
+ * @returns The sum of `a` and `b` as a `NonPositiveSafeInt`
107
108
  */
108
109
  readonly add: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>) => TtfImported_NonPositiveSafeInt;
109
110
  /**
110
- * Subtracts one NonPositiveSafeInt from another.
111
+ * Subtracts two non-positive safe integers, returning `a - b` as a
112
+ * `NonPositiveSafeInt`.
111
113
  *
112
- * @param a The minuend NonPositiveSafeInt.
113
- * @param b The subtrahend NonPositiveSafeInt.
114
- * @returns `a - b` clamped to [Number.MIN_SAFE_INTEGER, 0] as a
115
- * NonPositiveSafeInt (maximum 0).
114
+ * @param a - The first non-positive safe integer
115
+ * @param b - The second non-positive safe integer
116
+ * @returns The difference of `a` and `b` as a `NonPositiveSafeInt`
116
117
  */
117
118
  readonly sub: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>) => TtfImported_NonPositiveSafeInt;
118
119
  };
@@ -1 +1 @@
1
- {"version":3,"file":"non-positive-safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-positive-safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,IAAI,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAG1F,MAAM,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AA6BhE;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,oDAAK,CAAC;AAEvC;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;MAAW,CAAC;AAE7C;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;;;;;OAMG;;IAGH;;;;OAIG;;IAGH;;;;OAIG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;OAIG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
1
+ {"version":3,"file":"non-positive-safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-positive-safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,IAAI,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAG1F,MAAM,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AA6BhE;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,oDAAK,CAAC;AAEvC;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;MAAW,CAAC;AAE7C;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
@@ -23,80 +23,78 @@ const isNonPositiveSafeInt = is;
23
23
  const asNonPositiveSafeInt = castType;
24
24
  const NonPositiveSafeInt = {
25
25
  /**
26
- * Type guard to check if a value is a NonPositiveSafeInt.
26
+ * Type guard that checks if a value is a non-positive safe integer.
27
27
  *
28
- * @param value The value to check.
29
- * @returns `true` if the value is a non-positive safe integer, `false`
30
- * otherwise.
28
+ * @param value - The value to check
29
+ * @returns `true` if the value is a non-positive safe integer, `false` otherwise
30
+ * @see {@link isNonPositiveSafeInt} for usage examples
31
31
  */
32
32
  is,
33
33
  /**
34
- * The minimum value for a non-positive safe integer.
35
- *
36
- * @readonly
34
+ * The smallest value representable as `NonPositiveSafeInt`.
37
35
  */
38
36
  MIN_VALUE,
39
37
  /**
40
- * The maximum value for a non-positive safe integer.
41
- *
42
- * @readonly
38
+ * The largest value representable as `NonPositiveSafeInt`.
43
39
  */
44
40
  MAX_VALUE,
45
41
  /**
46
- * Returns the smaller of two NonPositiveSafeInt values.
42
+ * Returns the smallest of the given non-positive safe integers.
47
43
  *
48
- * @param a The first NonPositiveSafeInt.
49
- * @param b The second NonPositiveSafeInt.
50
- * @returns The minimum value as a NonPositiveSafeInt.
44
+ * @param values - The non-positive safe integers to compare (at least one required)
45
+ * @returns The smallest value as a `NonPositiveSafeInt`
51
46
  */
52
47
  min: min_,
53
48
  /**
54
- * Returns the larger of two NonPositiveSafeInt values.
49
+ * Returns the largest of the given non-positive safe integers.
55
50
  *
56
- * @param a The first NonPositiveSafeInt.
57
- * @param b The second NonPositiveSafeInt.
58
- * @returns The maximum value as a NonPositiveSafeInt.
51
+ * @param values - The non-positive safe integers to compare (at least one required)
52
+ * @returns The largest value as a `NonPositiveSafeInt`
59
53
  */
60
54
  max: max_,
61
55
  /**
62
- * Clamps a number to the NonPositiveSafeInt range.
56
+ * Clamps a `number` into the `NonPositiveSafeInt` range, rounding to the
57
+ * nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
63
58
  *
64
- * @param value The number to clamp.
65
- * @returns The value clamped to [Number.MIN_SAFE_INTEGER, 0] as a
66
- * NonPositiveSafeInt.
59
+ * @param value - The value to clamp
60
+ * @returns The clamped value as a `NonPositiveSafeInt`
67
61
  */
68
62
  clamp,
69
63
  /**
70
- * Generates a random NonPositiveSafeInt value within the valid range.
64
+ * Generates a random `NonPositiveSafeInt` within the given range.
65
+ *
66
+ * The range is inclusive on both ends.
71
67
  *
72
- * @returns A random NonPositiveSafeInt between Number.MIN_SAFE_INTEGER and 0.
68
+ * @param min - The minimum value (inclusive)
69
+ * @param max - The maximum value (inclusive)
70
+ * @returns A random `NonPositiveSafeInt` in `[min, max]`
73
71
  */
74
72
  random,
75
73
  /**
76
- * Raises a NonPositiveSafeInt to the power of another NonPositiveSafeInt.
74
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveSafeInt`
75
+ * (floored to an integer).
77
76
  *
78
- * @param a The base NonPositiveSafeInt.
79
- * @param b The exponent NonPositiveSafeInt.
80
- * @returns `a ** b` clamped to [Number.MIN_SAFE_INTEGER, 0] as a
81
- * NonPositiveSafeInt.
77
+ * @param a - The base non-positive safe integer
78
+ * @param b - The exponent non-positive safe integer
79
+ * @returns `a ** b` as a `NonPositiveSafeInt`
82
80
  */
83
81
  pow,
84
82
  /**
85
- * Adds two NonPositiveSafeInt values.
83
+ * Adds two non-positive safe integers, returning `a + b` as a
84
+ * `NonPositiveSafeInt`.
86
85
  *
87
- * @param a The first NonPositiveSafeInt.
88
- * @param b The second NonPositiveSafeInt.
89
- * @returns `a + b` clamped to [Number.MIN_SAFE_INTEGER, 0] as a
90
- * NonPositiveSafeInt.
86
+ * @param a - The first non-positive safe integer
87
+ * @param b - The second non-positive safe integer
88
+ * @returns The sum of `a` and `b` as a `NonPositiveSafeInt`
91
89
  */
92
90
  add,
93
91
  /**
94
- * Subtracts one NonPositiveSafeInt from another.
92
+ * Subtracts two non-positive safe integers, returning `a - b` as a
93
+ * `NonPositiveSafeInt`.
95
94
  *
96
- * @param a The minuend NonPositiveSafeInt.
97
- * @param b The subtrahend NonPositiveSafeInt.
98
- * @returns `a - b` clamped to [Number.MIN_SAFE_INTEGER, 0] as a
99
- * NonPositiveSafeInt (maximum 0).
95
+ * @param a - The first non-positive safe integer
96
+ * @param b - The second non-positive safe integer
97
+ * @returns The difference of `a` and `b` as a `NonPositiveSafeInt`
100
98
  */
101
99
  sub
102
100
  };
@@ -1 +1 @@
1
- {"version":3,"file":"non-positive-safe-int.mjs","sources":["../../../src/number/branded-types/non-positive-safe-int.mts"],"sourcesContent":["import { type NonPositiveSafeInt as TtfImported_NonPositiveSafeInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveSafeInt = TtfImported_NonPositiveSafeInt;\n\ntype ElementType = NonPositiveSafeInt;\n\nconst typeNameInMessage = 'a non-positive safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n 0\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: Number.MIN_SAFE_INTEGER,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\n/**\n * Checks if a number is a NonPositiveSafeInt (non-positive safe integer in the\n * range [Number.MIN_SAFE_INTEGER, 0]).\n *\n * @param value The value to check.\n * @returns `true` if the value is a NonPositiveSafeInt, `false` otherwise.\n */\nexport const isNonPositiveSafeInt = is;\n\n/**\n * Casts a number to a NonPositiveSafeInt type.\n *\n * @param value The value to cast.\n * @returns The value as a NonPositiveSafeInt type.\n * @throws {TypeError} If the value is not a non-positive safe integer.\n */\nexport const asNonPositiveSafeInt = castType;\n\n/**\n * Namespace providing type-safe arithmetic operations for non-positive\n * safe integers.\n *\n * All operations automatically clamp results to the valid NonPositiveSafeInt\n * range [Number.MIN_SAFE_INTEGER, 0]. This ensures that all arithmetic\n * maintains the non-positive safe integer constraint, with positive results\n * clamped to 0 and underflow results clamped to MIN_VALUE.\n */\nexport const NonPositiveSafeInt = {\n /**\n * Type guard to check if a value is a NonPositiveSafeInt.\n *\n * @param value The value to check.\n * @returns `true` if the value is a non-positive safe integer, `false`\n * otherwise.\n */\n is,\n\n /**\n * The minimum value for a non-positive safe integer.\n *\n * @readonly\n */\n MIN_VALUE,\n\n /**\n * The maximum value for a non-positive safe integer.\n *\n * @readonly\n */\n MAX_VALUE,\n\n /**\n * Returns the smaller of two NonPositiveSafeInt values.\n *\n * @param a The first NonPositiveSafeInt.\n * @param b The second NonPositiveSafeInt.\n * @returns The minimum value as a NonPositiveSafeInt.\n */\n min: min_,\n\n /**\n * Returns the larger of two NonPositiveSafeInt values.\n *\n * @param a The first NonPositiveSafeInt.\n * @param b The second NonPositiveSafeInt.\n * @returns The maximum value as a NonPositiveSafeInt.\n */\n max: max_,\n\n /**\n * Clamps a number to the NonPositiveSafeInt range.\n *\n * @param value The number to clamp.\n * @returns The value clamped to [Number.MIN_SAFE_INTEGER, 0] as a\n * NonPositiveSafeInt.\n */\n clamp,\n\n /**\n * Generates a random NonPositiveSafeInt value within the valid range.\n *\n * @returns A random NonPositiveSafeInt between Number.MIN_SAFE_INTEGER and 0.\n */\n random,\n\n /**\n * Raises a NonPositiveSafeInt to the power of another NonPositiveSafeInt.\n *\n * @param a The base NonPositiveSafeInt.\n * @param b The exponent NonPositiveSafeInt.\n * @returns `a ** b` clamped to [Number.MIN_SAFE_INTEGER, 0] as a\n * NonPositiveSafeInt.\n */\n pow,\n\n /**\n * Adds two NonPositiveSafeInt values.\n *\n * @param a The first NonPositiveSafeInt.\n * @param b The second NonPositiveSafeInt.\n * @returns `a + b` clamped to [Number.MIN_SAFE_INTEGER, 0] as a\n * NonPositiveSafeInt.\n */\n add,\n\n /**\n * Subtracts one NonPositiveSafeInt from another.\n *\n * @param a The minuend NonPositiveSafeInt.\n * @param b The subtrahend NonPositiveSafeInt.\n * @returns `a - b` clamped to [Number.MIN_SAFE_INTEGER, 0] as a\n * NonPositiveSafeInt (maximum 0).\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;AAOA,MAAM,iBAAA,GAAoB,6BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB,SAAA,EAAW,CAAA;AAAA,EACX;AACF,CAAU,CAAA;AASH,MAAM,oBAAA,GAAuB;AAS7B,MAAM,oBAAA,GAAuB;AAW7B,MAAM,kBAAA,GAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhC,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
1
+ {"version":3,"file":"non-positive-safe-int.mjs","sources":["../../../src/number/branded-types/non-positive-safe-int.mts"],"sourcesContent":["import { type NonPositiveSafeInt as TtfImported_NonPositiveSafeInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveSafeInt = TtfImported_NonPositiveSafeInt;\n\ntype ElementType = NonPositiveSafeInt;\n\nconst typeNameInMessage = 'a non-positive safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n 0\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: Number.MIN_SAFE_INTEGER,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-positive safe integer.\n *\n * Returns `true` for a non-positive safe integer — a value with no fractional\n * component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive safe integer, `false` otherwise\n */\nexport const isNonPositiveSafeInt = is;\n\n/**\n * Casts a `number` to the `NonPositiveSafeInt` branded type.\n *\n * Validates that the value is a non-positive safe integer and returns it with\n * the `NonPositiveSafeInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NonPositiveSafeInt`\n * @throws {TypeError} If the value is not a non-positive safe integer\n */\nexport const asNonPositiveSafeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NonPositiveSafeInt` branded\n * type.\n *\n * The `NonPositiveSafeInt` type represents a non-positive safe integer.\n * Division (`div`) uses floor division.\n */\nexport const NonPositiveSafeInt = {\n /**\n * Type guard that checks if a value is a non-positive safe integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive safe integer, `false` otherwise\n * @see {@link isNonPositiveSafeInt} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `NonPositiveSafeInt`.\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `NonPositiveSafeInt`.\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-positive safe integers.\n *\n * @param values - The non-positive safe integers to compare (at least one required)\n * @returns The smallest value as a `NonPositiveSafeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-positive safe integers.\n *\n * @param values - The non-positive safe integers to compare (at least one required)\n * @returns The largest value as a `NonPositiveSafeInt`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `NonPositiveSafeInt` range, rounding to the\n * nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `NonPositiveSafeInt`\n */\n clamp,\n\n /**\n * Generates a random `NonPositiveSafeInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `NonPositiveSafeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveSafeInt`\n * (floored to an integer).\n *\n * @param a - The base non-positive safe integer\n * @param b - The exponent non-positive safe integer\n * @returns `a ** b` as a `NonPositiveSafeInt`\n */\n pow,\n\n /**\n * Adds two non-positive safe integers, returning `a + b` as a\n * `NonPositiveSafeInt`.\n *\n * @param a - The first non-positive safe integer\n * @param b - The second non-positive safe integer\n * @returns The sum of `a` and `b` as a `NonPositiveSafeInt`\n */\n add,\n\n /**\n * Subtracts two non-positive safe integers, returning `a - b` as a\n * `NonPositiveSafeInt`.\n *\n * @param a - The first non-positive safe integer\n * @param b - The second non-positive safe integer\n * @returns The difference of `a` and `b` as a `NonPositiveSafeInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;AAOA,MAAM,iBAAA,GAAoB,6BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB,SAAA,EAAW,CAAA;AAAA,EACX;AACF,CAAU,CAAA;AAWH,MAAM,oBAAA,GAAuB;AAY7B,MAAM,oBAAA,GAAuB;AAS7B,MAAM,kBAAA,GAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhC,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}