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,7 +13,7 @@ const {
13
13
  MIN_VALUE,
14
14
  abs,
15
15
  castType,
16
- clamp,
16
+ fromNumber,
17
17
  is,
18
18
  max: max_,
19
19
  min: min_,
@@ -33,118 +33,122 @@ const {
33
33
  } as const);
34
34
 
35
35
  /**
36
- * Checks if a number is a NonZeroInt32 (32-bit non-zero signed integer in the
37
- * range [-2^31, 2^31) excluding 0).
36
+ * Type guard that checks if a value is a non-zero integer in [-2^31, 2^31).
38
37
  *
39
- * @param value The value to check.
40
- * @returns `true` if the value is a NonZeroInt32, `false` otherwise.
38
+ * Returns `true` for a non-zero integer in [-2^31, 2^31) — a value with no
39
+ * fractional component.
40
+ *
41
+ * @param value - The value to check
42
+ * @returns `true` if the value is a non-zero integer in [-2^31, 2^31), `false` otherwise
41
43
  */
42
44
  export const isNonZeroInt32 = is;
43
45
 
44
46
  /**
45
- * Casts a number to a NonZeroInt32 type.
47
+ * Casts a `number` to the `NonZeroInt32` branded type.
48
+ *
49
+ * Validates that the value is a non-zero integer in [-2^31, 2^31) and returns
50
+ * it with the `NonZeroInt32` brand. Throws a `TypeError` otherwise.
46
51
  *
47
- * @param value The value to cast.
48
- * @returns The value as a NonZeroInt32 type.
49
- * @throws {TypeError} If the value is not a non-zero integer in [-2^31, 2^31).
52
+ * @param value - The value to cast
53
+ * @returns The value as a `NonZeroInt32`
54
+ * @throws {TypeError} If the value is not a non-zero integer in [-2^31, 2^31)
50
55
  */
51
56
  export const asNonZeroInt32 = castType;
52
57
 
53
58
  /**
54
- * Namespace providing type-safe arithmetic operations for 32-bit non-zero
55
- * signed integers.
59
+ * Namespace providing type-safe operations for the `NonZeroInt32` branded type.
56
60
  *
57
- * All operations automatically clamp results to the valid NonZeroInt32 range
58
- * [-2147483648, 2147483647] excluding 0. This ensures that all arithmetic
59
- * maintains the 32-bit non-zero signed integer constraint, preventing zero
60
- * results and overflow.
61
+ * The `NonZeroInt32` type represents a non-zero integer in [-2^31, 2^31).
62
+ * Division (`div`) uses floor division.
61
63
  */
