ts-data-forge 11.0.0 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/README.md +2 -2
  2. package/dist/number/branded-types/finite-number.d.mts +47 -61
  3. package/dist/number/branded-types/finite-number.d.mts.map +1 -1
  4. package/dist/number/branded-types/finite-number.mjs +37 -41
  5. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  6. package/dist/number/branded-types/int.d.mts +40 -46
  7. package/dist/number/branded-types/int.d.mts.map +1 -1
  8. package/dist/number/branded-types/int.mjs +29 -31
  9. package/dist/number/branded-types/int.mjs.map +1 -1
  10. package/dist/number/branded-types/int16.d.mts +71 -59
  11. package/dist/number/branded-types/int16.d.mts.map +1 -1
  12. package/dist/number/branded-types/int16.mjs +56 -47
  13. package/dist/number/branded-types/int16.mjs.map +1 -1
  14. package/dist/number/branded-types/int32.d.mts +71 -59
  15. package/dist/number/branded-types/int32.d.mts.map +1 -1
  16. package/dist/number/branded-types/int32.mjs +56 -47
  17. package/dist/number/branded-types/int32.mjs.map +1 -1
  18. package/dist/number/branded-types/negative-finite-number.d.mts +76 -60
  19. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  20. package/dist/number/branded-types/negative-finite-number.mjs +62 -49
  21. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  22. package/dist/number/branded-types/negative-int.d.mts +66 -49
  23. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  24. package/dist/number/branded-types/negative-int.mjs +48 -39
  25. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  26. package/dist/number/branded-types/negative-safe-int.d.mts +64 -57
  27. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  28. package/dist/number/branded-types/negative-safe-int.mjs +49 -44
  29. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  30. package/dist/number/branded-types/non-negative-finite-number.d.mts +80 -65
  31. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  32. package/dist/number/branded-types/non-negative-finite-number.mjs +65 -53
  33. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  34. package/dist/number/branded-types/non-negative-int16.d.mts +71 -58
  35. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  36. package/dist/number/branded-types/non-negative-int16.mjs +55 -45
  37. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  38. package/dist/number/branded-types/non-negative-int32.d.mts +71 -59
  39. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  40. package/dist/number/branded-types/non-negative-int32.mjs +55 -46
  41. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  42. package/dist/number/branded-types/non-positive-finite-number.d.mts +70 -55
  43. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  44. package/dist/number/branded-types/non-positive-finite-number.mjs +55 -43
  45. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  46. package/dist/number/branded-types/non-positive-int.d.mts +46 -146
  47. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  48. package/dist/number/branded-types/non-positive-int.mjs +33 -108
  49. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  50. package/dist/number/branded-types/non-positive-safe-int.d.mts +62 -54
  51. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  52. package/dist/number/branded-types/non-positive-safe-int.mjs +46 -41
  53. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  54. package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
  55. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
  56. package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
  57. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  58. package/dist/number/branded-types/non-zero-int.d.mts +51 -38
  59. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
  60. package/dist/number/branded-types/non-zero-int.mjs +31 -27
  61. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  62. package/dist/number/branded-types/non-zero-int16.d.mts +59 -54
  63. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  64. package/dist/number/branded-types/non-zero-int16.mjs +44 -41
  65. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  66. package/dist/number/branded-types/non-zero-int32.d.mts +59 -55
  67. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  68. package/dist/number/branded-types/non-zero-int32.mjs +44 -42
  69. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  70. package/dist/number/branded-types/non-zero-safe-int.d.mts +60 -55
  71. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  72. package/dist/number/branded-types/non-zero-safe-int.mjs +44 -42
  73. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  74. package/dist/number/branded-types/non-zero-uint16.d.mts +59 -54
  75. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  76. package/dist/number/branded-types/non-zero-uint16.mjs +43 -41
  77. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  78. package/dist/number/branded-types/non-zero-uint32.d.mts +59 -54
  79. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  80. package/dist/number/branded-types/non-zero-uint32.mjs +43 -41
  81. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  82. package/dist/number/branded-types/positive-finite-number.d.mts +82 -64
  83. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  84. package/dist/number/branded-types/positive-finite-number.mjs +67 -52
  85. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  86. package/dist/number/branded-types/positive-int.d.mts +53 -70
  87. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  88. package/dist/number/branded-types/positive-int.mjs +42 -52
  89. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  90. package/dist/number/branded-types/positive-int16.d.mts +68 -58
  91. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  92. package/dist/number/branded-types/positive-int16.mjs +52 -45
  93. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  94. package/dist/number/branded-types/positive-int32.d.mts +68 -58
  95. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  96. package/dist/number/branded-types/positive-int32.mjs +52 -45
  97. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  98. package/dist/number/branded-types/positive-safe-int.d.mts +72 -61
  99. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  100. package/dist/number/branded-types/positive-safe-int.mjs +56 -48
  101. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  102. package/dist/number/branded-types/positive-uint16.d.mts +68 -58
  103. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  104. package/dist/number/branded-types/positive-uint16.mjs +52 -45
  105. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  106. package/dist/number/branded-types/positive-uint32.d.mts +68 -59
  107. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  108. package/dist/number/branded-types/positive-uint32.mjs +52 -46
  109. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  110. package/dist/number/branded-types/safe-int.d.mts +52 -66
  111. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  112. package/dist/number/branded-types/safe-int.mjs +45 -47
  113. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  114. package/dist/number/branded-types/safe-uint.d.mts +68 -58
  115. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  116. package/dist/number/branded-types/safe-uint.mjs +53 -46
  117. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  118. package/dist/number/branded-types/uint.d.mts +72 -55
  119. package/dist/number/branded-types/uint.d.mts.map +1 -1
  120. package/dist/number/branded-types/uint.mjs +52 -45
  121. package/dist/number/branded-types/uint.mjs.map +1 -1
  122. package/dist/number/branded-types/uint16.d.mts +66 -59
  123. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  124. package/dist/number/branded-types/uint16.mjs +51 -45
  125. package/dist/number/branded-types/uint16.mjs.map +1 -1
  126. package/dist/number/branded-types/uint32.d.mts +66 -57
  127. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  128. package/dist/number/branded-types/uint32.mjs +50 -45
  129. package/dist/number/branded-types/uint32.mjs.map +1 -1
  130. package/dist/number/enum/int8.d.mts +62 -66
  131. package/dist/number/enum/int8.d.mts.map +1 -1
  132. package/dist/number/enum/int8.mjs +57 -51
  133. package/dist/number/enum/int8.mjs.map +1 -1
  134. package/dist/number/enum/uint8.d.mts +66 -59
  135. package/dist/number/enum/uint8.d.mts.map +1 -1
  136. package/dist/number/enum/uint8.mjs +57 -51
  137. package/dist/number/enum/uint8.mjs.map +1 -1
  138. package/dist/number/refined-number-utils.d.mts +9 -9
  139. package/dist/number/refined-number-utils.d.mts.map +1 -1
  140. package/dist/number/refined-number-utils.mjs +7 -7
  141. package/dist/number/refined-number-utils.mjs.map +1 -1
  142. package/package.json +2 -1
  143. package/src/number/branded-types/finite-number.mts +47 -61
  144. package/src/number/branded-types/int.mts +40 -46
  145. package/src/number/branded-types/int16.mts +72 -60
  146. package/src/number/branded-types/int32.mts +72 -60
  147. package/src/number/branded-types/negative-finite-number.mts +78 -71
  148. package/src/number/branded-types/negative-finite-number.test.mts +4 -4
  149. package/src/number/branded-types/negative-int.mts +68 -60
  150. package/src/number/branded-types/negative-int.test.mts +5 -5
  151. package/src/number/branded-types/negative-safe-int.mts +66 -68
  152. package/src/number/branded-types/negative-safe-int.test.mts +4 -4
  153. package/src/number/branded-types/non-negative-finite-number.mts +81 -66
  154. package/src/number/branded-types/non-negative-int16.mts +72 -59
  155. package/src/number/branded-types/non-negative-int32.mts +72 -60
  156. package/src/number/branded-types/non-positive-finite-number.mts +71 -56
  157. package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
  158. package/src/number/branded-types/non-positive-int.mts +47 -147
  159. package/src/number/branded-types/non-positive-int.test.mts +7 -7
  160. package/src/number/branded-types/non-positive-safe-int.mts +63 -55
  161. package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
  162. package/src/number/branded-types/non-zero-finite-number.mts +62 -51
  163. package/src/number/branded-types/non-zero-int.mts +51 -38
  164. package/src/number/branded-types/non-zero-int16.mts +60 -55
  165. package/src/number/branded-types/non-zero-int32.mts +60 -56
  166. package/src/number/branded-types/non-zero-safe-int.mts +61 -56
  167. package/src/number/branded-types/non-zero-uint16.mts +60 -55
  168. package/src/number/branded-types/non-zero-uint32.mts +60 -55
  169. package/src/number/branded-types/positive-finite-number.mts +83 -65
  170. package/src/number/branded-types/positive-int.mts +54 -71
  171. package/src/number/branded-types/positive-int16.mts +69 -59
  172. package/src/number/branded-types/positive-int32.mts +69 -59
  173. package/src/number/branded-types/positive-safe-int.mts +73 -62
  174. package/src/number/branded-types/positive-uint16.mts +69 -59
  175. package/src/number/branded-types/positive-uint32.mts +69 -60
  176. package/src/number/branded-types/safe-int.mts +53 -67
  177. package/src/number/branded-types/safe-uint.mts +69 -59
  178. package/src/number/branded-types/uint.mts +73 -56
  179. package/src/number/branded-types/uint16.mts +67 -60
  180. package/src/number/branded-types/uint32.mts +67 -58
  181. package/src/number/enum/int8.mts +70 -73
  182. package/src/number/enum/int8.test.mts +7 -4
  183. package/src/number/enum/uint8.mts +74 -66
  184. package/src/number/enum/uint8.test.mts +7 -4
  185. package/src/number/refined-number-utils.mts +22 -19
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -34,131 +34,144 @@ const {
34
34
  } as const);
