ts-data-forge 11.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 (171) hide show
  1. package/dist/number/branded-types/finite-number.d.mts +47 -61
  2. package/dist/number/branded-types/finite-number.d.mts.map +1 -1
  3. package/dist/number/branded-types/finite-number.mjs +37 -41
  4. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  5. package/dist/number/branded-types/int.d.mts +40 -46
  6. package/dist/number/branded-types/int.d.mts.map +1 -1
  7. package/dist/number/branded-types/int.mjs +29 -31
  8. package/dist/number/branded-types/int.mjs.map +1 -1
  9. package/dist/number/branded-types/int16.d.mts +65 -58
  10. package/dist/number/branded-types/int16.d.mts.map +1 -1
  11. package/dist/number/branded-types/int16.mjs +49 -45
  12. package/dist/number/branded-types/int16.mjs.map +1 -1
  13. package/dist/number/branded-types/int32.d.mts +65 -58
  14. package/dist/number/branded-types/int32.d.mts.map +1 -1
  15. package/dist/number/branded-types/int32.mjs +49 -45
  16. package/dist/number/branded-types/int32.mjs.map +1 -1
  17. package/dist/number/branded-types/negative-finite-number.d.mts +68 -59
  18. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  19. package/dist/number/branded-types/negative-finite-number.mjs +52 -46
  20. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  21. package/dist/number/branded-types/negative-int.d.mts +60 -48
  22. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  23. package/dist/number/branded-types/negative-int.mjs +40 -36
  24. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  25. package/dist/number/branded-types/negative-safe-int.d.mts +57 -56
  26. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  27. package/dist/number/branded-types/negative-safe-int.mjs +40 -41
  28. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  29. package/dist/number/branded-types/non-negative-finite-number.d.mts +74 -64
  30. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  31. package/dist/number/branded-types/non-negative-finite-number.mjs +58 -51
  32. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  33. package/dist/number/branded-types/non-negative-int16.d.mts +64 -57
  34. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  35. package/dist/number/branded-types/non-negative-int16.mjs +47 -43
  36. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  37. package/dist/number/branded-types/non-negative-int32.d.mts +64 -58
  38. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  39. package/dist/number/branded-types/non-negative-int32.mjs +47 -44
  40. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  41. package/dist/number/branded-types/non-positive-finite-number.d.mts +64 -54
  42. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  43. package/dist/number/branded-types/non-positive-finite-number.mjs +48 -41
  44. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  45. package/dist/number/branded-types/non-positive-int.d.mts +41 -146
  46. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  47. package/dist/number/branded-types/non-positive-int.mjs +27 -107
  48. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  49. package/dist/number/branded-types/non-positive-safe-int.d.mts +54 -53
  50. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  51. package/dist/number/branded-types/non-positive-safe-int.mjs +37 -39
  52. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  53. package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
  54. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
  55. package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
  56. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  57. package/dist/number/branded-types/non-zero-int.d.mts +51 -38
  58. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
  59. package/dist/number/branded-types/non-zero-int.mjs +31 -27
  60. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  61. package/dist/number/branded-types/non-zero-int16.d.mts +52 -53
  62. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  63. package/dist/number/branded-types/non-zero-int16.mjs +36 -39
  64. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  65. package/dist/number/branded-types/non-zero-int32.d.mts +52 -54
  66. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  67. package/dist/number/branded-types/non-zero-int32.mjs +36 -40
  68. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  69. package/dist/number/branded-types/non-zero-safe-int.d.mts +53 -54
  70. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  71. package/dist/number/branded-types/non-zero-safe-int.mjs +36 -40
  72. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  73. package/dist/number/branded-types/non-zero-uint16.d.mts +52 -53
  74. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  75. package/dist/number/branded-types/non-zero-uint16.mjs +35 -39
  76. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  77. package/dist/number/branded-types/non-zero-uint32.d.mts +52 -53
  78. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  79. package/dist/number/branded-types/non-zero-uint32.mjs +35 -39
  80. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  81. package/dist/number/branded-types/positive-finite-number.d.mts +74 -63
  82. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  83. package/dist/number/branded-types/positive-finite-number.mjs +58 -50
  84. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  85. package/dist/number/branded-types/positive-int.d.mts +46 -68
  86. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  87. package/dist/number/branded-types/positive-int.mjs +34 -49
  88. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  89. package/dist/number/branded-types/positive-int16.d.mts +61 -57
  90. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  91. package/dist/number/branded-types/positive-int16.mjs +44 -43
  92. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  93. package/dist/number/branded-types/positive-int32.d.mts +61 -57
  94. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  95. package/dist/number/branded-types/positive-int32.mjs +44 -43
  96. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  97. package/dist/number/branded-types/positive-safe-int.d.mts +62 -57
  98. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  99. package/dist/number/branded-types/positive-safe-int.mjs +45 -43
  100. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  101. package/dist/number/branded-types/positive-uint16.d.mts +61 -57
  102. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  103. package/dist/number/branded-types/positive-uint16.mjs +44 -43
  104. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  105. package/dist/number/branded-types/positive-uint32.d.mts +61 -58
  106. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  107. package/dist/number/branded-types/positive-uint32.mjs +44 -44
  108. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  109. package/dist/number/branded-types/safe-int.d.mts +43 -62
  110. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  111. package/dist/number/branded-types/safe-int.mjs +35 -42
  112. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  113. package/dist/number/branded-types/safe-uint.d.mts +62 -57
  114. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  115. package/dist/number/branded-types/safe-uint.mjs +46 -44
  116. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  117. package/dist/number/branded-types/uint.d.mts +63 -50
  118. package/dist/number/branded-types/uint.d.mts.map +1 -1
  119. package/dist/number/branded-types/uint.mjs +42 -39
  120. package/dist/number/branded-types/uint.mjs.map +1 -1
  121. package/dist/number/branded-types/uint16.d.mts +60 -58
  122. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  123. package/dist/number/branded-types/uint16.mjs +44 -43
  124. package/dist/number/branded-types/uint16.mjs.map +1 -1
  125. package/dist/number/branded-types/uint32.d.mts +59 -55
  126. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  127. package/dist/number/branded-types/uint32.mjs +42 -42
  128. package/dist/number/branded-types/uint32.mjs.map +1 -1
  129. package/dist/number/enum/int8.d.mts +56 -65
  130. package/dist/number/enum/int8.d.mts.map +1 -1
  131. package/dist/number/enum/int8.mjs +44 -43
  132. package/dist/number/enum/int8.mjs.map +1 -1
  133. package/dist/number/enum/uint8.d.mts +60 -58
  134. package/dist/number/enum/uint8.d.mts.map +1 -1
  135. package/dist/number/enum/uint8.mjs +44 -43
  136. package/dist/number/enum/uint8.mjs.map +1 -1
  137. package/package.json +2 -1
  138. package/src/number/branded-types/finite-number.mts +47 -61
  139. package/src/number/branded-types/int.mts +40 -46
  140. package/src/number/branded-types/int16.mts +65 -58
  141. package/src/number/branded-types/int32.mts +65 -58
  142. package/src/number/branded-types/negative-finite-number.mts +68 -68
  143. package/src/number/branded-types/negative-int.mts +60 -57
  144. package/src/number/branded-types/negative-safe-int.mts +57 -65
  145. package/src/number/branded-types/non-negative-finite-number.mts +74 -64
  146. package/src/number/branded-types/non-negative-int16.mts +64 -57
  147. package/src/number/branded-types/non-negative-int32.mts +64 -58
  148. package/src/number/branded-types/non-positive-finite-number.mts +64 -54
  149. package/src/number/branded-types/non-positive-int.mts +41 -146
  150. package/src/number/branded-types/non-positive-safe-int.mts +54 -53
  151. package/src/number/branded-types/non-zero-finite-number.mts +62 -51
  152. package/src/number/branded-types/non-zero-int.mts +51 -38
  153. package/src/number/branded-types/non-zero-int16.mts +52 -53
  154. package/src/number/branded-types/non-zero-int32.mts +52 -54
  155. package/src/number/branded-types/non-zero-safe-int.mts +53 -54
  156. package/src/number/branded-types/non-zero-uint16.mts +52 -53
  157. package/src/number/branded-types/non-zero-uint32.mts +52 -53
  158. package/src/number/branded-types/positive-finite-number.mts +74 -63
  159. package/src/number/branded-types/positive-int.mts +46 -68
  160. package/src/number/branded-types/positive-int16.mts +61 -57
  161. package/src/number/branded-types/positive-int32.mts +61 -57
  162. package/src/number/branded-types/positive-safe-int.mts +62 -57
  163. package/src/number/branded-types/positive-uint16.mts +61 -57
  164. package/src/number/branded-types/positive-uint32.mts +61 -58
  165. package/src/number/branded-types/safe-int.mts +43 -62
  166. package/src/number/branded-types/safe-uint.mts +62 -57
  167. package/src/number/branded-types/uint.mts +63 -50
  168. package/src/number/branded-types/uint16.mts +60 -58
  169. package/src/number/branded-types/uint32.mts +59 -55
  170. package/src/number/enum/int8.mts +56 -65
  171. package/src/number/enum/uint8.mts +60 -58
