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
@@ -34,131 +34,135 @@ const {
34
34
  } as const);
35
35
 
36
36
  /**
37
- * Checks if a number is a PositiveUint16 (16-bit positive unsigned integer in
38
- * the range [1, 2^16)).
37
+ * Type guard that checks if a value is a positive integer in [1, 2^16).
39
38
  *
40
- * @param value The value to check.
41
- * @returns `true` if the value is a PositiveUint16, `false` otherwise.
39
+ * Returns `true` for a positive integer in [1, 2^16) — a value with no
40
+ * fractional component.
41
+ *
42
+ * @param value - The value to check
43
+ * @returns `true` if the value is a positive integer in [1, 2^16), `false` otherwise
42
44
  */
43
45
  export const isPositiveUint16 = is;
44
46
 
45
47
  /**
46
- * Casts a number to a PositiveUint16 type.
48
+ * Casts a `number` to the `PositiveUint16` branded type.
49
+ *
50
+ * Validates that the value is a positive integer in [1, 2^16) and returns it
51
+ * with the `PositiveUint16` brand. Throws a `TypeError` otherwise.
47
52
  *
48
- * @param value The value to cast.
49
- * @returns The value as a PositiveUint16 type.
50
- * @throws {TypeError} If the value is not a positive integer in [1, 2^16).
53
+ * @param value - The value to cast
54
+ * @returns The value as a `PositiveUint16`
55
+ * @throws {TypeError} If the value is not a positive integer in [1, 2^16)
51
56
  */
52
57
  export const asPositiveUint16 = castType;
53
58
 
54
59
  /**
55
- * Namespace providing type-safe arithmetic operations for 16-bit positive
56
- * unsigned integers.
60
+ * Namespace providing type-safe operations for the `PositiveUint16` branded
61
+ * type.
57
62
  *
58
- * All operations automatically clamp results to the valid PositiveUint16 range
59
- * [1, 65535]. This ensures that all arithmetic maintains the 16-bit positive
60
- * unsigned integer constraint, with results below 1 clamped to MIN_VALUE and
61
- * overflow results clamped to MAX_VALUE.
63
+ * The `PositiveUint16` type represents a positive integer in [1, 2^16).
64
+ * Division (`div`) uses floor division.
62
65
  */