35
35
 
36
36
  /**
37
- * Checks if a number is a NonNegativeInt16 (16-bit non-negative signed integer
38
- * in the range [0, 2^15)).
37
+ * Type guard that checks if a value is a non-negative integer in [0, 2^15).
39
38
  *
40
- * @param value The value to check.
41
- * @returns `true` if the value is a NonNegativeInt16, `false` otherwise.
39
+ * Returns `true` for a non-negative integer in [0, 2^15) — a value with no
40
+ * fractional component.
41
+ *
42
+ * @param value - The value to check
43
+ * @returns `true` if the value is a non-negative integer in [0, 2^15), `false` otherwise
42
44
  */
43
45
  export const isNonNegativeInt16 = is;
44
46
 
45
47
  /**
46
- * Casts a number to a NonNegativeInt16 type.
48
+ * Casts a `number` to the `NonNegativeInt16` branded type.
49
+ *
50
+ * Validates that the value is a non-negative integer in [0, 2^15) and returns
51
+ * it with the `NonNegativeInt16` brand. Throws a `TypeError` otherwise.
47
52
  *
48
- * @param value The value to cast.
49
- * @returns The value as a NonNegativeInt16 type.
50
- * @throws {TypeError} If the value is not a non-negative integer in [0, 2^15).
53
+ * @param value - The value to cast
54
+ * @returns The value as a `NonNegativeInt16`
55
+ * @throws {TypeError} If the value is not a non-negative integer in [0, 2^15)
51
56
  */
