ts-data-forge 11.0.1 → 12.1.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 (178) hide show
  1. package/README.md +2 -2
  2. package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +65 -5
  3. package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
  4. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +69 -27
  5. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
  6. package/dist/array/impl/index.mjs +1 -1
  7. package/dist/number/branded-types/int16.d.mts +12 -7
  8. package/dist/number/branded-types/int16.d.mts.map +1 -1
  9. package/dist/number/branded-types/int16.mjs +13 -8
  10. package/dist/number/branded-types/int16.mjs.map +1 -1
  11. package/dist/number/branded-types/int32.d.mts +12 -7
  12. package/dist/number/branded-types/int32.d.mts.map +1 -1
  13. package/dist/number/branded-types/int32.mjs +13 -8
  14. package/dist/number/branded-types/int32.mjs.map +1 -1
  15. package/dist/number/branded-types/negative-finite-number.d.mts +13 -6
  16. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  17. package/dist/number/branded-types/negative-finite-number.mjs +15 -8
  18. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  19. package/dist/number/branded-types/negative-int.d.mts +11 -6
  20. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  21. package/dist/number/branded-types/negative-int.mjs +13 -8
  22. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  23. package/dist/number/branded-types/negative-safe-int.d.mts +13 -7
  24. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  25. package/dist/number/branded-types/negative-safe-int.mjs +15 -9
  26. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  27. package/dist/number/branded-types/non-negative-finite-number.d.mts +11 -6
  28. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  29. package/dist/number/branded-types/non-negative-finite-number.mjs +12 -7
  30. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  31. package/dist/number/branded-types/non-negative-int16.d.mts +13 -7
  32. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  33. package/dist/number/branded-types/non-negative-int16.mjs +14 -8
  34. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  35. package/dist/number/branded-types/non-negative-int32.d.mts +13 -7
  36. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  37. package/dist/number/branded-types/non-negative-int32.mjs +14 -8
  38. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  39. package/dist/number/branded-types/non-positive-finite-number.d.mts +11 -6
  40. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  41. package/dist/number/branded-types/non-positive-finite-number.mjs +12 -7
  42. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  43. package/dist/number/branded-types/non-positive-int.d.mts +11 -6
  44. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  45. package/dist/number/branded-types/non-positive-int.mjs +12 -7
  46. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  47. package/dist/number/branded-types/non-positive-safe-int.d.mts +14 -7
  48. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  49. package/dist/number/branded-types/non-positive-safe-int.mjs +15 -8
  50. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  51. package/dist/number/branded-types/non-zero-int16.d.mts +13 -7
  52. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  53. package/dist/number/branded-types/non-zero-int16.mjs +14 -8
  54. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  55. package/dist/number/branded-types/non-zero-int32.d.mts +13 -7
  56. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  57. package/dist/number/branded-types/non-zero-int32.mjs +14 -8
  58. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  59. package/dist/number/branded-types/non-zero-safe-int.d.mts +13 -7
  60. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  61. package/dist/number/branded-types/non-zero-safe-int.mjs +14 -8
  62. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  63. package/dist/number/branded-types/non-zero-uint16.d.mts +13 -7
  64. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  65. package/dist/number/branded-types/non-zero-uint16.mjs +14 -8
  66. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  67. package/dist/number/branded-types/non-zero-uint32.d.mts +13 -7
  68. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  69. package/dist/number/branded-types/non-zero-uint32.mjs +14 -8
  70. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  71. package/dist/number/branded-types/positive-finite-number.d.mts +13 -6
  72. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  73. package/dist/number/branded-types/positive-finite-number.mjs +14 -7
  74. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  75. package/dist/number/branded-types/positive-int.d.mts +13 -8
  76. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  77. package/dist/number/branded-types/positive-int.mjs +14 -9
  78. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  79. package/dist/number/branded-types/positive-int16.d.mts +13 -7
  80. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  81. package/dist/number/branded-types/positive-int16.mjs +14 -8
  82. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  83. package/dist/number/branded-types/positive-int32.d.mts +13 -7
  84. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  85. package/dist/number/branded-types/positive-int32.mjs +14 -8
  86. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  87. package/dist/number/branded-types/positive-safe-int.d.mts +16 -10
  88. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  89. package/dist/number/branded-types/positive-safe-int.mjs +17 -11
  90. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  91. package/dist/number/branded-types/positive-uint16.d.mts +13 -7
  92. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  93. package/dist/number/branded-types/positive-uint16.mjs +14 -8
  94. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  95. package/dist/number/branded-types/positive-uint32.d.mts +13 -7
  96. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  97. package/dist/number/branded-types/positive-uint32.mjs +14 -8
  98. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  99. package/dist/number/branded-types/safe-int.d.mts +15 -10
  100. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  101. package/dist/number/branded-types/safe-int.mjs +16 -11
  102. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  103. package/dist/number/branded-types/safe-uint.d.mts +12 -7
  104. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  105. package/dist/number/branded-types/safe-uint.mjs +13 -8
  106. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  107. package/dist/number/branded-types/uint.d.mts +14 -10
  108. package/dist/number/branded-types/uint.d.mts.map +1 -1
  109. package/dist/number/branded-types/uint.mjs +15 -11
  110. package/dist/number/branded-types/uint.mjs.map +1 -1
  111. package/dist/number/branded-types/uint16.d.mts +12 -7
  112. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  113. package/dist/number/branded-types/uint16.mjs +13 -8
  114. package/dist/number/branded-types/uint16.mjs.map +1 -1
  115. package/dist/number/branded-types/uint32.d.mts +12 -7
  116. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  117. package/dist/number/branded-types/uint32.mjs +13 -8
  118. package/dist/number/branded-types/uint32.mjs.map +1 -1
  119. package/dist/number/enum/int8.d.mts +12 -7
  120. package/dist/number/enum/int8.d.mts.map +1 -1
  121. package/dist/number/enum/int8.mjs +19 -14
  122. package/dist/number/enum/int8.mjs.map +1 -1
  123. package/dist/number/enum/uint8.d.mts +12 -7
  124. package/dist/number/enum/uint8.d.mts.map +1 -1
  125. package/dist/number/enum/uint8.mjs +19 -14
  126. package/dist/number/enum/uint8.mjs.map +1 -1
  127. package/dist/number/refined-number-utils.d.mts +9 -9
  128. package/dist/number/refined-number-utils.d.mts.map +1 -1
  129. package/dist/number/refined-number-utils.mjs +7 -7
  130. package/dist/number/refined-number-utils.mjs.map +1 -1
  131. package/dist/string/str.d.mts +70 -5
  132. package/dist/string/str.d.mts.map +1 -1
  133. package/dist/string/str.mjs +72 -26
  134. package/dist/string/str.mjs.map +1 -1
  135. package/package.json +1 -1
  136. package/src/array/impl/array-utils-length-bounded-array-cast.mts +204 -39
  137. package/src/array/impl/array-utils-length-bounded-array-cast.test.mts +126 -0
  138. package/src/number/branded-types/int16.mts +13 -8
  139. package/src/number/branded-types/int32.mts +13 -8
  140. package/src/number/branded-types/negative-finite-number.mts +15 -8
  141. package/src/number/branded-types/negative-finite-number.test.mts +4 -4
  142. package/src/number/branded-types/negative-int.mts +13 -8
  143. package/src/number/branded-types/negative-int.test.mts +5 -5
  144. package/src/number/branded-types/negative-safe-int.mts +15 -9
  145. package/src/number/branded-types/negative-safe-int.test.mts +4 -4
  146. package/src/number/branded-types/non-negative-finite-number.mts +12 -7
  147. package/src/number/branded-types/non-negative-int16.mts +14 -8
  148. package/src/number/branded-types/non-negative-int32.mts +14 -8
  149. package/src/number/branded-types/non-positive-finite-number.mts +12 -7
  150. package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
  151. package/src/number/branded-types/non-positive-int.mts +12 -7
  152. package/src/number/branded-types/non-positive-int.test.mts +7 -7
  153. package/src/number/branded-types/non-positive-safe-int.mts +15 -8
  154. package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
  155. package/src/number/branded-types/non-zero-int16.mts +14 -8
  156. package/src/number/branded-types/non-zero-int32.mts +14 -8
  157. package/src/number/branded-types/non-zero-safe-int.mts +14 -8
  158. package/src/number/branded-types/non-zero-uint16.mts +14 -8
  159. package/src/number/branded-types/non-zero-uint32.mts +14 -8
  160. package/src/number/branded-types/positive-finite-number.mts +14 -7
  161. package/src/number/branded-types/positive-int.mts +14 -9
  162. package/src/number/branded-types/positive-int16.mts +14 -8
  163. package/src/number/branded-types/positive-int32.mts +14 -8
  164. package/src/number/branded-types/positive-safe-int.mts +17 -11
  165. package/src/number/branded-types/positive-uint16.mts +14 -8
  166. package/src/number/branded-types/positive-uint32.mts +14 -8
  167. package/src/number/branded-types/safe-int.mts +16 -11
  168. package/src/number/branded-types/safe-uint.mts +13 -8
  169. package/src/number/branded-types/uint.mts +15 -11
  170. package/src/number/branded-types/uint16.mts +13 -8
  171. package/src/number/branded-types/uint32.mts +13 -8
  172. package/src/number/enum/int8.mts +20 -14
  173. package/src/number/enum/int8.test.mts +7 -4
  174. package/src/number/enum/uint8.mts +20 -14
  175. package/src/number/enum/uint8.test.mts +7 -4
  176. package/src/number/refined-number-utils.mts +22 -19
  177. package/src/string/str.mts +201 -39
  178. package/src/string/str.test.mts +76 -0