@@ -30,15 +30,6 @@ const {
30
30
  typeNameInMessage,
31
31
  } as const);
32
32
 
33
- /**
34
- * Returns the absolute value of a negative finite number.
35
- *
36
- * The absolute value of a negative finite number is always a positive finite
37
- * number, so the result is typed as a {@link PositiveFiniteNumber}.
38
- *
39
- * @param x - The negative finite number.
40
- * @returns `|x|` as a PositiveFiniteNumber.
41
- */
42
33
  const abs = (x: ElementType): PositiveFiniteNumber =>
43
34
  PositiveFiniteNumber.clamp(Math.abs(x));
44
35
 
@@ -71,140 +62,149 @@ const round = (
71
62
  >;
72
63
 
73
64
  /**
74
- * Checks if a number is a NegativeFiniteNumber (a finite number `< 0`).
65
+ * Type guard that checks if a value is a negative finite number.
66
+ *
67
+ * Returns `true` only for a finite value — never `NaN`, `Infinity`, or
68
+ * `-Infinity`.
75
69
  *
76
- * @param value The value to check.
77
- * @returns `true` if the value is a NegativeFiniteNumber, `false` otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a negative finite number, `false` otherwise
78
72
  */
79
73
  export const isNegativeFiniteNumber = is;
80
74
 
81
75
  /**
82
- * Casts a number to a NegativeFiniteNumber type.
76
+ * Casts a `number` to the `NegativeFiniteNumber` branded type.
83
77
  *
84
- * @param value The value to cast.
85
- * @returns The value as a NegativeFiniteNumber type.
86
- * @throws {TypeError} If the value is not a negative finite number.
78
+ * Validates that the value is a negative finite number and returns it with the
79
+ * `NegativeFiniteNumber` brand. Throws a `TypeError` otherwise.
80
+ *
81
+ * @param value - The value to cast
82
+ * @returns The value as a `NegativeFiniteNumber`
83
+ * @throws {TypeError} If the value is not a negative finite number
87
84
  */
88
85
  export const asNegativeFiniteNumber = castType;
89
86
 
90
87
  /**
91
- * Namespace providing type-safe arithmetic operations for negative finite
92
- * numbers.
88
+ * Namespace providing type-safe operations for the `NegativeFiniteNumber`
89
+ * branded type.
93
90
  *
94
- * All operations keep results finite (excluding NaN and Infinity). Operations
95
- * that stay within the negative finite numbers clamp their results to the valid
96
- * range, while operations whose result leaves the set (`mul`, `div`, `abs`) are
97
- * typed to reflect the actual sign of the result.
91
+ * The `NegativeFiniteNumber` type represents a negative finite number.
98
92
  */
99
93
  export const NegativeFiniteNumber = {
100
94
  /**
101
- * Type guard to check if a value is a NegativeFiniteNumber.
95
+ * Type guard that checks if a value is a negative finite number.
102
96
  *
103
- * @param value The value to check.
104
- * @returns `true` if the value is a negative finite number, `false`
105
- * otherwise.
97
+ * @param value - The value to check
98
+ * @returns `true` if the value is a negative finite number, `false` otherwise
99
+ * @see {@link isNegativeFiniteNumber} for usage examples
106
100
  */
107
101
  is,
108
102
 
109
103
  /**
110
- * The maximum value for a negative finite number.
111
- *
112
- * @readonly
104
+ * The largest value representable as `NegativeFiniteNumber`.
113
105
  */
114
106
  MAX_VALUE,
115
107
 
116
108
  /**
117
109
  * Returns the absolute value of a negative finite number.
118
110
  *
119
- * @param a The negative finite number.
120
- * @returns The absolute value as a PositiveFiniteNumber.
111
+ * The result is non-negative and keeps the `NegativeFiniteNumber` brand.
112
+ *
113
+ * @param a - The negative finite number value
114
+ * @returns The absolute value as a non-negative `NegativeFiniteNumber`
121
115
  */
122
116
  abs,
123
117
 
124
118
  /**
125
- * Returns the smaller of two NegativeFiniteNumber values.
119
+ * Returns the smallest of the given negative finite numbers.
126
120
  *
127
- * @param a The first NegativeFiniteNumber.
128
- * @param b The second NegativeFiniteNumber.
129
- * @returns The minimum value as a NegativeFiniteNumber.
121
+ * @param values - The negative finite numbers to compare (at least one required)
122
+ * @returns The smallest value as a `NegativeFiniteNumber`
130
123
  */
131
124
  min: min_,
132
125
 
133
126
  /**
134
- * Returns the larger of two NegativeFiniteNumber values.
127
+ * Returns the largest of the given negative finite numbers.
135
128
  *
136
- * @param a The first NegativeFiniteNumber.
137
- * @param b The second NegativeFiniteNumber.
138
- * @returns The maximum value as a NegativeFiniteNumber.
129
+ * @param values - The negative finite numbers to compare (at least one required)
130
+ * @returns The largest value as a `NegativeFiniteNumber`
139
131
  */
140
132
  max: max_,
141
133
 
142
134
  /**
143
- * Clamps a number to the negative finite range.
135
+ * Clamps a `number` into the `NegativeFiniteNumber` range `[MIN_VALUE,
136
+ * MAX_VALUE]`.
144
137
  *
145
- * @param value The number to clamp.
146
- * @returns The value clamped to `(-∞, 0)` as a NegativeFiniteNumber.
138
+ * @param value - The value to clamp
139
+ * @returns The clamped value as a `NegativeFiniteNumber`
147
140
  */
148
141
  clamp,
149
142
 
150
143
  /**
151
- * Rounds down a NegativeFiniteNumber to the nearest integer.
144
+ * Returns the greatest integer less than or equal to a negative finite
145
+ * number.
152
146
  *
153
- * @param x The NegativeFiniteNumber to round down.
154
- * @returns The floor value as a NegativeInt (always `<= -1`).
147
+ * @param a - The negative finite number value
148
+ * @returns The floored value as an integer
155
149
  */
156
150
  floor,
157
151
 
158
152
  /**
159
- * Rounds up a NegativeFiniteNumber to the nearest integer.
153
+ * Returns the smallest integer greater than or equal to a negative finite
154
+ * number.
160
155
  *
161
- * @param x The NegativeFiniteNumber to round up.
162
- * @returns The ceiling value as a NonPositiveInt (can be 0).
156
+ * @param a - The negative finite number value
157
+ * @returns The ceiled value as an integer
163
158
  */
164
159
  ceil,
165
160
 
166
161
  /**
167
- * Rounds a NegativeFiniteNumber to the nearest integer.
162
+ * Returns the value of a negative finite number rounded to the nearest
163
+ * integer.
168
164
  *
169
- * @param x The NegativeFiniteNumber to round.
170
- * @returns The rounded value as a NonPositiveInt (can be 0 if x > -0.5).
165
+ * @param a - The negative finite number value
166
+ * @returns The rounded value as an integer
171
167
  */
172
168
  round,
173
169
 
174
170
  /**
175
- * Generates a random NegativeFiniteNumber value.
171
+ * Generates a random `NegativeFiniteNumber` within the given range.
176
172
  *
177
- * @returns A random negative finite number.
173
+ * The range is inclusive on both ends.
174
+ *
175
+ * @param min - The minimum value (inclusive)
176
+ * @param max - The maximum value (inclusive)
177
+ * @returns A random `NegativeFiniteNumber` in `[min, max]`
178
178
  */
179
179
  random,
180
180
 
181
181
  /**
182
- * Raises a NegativeFiniteNumber to the power of another NegativeFiniteNumber.
182
+ * Raises `a` to the power `b`, returning `a ** b` as a
183
+ * `NegativeFiniteNumber`.
183
184
  *
184
- * @param a The base NegativeFiniteNumber.
185
- * @param b The exponent NegativeFiniteNumber.
186
- * @returns `a ** b` clamped to `(-∞, 0)` as a NegativeFiniteNumber.
185
+ * @param a - The base negative finite number
186
+ * @param b - The exponent negative finite number
187
+ * @returns `a ** b` as a `NegativeFiniteNumber`
187
188
  */
188
189
  pow,
189
190
 
190
191
  /**
191
- * Adds two NegativeFiniteNumber values.
192
+ * Adds two negative finite numbers, returning `a + b` as a
193
+ * `NegativeFiniteNumber`.
192
194
  *
193
- * @param a The first NegativeFiniteNumber.
194
- * @param b The second NegativeFiniteNumber.
195
- * @returns `a + b` as a NegativeFiniteNumber.
195
+ * @param a - The first negative finite number
196
+ * @param b - The second negative finite number
197
+ * @returns The sum of `a` and `b` as a `NegativeFiniteNumber`
196
198
  */
197
199
  add,
198
200
 
199
201
  /**
200
- * Subtracts one NegativeFiniteNumber from another.
201
- *
202
- * The mathematical result can be positive, so it is clamped to the negative
203
- * finite range (maximum `-Number.MIN_VALUE`).
202
+ * Subtracts two negative finite numbers, returning `a - b` as a
203
+ * `NegativeFiniteNumber`.
204
204
  *
205
- * @param a The minuend NegativeFiniteNumber.
206
- * @param b The subtrahend NegativeFiniteNumber.
207
- * @returns `a - b` clamped to `(-∞, 0)` as a NegativeFiniteNumber.
205
+ * @param a - The first negative finite number
206
+ * @param b - The second negative finite number
207
+ * @returns The difference of `a` and `b` as a `NegativeFiniteNumber`
208
208
  */
209
209
  sub,
210
210
  } as const;
@@ -34,127 +34,130 @@ const {
34
34
  typeNameInMessage,
35
35
  } as const);