52
57
  export const asNonNegativeInt16 = castType;
53
58
 
54
59
  /**
55
- * Namespace providing type-safe arithmetic operations for 16-bit non-negative
56
- * integers.
60
+ * Namespace providing type-safe operations for the `NonNegativeInt16` branded
61
+ * type.
57
62
  *
58
- * All operations automatically clamp results to the valid NonNegativeInt16
59
- * range [0, 32767]. This ensures that all arithmetic maintains the 16-bit
60
- * non-negative integer constraint, with negative results clamped to 0 and
61
- * overflow results clamped to MAX_VALUE.
63
+ * The `NonNegativeInt16` type represents a non-negative integer in [0, 2^15).
64
+ * Division (`div`) uses floor division.
62
65
  */
63
66
  export const NonNegativeInt16 = {
64
67
  /**
65
- * Type guard to check if a value is a NonNegativeInt16.
68
+ * Type guard that checks if a value is a non-negative integer in [0, 2^15).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 16-bit non-negative integer, `false`
69
- * otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a non-negative integer in [0, 2^15), `false` otherwise
72
+ * @see {@link isNonNegativeInt16} for usage examples
70
73
  */
71
74
  is,
72
75
 
73
76
  /**
74
- * The minimum value for a 16-bit non-negative integer.
75
- *
76
- * @readonly
77
+ * The smallest value representable as `NonNegativeInt16` (the lower
78
+ * saturation target of `fromNumber`).
77
79
  */
78
80
  MIN_VALUE,
79
81
 
80
82
  /**
81
- * The maximum value for a 16-bit non-negative integer.
82
- *
83
- * @readonly
83
+ * The largest value representable as `NonNegativeInt16` (the upper saturation
84
+ * target of `fromNumber`).
84
85
  */
85
86
  MAX_VALUE,
86
87
 
87
88
  /**
88
- * Returns the smaller of two NonNegativeInt16 values.
89
+ * Returns the smallest of the given non-negative integers.
89
90
  *
90
- * @param a The first NonNegativeInt16.
91
- * @param b The second NonNegativeInt16.
92
- * @returns The minimum value as a NonNegativeInt16.
91
+ * @param values - The non-negative integers to compare (at least one required)
92
+ * @returns The smallest value as a `NonNegativeInt16`
93
93
  */
94
94
  min: min_,
95
95
 
96
96
  /**
97
- * Returns the larger of two NonNegativeInt16 values.
97
+ * Returns the largest of the given non-negative integers.
98
98
  *
99
- * @param a The first NonNegativeInt16.
100
- * @param b The second NonNegativeInt16.
101
- * @returns The maximum value as a NonNegativeInt16.
99
+ * @param values - The non-negative integers to compare (at least one required)
100
+ * @returns The largest value as a `NonNegativeInt16`
102
101
  */
103
102
  max: max_,
104
103
 
105
104
  /**
106
- * Clamps a number to the NonNegativeInt16 range.
105
+ * Converts an arbitrary `number` into a `NonNegativeInt16`, rounding to the
106
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
107
+ * MAX_VALUE]`.
108
+ *
109
+ * Unlike `asNonNegativeInt16`, this is total: out-of-range inputs are clamped
110
+ * to the nearest representable `NonNegativeInt16` instead of throwing.
107
111
  *
108
- * @param value The number to clamp.
109
- * @returns The value clamped to [0, 32767] as a NonNegativeInt16.
112
+ * @param value - The value to convert
113
+ * @returns The value as a `NonNegativeInt16`
110
114
  */
111
- clamp,
115
+ fromNumber,
112
116
 
113
117
  /**
114
- * Generates a random NonNegativeInt16 value within the valid range.
118
+ * Generates a random `NonNegativeInt16` within the given range.
119
+ *
120
+ * The range is inclusive on both ends.
115
121
  *
116
- * @returns A random NonNegativeInt16 between 0 and 32767.
122
+ * @param min - The minimum value (inclusive)
123
+ * @param max - The maximum value (inclusive)
124
+ * @returns A random `NonNegativeInt16` in `[min, max]`
117
125
  */
118
126
  random,
119
127
 
120
128
  /**
121
- * Raises a NonNegativeInt16 to the power of another NonNegativeInt16.
129
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonNegativeInt16`
130
+ * (floored to an integer).
122
131
  *
123
- * @param a The base NonNegativeInt16.
124
- * @param b The exponent NonNegativeInt16.
125
- * @returns `a ** b` clamped to [0, 32767] as a NonNegativeInt16.
132
+ * @param a - The base non-negative integer
133
+ * @param b - The exponent non-negative integer
134
+ * @returns `a ** b` as a `NonNegativeInt16`
126
135
  */
127
136
  pow,
128
137
 
129
138
  /**
130
- * Adds two NonNegativeInt16 values.
139
+ * Adds two non-negative integers, returning `a + b` as a `NonNegativeInt16`.
131
140
  *
132
- * @param a The first NonNegativeInt16.
133
- * @param b The second NonNegativeInt16.
134
- * @returns `a + b` clamped to [0, 32767] as a NonNegativeInt16.
141
+ * @param a - The first non-negative integer
142
+ * @param b - The second non-negative integer
143
+ * @returns The sum of `a` and `b` as a `NonNegativeInt16`
135
144
  */
136
145
  add,
137
146
 
138
147
  /**
139
- * Subtracts one NonNegativeInt16 from another.
148
+ * Subtracts two non-negative integers, returning `a - b` as a
149
+ * `NonNegativeInt16`.
140
150
  *
141
- * @param a The minuend NonNegativeInt16.
142
- * @param b The subtrahend NonNegativeInt16.
143
- * @returns `a - b` clamped to [0, 32767] as a NonNegativeInt16 (minimum 0).
151
+ * @param a - The first non-negative integer
152
+ * @param b - The second non-negative integer
153
+ * @returns The difference of `a` and `b` as a `NonNegativeInt16`
144
154
  */
145
155
  sub,
146
156
 
147
157
  /**
148
- * Multiplies two NonNegativeInt16 values.
158
+ * Multiplies two non-negative integers, returning `a * b` as a
159
+ * `NonNegativeInt16`.
149
160
  *
150
- * @param a The first NonNegativeInt16.
151
- * @param b The second NonNegativeInt16.
152
- * @returns `a * b` clamped to [0, 32767] as a NonNegativeInt16.
161
+ * @param a - The first non-negative integer
162
+ * @param b - The second non-negative integer
163
+ * @returns The product of `a` and `b` as a `NonNegativeInt16`
153
164
  */
154
165
  mul,
155
166
 
156
167
  /**
157
- * Divides one NonNegativeInt16 by another using floor division.
168
+ * Divides two non-negative integers using floor division (`⌊a / b⌋`): the
169
+ * result is `a / b` rounded toward negative infinity, as a
170
+ * `NonNegativeInt16`.
158
171
  *
159
- * @param a The dividend NonNegativeInt16.
160
- * @param b The divisor NonNegativeInt16.
161
- * @returns `⌊a / b⌋` clamped to [0, 32767] as a NonNegativeInt16.
172
+ * @param a - The dividend
173
+ * @param b - The divisor (must be non-zero)
174
+ * @returns The floored quotient as a `NonNegativeInt16`
162
175
  */
163
176
  div,
164
177
  } as const;
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -34,132 +34,144 @@ const {
34
34
  } as const);