@@ -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_,
@@ -79,12 +79,14 @@ export const NonZeroSafeInt = {
79
79
  is,
80
80
 
81
81
  /**
82
- * The smallest value representable as `NonZeroSafeInt`.
82
+ * The smallest value representable as `NonZeroSafeInt` (the lower saturation
83
+ * target of `fromNumber`).
83
84
  */
84
85
  MIN_VALUE,
85
86
 
86
87
  /**
87
- * The largest value representable as `NonZeroSafeInt`.
88
+ * The largest value representable as `NonZeroSafeInt` (the upper saturation
89
+ * target of `fromNumber`).
88
90
  */
89
91
  MAX_VALUE,
90
92
 
@@ -115,13 +117,17 @@ export const NonZeroSafeInt = {
115
117
  max: max_,
116
118
 
117
119
  /**
118
- * Clamps a `number` into the `NonZeroSafeInt` range, rounding to the nearest
119
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
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]`.
120
123
  *
121
- * @param value - The value to clamp
122
- * @returns The clamped value as a `NonZeroSafeInt`
124
+ * Unlike `asNonZeroSafeInt`, this is total: out-of-range inputs are clamped
125
+ * to the nearest representable `NonZeroSafeInt` instead of throwing.
126
+ *
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
133
  * Generates a random `NonZeroSafeInt` within the given range.
@@ -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_,
@@ -73,12 +73,14 @@ export const NonZeroUint16 = {
73
73
  is,
74
74
 
75
75
  /**
76
- * The smallest value representable as `NonZeroUint16`.
76
+ * The smallest value representable as `NonZeroUint16` (the lower saturation
77
+ * target of `fromNumber`).
77
78
  */
78
79
  MIN_VALUE,
79
80
 
80
81
  /**
81
- * The largest value representable as `NonZeroUint16`.
82
+ * The largest value representable as `NonZeroUint16` (the upper saturation
83
+ * target of `fromNumber`).
82
84
  */
83
85
  MAX_VALUE,
84
86
 
@@ -99,13 +101,17 @@ export const NonZeroUint16 = {
99
101
  max: max_,
100
102
 
101
103
  /**
102
- * Clamps a `number` into the `NonZeroUint16` range, rounding to the nearest
103
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
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]`.
104
107
  *
105
- * @param value - The value to clamp
106
- * @returns The clamped value 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`
107
113
  */
108
- clamp,
114
+ fromNumber,
109
115
 
110
116
  /**
111
117
  * Generates a random `NonZeroUint16` within the given range.
@@ -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_,
@@ -73,12 +73,14 @@ export const NonZeroUint32 = {
73
73
  is,
74
74
 
75
75
  /**
76
- * The smallest value representable as `NonZeroUint32`.
76
+ * The smallest value representable as `NonZeroUint32` (the lower saturation
77
+ * target of `fromNumber`).
77
78
  */
78
79
  MIN_VALUE,
79
80
 
80
81
  /**
81
- * The largest value representable as `NonZeroUint32`.
82
+ * The largest value representable as `NonZeroUint32` (the upper saturation
83
+ * target of `fromNumber`).
82
84
  */
83
85
  MAX_VALUE,
84
86
 
@@ -99,13 +101,17 @@ export const NonZeroUint32 = {
99
101
  max: max_,
100
102
 
101
103
  /**
102
- * Clamps a `number` into the `NonZeroUint32` range, rounding to the nearest
103
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
104
+ * Converts an arbitrary `number` into a `NonZeroUint32`, rounding to the
105
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
106
+ * MAX_VALUE]`.
104
107
  *
105
- * @param value - The value to clamp
106
- * @returns The clamped value as a `NonZeroUint32`
108
+ * Unlike `asNonZeroUint32`, this is total: out-of-range inputs are clamped to
109
+ * the nearest representable `NonZeroUint32` instead of throwing.
110
+ *
111
+ * @param value - The value to convert
112
+ * @returns The value as a `NonZeroUint32`
107
113
  */
108
- clamp,
114
+ fromNumber,
109
115
 
110
116
  /**
111
117
  * Generates a random `NonZeroUint32` within the given range.
@@ -16,8 +16,8 @@ const {
16
16
  MIN_VALUE,
17
17
  add,
18
18
  castType,
19
- clamp,
20
19
  div,
20
+ fromNumber,
21
21
  is,
22
22
  max: max_,
23
23
  min: min_,
@@ -117,7 +117,10 @@ export const PositiveFiniteNumber = {
117
117
  is,
118
118
 
119
119
  /**
120
- * The smallest value representable as `PositiveFiniteNumber`.
120
+ * The smallest value representable as `PositiveFiniteNumber` (the lower
121
+ * saturation target of `fromNumber`). The domain is open at `0` (excluded),
122
+ * so this is `Number.MIN_VALUE` — the smallest positive double — rather than
123
+ * `0`.
121
124
  */
122
125
  MIN_VALUE,
123
126
 
@@ -138,13 +141,17 @@ export const PositiveFiniteNumber = {
138
141
  max: max_,
139
142
 
140
143
  /**
141
- * Clamps a `number` into the `PositiveFiniteNumber` range `[MIN_VALUE,
142
- * MAX_VALUE]`.
144
+ * Converts an arbitrary `number` into a `PositiveFiniteNumber`, saturating it
145
+ * into the range `[MIN_VALUE, MAX_VALUE]`.
143
146
  *
144
- * @param value - The value to clamp
145
- * @returns The clamped value as a `PositiveFiniteNumber`
147
+ * Unlike `asPositiveFiniteNumber`, this is total: out-of-range inputs are
148
+ * clamped to the nearest representable `PositiveFiniteNumber` instead of
149
+ * throwing.
150
+ *
151
+ * @param value - The value to convert
152
+ * @returns The value as a `PositiveFiniteNumber`
146
153
  */
147
- clamp,
154
+ fromNumber,
148
155
 
149
156
  /**
150
157
  * Returns the greatest integer less than or equal to a positive finite
@@ -12,8 +12,8 @@ const {
12
12
  MIN_VALUE,
13
13
  add,
14
14
  castType,
15
- clamp,
16
15
  div,
16
+ fromNumber,
17
17
  is,
18
18
  max: max_,
19
19
  min: min_,
@@ -106,7 +106,8 @@ export const PositiveInt = {
106
106
  is,
107
107
 
108
108
  /**
109
- * The smallest value representable as `PositiveInt`.
109
+ * The smallest value representable as `PositiveInt` (the lower saturation
110
+ * target of `fromNumber`).
110
111
  */
111
112
  MIN_VALUE,
112
113
 
@@ -151,25 +152,29 @@ export const PositiveInt = {
151
152
  max: max_,
152
153
 
153
154
  /**
154
- * Clamps a `number` into the `PositiveInt` range, rounding to the nearest
155
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
155
+ * Converts an arbitrary `number` into a `PositiveInt`, rounding to the
156
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
157
+ * MAX_VALUE]`.
158
+ *
159
+ * Unlike `asPositiveInt`, this is total: out-of-range inputs are clamped to
160
+ * the nearest representable `PositiveInt` instead of throwing.
156
161
  *
157
162
  * @example
158
163
  *
159
164
  * ```ts
160
- * const belowRange = PositiveInt.clamp(0);
165
+ * const belowRange = PositiveInt.fromNumber(0);
161
166
  *
162
- * const withinRange = PositiveInt.clamp(10);
167
+ * const withinRange = PositiveInt.fromNumber(10);
163
168
  *
164
169
  * assert.isTrue(belowRange === 1);
165
170
  *
166
171
  * assert.isTrue(withinRange === 10);
167
172
  * ```
168
173
  *
169
- * @param value - The value to clamp
170
- * @returns The clamped value as a `PositiveInt`
174
+ * @param value - The value to convert
175
+ * @returns The value as a `PositiveInt`
171
176
  */
172
- clamp,
177
+ fromNumber,
173
178
 
174
179
  /**
175
180
  * Generates a random `PositiveInt` within the given range.
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -74,12 +74,14 @@ export const PositiveInt16 = {
74
74
  is,
75
75
 
76
76
  /**
77
- * The smallest value representable as `PositiveInt16`.
77
+ * The smallest value representable as `PositiveInt16` (the lower saturation
78
+ * target of `fromNumber`).
78
79
  */
79
80
  MIN_VALUE,
80
81
 
81
82
  /**
82
- * The largest value representable as `PositiveInt16`.
83
+ * The largest value representable as `PositiveInt16` (the upper saturation
84
+ * target of `fromNumber`).
83
85
  */
84
86
  MAX_VALUE,
85
87
 
@@ -100,13 +102,17 @@ export const PositiveInt16 = {
100
102
  max: max_,
101
103
 
102
104
  /**
103
- * Clamps a `number` into the `PositiveInt16` range, rounding to the nearest
104
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
105
+ * Converts an arbitrary `number` into a `PositiveInt16`, rounding to the
106
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
107
+ * MAX_VALUE]`.
105
108
  *
106
- * @param value - The value to clamp
107
- * @returns The clamped value as a `PositiveInt16`
109
+ * Unlike `asPositiveInt16`, this is total: out-of-range inputs are clamped to
110
+ * the nearest representable `PositiveInt16` instead of throwing.
111
+ *
112
+ * @param value - The value to convert
113
+ * @returns The value as a `PositiveInt16`
108
114
  */
109
- clamp,
115
+ fromNumber,
110
116
 
111
117
  /**
112
118
  * Generates a random `PositiveInt16` within the given range.
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -74,12 +74,14 @@ export const PositiveInt32 = {
74
74
  is,
75
75
 
76
76
  /**
77
- * The smallest value representable as `PositiveInt32`.
77
+ * The smallest value representable as `PositiveInt32` (the lower saturation
78
+ * target of `fromNumber`).
78
79
  */
79
80
  MIN_VALUE,
80
81
 
81
82
  /**
82
- * The largest value representable as `PositiveInt32`.
83
+ * The largest value representable as `PositiveInt32` (the upper saturation
84
+ * target of `fromNumber`).
83
85
  */
84
86
  MAX_VALUE,
85
87
 
@@ -100,13 +102,17 @@ export const PositiveInt32 = {
100
102
  max: max_,
101
103
 
102
104
  /**
103
- * Clamps a `number` into the `PositiveInt32` range, rounding to the nearest
104
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
105
+ * Converts an arbitrary `number` into a `PositiveInt32`, rounding to the
106
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
107
+ * MAX_VALUE]`.
105
108
  *
106
- * @param value - The value to clamp
107
- * @returns The clamped value as a `PositiveInt32`
109
+ * Unlike `asPositiveInt32`, this is total: out-of-range inputs are clamped to
110
+ * the nearest representable `PositiveInt32` instead of throwing.
111
+ *
112
+ * @param value - The value to convert
113
+ * @returns The value as a `PositiveInt32`
108
114
  */
109
- clamp,
115
+ fromNumber,
110
116
 
111
117
  /**
112
118
  * Generates a random `PositiveInt32` within the given range.
@@ -16,8 +16,8 @@ const {
16
16
  MIN_VALUE,
17
17
  add,
18
18
  castType,
19
- clamp,
20
19
  div,
20
+ fromNumber,
21
21
  is,
22
22
  max: max_,
23
23
  min: min_,
@@ -112,12 +112,14 @@ export const PositiveSafeInt = {
112
112
  is,
113
113
 
114
114
  /**
115
- * The smallest value representable as `PositiveSafeInt`.
115
+ * The smallest value representable as `PositiveSafeInt` (the lower saturation
116
+ * target of `fromNumber`).
116
117
  */
117
118
  MIN_VALUE,
118
119
 
119
120
  /**
120
- * The largest value representable as `PositiveSafeInt`.
121
+ * The largest value representable as `PositiveSafeInt` (the upper saturation
122
+ * target of `fromNumber`).
121
123
  */
122
124
  MAX_VALUE,
123
125
 
@@ -160,17 +162,21 @@ export const PositiveSafeInt = {
160
162
  max: max_,
161
163
 
162
164
  /**
163
- * Clamps a `number` into the `PositiveSafeInt` range, rounding to the nearest
164
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
165
+ * Converts an arbitrary `number` into a `PositiveSafeInt`, rounding to the
166
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
167
+ * MAX_VALUE]`.
168
+ *
169
+ * Unlike `asPositiveSafeInt`, this is total: out-of-range inputs are clamped
170
+ * to the nearest representable `PositiveSafeInt` instead of throwing.
165
171
  *
166
172
  * @example
167
173
  *
168
174
  * ```ts
169
- * const belowRange = PositiveSafeInt.clamp(0);
175
+ * const belowRange = PositiveSafeInt.fromNumber(0);
170
176
  *
171
- * const withinRange = PositiveSafeInt.clamp(123);
177
+ * const withinRange = PositiveSafeInt.fromNumber(123);
172
178
  *
173
- * const aboveRange = PositiveSafeInt.clamp(Number.MAX_SAFE_INTEGER + 10);
179
+ * const aboveRange = PositiveSafeInt.fromNumber(Number.MAX_SAFE_INTEGER + 10);
174
180
  *
175
181
  * assert.isTrue(belowRange === 1);
176
182
  *
@@ -179,10 +185,10 @@ export const PositiveSafeInt = {
179
185
  * assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
180
186
  * ```
181
187
  *
182
- * @param value - The value to clamp
183
- * @returns The clamped value as a `PositiveSafeInt`
188
+ * @param value - The value to convert
189
+ * @returns The value as a `PositiveSafeInt`
184
190
  */
185
- clamp,
191
+ fromNumber,
186
192
 
187
193
  /**
188
194
  * Generates a random `PositiveSafeInt` within the given range.
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -74,12 +74,14 @@ export const PositiveUint16 = {
74
74
  is,
75
75
 
76
76
  /**
77
- * The smallest value representable as `PositiveUint16`.
77
+ * The smallest value representable as `PositiveUint16` (the lower saturation
78
+ * target of `fromNumber`).
78
79
  */
79
80
  MIN_VALUE,
80
81
 
81
82
  /**
82
- * The largest value representable as `PositiveUint16`.
83
+ * The largest value representable as `PositiveUint16` (the upper saturation
84
+ * target of `fromNumber`).
83
85
  */
84
86
  MAX_VALUE,
85
87
 
@@ -100,13 +102,17 @@ export const PositiveUint16 = {
100
102
  max: max_,
101
103
 
102
104
  /**
103
- * Clamps a `number` into the `PositiveUint16` range, rounding to the nearest
104
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
105
+ * Converts an arbitrary `number` into a `PositiveUint16`, rounding to the
106
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
107
+ * MAX_VALUE]`.
105
108
  *
106
- * @param value - The value to clamp
107
- * @returns The clamped value as a `PositiveUint16`
109
+ * Unlike `asPositiveUint16`, this is total: out-of-range inputs are clamped
110
+ * to the nearest representable `PositiveUint16` instead of throwing.
111
+ *
112
+ * @param value - The value to convert
113
+ * @returns The value as a `PositiveUint16`
108
114
  */
109
- clamp,
115
+ fromNumber,
110
116
 
111
117
  /**
112
118
  * Generates a random `PositiveUint16` within the given range.
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -74,12 +74,14 @@ export const PositiveUint32 = {
74
74
  is,
75
75
 
76
76
  /**
77
- * The smallest value representable as `PositiveUint32`.
77
+ * The smallest value representable as `PositiveUint32` (the lower saturation
78
+ * target of `fromNumber`).
78
79
  */
79
80
  MIN_VALUE,
80
81
 
81
82
  /**
82
- * The largest value representable as `PositiveUint32`.
83
+ * The largest value representable as `PositiveUint32` (the upper saturation
84
+ * target of `fromNumber`).
83
85
  */
84
86
  MAX_VALUE,
85
87
 
@@ -100,13 +102,17 @@ export const PositiveUint32 = {
100
102
  max: max_,
101
103
 
102
104
  /**
103
- * Clamps a `number` into the `PositiveUint32` range, rounding to the nearest
104
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
105
+ * Converts an arbitrary `number` into a `PositiveUint32`, rounding to the
106
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
107
+ * MAX_VALUE]`.
105
108
  *
106
- * @param value - The value to clamp
107
- * @returns The clamped value as a `PositiveUint32`
109
+ * Unlike `asPositiveUint32`, this is total: out-of-range inputs are clamped
110
+ * to the nearest representable `PositiveUint32` instead of throwing.
111
+ *
112
+ * @param value - The value to convert
113
+ * @returns The value as a `PositiveUint32`
108
114
  */
109
- clamp,
115
+ fromNumber,
110
116
 
111
117
  /**
112
118
  * Generates a random `PositiveUint32` within the given range.
@@ -17,8 +17,8 @@ const {
17
17
  abs,
18
18
  add,
19
19
  castType,
20
- clamp,
21
20
  div,
21
+ fromNumber,
22
22
  is,
23
23
  max: max_,
24
24
  min: min_,
@@ -108,12 +108,14 @@ export const SafeInt = {
108
108
  is,
109
109
 
110
110
  /**
111
- * The smallest value representable as `SafeInt`.
111
+ * The smallest value representable as `SafeInt` (the lower saturation target
112
+ * of `fromNumber`).
112
113
  */
113
114
  MIN_VALUE,
114
115
 
115
116
  /**
116
- * The largest value representable as `SafeInt`.
117
+ * The largest value representable as `SafeInt` (the upper saturation target
118
+ * of `fromNumber`).
117
119
  */
118
120
  MAX_VALUE,
119
121
 
@@ -172,17 +174,20 @@ export const SafeInt = {
172
174
  max: max_,
173
175
 
174
176
  /**
175
- * Clamps a `number` into the `SafeInt` range, rounding to the nearest integer
176
- * and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
177
+ * Converts an arbitrary `number` into a `SafeInt`, rounding to the nearest
178
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
179
+ *
180
+ * Unlike `asSafeInt`, this is total: out-of-range inputs are clamped to the
181
+ * nearest representable `SafeInt` instead of throwing.
177
182
  *
178
183
  * @example
179
184
  *
180
185
  * ```ts
181
- * const aboveRange = SafeInt.clamp(1e20);
186
+ * const aboveRange = SafeInt.fromNumber(1e20);
182
187
  *
183
- * const withinRange = SafeInt.clamp(123);
188
+ * const withinRange = SafeInt.fromNumber(123);
184
189
  *
185
- * const belowRange = SafeInt.clamp(-1e20);
190
+ * const belowRange = SafeInt.fromNumber(-1e20);
186
191
  *
187
192
  * assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
188
193
  *
@@ -191,10 +196,10 @@ export const SafeInt = {
191
196
  * assert.isTrue(belowRange === Number.MIN_SAFE_INTEGER);
192
197
  * ```
193
198
  *
194
- * @param value - The value to clamp
195
- * @returns The clamped value as a `SafeInt`
199
+ * @param value - The value to convert
200
+ * @returns The value as a `SafeInt`
196
201
  */
197
- clamp,
202
+ fromNumber,
198
203
 
199
204
  /**
200
205
  * Generates a random `SafeInt` within the given range.
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -74,12 +74,14 @@ export const SafeUint = {
74
74
  is,
75
75
 
76
76
  /**
77
- * The smallest value representable as `SafeUint`.
77
+ * The smallest value representable as `SafeUint` (the lower saturation target
78
+ * of `fromNumber`).
78
79
  */
79
80
  MIN_VALUE,
80
81
 
81
82
  /**
82
- * The largest value representable as `SafeUint`.
83
+ * The largest value representable as `SafeUint` (the upper saturation target
84
+ * of `fromNumber`).
83
85
  */
84
86
  MAX_VALUE,
85
87
 
@@ -100,13 +102,16 @@ export const SafeUint = {
100
102
  max: max_,
101
103
 
102
104
  /**
103
- * Clamps a `number` into the `SafeUint` range, rounding to the nearest
104
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
105
+ * Converts an arbitrary `number` into a `SafeUint`, rounding to the nearest
106
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
105
107
  *
106
- * @param value - The value to clamp
107
- * @returns The clamped value as a `SafeUint`
108
+ * Unlike `asSafeUint`, this is total: out-of-range inputs are clamped to the
109
+ * nearest representable `SafeUint` instead of throwing.
110
+ *
111
+ * @param value - The value to convert
112
+ * @returns The value as a `SafeUint`
108
113
  */
109
- clamp,
114
+ fromNumber,
110
115
 
111
116
  /**
112
117
  * Generates a random `SafeUint` within the given range.