36
36
 
37
- /**
38
- * Returns the absolute value of a negative integer.
39
- *
40
- * The absolute value of a negative integer is always a positive integer
41
- * (`>= 1`), so the result is typed as a {@link PositiveInt}.
42
- *
43
- * @param x - The negative integer.
44
- * @returns `|x|` as a PositiveInt.
45
- */
46
37
  const abs = (x: WithSmallInt<ElementType>): PositiveInt =>
47
38
  PositiveInt.clamp(Math.abs(x));
48
39
 
49
40
  /**
50
- * Checks if a number is a NegativeInt (a negative integer `<= -1`).
41
+ * Type guard that checks if a value is a negative integer.
42
+ *
43
+ * Returns `true` for a negative integer — a value with no fractional component,
44
+ * including values outside the safe integer range (unlike `SafeInt`).
51
45
  *
52
- * @param value The value to check.
53
- * @returns `true` if the value is a NegativeInt, `false` otherwise.
46
+ * @param value - The value to check
47
+ * @returns `true` if the value is a negative integer, `false` otherwise
54
48
  */
55
49
  export const isNegativeInt = is;
56
50
 
57
51
  /**
58
- * Casts a number to a NegativeInt type.
52
+ * Casts a `number` to the `NegativeInt` branded type.
53
+ *
54
+ * Validates that the value is a negative integer and returns it with the
55
+ * `NegativeInt` brand. Throws a `TypeError` otherwise.
59
56
  *
60
- * @param value The value to cast.
61
- * @returns The value as a NegativeInt type.
62
- * @throws {TypeError} If the value is not a negative integer.
57
+ * @param value - The value to cast
58
+ * @returns The value as a `NegativeInt`
59
+ * @throws {TypeError} If the value is not a negative integer
63
60
  */