35
35
 
36
36
  /**
37
- * Checks if a number is a NonNegativeInt32 (32-bit non-negative signed integer
38
- * in the range [0, 2^31)).
37
+ * Type guard that checks if a value is a non-negative integer in [0, 2^31).
39
38
  *
40
- * @param value The value to check.
41
- * @returns `true` if the value is a NonNegativeInt32, `false` otherwise.
39
+ * Returns `true` for a non-negative integer in [0, 2^31) — a value with no
40
+ * fractional component.
41
+ *
42
+ * @param value - The value to check
43
+ * @returns `true` if the value is a non-negative integer in [0, 2^31), `false` otherwise
42
44
  */
43
45
  export const isNonNegativeInt32 = is;
44
46
 
45
47
  /**
46
- * Casts a number to a NonNegativeInt32 type.
48
+ * Casts a `number` to the `NonNegativeInt32` branded type.
49
+ *
50
+ * Validates that the value is a non-negative integer in [0, 2^31) and returns
51
+ * it with the `NonNegativeInt32` brand. Throws a `TypeError` otherwise.
47
52
  *
48
- * @param value The value to cast.
49
- * @returns The value as a NonNegativeInt32 type.
50
- * @throws {TypeError} If the value is not a non-negative integer in [0, 2^31).
53
+ * @param value - The value to cast
54
+ * @returns The value as a `NonNegativeInt32`
55
+ * @throws {TypeError} If the value is not a non-negative integer in [0, 2^31)
51
56
  */