62
64
  export const NonZeroInt32 = {
63
65
  /**
64
- * Type guard to check if a value is a NonZeroInt32.
66
+ * Type guard that checks if a value is a non-zero integer in [-2^31, 2^31).
65
67
  *
66
- * @param value The value to check.
67
- * @returns `true` if the value is a 32-bit non-zero signed integer, `false`
68
- * otherwise.
68
+ * @param value - The value to check
69
+ * @returns `true` if the value is a non-zero integer in [-2^31, 2^31), `false` otherwise
70
+ * @see {@link isNonZeroInt32} for usage examples
69
71
  */
70
72
  is,
71
73
 
72
74
  /**
73
- * The minimum value for a 32-bit non-zero signed integer.
74
- *
75
- * @readonly
75
+ * The smallest value representable as `NonZeroInt32` (the lower saturation
76
+ * target of `fromNumber`).
76
77
  */
77
78
  MIN_VALUE,
78
79
 
79
80
  /**
80
- * The maximum value for a 32-bit non-zero signed integer.
81
- *
82
- * @readonly
81
+ * The largest value representable as `NonZeroInt32` (the upper saturation
82
+ * target of `fromNumber`).
83
83
  */
84
84
  MAX_VALUE,
85
85
 
86
86
  /**
87
- * Returns the absolute value of a 32-bit non-zero signed integer.
87
+ * Returns the absolute value of a non-zero integer in [-2^31, 2^31).
88
88
  *
89
- * @param a The NonZeroInt32 value.
90
- * @returns The absolute value as a NonZeroInt32, clamped to valid range.
89
+ * The result is non-negative and keeps the `NonZeroInt32` brand.
90
+ *
91
+ * @param a - The non-zero integer value
92
+ * @returns The absolute value as a non-negative `NonZeroInt32`
91
93
  */
92
94
  abs,
93
95
 
94
96
  /**
95
- * Returns the smaller of two NonZeroInt32 values.
97
+ * Returns the smallest of the given non-zero integers.
96
98
  *
97
- * @param a The first NonZeroInt32.
98
- * @param b The second NonZeroInt32.
99
- * @returns The minimum value as a NonZeroInt32.
99
+ * @param values - The non-zero integers to compare (at least one required)
100
+ * @returns The smallest value as a `NonZeroInt32`
100
101
  */
101
102
  min: min_,
102
103
 
103
104
  /**
104
- * Returns the larger of two NonZeroInt32 values.
105
+ * Returns the largest of the given non-zero integers.
105
106
  *
106
- * @param a The first NonZeroInt32.
107
- * @param b The second NonZeroInt32.
108
- * @returns The maximum value as a NonZeroInt32.
107
+ * @param values - The non-zero integers to compare (at least one required)
108
+ * @returns The largest value as a `NonZeroInt32`
109
109
  */
110
110
  max: max_,
111
111
 
112
112
  /**
113
- * Clamps a number to the NonZeroInt32 range (avoiding zero).
113
+ * Converts an arbitrary `number` into a `NonZeroInt32`, rounding to the
114
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
115
+ * MAX_VALUE]`.
116
+ *
117
+ * Unlike `asNonZeroInt32`, this is total: out-of-range inputs are clamped to
118
+ * the nearest representable `NonZeroInt32` instead of throwing.
114
119
  *
115
- * @param value The number to clamp.
116
- * @returns The value clamped to [-2147483648, 2147483647] \ {0} as a
117
- * NonZeroInt32.
120
+ * @param value - The value to convert
121
+ * @returns The value as a `NonZeroInt32`
118
122
  */
119
- clamp,
123
+ fromNumber,
120
124
 
121
125
  /**
122
- * Generates a random NonZeroInt32 value within the valid range.
126
+ * Generates a random `NonZeroInt32` within the given range.
123
127
  *
124
- * @returns A random NonZeroInt32 between MIN_VALUE and MAX_VALUE (excluding
125
- * 0).
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 `NonZeroInt32` in `[min, max]`
126
133
  */
127
134
  random,
128
135
 
129
136
  /**
130
- * Raises a NonZeroInt32 to the power of another NonZeroInt32.
137
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonZeroInt32`
138
+ * (floored to an integer).
131
139
  *
132
- * @param a The base NonZeroInt32.
133
- * @param b The exponent NonZeroInt32.
134
- * @returns `a ** b` clamped to [-2147483648, 2147483647] as a NonZeroInt32.
140
+ * @param a - The base non-zero integer
141
+ * @param b - The exponent non-zero integer
142
+ * @returns `a ** b` as a `NonZeroInt32`
135
143
  */
136
144
  pow,
137
145
 
138
146
  /**
139
- * Multiplies two NonZeroInt32 values.
140
- *
141
- * The product of two non-zero integers is always non-zero, so this stays
142
- * closed; for the non-closed operations (`add`/`sub`/`div`, whose result may
143
- * be `0`) use {@link Num.add}/{@link Num.sub}/{@link Num.divInt}.
147
+ * Multiplies two non-zero integers, returning `a * b` as a `NonZeroInt32`.
144
148
  *
145
- * @param a The first NonZeroInt32.
146
- * @param b The second NonZeroInt32.
147
- * @returns `a * b` clamped to [-2147483648, 2147483647] as a NonZeroInt32.
149
+ * @param a - The first non-zero integer
150
+ * @param b - The second non-zero integer
151
+ * @returns The product of `a` and `b` as a `NonZeroInt32`
148
152
  */
149
153
  mul,
150
154
  } as const;