64
61
  export const asNegativeInt = castType;
65
62
 
66
63
  /**
67
- * Namespace providing type-safe arithmetic operations for negative integers.
64
+ * Namespace providing type-safe operations for the `NegativeInt` branded type.
68
65
  *
69
- * NegativeInt represents integers that are strictly less than zero (`<= -1`).
70
- * Operations that stay within the negative integers (such as `add`) clamp their
71
- * results to the valid range, while operations whose result leaves the set
72
- * (`mul`, `div`, `abs`) are typed to reflect the actual sign of the result.
66
+ * The `NegativeInt` type represents a negative integer. Division (`div`) uses
67
+ * floor division.
68
+ *
69
+ * Unlike `SafeInt`, `NegativeInt` allows values outside the safe integer range
70
+ * (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's
71
+ * `number` type.
73
72
  */
74
73
  export const NegativeInt = {
75
74
  /**
76
- * Type guard to check if a value is a NegativeInt.
75
+ * Type guard that checks if a value is a negative integer.
77
76
  *
78
- * @param value The value to check.
79
- * @returns `true` if the value is a negative integer, `false` otherwise.
77
+ * @param value - The value to check
78
+ * @returns `true` if the value is a negative integer, `false` otherwise
79
+ * @see {@link isNegativeInt} for usage examples
80
80
  */
81
81
  is,
82
82
 
83
83
  /**
84
- * The maximum value for a negative integer.
85
- *
86
- * @readonly
84
+ * The largest value representable as `NegativeInt`.
87
85
  */
88
86
  MAX_VALUE,
89
87
 
90
88
  /**
91
89
  * Returns the absolute value of a negative integer.
92
90
  *
93
- * @param a The negative integer.
94
- * @returns The absolute value as a PositiveInt.
91
+ * The result is non-negative and keeps the `NegativeInt` brand. Note that
92
+ * `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so
93
+ * use `SafeInt` for guaranteed precision.
94
+ *
95
+ * @param a - The negative integer value
96
+ * @returns The absolute value as a non-negative `NegativeInt`
95
97
  */
96
98
  abs,
97
99
 
98
100
  /**
99
- * Returns the smaller of two negative integers.
101
+ * Returns the smallest of the given negative integers.
100
102
  *
101
- * @param a The first negative integer.
102
- * @param b The second negative integer.
103
- * @returns The minimum value as a NegativeInt.
103
+ * @param values - The negative integers to compare (at least one required)
104
+ * @returns The smallest value as a `NegativeInt`
104
105
  */
105
106
  min: min_,
106
107
 
107
108
  /**
108
- * Returns the larger of two negative integers.
109
+ * Returns the largest of the given negative integers.
109
110
  *
110
- * @param a The first negative integer.
111
- * @param b The second negative integer.
112
- * @returns The maximum value as a NegativeInt.
111
+ * @param values - The negative integers to compare (at least one required)
112
+ * @returns The largest value as a `NegativeInt`
113
113
  */
114
114
  max: max_,
115
115
 
116
116
  /**
117
- * Clamps a number to the negative integer range.
117
+ * Clamps a `number` into the `NegativeInt` range, rounding to the nearest
118
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
118
119
  *
119
- * @param value The number to clamp.
120
- * @returns The value clamped to `[-∞, -1]` as a NegativeInt.
120
+ * @param value - The value to clamp
121
+ * @returns The clamped value as a `NegativeInt`
121
122
  */
122
123
  clamp,
123
124
 
124
125
  /**
125
- * Generates a random NegativeInt value within the valid range.
126
+ * Generates a random `NegativeInt` within the given range.
126
127
  *
127
- * @returns A random negative integer.
128
+ * The range is inclusive on both ends.
129
+ *
130
+ * @param min - The minimum value (inclusive)
131
+ * @param max - The maximum value (inclusive)
132
+ * @returns A random `NegativeInt` in `[min, max]`
128
133
  */
129
134
  random,
130
135
 
131
136
  /**
132
- * Raises a negative integer to the power of another negative integer.
137
+ * Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored
138
+ * to an integer).
133
139
  *
134
- * @param a The base negative integer.
135
- * @param b The exponent negative integer.
136
- * @returns `a ** b` clamped to the negative integer range.
140
+ * @param a - The base negative integer
141
+ * @param b - The exponent negative integer
142
+ * @returns `a ** b` as a `NegativeInt`
137
143
  */
138
144
  pow,
139
145
 
140
146
  /**
141
- * Adds two negative integers.
147
+ * Adds two negative integers, returning `a + b` as a `NegativeInt`.
142
148
  *
143
- * @param a The first negative integer.
144
- * @param b The second negative integer.
145
- * @returns `a + b` as a NegativeInt.
149
+ * @param a - The first negative integer
150
+ * @param b - The second negative integer
151
+ * @returns The sum of `a` and `b` as a `NegativeInt`
146
152
  */
147
153
  add,
148
154
 
149
155
  /**
150
- * Subtracts one negative integer from another.
151
- *
152
- * The mathematical result can be positive, so it is clamped to the negative
153
- * integer range (maximum `-1`).
156
+ * Subtracts two negative integers, returning `a - b` as a `NegativeInt`.
154
157
  *
155
- * @param a The minuend negative integer.
156
- * @param b The subtrahend negative integer.
157
- * @returns `a - b` clamped to the negative integer range.
158
+ * @param a - The first negative integer
159
+ * @param b - The second negative integer
160
+ * @returns The difference of `a` and `b` as a `NegativeInt`
158
161
  */
159
162
  sub,
160
163
  } as const;