52
57
  export const asNonNegativeInt32 = castType;
53
58
 
54
59
  /**
55
- * Namespace providing type-safe arithmetic operations for 32-bit non-negative
56
- * integers.
60
+ * Namespace providing type-safe operations for the `NonNegativeInt32` branded
61
+ * type.
57
62
  *
58
- * All operations automatically clamp results to the valid NonNegativeInt32
59
- * range [0, 2147483647]. This ensures that all arithmetic maintains the 32-bit
60
- * non-negative integer constraint, with negative results clamped to 0 and
61
- * overflow results clamped to MAX_VALUE.
63
+ * The `NonNegativeInt32` type represents a non-negative integer in [0, 2^31).
64
+ * Division (`div`) uses floor division.
62
65
  */
63
66
  export const NonNegativeInt32 = {
64
67
  /**
65
- * Type guard to check if a value is a NonNegativeInt32.
68
+ * Type guard that checks if a value is a non-negative integer in [0, 2^31).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 32-bit non-negative integer, `false`
69
- * otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a non-negative integer in [0, 2^31), `false` otherwise
72
+ * @see {@link isNonNegativeInt32} for usage examples
70
73
  */
71
74
  is,
72
75
 
73
76
  /**
74
- * The minimum value for a 32-bit non-negative integer.
75
- *
76
- * @readonly
77
+ * The smallest value representable as `NonNegativeInt32` (the lower
78
+ * saturation target of `fromNumber`).
77
79
  */
78
80
  MIN_VALUE,
79
81
 
80
82
  /**
81
- * The maximum value for a 32-bit non-negative integer.
82
- *
83
- * @readonly
83
+ * The largest value representable as `NonNegativeInt32` (the upper saturation
84
+ * target of `fromNumber`).
84
85
  */
85
86
  MAX_VALUE,
86
87
 
87
88
  /**
88
- * Returns the smaller of two NonNegativeInt32 values.
89
+ * Returns the smallest of the given non-negative integers.
89
90
  *
90
- * @param a The first NonNegativeInt32.
91
- * @param b The second NonNegativeInt32.
92
- * @returns The minimum value as a NonNegativeInt32.
91
+ * @param values - The non-negative integers to compare (at least one required)
92
+ * @returns The smallest value as a `NonNegativeInt32`
93
93
  */
94
94
  min: min_,
95
95
 
96
96
  /**
97
- * Returns the larger of two NonNegativeInt32 values.
97
+ * Returns the largest of the given non-negative integers.
98
98
  *
99
- * @param a The first NonNegativeInt32.
100
- * @param b The second NonNegativeInt32.
101
- * @returns The maximum value as a NonNegativeInt32.
99
+ * @param values - The non-negative integers to compare (at least one required)
100
+ * @returns The largest value as a `NonNegativeInt32`
102
101
  */
103
102
  max: max_,
104
103
 
105
104
  /**
106
- * Clamps a number to the NonNegativeInt32 range.
105
+ * Converts an arbitrary `number` into a `NonNegativeInt32`, rounding to the
106
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
107
+ * MAX_VALUE]`.
108
+ *
109
+ * Unlike `asNonNegativeInt32`, this is total: out-of-range inputs are clamped
110
+ * to the nearest representable `NonNegativeInt32` instead of throwing.
107
111
  *
108
- * @param value The number to clamp.
109
- * @returns The value clamped to [0, 2147483647] as a NonNegativeInt32.
112
+ * @param value - The value to convert
113
+ * @returns The value as a `NonNegativeInt32`
110
114
  */
111
- clamp,
115
+ fromNumber,
112
116
 
113
117
  /**
114
- * Generates a random NonNegativeInt32 value within the valid range.
118
+ * Generates a random `NonNegativeInt32` within the given range.
119
+ *
120
+ * The range is inclusive on both ends.
115
121
  *
116
- * @returns A random NonNegativeInt32 between 0 and 2147483647.
122
+ * @param min - The minimum value (inclusive)
123
+ * @param max - The maximum value (inclusive)
124
+ * @returns A random `NonNegativeInt32` in `[min, max]`
117
125
  */
118
126
  random,
119
127
 
120
128
  /**
121
- * Raises a NonNegativeInt32 to the power of another NonNegativeInt32.
129
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonNegativeInt32`
130
+ * (floored to an integer).
122
131
  *
123
- * @param a The base NonNegativeInt32.
124
- * @param b The exponent NonNegativeInt32.
125
- * @returns `a ** b` clamped to [0, 2147483647] as a NonNegativeInt32.
132
+ * @param a - The base non-negative integer
133
+ * @param b - The exponent non-negative integer
134
+ * @returns `a ** b` as a `NonNegativeInt32`
126
135
  */
127
136
  pow,
128
137
 
129
138
  /**
130
- * Adds two NonNegativeInt32 values.
139
+ * Adds two non-negative integers, returning `a + b` as a `NonNegativeInt32`.
131
140
  *
132
- * @param a The first NonNegativeInt32.
133
- * @param b The second NonNegativeInt32.
134
- * @returns `a + b` clamped to [0, 2147483647] as a NonNegativeInt32.
141
+ * @param a - The first non-negative integer
142
+ * @param b - The second non-negative integer
143
+ * @returns The sum of `a` and `b` as a `NonNegativeInt32`
135
144
  */
136
145
  add,
137
146
 
138
147
  /**
139
- * Subtracts one NonNegativeInt32 from another.
148
+ * Subtracts two non-negative integers, returning `a - b` as a
149
+ * `NonNegativeInt32`.
140
150
  *
141
- * @param a The minuend NonNegativeInt32.
142
- * @param b The subtrahend NonNegativeInt32.
143
- * @returns `a - b` clamped to [0, 2147483647] as a NonNegativeInt32 (minimum
144
- * 0).
151
+ * @param a - The first non-negative integer
152
+ * @param b - The second non-negative integer
153
+ * @returns The difference of `a` and `b` as a `NonNegativeInt32`
145
154
  */
146
155
  sub,
147
156
 
148
157
  /**
149
- * Multiplies two NonNegativeInt32 values.
158
+ * Multiplies two non-negative integers, returning `a * b` as a
159
+ * `NonNegativeInt32`.
150
160
  *
151
- * @param a The first NonNegativeInt32.
152
- * @param b The second NonNegativeInt32.
153
- * @returns `a * b` clamped to [0, 2147483647] as a NonNegativeInt32.
161
+ * @param a - The first non-negative integer
162
+ * @param b - The second non-negative integer
163
+ * @returns The product of `a` and `b` as a `NonNegativeInt32`
154
164
  */
155
165
  mul,
156
166
 
157
167
  /**
158
- * Divides one NonNegativeInt32 by another using floor division.
168
+ * Divides two non-negative integers using floor division (`⌊a / b⌋`): the
169
+ * result is `a / b` rounded toward negative infinity, as a
170
+ * `NonNegativeInt32`.
159
171
  *
160
- * @param a The dividend NonNegativeInt32.
161
- * @param b The divisor NonNegativeInt32.
162
- * @returns `⌊a / b⌋` clamped to [0, 2147483647] as a NonNegativeInt32.
172
+ * @param a - The dividend
173
+ * @param b - The divisor (must be non-zero)
174
+ * @returns The floored quotient as a `NonNegativeInt32`
163
175
  */
164
176
  div,
165
177
  } as const;