63
66
  export const PositiveUint16 = {
64
67
  /**
65
- * Type guard to check if a value is a PositiveUint16.
68
+ * Type guard that checks if a value is a positive integer in [1, 2^16).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 16-bit positive unsigned integer, `false`
69
- * otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a positive integer in [1, 2^16), `false` otherwise
72
+ * @see {@link isPositiveUint16} for usage examples
70
73
  */
71
74
  is,
72
75
 
73
76
  /**
74
- * The minimum value for a 16-bit positive unsigned integer.
75
- *
76
- * @readonly
77
+ * The smallest value representable as `PositiveUint16`.
77
78
  */
78
79
  MIN_VALUE,
79
80
 
80
81
  /**
81
- * The maximum value for a 16-bit positive unsigned integer.
82
- *
83
- * @readonly
82
+ * The largest value representable as `PositiveUint16`.
84
83
  */
85
84
  MAX_VALUE,
86
85
 
87
86
  /**
88
- * Returns the smaller of two PositiveUint16 values.
87
+ * Returns the smallest of the given positive integers.
89
88
  *
90
- * @param a The first PositiveUint16.
91
- * @param b The second PositiveUint16.
92
- * @returns The minimum value as a PositiveUint16.
89
+ * @param values - The positive integers to compare (at least one required)
90
+ * @returns The smallest value as a `PositiveUint16`
93
91
  */
94
92
  min: min_,
95
93
 
96
94
  /**
97
- * Returns the larger of two PositiveUint16 values.
95
+ * Returns the largest of the given positive integers.
98
96
  *
99
- * @param a The first PositiveUint16.
100
- * @param b The second PositiveUint16.
101
- * @returns The maximum value as a PositiveUint16.
97
+ * @param values - The positive integers to compare (at least one required)
98
+ * @returns The largest value as a `PositiveUint16`
102
99
  */
103
100
  max: max_,
104
101
 
105
102
  /**
106
- * Clamps a number to the PositiveUint16 range.
103
+ * Clamps a `number` into the `PositiveUint16` range, rounding to the nearest
104
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
107
105
  *
108
- * @param value The number to clamp.
109
- * @returns The value clamped to [1, 65535] as a PositiveUint16.
106
+ * @param value - The value to clamp
107
+ * @returns The clamped value as a `PositiveUint16`
110
108
  */
111
109
  clamp,
112
110
 
113
111
  /**
114
- * Generates a random PositiveUint16 value within the valid range.
112
+ * Generates a random `PositiveUint16` within the given range.
113
+ *
114
+ * The range is inclusive on both ends.
115
115
  *
116
- * @returns A random PositiveUint16 between 1 and 65535.
116
+ * @param min - The minimum value (inclusive)
117
+ * @param max - The maximum value (inclusive)
118
+ * @returns A random `PositiveUint16` in `[min, max]`
117
119
  */
118
120
  random,
119
121
 
120
122
  /**
121
- * Raises a PositiveUint16 to the power of another PositiveUint16.
123
+ * Raises `a` to the power `b`, returning `a ** b` as a `PositiveUint16`
124
+ * (floored to an integer).
122
125
  *
123
- * @param a The base PositiveUint16.
124
- * @param b The exponent PositiveUint16.
125
- * @returns `a ** b` clamped to [1, 65535] as a PositiveUint16.
126
+ * @param a - The base positive integer
127
+ * @param b - The exponent positive integer
128
+ * @returns `a ** b` as a `PositiveUint16`
126
129
  */
127
130
  pow,
128
131
 
129
132
  /**
130
- * Adds two PositiveUint16 values.
133
+ * Adds two positive integers, returning `a + b` as a `PositiveUint16`.
131
134
  *
132
- * @param a The first PositiveUint16.
133
- * @param b The second PositiveUint16.
134
- * @returns `a + b` clamped to [1, 65535] as a PositiveUint16.
135
+ * @param a - The first positive integer
136
+ * @param b - The second positive integer
137
+ * @returns The sum of `a` and `b` as a `PositiveUint16`
135
138
  */
136
139
  add,
137
140
 
138
141
  /**
139
- * Subtracts one PositiveUint16 from another.
142
+ * Subtracts two positive integers, returning `a - b` as a `PositiveUint16`.
140
143
  *
141
- * @param a The minuend PositiveUint16.
142
- * @param b The subtrahend PositiveUint16.
143
- * @returns `a - b` clamped to [1, 65535] as a PositiveUint16 (minimum 1).
144
+ * @param a - The first positive integer
145
+ * @param b - The second positive integer
146
+ * @returns The difference of `a` and `b` as a `PositiveUint16`
144
147
  */
145
148
  sub,
146
149
 
147
150
  /**
148
- * Multiplies two PositiveUint16 values.
151
+ * Multiplies two positive integers, returning `a * b` as a `PositiveUint16`.
149
152
  *
150
- * @param a The first PositiveUint16.
151
- * @param b The second PositiveUint16.
152
- * @returns `a * b` clamped to [1, 65535] as a PositiveUint16.
153
+ * @param a - The first positive integer
154
+ * @param b - The second positive integer
155
+ * @returns The product of `a` and `b` as a `PositiveUint16`
153
156
  */
154
157
  mul,
155
158
 
156
159
  /**
157
- * Divides one PositiveUint16 by another using floor division.
160
+ * Divides two positive integers using floor division (`⌊a / b⌋`): the result
161
+ * is `a / b` rounded toward negative infinity, as a `PositiveUint16`.
158
162
  *
159
- * @param a The dividend PositiveUint16.
160
- * @param b The divisor PositiveUint16.
161
- * @returns `⌊a / b⌋` clamped to [1, 65535] as a PositiveUint16.
163
+ * @param a - The dividend
164
+ * @param b - The divisor (must be non-zero)
165
+ * @returns The floored quotient as a `PositiveUint16`
162
166
  */
163
167
  div,
164
168
  } as const;
@@ -34,132 +34,135 @@ const {
34
34
  } as const);
35
35
 
36
36
  /**
37
- * Checks if a number is a PositiveUint32 (32-bit positive unsigned integer in
38
- * the range [1, 2^32)).
37
+ * Type guard that checks if a value is a positive integer in [1, 2^32).
39
38
  *
40
- * @param value The value to check.
41
- * @returns `true` if the value is a PositiveUint32, `false` otherwise.
39
+ * Returns `true` for a positive integer in [1, 2^32) — a value with no
40
+ * fractional component.
41
+ *
42
+ * @param value - The value to check
43
+ * @returns `true` if the value is a positive integer in [1, 2^32), `false` otherwise
42
44
  */
