ts-data-forge 11.0.1 → 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 (165) hide show
  1. package/README.md +2 -2
  2. package/dist/number/branded-types/int16.d.mts +12 -7
  3. package/dist/number/branded-types/int16.d.mts.map +1 -1
  4. package/dist/number/branded-types/int16.mjs +13 -8
  5. package/dist/number/branded-types/int16.mjs.map +1 -1
  6. package/dist/number/branded-types/int32.d.mts +12 -7
  7. package/dist/number/branded-types/int32.d.mts.map +1 -1
  8. package/dist/number/branded-types/int32.mjs +13 -8
  9. package/dist/number/branded-types/int32.mjs.map +1 -1
  10. package/dist/number/branded-types/negative-finite-number.d.mts +13 -6
  11. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  12. package/dist/number/branded-types/negative-finite-number.mjs +15 -8
  13. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  14. package/dist/number/branded-types/negative-int.d.mts +11 -6
  15. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  16. package/dist/number/branded-types/negative-int.mjs +13 -8
  17. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  18. package/dist/number/branded-types/negative-safe-int.d.mts +13 -7
  19. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  20. package/dist/number/branded-types/negative-safe-int.mjs +15 -9
  21. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  22. package/dist/number/branded-types/non-negative-finite-number.d.mts +11 -6
  23. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  24. package/dist/number/branded-types/non-negative-finite-number.mjs +12 -7
  25. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  26. package/dist/number/branded-types/non-negative-int16.d.mts +13 -7
  27. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  28. package/dist/number/branded-types/non-negative-int16.mjs +14 -8
  29. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  30. package/dist/number/branded-types/non-negative-int32.d.mts +13 -7
  31. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  32. package/dist/number/branded-types/non-negative-int32.mjs +14 -8
  33. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  34. package/dist/number/branded-types/non-positive-finite-number.d.mts +11 -6
  35. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  36. package/dist/number/branded-types/non-positive-finite-number.mjs +12 -7
  37. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  38. package/dist/number/branded-types/non-positive-int.d.mts +11 -6
  39. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  40. package/dist/number/branded-types/non-positive-int.mjs +12 -7
  41. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  42. package/dist/number/branded-types/non-positive-safe-int.d.mts +14 -7
  43. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  44. package/dist/number/branded-types/non-positive-safe-int.mjs +15 -8
  45. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  46. package/dist/number/branded-types/non-zero-int16.d.mts +13 -7
  47. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  48. package/dist/number/branded-types/non-zero-int16.mjs +14 -8
  49. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  50. package/dist/number/branded-types/non-zero-int32.d.mts +13 -7
  51. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  52. package/dist/number/branded-types/non-zero-int32.mjs +14 -8
  53. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  54. package/dist/number/branded-types/non-zero-safe-int.d.mts +13 -7
  55. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  56. package/dist/number/branded-types/non-zero-safe-int.mjs +14 -8
  57. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  58. package/dist/number/branded-types/non-zero-uint16.d.mts +13 -7
  59. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  60. package/dist/number/branded-types/non-zero-uint16.mjs +14 -8
  61. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  62. package/dist/number/branded-types/non-zero-uint32.d.mts +13 -7
  63. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  64. package/dist/number/branded-types/non-zero-uint32.mjs +14 -8
  65. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  66. package/dist/number/branded-types/positive-finite-number.d.mts +13 -6
  67. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  68. package/dist/number/branded-types/positive-finite-number.mjs +14 -7
  69. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  70. package/dist/number/branded-types/positive-int.d.mts +13 -8
  71. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  72. package/dist/number/branded-types/positive-int.mjs +14 -9
  73. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  74. package/dist/number/branded-types/positive-int16.d.mts +13 -7
  75. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  76. package/dist/number/branded-types/positive-int16.mjs +14 -8
  77. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  78. package/dist/number/branded-types/positive-int32.d.mts +13 -7
  79. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  80. package/dist/number/branded-types/positive-int32.mjs +14 -8
  81. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  82. package/dist/number/branded-types/positive-safe-int.d.mts +16 -10
  83. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  84. package/dist/number/branded-types/positive-safe-int.mjs +17 -11
  85. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  86. package/dist/number/branded-types/positive-uint16.d.mts +13 -7
  87. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  88. package/dist/number/branded-types/positive-uint16.mjs +14 -8
  89. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  90. package/dist/number/branded-types/positive-uint32.d.mts +13 -7
  91. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  92. package/dist/number/branded-types/positive-uint32.mjs +14 -8
  93. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  94. package/dist/number/branded-types/safe-int.d.mts +15 -10
  95. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  96. package/dist/number/branded-types/safe-int.mjs +16 -11
  97. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  98. package/dist/number/branded-types/safe-uint.d.mts +12 -7
  99. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  100. package/dist/number/branded-types/safe-uint.mjs +13 -8
  101. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  102. package/dist/number/branded-types/uint.d.mts +14 -10
  103. package/dist/number/branded-types/uint.d.mts.map +1 -1
  104. package/dist/number/branded-types/uint.mjs +15 -11
  105. package/dist/number/branded-types/uint.mjs.map +1 -1
  106. package/dist/number/branded-types/uint16.d.mts +12 -7
  107. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  108. package/dist/number/branded-types/uint16.mjs +13 -8
  109. package/dist/number/branded-types/uint16.mjs.map +1 -1
  110. package/dist/number/branded-types/uint32.d.mts +12 -7
  111. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  112. package/dist/number/branded-types/uint32.mjs +13 -8
  113. package/dist/number/branded-types/uint32.mjs.map +1 -1
  114. package/dist/number/enum/int8.d.mts +12 -7
  115. package/dist/number/enum/int8.d.mts.map +1 -1
  116. package/dist/number/enum/int8.mjs +19 -14
  117. package/dist/number/enum/int8.mjs.map +1 -1
  118. package/dist/number/enum/uint8.d.mts +12 -7
  119. package/dist/number/enum/uint8.d.mts.map +1 -1
  120. package/dist/number/enum/uint8.mjs +19 -14
  121. package/dist/number/enum/uint8.mjs.map +1 -1
  122. package/dist/number/refined-number-utils.d.mts +9 -9
  123. package/dist/number/refined-number-utils.d.mts.map +1 -1
  124. package/dist/number/refined-number-utils.mjs +7 -7
  125. package/dist/number/refined-number-utils.mjs.map +1 -1
  126. package/package.json +1 -1
  127. package/src/number/branded-types/int16.mts +13 -8
  128. package/src/number/branded-types/int32.mts +13 -8
  129. package/src/number/branded-types/negative-finite-number.mts +15 -8
  130. package/src/number/branded-types/negative-finite-number.test.mts +4 -4
  131. package/src/number/branded-types/negative-int.mts +13 -8
  132. package/src/number/branded-types/negative-int.test.mts +5 -5
  133. package/src/number/branded-types/negative-safe-int.mts +15 -9
  134. package/src/number/branded-types/negative-safe-int.test.mts +4 -4
  135. package/src/number/branded-types/non-negative-finite-number.mts +12 -7
  136. package/src/number/branded-types/non-negative-int16.mts +14 -8
  137. package/src/number/branded-types/non-negative-int32.mts +14 -8
  138. package/src/number/branded-types/non-positive-finite-number.mts +12 -7
  139. package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
  140. package/src/number/branded-types/non-positive-int.mts +12 -7
  141. package/src/number/branded-types/non-positive-int.test.mts +7 -7
  142. package/src/number/branded-types/non-positive-safe-int.mts +15 -8
  143. package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
  144. package/src/number/branded-types/non-zero-int16.mts +14 -8
  145. package/src/number/branded-types/non-zero-int32.mts +14 -8
  146. package/src/number/branded-types/non-zero-safe-int.mts +14 -8
  147. package/src/number/branded-types/non-zero-uint16.mts +14 -8
  148. package/src/number/branded-types/non-zero-uint32.mts +14 -8
  149. package/src/number/branded-types/positive-finite-number.mts +14 -7
  150. package/src/number/branded-types/positive-int.mts +14 -9
  151. package/src/number/branded-types/positive-int16.mts +14 -8
  152. package/src/number/branded-types/positive-int32.mts +14 -8
  153. package/src/number/branded-types/positive-safe-int.mts +17 -11
  154. package/src/number/branded-types/positive-uint16.mts +14 -8
  155. package/src/number/branded-types/positive-uint32.mts +14 -8
  156. package/src/number/branded-types/safe-int.mts +16 -11
  157. package/src/number/branded-types/safe-uint.mts +13 -8
  158. package/src/number/branded-types/uint.mts +15 -11
  159. package/src/number/branded-types/uint16.mts +13 -8
  160. package/src/number/branded-types/uint32.mts +13 -8
  161. package/src/number/enum/int8.mts +20 -14
  162. package/src/number/enum/int8.test.mts +7 -4
  163. package/src/number/enum/uint8.mts +20 -14
  164. package/src/number/enum/uint8.test.mts +7 -4
  165. package/src/number/refined-number-utils.mts +22 -19