@@ -11,7 +11,7 @@ const {
11
11
  MAX_VALUE,
12
12
  add,
13
13
  castType,
14
- clamp,
14
+ fromNumber,
15
15
  is,
16
16
  max: max_,
17
17
  min: min_,
@@ -63,129 +63,144 @@ const round = (
63
63
  >;
64
64
 
65
65
  /**
66
- * Checks if a number is a NonPositiveFiniteNumber (a finite number <= 0).
66
+ * Type guard that checks if a value is a non-positive finite number.
67
67
  *
68
- * @param value The value to check.
69
- * @returns `true` if the value is a NonPositiveFiniteNumber, `false` otherwise.
68
+ * Returns `true` only for a finite value — never `NaN`, `Infinity`, or
69
+ * `-Infinity`.
70
+ *
71
+ * @param value - The value to check
72
+ * @returns `true` if the value is a non-positive finite number, `false` otherwise
70
73
  */
71
74
  export const isNonPositiveFiniteNumber = is;
72
75
 
73
76
  /**
74
- * Casts a number to a NonPositiveFiniteNumber type.
77
+ * Casts a `number` to the `NonPositiveFiniteNumber` branded type.
78
+ *
79
+ * Validates that the value is a non-positive finite number and returns it with
80
+ * the `NonPositiveFiniteNumber` brand. Throws a `TypeError` otherwise.
75
81
  *
76
- * @param value The value to cast.
77
- * @returns The value as a NonPositiveFiniteNumber type.
78
- * @throws {TypeError} If the value is not a non-positive finite number.
82
+ * @param value - The value to cast
83
+ * @returns The value as a `NonPositiveFiniteNumber`
84
+ * @throws {TypeError} If the value is not a non-positive finite number
79
85
  */
80
86
  export const asNonPositiveFiniteNumber = castType;
81
87
 
82
88
  /**
83
- * Namespace providing type-safe arithmetic operations for non-positive finite
84
- * numbers.
89
+ * Namespace providing type-safe operations for the `NonPositiveFiniteNumber`
90
+ * branded type.
85
91
  *
86
- * All operations maintain the non-positive constraint by clamping positive
87
- * results to MAX_VALUE (0), while ensuring results remain finite (excluding NaN
88
- * and Infinity). This type is useful for representing quantities that must
89
- * always be non-positive, such as debts, penalties, and negative offsets.
92
+ * The `NonPositiveFiniteNumber` type represents a non-positive finite number.
90
93
  */
91
94
  export const NonPositiveFiniteNumber = {
92
95
  /**
93
- * Type guard to check if a value is a NonPositiveFiniteNumber.
96
+ * Type guard that checks if a value is a non-positive finite number.
94
97
  *
95
- * @param value The value to check.
96
- * @returns `true` if the value is a non-positive finite number, `false`
97
- * otherwise.
98
+ * @param value - The value to check
99
+ * @returns `true` if the value is a non-positive finite number, `false` otherwise
100
+ * @see {@link isNonPositiveFiniteNumber} for usage examples
98
101
  */
99
102
  is,
100
103
 
101
104
  /**
102
- * The maximum value for a non-positive finite number.
103
- *
104
- * @readonly
105
+ * The largest value representable as `NonPositiveFiniteNumber` (the upper
106
+ * saturation target of `fromNumber`).
105
107
  */
106
108
  MAX_VALUE,
107
109
 
108
110
  /**
109
- * Returns the smaller of two NonPositiveFiniteNumber values.
111
+ * Returns the smallest of the given non-positive finite numbers.
110
112
  *
111
- * @param a The first NonPositiveFiniteNumber.
112
- * @param b The second NonPositiveFiniteNumber.
113
- * @returns The minimum value as a NonPositiveFiniteNumber.
113
+ * @param values - The non-positive finite numbers to compare (at least one required)
114
+ * @returns The smallest value as a `NonPositiveFiniteNumber`
114
115
  */
115
116
  min: min_,
116
117
 
117
118
  /**
118
- * Returns the larger of two NonPositiveFiniteNumber values.
119
+ * Returns the largest of the given non-positive finite numbers.
119
120
  *
120
- * @param a The first NonPositiveFiniteNumber.
121
- * @param b The second NonPositiveFiniteNumber.
122
- * @returns The maximum value as a NonPositiveFiniteNumber.
121
+ * @param values - The non-positive finite numbers to compare (at least one required)
122
+ * @returns The largest value as a `NonPositiveFiniteNumber`
123
123
  */
124
124
  max: max_,
125
125
 
126
126
  /**
127
- * Clamps a number to the non-positive finite range.
127
+ * Converts an arbitrary `number` into a `NonPositiveFiniteNumber`, saturating
128
+ * it into the range `[MIN_VALUE, MAX_VALUE]`.
128
129
  *
129
- * @param value The number to clamp.
130
- * @returns The value clamped to (-∞, 0] as a NonPositiveFiniteNumber.
130
+ * Unlike `asNonPositiveFiniteNumber`, this is total: out-of-range inputs are
131
+ * clamped to the nearest representable `NonPositiveFiniteNumber` instead of
132
+ * throwing.
133
+ *
134
+ * @param value - The value to convert
135
+ * @returns The value as a `NonPositiveFiniteNumber`
131
136
  */
132
- clamp,
137
+ fromNumber,
133
138
 
134
139
  /**
135
- * Rounds down a NonPositiveFiniteNumber to the nearest integer.
140
+ * Returns the greatest integer less than or equal to a non-positive finite
141
+ * number.
136
142
  *
137
- * @param x The NonPositiveFiniteNumber to round down.
138
- * @returns The floor value as a NonPositiveInt (can be 0).
143
+ * @param a - The non-positive finite number value
144
+ * @returns The floored value as an integer
139
145
  */
140
146
  floor,
141
147
 
142
148
  /**
143
- * Rounds up a NonPositiveFiniteNumber to the nearest integer.
149
+ * Returns the smallest integer greater than or equal to a non-positive finite
150
+ * number.
144
151
  *
145
- * @param x The NonPositiveFiniteNumber to round up.
146
- * @returns The ceiling value as a NegativeInt (always <= -1) or 0.
152
+ * @param a - The non-positive finite number value
153
+ * @returns The ceiled value as an integer
147
154
  */
148
155
  ceil,
149
156
 
150
157
  /**
151
- * Rounds a NonPositiveFiniteNumber to the nearest integer.
158
+ * Returns the value of a non-positive finite number rounded to the nearest
159
+ * integer.
152
160
  *
153
- * @param x The NonPositiveFiniteNumber to round.
154
- * @returns The rounded value as a NonPositiveInt (can be 0 if x > -0.5).
161
+ * @param a - The non-positive finite number value
162
+ * @returns The rounded value as an integer
155
163
  */
156
164
  round,
157
165
 
158
166
  /**
159
- * Generates a random NonPositiveFiniteNumber value.
167
+ * Generates a random `NonPositiveFiniteNumber` within the given range.
168
+ *
169
+ * The range is inclusive on both ends.
160
170
  *
161
- * @returns A random non-positive finite number.
171
+ * @param min - The minimum value (inclusive)
172
+ * @param max - The maximum value (inclusive)
173
+ * @returns A random `NonPositiveFiniteNumber` in `[min, max]`
162
174
  */
163
175
  random,
164
176
 
165
177
  /**
166
- * Raises a NonPositiveFiniteNumber to the power of another NonPositiveFiniteNumber.
178
+ * Raises `a` to the power `b`, returning `a ** b` as a
179
+ * `NonPositiveFiniteNumber`.
167
180
  *
168
- * @param a The base NonPositiveFiniteNumber.
169
- * @param b The exponent NonPositiveFiniteNumber.
170
- * @returns `a ** b` clamped to (-∞, 0] as a NonPositiveFiniteNumber.
181
+ * @param a - The base non-positive finite number
182
+ * @param b - The exponent non-positive finite number
183
+ * @returns `a ** b` as a `NonPositiveFiniteNumber`
171
184
  */
172
185
  pow,
173
186
 
174
187
  /**
175
- * Adds two NonPositiveFiniteNumber values.
188
+ * Adds two non-positive finite numbers, returning `a + b` as a
189
+ * `NonPositiveFiniteNumber`.
176
190
  *
177
- * @param a The first NonPositiveFiniteNumber.
178
- * @param b The second NonPositiveFiniteNumber.
179
- * @returns `a + b` clamped to (-∞, 0] as a NonPositiveFiniteNumber.
191
+ * @param a - The first non-positive finite number
192
+ * @param b - The second non-positive finite number
193
+ * @returns The sum of `a` and `b` as a `NonPositiveFiniteNumber`
180
194
  */
181
195
  add,
182
196
 
183
197
  /**
184
- * Subtracts one NonPositiveFiniteNumber from another.
198
+ * Subtracts two non-positive finite numbers, returning `a - b` as a
199
+ * `NonPositiveFiniteNumber`.
185
200
  *
186
- * @param a The minuend NonPositiveFiniteNumber.
187
- * @param b The subtrahend NonPositiveFiniteNumber.
188
- * @returns `a - b` clamped to (-∞, 0] as a NonPositiveFiniteNumber (maximum 0).
201
+ * @param a - The first non-positive finite number
202
+ * @param b - The second non-positive finite number
203
+ * @returns The difference of `a` and `b` as a `NonPositiveFiniteNumber`
189
204
  */
190
205
  sub,
191
206
  } as const;