43
45
  export const isPositiveUint32 = is;
44
46
 
45
47
  /**
46
- * Casts a number to a PositiveUint32 type.
48
+ * Casts a `number` to the `PositiveUint32` branded type.
49
+ *
50
+ * Validates that the value is a positive integer in [1, 2^32) and returns it
51
+ * with the `PositiveUint32` brand. Throws a `TypeError` otherwise.
47
52
  *
48
- * @param value The value to cast.
49
- * @returns The value as a PositiveUint32 type.
50
- * @throws {TypeError} If the value is not a positive integer in [1, 2^32).
53
+ * @param value - The value to cast
54
+ * @returns The value as a `PositiveUint32`
55
+ * @throws {TypeError} If the value is not a positive integer in [1, 2^32)
51
56
  */
52
57
  export const asPositiveUint32 = castType;
53
58
 
54
59
  /**
55
- * Namespace providing type-safe arithmetic operations for 32-bit positive
56
- * unsigned integers.
60
+ * Namespace providing type-safe operations for the `PositiveUint32` branded
61
+ * type.
57
62
  *
58
- * All operations automatically clamp results to the valid PositiveUint32 range
59
- * [1, 4294967295]. This ensures that all arithmetic maintains the 32-bit
60
- * positive unsigned integer constraint, with results below 1 clamped to
61
- * MIN_VALUE and overflow results clamped to MAX_VALUE.
63
+ * The `PositiveUint32` type represents a positive integer in [1, 2^32).
64
+ * Division (`div`) uses floor division.
62
65
  */