@@ -17,7 +17,7 @@ const {
17
17
  MIN_VALUE,
18
18
  abs,
19
19
  castType,
20
- clamp,
20
+ fromNumber,
21
21
  is,
22
22
  max: max_,
23
23
  min: min_,
@@ -39,119 +39,124 @@ const {
39
39
  } as const);
40
40
 
41
41
  /**
42
- * Checks if a number is a NonZeroSafeInt (a non-zero safe integer in the range
43
- * [MIN_SAFE_INTEGER, MAX_SAFE_INTEGER] excluding 0).
42
+ * Type guard that checks if a value is a non-zero safe integer.
44
43
  *
45
- * @param value The value to check.
46
- * @returns `true` if the value is a NonZeroSafeInt, `false` otherwise.
44
+ * Returns `true` for a non-zero safe integer — a value with no fractional
45
+ * component.
46
+ *
47
+ * @param value - The value to check
48
+ * @returns `true` if the value is a non-zero safe integer, `false` otherwise
47
49
  */
48
50
  export const isNonZeroSafeInt = is;
49
51
 
50
52
  /**
51
- * Casts a number to a NonZeroSafeInt type.
53
+ * Casts a `number` to the `NonZeroSafeInt` branded type.
54
+ *
55
+ * Validates that the value is a non-zero safe integer and returns it with the
56
+ * `NonZeroSafeInt` brand. Throws a `TypeError` otherwise.
52
57
  *
53
- * @param value The value to cast.
54
- * @returns The value as a NonZeroSafeInt type.
55
- * @throws {TypeError} If the value is not a non-zero safe integer.
58
+ * @param value - The value to cast
59
+ * @returns The value as a `NonZeroSafeInt`
60
+ * @throws {TypeError} If the value is not a non-zero safe integer
56
61
  */
57
62
  export const asNonZeroSafeInt = castType;
58
63
 
59
64
  /**
60
- * Namespace providing type-safe arithmetic operations for non-zero safe
61
- * integers.
65
+ * Namespace providing type-safe operations for the `NonZeroSafeInt` branded
66
+ * type.
62
67
  *
63
- * All operations automatically clamp results to the non-zero safe integer
64
- * range, excluding zero. This ensures that all arithmetic maintains both the
65
- * non-zero constraint and IEEE 754 precision guarantees, preventing precision
66
- * loss while ensuring results are never zero.
68
+ * The `NonZeroSafeInt` type represents a non-zero safe integer. Division
69
+ * (`div`) uses floor division.
67
70
  */