@@ -35,139 +35,131 @@ const {
35
35
  typeNameInMessage,
36
36
  } as const);
37
37
 
38
- /**
39
- * Returns the absolute value of a negative safe integer.
40
- *
41
- * The absolute value of a negative safe integer is always a positive safe
42
- * integer (`>= 1`), so the result is typed as a {@link PositiveSafeInt}.
43
- *
44
- * @param x - The negative safe integer.
45
- * @returns `|x|` as a PositiveSafeInt.
46
- */
47
38
  const abs = (x: WithSmallInt<ElementType>): PositiveSafeInt =>
48
39
  PositiveSafeInt.clamp(Math.abs(x));
49
40
 
50
41
  /**
51
- * Checks if a number is a NegativeSafeInt (a negative safe integer in the range
52
- * `[Number.MIN_SAFE_INTEGER, -1]`).
42
+ * Type guard that checks if a value is a negative safe integer.
43
+ *
44
+ * Returns `true` for a negative safe integer — a value with no fractional
45
+ * component.
53
46
  *
54
- * @param value The value to check.
55
- * @returns `true` if the value is a NegativeSafeInt, `false` otherwise.
47
+ * @param value - The value to check
48
+ * @returns `true` if the value is a negative safe integer, `false` otherwise
56
49
  */