63
66
  export const PositiveUint32 = {
64
67
  /**
65
- * Type guard to check if a value is a PositiveUint32.
68
+ * Type guard that checks if a value is a positive integer in [1, 2^32).
66
69
  *
67
- * @param value The value to check.
68
- * @returns `true` if the value is a 32-bit positive unsigned integer, `false`
69
- * otherwise.
70
+ * @param value - The value to check
71
+ * @returns `true` if the value is a positive integer in [1, 2^32), `false` otherwise
72
+ * @see {@link isPositiveUint32} for usage examples
70
73
  */
71
74
  is,
72
75
 
73
76
  /**
74
- * The minimum value for a 32-bit positive unsigned integer.
75
- *
76
- * @readonly
77
+ * The smallest value representable as `PositiveUint32`.
77
78
  */
78
79
  MIN_VALUE,
79
80
 
80
81
  /**
81
- * The maximum value for a 32-bit positive unsigned integer.
82
- *
83
- * @readonly
82
+ * The largest value representable as `PositiveUint32`.
84
83
  */
85
84
  MAX_VALUE,
86
85
 
87
86
  /**
88
- * Returns the smaller of two PositiveUint32 values.
87
+ * Returns the smallest of the given positive integers.
89
88
  *
90
- * @param a The first PositiveUint32.
91
- * @param b The second PositiveUint32.
92
- * @returns The minimum value as a PositiveUint32.
89
+ * @param values - The positive integers to compare (at least one required)
90
+ * @returns The smallest value as a `PositiveUint32`
93
91
  */
94
92
  min: min_,
95
93
 
96
94
  /**
97
- * Returns the larger of two PositiveUint32 values.
95
+ * Returns the largest of the given positive integers.
98
96
  *
99
- * @param a The first PositiveUint32.
100
- * @param b The second PositiveUint32.
101
- * @returns The maximum value as a PositiveUint32.
97
+ * @param values - The positive integers to compare (at least one required)
98
+ * @returns The largest value as a `PositiveUint32`
102
99
  */
103
100
  max: max_,
104
101
 
105
102
  /**
106
- * Clamps a number to the PositiveUint32 range.
103
+ * Clamps a `number` into the `PositiveUint32` range, rounding to the nearest
104
+ * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
107
105
  *
108
- * @param value The number to clamp.
109
- * @returns The value clamped to [1, 4294967295] as a PositiveUint32.
106
+ * @param value - The value to clamp
107
+ * @returns The clamped value as a `PositiveUint32`
110
108
  */
111
109
  clamp,
112
110
 
113
111
  /**
114
- * Generates a random PositiveUint32 value within the valid range.
112
+ * Generates a random `PositiveUint32` within the given range.
113
+ *
114
+ * The range is inclusive on both ends.
115
115
  *
116
- * @returns A random PositiveUint32 between 1 and 4294967295.
116
+ * @param min - The minimum value (inclusive)
117
+ * @param max - The maximum value (inclusive)
118
+ * @returns A random `PositiveUint32` in `[min, max]`
117
119
  */
118
120
  random,
119
121
 
120
122
  /**
121
- * Raises a PositiveUint32 to the power of another PositiveUint32.
123
+ * Raises `a` to the power `b`, returning `a ** b` as a `PositiveUint32`
124
+ * (floored to an integer).
122
125
  *
123
- * @param a The base PositiveUint32.
124
- * @param b The exponent PositiveUint32.
125
- * @returns `a ** b` clamped to [1, 4294967295] as a PositiveUint32.
126
+ * @param a - The base positive integer
127
+ * @param b - The exponent positive integer
128
+ * @returns `a ** b` as a `PositiveUint32`
126
129
  */
127
130
  pow,
128
131
 
129
132
  /**
130
- * Adds two PositiveUint32 values.
133
+ * Adds two positive integers, returning `a + b` as a `PositiveUint32`.
131
134
  *
132
- * @param a The first PositiveUint32.
133
- * @param b The second PositiveUint32.
134
- * @returns `a + b` clamped to [1, 4294967295] as a PositiveUint32.
135
+ * @param a - The first positive integer
136
+ * @param b - The second positive integer
137
+ * @returns The sum of `a` and `b` as a `PositiveUint32`
135
138
  */
136
139
  add,
137
140
 
138
141
  /**
139
- * Subtracts one PositiveUint32 from another.
142
+ * Subtracts two positive integers, returning `a - b` as a `PositiveUint32`.
140
143
  *
141
- * @param a The minuend PositiveUint32.
142
- * @param b The subtrahend PositiveUint32.
143
- * @returns `a - b` clamped to [1, 4294967295] as a PositiveUint32 (minimum
144
- * 1).
144
+ * @param a - The first positive integer
145
+ * @param b - The second positive integer
146
+ * @returns The difference of `a` and `b` as a `PositiveUint32`
145
147
  */
146
148
  sub,
147
149
 
148
150
  /**
149
- * Multiplies two PositiveUint32 values.
151
+ * Multiplies two positive integers, returning `a * b` as a `PositiveUint32`.
150
152
  *
151
- * @param a The first PositiveUint32.
152
- * @param b The second PositiveUint32.
153
- * @returns `a * b` clamped to [1, 4294967295] as a PositiveUint32.
153
+ * @param a - The first positive integer
154
+ * @param b - The second positive integer
155
+ * @returns The product of `a` and `b` as a `PositiveUint32`
154
156
  */
155
157
  mul,
156
158
 
157
159
  /**
158
- * Divides one PositiveUint32 by another using floor division.
160
+ * Divides two positive integers using floor division (`⌊a / b⌋`): the result
161
+ * is `a / b` rounded toward negative infinity, as a `PositiveUint32`.
159
162
  *
160
- * @param a The dividend PositiveUint32.
161
- * @param b The divisor PositiveUint32.
162
- * @returns `⌊a / b⌋` clamped to [1, 4294967295] as a PositiveUint32.
163
+ * @param a - The dividend
164
+ * @param b - The divisor (must be non-zero)
165
+ * @returns The floored quotient as a `PositiveUint32`
163
166
  */
164
167
  div,
165
168
  } as const;