68
71
  export const NonZeroSafeInt = {
69
72
  /**
70
- * Type guard to check if a value is a NonZeroSafeInt.
73
+ * Type guard that checks if a value is a non-zero safe integer.
71
74
  *
72
- * @param value The value to check.
73
- * @returns `true` if the value is a non-zero safe integer, `false` otherwise.
75
+ * @param value - The value to check
76
+ * @returns `true` if the value is a non-zero safe integer, `false` otherwise
77
+ * @see {@link isNonZeroSafeInt} for usage examples
74
78
  */
75
79
  is,
76
80
 
77
81
  /**
78
- * The minimum safe integer value (-(2^53 - 1)).
79
- *
80
- * @readonly
82
+ * The smallest value representable as `NonZeroSafeInt` (the lower saturation
83
+ * target of `fromNumber`).
81
84
  */
82
85
  MIN_VALUE,
83
86
 
84
87
  /**
85
- * The maximum safe integer value (2^53 - 1).
86
- *
87
- * @readonly
88
+ * The largest value representable as `NonZeroSafeInt` (the upper saturation
89
+ * target of `fromNumber`).
88
90
  */
89
91
  MAX_VALUE,
90
92
 
91
93
  /**
92
94
  * Returns the absolute value of a non-zero safe integer.
93
95
  *
94
- * @param a The NonZeroSafeInt value.
95
- * @returns The absolute value as a NonZeroSafeInt, clamped to safe range.
96
+ * The result is non-negative and keeps the `NonZeroSafeInt` brand.
97
+ *
98
+ * @param a - The non-zero safe integer value
99
+ * @returns The absolute value as a non-negative `NonZeroSafeInt`
96
100
  */
97
101
  abs,
98
102
 
99
103
  /**
100
- * Returns the smaller of two NonZeroSafeInt values.
104
+ * Returns the smallest of the given non-zero safe integers.
101
105
  *
102
- * @param a The first NonZeroSafeInt.
103
- * @param b The second NonZeroSafeInt.
104
- * @returns The minimum value as a NonZeroSafeInt.
106
+ * @param values - The non-zero safe integers to compare (at least one required)
107
+ * @returns The smallest value as a `NonZeroSafeInt`
105
108
  */
106
109
  min: min_,
107
110
 
108
111
  /**
109
- * Returns the larger of two NonZeroSafeInt values.
112
+ * Returns the largest of the given non-zero safe integers.
110
113
  *
111
- * @param a The first NonZeroSafeInt.
112
- * @param b The second NonZeroSafeInt.
113
- * @returns The maximum value as a NonZeroSafeInt.
114
+ * @param values - The non-zero safe integers to compare (at least one required)
115
+ * @returns The largest value as a `NonZeroSafeInt`
114
116
  */
115
117
  max: max_,
116
118
 
117
119
  /**
118
- * Clamps a number to the non-zero safe integer range.
120
+ * Converts an arbitrary `number` into a `NonZeroSafeInt`, rounding to the
121
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
122
+ * MAX_VALUE]`.
123
+ *
124
+ * Unlike `asNonZeroSafeInt`, this is total: out-of-range inputs are clamped
125
+ * to the nearest representable `NonZeroSafeInt` instead of throwing.
119
126
  *
120
- * @param value The number to clamp.
121
- * @returns The value clamped to [MIN_SAFE_INTEGER, MAX_SAFE_INTEGER] \ {0} as
122
- * a NonZeroSafeInt.
127
+ * @param value - The value to convert
128
+ * @returns The value as a `NonZeroSafeInt`
123
129
  */
124
- clamp,
130
+ fromNumber,
125
131
 
126
132
  /**
127
- * Generates a random NonZeroSafeInt value within the valid range.
133
+ * Generates a random `NonZeroSafeInt` within the given range.
128
134
  *
129
- * @returns A random non-zero safe integer between MIN_SAFE_INTEGER and
130
- * MAX_SAFE_INTEGER.
135
+ * The range is inclusive on both ends.
136
+ *
137
+ * @param min - The minimum value (inclusive)
138
+ * @param max - The maximum value (inclusive)
139
+ * @returns A random `NonZeroSafeInt` in `[min, max]`
131
140
  */
132
141
  random,
133
142
 
134
143
  /**
135
- * Raises a NonZeroSafeInt to the power of another NonZeroSafeInt.
144
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonZeroSafeInt`
145
+ * (floored to an integer).
136
146
  *
137
- * @param a The base NonZeroSafeInt.
138
- * @param b The exponent NonZeroSafeInt.
139
- * @returns `a ** b` clamped to non-zero safe integer range as a
140
- * NonZeroSafeInt.
147
+ * @param a - The base non-zero safe integer
148
+ * @param b - The exponent non-zero safe integer
149
+ * @returns `a ** b` as a `NonZeroSafeInt`
141
150
  */
142
151
  pow,
143
152
 
144
153
  /**
145
- * Multiplies two NonZeroSafeInt values.
146
- *
147
- * The product of two non-zero safe integers is always non-zero, so this stays
148
- * closed; for the non-closed operations (`add`/`sub`/`div`, whose result may
149
- * be `0`) use {@link Num.add}/{@link Num.sub}/{@link Num.divInt}.
154
+ * Multiplies two non-zero safe integers, returning `a * b` as a
155
+ * `NonZeroSafeInt`.
150
156
  *
151
- * @param a The first NonZeroSafeInt.
152
- * @param b The second NonZeroSafeInt.
153
- * @returns `a * b` clamped to non-zero safe integer range as a
154
- * NonZeroSafeInt.
157
+ * @param a - The first non-zero safe integer
158
+ * @param b - The second non-zero safe integer
159
+ * @returns The product of `a` and `b` as a `NonZeroSafeInt`
155
160
  */
156
161
  mul,
157
162
  } as const;