57
50
  export const isNegativeSafeInt = is;
58
51
 
59
52
  /**
60
- * Casts a number to a NegativeSafeInt type.
53
+ * Casts a `number` to the `NegativeSafeInt` branded type.
54
+ *
55
+ * Validates that the value is a negative safe integer and returns it with the
56
+ * `NegativeSafeInt` brand. Throws a `TypeError` otherwise.
61
57
  *
62
- * @param value The value to cast.
63
- * @returns The value as a NegativeSafeInt type.
64
- * @throws {TypeError} If the value is not a negative safe integer.
58
+ * @param value - The value to cast
59
+ * @returns The value as a `NegativeSafeInt`
60
+ * @throws {TypeError} If the value is not a negative safe integer
65
61
  */
66
62
  export const asNegativeSafeInt = castType;
67
63
 
68
64
  /**
69
- * Namespace providing type-safe arithmetic operations for negative safe
70
- * integers.
65
+ * Namespace providing type-safe operations for the `NegativeSafeInt` branded
66
+ * type.
71
67
  *
72
- * NegativeSafeInt represents safe integers that are strictly less than zero
73
- * (`[Number.MIN_SAFE_INTEGER, -1]`). Operations that stay within the negative
74
- * safe integers clamp their results to the valid range, while operations whose
75
- * result leaves the set (`mul`, `div`, `abs`) are typed to reflect the actual
76
- * sign of the result.
68
+ * The `NegativeSafeInt` type represents a negative safe integer. Division
69
+ * (`div`) uses floor division.
77
70
  */