@@ -42,8 +42,7 @@ const {
42
42
  /**
43
43
  * Type guard that checks if a value is a safe integer.
44
44
  *
45
- * A safe integer is an integer that can be exactly represented in JavaScript
46
- * without precision loss. The range is [±(2^53 - 1)].
45
+ * Returns `true` for a safe integer — a value with no fractional component.
47
46
  *
48
47
  * @example
49
48
  *
@@ -61,11 +60,10 @@ const {
61
60
  export const isSafeInt = is;
62
61
 
63
62
  /**
64
- * Casts a number to a SafeInt branded type.
63
+ * Casts a `number` to the `SafeInt` branded type.
65
64
  *
66
- * This function validates that the input is a safe integer (within ±(2^53 - 1))
67
- * and returns it with the SafeInt brand. This ensures type safety for
68
- * operations that require precise integer arithmetic.
65
+ * Validates that the value is a safe integer and returns it with the `SafeInt`
66
+ * brand. Throws a `TypeError` otherwise.
69
67
  *
70
68
  * @example
71
69
  *
@@ -78,26 +76,16 @@ export const isSafeInt = is;
78
76
  * ```
79
77
  *
80
78
  * @param value - The value to cast
81
- * @returns The value as a SafeInt branded type
79
+ * @returns The value as a `SafeInt`
82
80
  * @throws {TypeError} If the value is not a safe integer
83
81
  */
84
82
  export const asSafeInt = castType;
85
83
 
86
84
  /**
87
- * Namespace providing type-safe operations for SafeInt branded types.
85
+ * Namespace providing type-safe operations for the `SafeInt` branded type.
88
86
  *
89
- * SafeInt represents integers that can be exactly represented in JavaScript's
90
- * number type without precision loss. The range is [±(2^53 - 1)], which covers
91
- * approximately ±9 quadrillion.
92
- *
93
- * All operations automatically clamp results to stay within the safe range,
94
- * preventing precision loss that occurs with larger integers. This makes
95
- * SafeInt ideal for:
96
- *
97
- * - Financial calculations requiring exact cents
98
- * - Database IDs and counters
99
- * - Array indices and sizes
100
- * - Any integer arithmetic requiring precision guarantees
87
+ * The `SafeInt` type represents a safe integer. Division (`div`) uses floor
88
+ * division.
101
89
  */
102
90
  export const SafeInt = {
103
91
  /**
@@ -120,24 +108,19 @@ export const SafeInt = {
120
108
  is,
121
109
 
122
110
  /**
123
- * The minimum safe integer value (-(2^53 - 1)).
124
- *
125
- * @readonly
111
+ * The smallest value representable as `SafeInt`.
126
112
  */
127
113
  MIN_VALUE,
128
114
 
129
115
  /**
130
- * The maximum safe integer value (2^53 - 1).
131
- *
132
- * @readonly
116
+ * The largest value representable as `SafeInt`.
133
117
  */
134
118
  MAX_VALUE,
135
119
 
136
120
  /**
137
121
  * Returns the absolute value of a safe integer.
138
122
  *
139
- * Note: `Math.abs(MIN_SAFE_INTEGER)` would exceed `MAX_SAFE_INTEGER`, so this
140
- * function clamps the result to maintain the safe integer guarantee.
123
+ * The result is non-negative and keeps the `SafeInt` brand.
141
124
  *
142
125
  * @example
143
126
  *
@@ -152,12 +135,12 @@ export const SafeInt = {
152
135
  * ```
153
136
  *
154
137
  * @param a - The safe integer value
155
- * @returns The absolute value as a SafeInt, clamped if necessary
138
+ * @returns The absolute value as a non-negative `SafeInt`
156
139
  */
157
140
  abs,
158
141
 
159
142
  /**
160
- * Returns the minimum value from a list of safe integers.
143
+ * Returns the smallest of the given safe integers.
161
144
  *
162
145
  * @example
163
146
  *
@@ -168,12 +151,12 @@ export const SafeInt = {
168
151
  * ```
169
152
  *
170
153
  * @param values - The safe integers to compare (at least one required)
171
- * @returns The smallest value as a SafeInt
154
+ * @returns The smallest value as a `SafeInt`
172
155
  */
173
156
  min: min_,
174
157
 
175
158
  /**
176
- * Returns the maximum value from a list of safe integers.
159
+ * Returns the largest of the given safe integers.
177
160
  *
178
161
  * @example
179
162
  *
@@ -184,12 +167,13 @@ export const SafeInt = {
184
167
  * ```
185
168
  *
186
169
  * @param values - The safe integers to compare (at least one required)
187
- * @returns The largest value as a SafeInt
170
+ * @returns The largest value as a `SafeInt`
188
171
  */
189
172
  max: max_,
190
173
 
191
174
  /**
192
- * Clamps a number to the safe integer range.
175
+ * Clamps a `number` into the `SafeInt` range, rounding to the nearest integer
176
+ * and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
193
177
  *
194
178
  * @example
195
179
  *
@@ -207,17 +191,15 @@ export const SafeInt = {
207
191
  * assert.isTrue(belowRange === Number.MIN_SAFE_INTEGER);
208
192
  * ```
209
193
  *
210
- * @param value The number to clamp.
211
- * @returns The value clamped to [MIN_SAFE_INTEGER, MAX_SAFE_INTEGER] as a
212
- * SafeInt.
194
+ * @param value - The value to clamp
195
+ * @returns The clamped value as a `SafeInt`
213
196
  */
214
197
  clamp,
215
198
 
216
199
  /**
217
- * Generates a random safe integer within the specified range (inclusive).
200
+ * Generates a random `SafeInt` within the given range.
218
201
  *
219
- * The range is inclusive on both ends. If min > max, they are automatically
220
- * swapped.
202
+ * The range is inclusive on both ends.
221
203
  *
222
204
  * @example
223
205
  *
@@ -235,12 +217,13 @@ export const SafeInt = {
235
217
  *
236
218
  * @param min - The minimum value (inclusive)
237
219
  * @param max - The maximum value (inclusive)
238
- * @returns A random SafeInt in the range [min, max]
220
+ * @returns A random `SafeInt` in `[min, max]`
239
221
  */
240
222
  random,
241
223
 
242
224
  /**
243
- * Raises a SafeInt to the power of another SafeInt.
225
+ * Raises `a` to the power `b`, returning `a ** b` as a `SafeInt` (floored to
226
+ * an integer).
244
227
  *
245
228
  * @example
246
229
  *
@@ -256,14 +239,14 @@ export const SafeInt = {
256
239
  * assert.isTrue(SafeInt.is(power));
257
240
  * ```
258
241
  *
259
- * @param a The base SafeInt.
260
- * @param b The exponent SafeInt.
261
- * @returns `a ** b` clamped to safe integer range as a SafeInt.
242
+ * @param a - The base safe integer
243
+ * @param b - The exponent safe integer
244
+ * @returns `a ** b` as a `SafeInt`
262
245
  */
263
246
  pow,
264
247
 
265
248
  /**
266
- * Adds two SafeInt values.
249
+ * Adds two safe integers, returning `a + b` as a `SafeInt`.
267
250
  *
268
251
  * @example
269
252
  *
@@ -275,14 +258,14 @@ export const SafeInt = {
275
258
  * assert.isTrue(SafeInt.is(sum));
276
259
  * ```
277
260
  *
278
- * @param a The first SafeInt.
279
- * @param b The second SafeInt.
280
- * @returns `a + b` clamped to safe integer range as a SafeInt.
261
+ * @param a - The first safe integer
262
+ * @param b - The second safe integer
263
+ * @returns The sum of `a` and `b` as a `SafeInt`
281
264
  */
282
265
  add,
283
266
 
284
267
  /**
285
- * Subtracts one SafeInt from another.
268
+ * Subtracts two safe integers, returning `a - b` as a `SafeInt`.
286
269
  *
287
270
  * @example
288
271
  *
@@ -294,14 +277,14 @@ export const SafeInt = {
294
277
  * assert.isTrue(SafeInt.is(difference));
295
278
  * ```
296
279
  *
297
- * @param a The minuend SafeInt.
298
- * @param b The subtrahend SafeInt.
299
- * @returns `a - b` clamped to safe integer range as a SafeInt.
280
+ * @param a - The first safe integer
281
+ * @param b - The second safe integer
282
+ * @returns The difference of `a` and `b` as a `SafeInt`
300
283
  */
301
284
  sub,
302
285
 
303
286
  /**
304
- * Multiplies two SafeInt values.
287
+ * Multiplies two safe integers, returning `a * b` as a `SafeInt`.
305
288
  *
306
289
  * @example
307
290
  *
@@ -313,17 +296,15 @@ export const SafeInt = {
313
296
  * assert.isTrue(SafeInt.is(product));
314
297
  * ```
315
298
  *
316
- * @param a The first SafeInt.
317
- * @param b The second SafeInt.
318
- * @returns `a * b` clamped to safe integer range as a SafeInt.
299
+ * @param a - The first safe integer
300
+ * @param b - The second safe integer
301
+ * @returns The product of `a` and `b` as a `SafeInt`
319
302
  */
320
303
  mul,
321
304
 
322
305
  /**
323
- * Divides one SafeInt by another using floor division.
324
- *
325
- * Performs mathematical floor division: `⌊a / b⌋`. The divisor must be
326
- * non-zero (enforced by type constraints).
306
+ * Divides two safe integers using floor division (`⌊a / b⌋`): the result is
307
+ * `a / b` rounded toward negative infinity, as a `SafeInt`.
327
308
  *
328
309
  * @example
329
310
  *
@@ -337,7 +318,7 @@ export const SafeInt = {
337
318
  *
338
319
  * @param a - The dividend
339
320
  * @param b - The divisor (must be non-zero)
340
- * @returns The integer quotient as a SafeInt
321
+ * @returns The floored quotient as a `SafeInt`
341
322
  */
342
323
  div,
343
324
  } as const;