@@ -13,7 +13,7 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
16
+ fromNumber,
17
17
  is,
18
18
  max: max_,
19
19
  min: min_,
@@ -33,117 +33,122 @@ const {
33
33
  } as const);
34
34
 
35
35
  /**
36
- * Checks if a number is a NonZeroUint16 (16-bit non-zero unsigned integer in
37
- * the range [1, 2^16)).
36
+ * Type guard that checks if a value is a non-zero integer in [1, 2^16).
38
37
  *
39
- * @param value The value to check.
40
- * @returns `true` if the value is a NonZeroUint16, `false` otherwise.
38
+ * Returns `true` for a non-zero integer in [1, 2^16) — a value with no
39
+ * fractional component.
40
+ *
41
+ * @param value - The value to check
42
+ * @returns `true` if the value is a non-zero integer in [1, 2^16), `false` otherwise
41
43
  */
42
44
  export const isNonZeroUint16 = is;
43
45
 
44
46
  /**
45
- * Casts a number to a NonZeroUint16 type.
47
+ * Casts a `number` to the `NonZeroUint16` branded type.
48
+ *
49
+ * Validates that the value is a non-zero integer in [1, 2^16) and returns it
50
+ * with the `NonZeroUint16` brand. Throws a `TypeError` otherwise.
46
51
  *
47
- * @param value The value to cast.
48
- * @returns The value as a NonZeroUint16 type.
49
- * @throws {TypeError} If the value is not a non-zero integer in [1, 2^16).
52
+ * @param value - The value to cast
53
+ * @returns The value as a `NonZeroUint16`
54
+ * @throws {TypeError} If the value is not a non-zero integer in [1, 2^16)
50
55
  */
51
56
  export const asNonZeroUint16 = castType;
52
57
 
53
58
  /**
54
- * Namespace providing type-safe arithmetic operations for 16-bit non-zero
55
- * unsigned integers.
59
+ * Namespace providing type-safe operations for the `NonZeroUint16` branded
60
+ * type.
56
61
  *
57
- * All operations automatically clamp results to the valid NonZeroUint16 range
58
- * [1, 65535]. This ensures that all arithmetic maintains the 16-bit non-zero
59
- * unsigned integer constraint, with results below 1 clamped to MIN_VALUE and
60
- * overflow results clamped to MAX_VALUE.
62
+ * The `NonZeroUint16` type represents a non-zero integer in [1, 2^16). Division
63
+ * (`div`) uses floor division.
61
64
  */