@@ -13,8 +13,8 @@ const {
13
13
  MIN_VALUE,
14
14
  add,
15
15
  castType,
16
- clamp,
17
16
  div,
17
+ fromNumber,
18
18
  is,
19
19
  max: max_,
20
20
  min: min_,
@@ -74,12 +74,14 @@ export const NonNegativeInt32 = {
74
74
  is,
75
75
 
76
76
  /**
77
- * The smallest value representable as `NonNegativeInt32`.
77
+ * The smallest value representable as `NonNegativeInt32` (the lower
78
+ * saturation target of `fromNumber`).
78
79
  */
79
80
  MIN_VALUE,
80
81
 
81
82
  /**
82
- * The largest value representable as `NonNegativeInt32`.
83
+ * The largest value representable as `NonNegativeInt32` (the upper saturation
84
+ * target of `fromNumber`).
83
85
  */
84
86
  MAX_VALUE,
85
87
 
@@ -100,13 +102,17 @@ export const NonNegativeInt32 = {
100
102
  max: max_,
101
103
 
102
104
  /**
103
- * Clamps a `number` into the `NonNegativeInt32` range, rounding to the
104
- * nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
105
+ * Converts an arbitrary `number` into a `NonNegativeInt32`, rounding to the
106
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
107
+ * MAX_VALUE]`.
105
108
  *
106
- * @param value - The value to clamp
107
- * @returns The clamped value as a `NonNegativeInt32`
109
+ * Unlike `asNonNegativeInt32`, this is total: out-of-range inputs are clamped
110
+ * to the nearest representable `NonNegativeInt32` instead of throwing.
111
+ *
112
+ * @param value - The value to convert
113
+ * @returns The value as a `NonNegativeInt32`
108
114
  */
109
- clamp,
115
+ fromNumber,
110
116
 
111
117
  /**
112
118
  * Generates a random `NonNegativeInt32` within the given range.
@@ -11,7 +11,7 @@ const {
11
11
  MAX_VALUE,
12
12
  add,
13
13
  castType,
14
- clamp,
14
+ fromNumber,
15
15
  is,
16
16
  max: max_,
17
17
  min: min_,
@@ -102,7 +102,8 @@ export const NonPositiveFiniteNumber = {
102
102
  is,
103
103
 
104
104
  /**
105
- * The largest value representable as `NonPositiveFiniteNumber`.
105
+ * The largest value representable as `NonPositiveFiniteNumber` (the upper
106
+ * saturation target of `fromNumber`).
106
107
  */
107
108
  MAX_VALUE,
108
109
 
@@ -123,13 +124,17 @@ export const NonPositiveFiniteNumber = {
123
124
  max: max_,
124
125
 
125
126
  /**
126
- * Clamps a `number` into the `NonPositiveFiniteNumber` range `[MIN_VALUE,
127
- * MAX_VALUE]`.
127
+ * Converts an arbitrary `number` into a `NonPositiveFiniteNumber`, saturating
128
+ * it into the range `[MIN_VALUE, MAX_VALUE]`.
128
129
  *
129
- * @param value - The value to clamp
130
- * @returns The clamped value as a `NonPositiveFiniteNumber`
130
+ * Unlike `asNonPositiveFiniteNumber`, this is total: out-of-range inputs are
131
+ * clamped to the nearest representable `NonPositiveFiniteNumber` instead of
132
+ * throwing.
133
+ *
134
+ * @param value - The value to convert
135
+ * @returns The value as a `NonPositiveFiniteNumber`
131
136
  */
132
- clamp,
137
+ fromNumber,
133
138
 
134
139
  /**
135
140
  * Returns the greatest integer less than or equal to a non-positive finite
@@ -139,23 +139,23 @@ describe('NonPositiveFiniteNumber test', () => {
139
139
  });
140
140
  });
141
141
 
142
- describe('NonPositiveFiniteNumber.clamp', () => {
142
+ describe('NonPositiveFiniteNumber.fromNumber', () => {
143
143
  test('returns the same value if within range', () => {
144
- expect(NonPositiveFiniteNumber.clamp(-5.5)).toBe(-5.5);
144
+ expect(NonPositiveFiniteNumber.fromNumber(-5.5)).toBe(-5.5);
145
145
 
146
- expect(NonPositiveFiniteNumber.clamp(0)).toBe(0);
146
+ expect(NonPositiveFiniteNumber.fromNumber(0)).toBe(0);
147
147
 
148
- expect(NonPositiveFiniteNumber.clamp(-1000.5)).toBe(-1000.5);
148
+ expect(NonPositiveFiniteNumber.fromNumber(-1000.5)).toBe(-1000.5);
149
149
  });
150
150
 
151
151
  test('clamps positive values to MAX_VALUE (0)', () => {
152
- expect(NonPositiveFiniteNumber.clamp(5.5)).toBe(0);
152
+ expect(NonPositiveFiniteNumber.fromNumber(5.5)).toBe(0);
153
153
 
154
- expect(NonPositiveFiniteNumber.clamp(1000)).toBe(0);
154
+ expect(NonPositiveFiniteNumber.fromNumber(1000)).toBe(0);
155
155
  });
156
156
 
157
157
  test('clamps -Infinity to the lower bound', () => {
158
- expect(NonPositiveFiniteNumber.clamp(Number.NEGATIVE_INFINITY)).toBe(
158
+ expect(NonPositiveFiniteNumber.fromNumber(Number.NEGATIVE_INFINITY)).toBe(
159
159
  -Number.MAX_VALUE,
160
160
  );
161
161
  });
@@ -11,7 +11,7 @@ const {
11
11
  MAX_VALUE,
12
12
  add,
13
13
  castType,
14
- clamp,
14
+ fromNumber,
15
15
  is,
16
16
  max: max_,
17
17
  min: min_,
@@ -75,7 +75,8 @@ export const NonPositiveInt = {
75
75
  is,
76
76
 
77
77
  /**
78
- * The largest value representable as `NonPositiveInt`.
78
+ * The largest value representable as `NonPositiveInt` (the upper saturation
79
+ * target of `fromNumber`).
79
80
  */
80
81
  MAX_VALUE,
81
82
 
@@ -96,13 +97,17 @@ export const NonPositiveInt = {
96
97
  max: max_,
97
98
 
98
99
  /**
99
- * Clamps a `number` into the `NonPositiveInt` range, rounding to the nearest
100
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
100
+ * Converts an arbitrary `number` into a `NonPositiveInt`, rounding to the
101
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
102
+ * MAX_VALUE]`.
101
103
  *
102
- * @param value - The value to clamp
103
- * @returns The clamped value as a `NonPositiveInt`
104
+ * Unlike `asNonPositiveInt`, this is total: out-of-range inputs are clamped
105
+ * to the nearest representable `NonPositiveInt` instead of throwing.
106
+ *
107
+ * @param value - The value to convert
108
+ * @returns The value as a `NonPositiveInt`
104
109
  */
105
- clamp,
110
+ fromNumber,
106
111
 
107
112
  /**
108
113
  * Generates a random `NonPositiveInt` within the given range.
@@ -131,23 +131,23 @@ describe('NonPositiveInt test', () => {
131
131
  });
132
132
  });
133
133
 
134
- describe('NonPositiveInt.clamp', () => {
134
+ describe('NonPositiveInt.fromNumber', () => {
135
135
  test('returns the same value if within range', () => {
136
- expect(NonPositiveInt.clamp(-5)).toBe(-5);
136
+ expect(NonPositiveInt.fromNumber(-5)).toBe(-5);
137
137
 
138
- expect(NonPositiveInt.clamp(0)).toBe(0);
138
+ expect(NonPositiveInt.fromNumber(0)).toBe(0);
139
139
 
140
- expect(NonPositiveInt.clamp(-1000)).toBe(-1000);
140
+ expect(NonPositiveInt.fromNumber(-1000)).toBe(-1000);
141
141
  });
142
142
 
143
143
  test('clamps positive values to MAX_VALUE (0)', () => {
144
- expect(NonPositiveInt.clamp(5)).toBe(0);
144
+ expect(NonPositiveInt.fromNumber(5)).toBe(0);
145
145
 
146
- expect(NonPositiveInt.clamp(1000)).toBe(0);
146
+ expect(NonPositiveInt.fromNumber(1000)).toBe(0);
147
147
  });
148
148
 
149
149
  test('clamps -Infinity to the lower bound', () => {
150
- expect(NonPositiveInt.clamp(Number.NEGATIVE_INFINITY)).toBe(
150
+ expect(NonPositiveInt.fromNumber(Number.NEGATIVE_INFINITY)).toBe(
151
151
  -Number.MAX_VALUE,
152
152
  );
153
153
  });
@@ -12,7 +12,7 @@ const {
12
12
  MIN_VALUE,
13
13
  add,
14
14
  castType,
15
- clamp,
15
+ fromNumber,
16
16
  is,
17
17
  max: max_,
18
18
  min: min_,
@@ -71,12 +71,14 @@ export const NonPositiveSafeInt = {
71
71
  is,
72
72
 
73
73
  /**
74
- * The smallest value representable as `NonPositiveSafeInt`.
74
+ * The smallest value representable as `NonPositiveSafeInt` (the lower
75
+ * saturation target of `fromNumber`).
75
76
  */
76
77
  MIN_VALUE,
77
78
 
78
79
  /**
79
- * The largest value representable as `NonPositiveSafeInt`.
80
+ * The largest value representable as `NonPositiveSafeInt` (the upper
81
+ * saturation target of `fromNumber`).
80
82
  */
81
83
  MAX_VALUE,
82
84
 
@@ -97,13 +99,18 @@ export const NonPositiveSafeInt = {
97
99
  max: max_,
98
100
 
99
101
  /**
100
- * Clamps a `number` into the `NonPositiveSafeInt` range, rounding to the
101
- * nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
102
+ * Converts an arbitrary `number` into a `NonPositiveSafeInt`, rounding to the
103
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
104
+ * MAX_VALUE]`.
102
105
  *
103
- * @param value - The value to clamp
104
- * @returns The clamped value as a `NonPositiveSafeInt`
106
+ * Unlike `asNonPositiveSafeInt`, this is total: out-of-range inputs are
107
+ * clamped to the nearest representable `NonPositiveSafeInt` instead of
108
+ * throwing.
109
+ *
110
+ * @param value - The value to convert
111
+ * @returns The value as a `NonPositiveSafeInt`
105
112
  */
106
- clamp,
113
+ fromNumber,
107
114
 
108
115
  /**
109
116
  * Generates a random `NonPositiveSafeInt` within the given range.
@@ -163,23 +163,23 @@ describe('NonPositiveSafeInt test', () => {
163
163
  });
164
164
  });
165
165
 
166
- describe('NonPositiveSafeInt.clamp', () => {
166
+ describe('NonPositiveSafeInt.fromNumber', () => {
167
167
  test('returns the same value if within range', () => {
168
- expect(NonPositiveSafeInt.clamp(-5)).toBe(-5);
168
+ expect(NonPositiveSafeInt.fromNumber(-5)).toBe(-5);
169
169
 
170
- expect(NonPositiveSafeInt.clamp(0)).toBe(0);
170
+ expect(NonPositiveSafeInt.fromNumber(0)).toBe(0);
171
171
 
172
- expect(NonPositiveSafeInt.clamp(-1000)).toBe(-1000);
172
+ expect(NonPositiveSafeInt.fromNumber(-1000)).toBe(-1000);
173
173
  });
174
174
 
175
175
  test('clamps positive values to MAX_VALUE (0)', () => {
176
- expect(NonPositiveSafeInt.clamp(5)).toBe(0);
176
+ expect(NonPositiveSafeInt.fromNumber(5)).toBe(0);
177
177
 
178
- expect(NonPositiveSafeInt.clamp(1000)).toBe(0);
178
+ expect(NonPositiveSafeInt.fromNumber(1000)).toBe(0);
179
179
  });
180
180
 
181
181
  test('clamps out-of-range negative values to MIN_VALUE', () => {
182
- expect(NonPositiveSafeInt.clamp(Number.MIN_SAFE_INTEGER - 1)).toBe(
182
+ expect(NonPositiveSafeInt.fromNumber(Number.MIN_SAFE_INTEGER - 1)).toBe(
183
183
  Number.MIN_SAFE_INTEGER,
184
184
  );
185
185
  });
@@ -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_,
@@ -72,12 +72,14 @@ export const NonZeroInt16 = {
72
72
  is,
73
73
 
74
74
  /**
75
- * The smallest value representable as `NonZeroInt16`.
75
+ * The smallest value representable as `NonZeroInt16` (the lower saturation
76
+ * target of `fromNumber`).
76
77
  */
77
78
  MIN_VALUE,
78
79
 
79
80
  /**
80
- * The largest value representable as `NonZeroInt16`.
81
+ * The largest value representable as `NonZeroInt16` (the upper saturation
82
+ * target of `fromNumber`).
81
83
  */
82
84
  MAX_VALUE,
83
85
 
@@ -108,13 +110,17 @@ export const NonZeroInt16 = {
108
110
  max: max_,
109
111
 
110
112
  /**
111
- * Clamps a `number` into the `NonZeroInt16` range, rounding to the nearest
112
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
113
+ * Converts an arbitrary `number` into a `NonZeroInt16`, rounding to the
114
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
115
+ * MAX_VALUE]`.
113
116
  *
114
- * @param value - The value to clamp
115
- * @returns The clamped value as a `NonZeroInt16`
117
+ * Unlike `asNonZeroInt16`, this is total: out-of-range inputs are clamped to
118
+ * the nearest representable `NonZeroInt16` instead of throwing.
119
+ *
120
+ * @param value - The value to convert
121
+ * @returns The value as a `NonZeroInt16`
116
122
  */
117
- clamp,
123
+ fromNumber,
118
124
 
119
125
  /**
120
126
  * Generates a random `NonZeroInt16` within the given range.
@@ -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_,
@@ -72,12 +72,14 @@ export const NonZeroInt32 = {
72
72
  is,
73
73
 
74
74
  /**
75
- * The smallest value representable as `NonZeroInt32`.
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 largest value representable as `NonZeroInt32`.
81
+ * The largest value representable as `NonZeroInt32` (the upper saturation
82
+ * target of `fromNumber`).
81
83
  */
82
84
  MAX_VALUE,
83
85
 
@@ -108,13 +110,17 @@ export const NonZeroInt32 = {
108
110
  max: max_,
109
111
 
110
112
  /**
111
- * Clamps a `number` into the `NonZeroInt32` range, rounding to the nearest
112
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
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]`.
113
116
  *
114
- * @param value - The value to clamp
115
- * @returns The clamped value as a `NonZeroInt32`
117
+ * Unlike `asNonZeroInt32`, this is total: out-of-range inputs are clamped to
118
+ * the nearest representable `NonZeroInt32` instead of throwing.
119
+ *
120
+ * @param value - The value to convert
121
+ * @returns The value as a `NonZeroInt32`
116
122
  */
117
- clamp,
123
+ fromNumber,
118
124
 
119
125
  /**
120
126
  * Generates a random `NonZeroInt32` within the given range.
@@ -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.