78
71
  export const NegativeSafeInt = {
79
72
  /**
80
- * Type guard to check if a value is a NegativeSafeInt.
73
+ * Type guard that checks if a value is a negative safe integer.
81
74
  *
82
- * @param value The value to check.
83
- * @returns `true` if the value is a negative safe integer, `false` otherwise.
75
+ * @param value - The value to check
76
+ * @returns `true` if the value is a negative safe integer, `false` otherwise
77
+ * @see {@link isNegativeSafeInt} for usage examples
84
78
  */
85
79
  is,
86
80
 
87
81
  /**
88
- * The minimum value for a negative safe integer.
89
- *
90
- * @readonly
82
+ * The smallest value representable as `NegativeSafeInt`.
91
83
  */
92
84
  MIN_VALUE,
93
85
 
94
86
  /**
95
- * The maximum value for a negative safe integer.
96
- *
97
- * @readonly
87
+ * The largest value representable as `NegativeSafeInt`.
98
88
  */
99
89
  MAX_VALUE,
100
90
 
101
91
  /**
102
92
  * Returns the absolute value of a negative safe integer.
103
93
  *
104
- * @param a The negative safe integer.
105
- * @returns The absolute value as a PositiveSafeInt.
94
+ * The result is non-negative and keeps the `NegativeSafeInt` brand.
95
+ *
96
+ * @param a - The negative safe integer value
97
+ * @returns The absolute value as a non-negative `NegativeSafeInt`
106
98
  */
107
99
  abs,
108
100
 
109
101
  /**
110
- * Returns the smaller of two negative safe integers.
102
+ * Returns the smallest of the given negative safe integers.
111
103
  *
112
- * @param a The first negative safe integer.
113
- * @param b The second negative safe integer.
114
- * @returns The minimum value as a NegativeSafeInt.
104
+ * @param values - The negative safe integers to compare (at least one required)
105
+ * @returns The smallest value as a `NegativeSafeInt`
115
106
  */
116
107
  min: min_,
117
108
 
118
109
  /**
119
- * Returns the larger of two negative safe integers.
110
+ * Returns the largest of the given negative safe integers.
120
111
  *
121
- * @param a The first negative safe integer.
122
- * @param b The second negative safe integer.
123
- * @returns The maximum value as a NegativeSafeInt.
112
+ * @param values - The negative safe integers to compare (at least one required)
113
+ * @returns The largest value as a `NegativeSafeInt`
124
114
  */
125
115
  max: max_,
126
116
 
127
117
  /**
128
- * Clamps a number to the NegativeSafeInt range.
118
+ * Clamps a `number` into the `NegativeSafeInt` range, rounding to the nearest
119
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
129
120
  *
130
- * @param value The number to clamp.
131
- * @returns The value clamped to `[Number.MIN_SAFE_INTEGER, -1]` as a
132
- * NegativeSafeInt.
121
+ * @param value - The value to clamp
122
+ * @returns The clamped value as a `NegativeSafeInt`
133
123
  */
134
124
  clamp,
135
125
 
136
126
  /**
137
- * Generates a random NegativeSafeInt value within the valid range.
127
+ * Generates a random `NegativeSafeInt` within the given range.
138
128
  *
139
- * @returns A random NegativeSafeInt between Number.MIN_SAFE_INTEGER and -1.
129
+ * The range is inclusive on both ends.
130
+ *
131
+ * @param min - The minimum value (inclusive)
132
+ * @param max - The maximum value (inclusive)
133
+ * @returns A random `NegativeSafeInt` in `[min, max]`
140
134
  */
141
135
  random,
142
136
 
143
137
  /**
144
- * Raises a negative safe integer to the power of another negative safe
145
- * integer.
138
+ * Raises `a` to the power `b`, returning `a ** b` as a `NegativeSafeInt`
139
+ * (floored to an integer).
146
140
  *
147
- * @param a The base negative safe integer.
148
- * @param b The exponent negative safe integer.
149
- * @returns `a ** b` clamped to the NegativeSafeInt range.
141
+ * @param a - The base negative safe integer
142
+ * @param b - The exponent negative safe integer
143
+ * @returns `a ** b` as a `NegativeSafeInt`
150
144
  */
151
145
  pow,
152
146
 
153
147
  /**
154
- * Adds two negative safe integers.
148
+ * Adds two negative safe integers, returning `a + b` as a `NegativeSafeInt`.
155
149
  *
156
- * @param a The first negative safe integer.
157
- * @param b The second negative safe integer.
158
- * @returns `a + b` clamped to the NegativeSafeInt range.
150
+ * @param a - The first negative safe integer
151
+ * @param b - The second negative safe integer
152
+ * @returns The sum of `a` and `b` as a `NegativeSafeInt`
159
153
  */
160
154
  add,
161
155
 
162
156
  /**
163
- * Subtracts one negative safe integer from another.
164
- *
165
- * The mathematical result can be positive, so it is clamped to the
166
- * NegativeSafeInt range (maximum `-1`).
157
+ * Subtracts two negative safe integers, returning `a - b` as a
158
+ * `NegativeSafeInt`.
167
159
  *
168
- * @param a The minuend negative safe integer.
169
- * @param b The subtrahend negative safe integer.
170
- * @returns `a - b` clamped to the NegativeSafeInt range.
160
+ * @param a - The first negative safe integer
161
+ * @param b - The second negative safe integer
162
+ * @returns The difference of `a` and `b` as a `NegativeSafeInt`
171
163
  */
172
164
  sub,
173
165
  } as const;