62
65
  export const NonZeroUint16 = {
63
66
  /**
64
- * Type guard to check if a value is a NonZeroUint16.
67
+ * Type guard that checks if a value is a non-zero integer in [1, 2^16).
65
68
  *
66
- * @param value The value to check.
67
- * @returns `true` if the value is a 16-bit non-zero unsigned integer, `false`
68
- * otherwise.
69
+ * @param value - The value to check
70
+ * @returns `true` if the value is a non-zero integer in [1, 2^16), `false` otherwise
71
+ * @see {@link isNonZeroUint16} for usage examples
69
72
  */
70
73
  is,
71
74
 
72
75
  /**
73
- * The minimum value for a 16-bit non-zero unsigned integer.
74
- *
75
- * @readonly
76
+ * The smallest value representable as `NonZeroUint16` (the lower saturation
77
+ * target of `fromNumber`).
76
78
  */
77
79
  MIN_VALUE,
78
80
 
79
81
  /**
80
- * The maximum value for a 16-bit non-zero unsigned integer.
81
- *
82
- * @readonly
82
+ * The largest value representable as `NonZeroUint16` (the upper saturation
83
+ * target of `fromNumber`).
83
84
  */
84
85
  MAX_VALUE,
85
86
 
86
87
  /**
87
- * Returns the smaller of two NonZeroUint16 values.
88
+ * Returns the smallest of the given non-zero integers.
88
89
  *
89
- * @param a The first NonZeroUint16.
90
- * @param b The second NonZeroUint16.
91
- * @returns The minimum value as a NonZeroUint16.
90
+ * @param values - The non-zero integers to compare (at least one required)
91
+ * @returns The smallest value as a `NonZeroUint16`
92
92
  */
93
93
  min: min_,
94
94
 
95
95
  /**
96
- * Returns the larger of two NonZeroUint16 values.
96
+ * Returns the largest of the given non-zero integers.
97
97
  *
98
- * @param a The first NonZeroUint16.
99
- * @param b The second NonZeroUint16.
100
- * @returns The maximum value as a NonZeroUint16.
98
+ * @param values - The non-zero integers to compare (at least one required)
99
+ * @returns The largest value as a `NonZeroUint16`
101
100
  */
102
101
  max: max_,
103
102
 
104
103
  /**
105
- * Clamps a number to the NonZeroUint16 range.
104
+ * Converts an arbitrary `number` into a `NonZeroUint16`, rounding to the
105
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
106
+ * MAX_VALUE]`.
106
107
  *
107
- * @param value The number to clamp.
108
- * @returns The value clamped to [1, 65535] as a NonZeroUint16.
108
+ * Unlike `asNonZeroUint16`, this is total: out-of-range inputs are clamped to
109
+ * the nearest representable `NonZeroUint16` instead of throwing.
110
+ *
111
+ * @param value - The value to convert
112
+ * @returns The value as a `NonZeroUint16`
109
113
  */
110
- clamp,
114
+ fromNumber,
111
115
 
112
116
  /**
113
- * Generates a random NonZeroUint16 value within the valid range.
117
+ * Generates a random `NonZeroUint16` within the given range.
118
+ *
119
+ * The range is inclusive on both ends.
114
120
  *
115
- * @returns A random NonZeroUint16 between 1 and 65535.
121
+ * @param min - The minimum value (inclusive)
122
+ * @param max - The maximum value (inclusive)
123
+ * @returns A random `NonZeroUint16` in `[min, max]`
116
124
  */
117
125
  random,
118
126
 
119
127
  /**
120
- * Raises a NonZeroUint16 to the power of another NonZeroUint16.
128
+ * Raises `a` to the power `b`, returning `a ** b` as a `NonZeroUint16`
129
+ * (floored to an integer).
121
130
  *
122
- * @param a The base NonZeroUint16.
123
- * @param b The exponent NonZeroUint16.
124
- * @returns `a ** b` clamped to [1, 65535] as a NonZeroUint16.
131
+ * @param a - The base non-zero integer
132
+ * @param b - The exponent non-zero integer
133
+ * @returns `a ** b` as a `NonZeroUint16`
125
134
  */
126
135
  pow,
127
136
 
128
137
  /**
129
- * Adds two NonZeroUint16 values.
138
+ * Adds two non-zero integers, returning `a + b` as a `NonZeroUint16`.
130
139
  *
131
- * @param a The first NonZeroUint16.
132
- * @param b The second NonZeroUint16.
133
- * @returns `a + b` clamped to [1, 65535] as a NonZeroUint16.
140
+ * @param a - The first non-zero integer
141
+ * @param b - The second non-zero integer
142
+ * @returns The sum of `a` and `b` as a `NonZeroUint16`
134
143
  */
135
144
  add,
136
145
 
137
146
  /**
138
- * Multiplies two NonZeroUint16 values.
139
- *
140
- * Both `add` and `mul` stay within `[1, 65535]`. For the non-closed
141
- * operations (`sub`/`div`, whose result may be `0`) use {@link Num.sub} /
142
- * {@link Num.divInt}.
147
+ * Multiplies two non-zero integers, returning `a * b` as a `NonZeroUint16`.
143
148
  *
144
- * @param a The first NonZeroUint16.
145
- * @param b The second NonZeroUint16.
146
- * @returns `a * b` clamped to [1, 65535] as a NonZeroUint16.
149
+ * @param a - The first non-zero integer
150
+ * @param b - The second non-zero integer
151
+ * @returns The product of `a` and `b` as a `NonZeroUint16`
147
152
  */
148
153
  mul,
149
154
  } as const;