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
@@ -15,7 +15,7 @@ const {
15
15
  MAX_VALUE,
16
16
  add,
17
17
  castType,
18
- clamp,
18
+ fromNumber,
19
19
  is,
20
20
  max: max_,
21
21
  min: min_,
@@ -35,7 +35,7 @@ const {
35
35
  } as const);
36
36
 
37
37
  const abs = (x: WithSmallInt<ElementType>): PositiveInt =>
38
- PositiveInt.clamp(Math.abs(x));
38
+ PositiveInt.fromNumber(Math.abs(x));
39
39
 
40
40
  /**
41
41
  * Type guard that checks if a value is a negative integer.
@@ -81,7 +81,8 @@ export const NegativeInt = {
81
81
  is,
82
82
 
83
83
  /**
84
- * The largest value representable as `NegativeInt`.
84
+ * The largest value representable as `NegativeInt` (the upper saturation
85
+ * target of `fromNumber`).
85
86
  */
86
87
  MAX_VALUE,
87
88
 
@@ -114,13 +115,17 @@ export const NegativeInt = {
114
115
  max: max_,
115
116
 
116
117
  /**
117
- * Clamps a `number` into the `NegativeInt` range, rounding to the nearest
118
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
118
+ * Converts an arbitrary `number` into a `NegativeInt`, rounding to the
119
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
120
+ * MAX_VALUE]`.
119
121
  *
120
- * @param value - The value to clamp
121
- * @returns The clamped value as a `NegativeInt`
122
+ * Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to
123
+ * the nearest representable `NegativeInt` instead of throwing.
124
+ *
125
+ * @param value - The value to convert
126
+ * @returns The value as a `NegativeInt`
122
127
  */
123
- clamp,
128
+ fromNumber,
124
129
 
125
130
  /**
126
131
  * Generates a random `NegativeInt` within the given range.
@@ -96,17 +96,17 @@ describe('NegativeInt test', () => {
96
96
  });
97
97
  });
98
98
 
99
- describe('NegativeInt.clamp', () => {
99
+ describe('NegativeInt.fromNumber', () => {
100
100
  test('returns the same value if within range', () => {
101
- expect(NegativeInt.clamp(-5)).toBe(-5);
101
+ expect(NegativeInt.fromNumber(-5)).toBe(-5);
102
102
 
103
- expect(NegativeInt.clamp(-1000)).toBe(-1000);
103
+ expect(NegativeInt.fromNumber(-1000)).toBe(-1000);
104
104
  });
105
105
 
106
106
  test('clamps non-negative values to MAX_VALUE (-1)', () => {
107
- expect(NegativeInt.clamp(0)).toBe(-1);
107
+ expect(NegativeInt.fromNumber(0)).toBe(-1);
108
108
 
109
- expect(NegativeInt.clamp(5)).toBe(-1);
109
+ expect(NegativeInt.fromNumber(5)).toBe(-1);
110
110
  });
111
111
  });
112
112
 
@@ -16,7 +16,7 @@ const {
16
16
  MIN_VALUE,
17
17
  add,
18
18
  castType,
19
- clamp,
19
+ fromNumber,
20
20
  is,
21
21
  max: max_,
22
22
  min: min_,
@@ -36,7 +36,7 @@ const {
36
36
  } as const);
37
37
 
38
38
  const abs = (x: WithSmallInt<ElementType>): PositiveSafeInt =>
39
- PositiveSafeInt.clamp(Math.abs(x));
39
+ PositiveSafeInt.fromNumber(Math.abs(x));
40
40
 
41
41
  /**
42
42
  * Type guard that checks if a value is a negative safe integer.
@@ -79,12 +79,14 @@ export const NegativeSafeInt = {
79
79
  is,
80
80
 
81
81
  /**
82
- * The smallest value representable as `NegativeSafeInt`.
82
+ * The smallest value representable as `NegativeSafeInt` (the lower saturation
83
+ * target of `fromNumber`).
83
84
  */
84
85
  MIN_VALUE,
85
86
 
86
87
  /**
87
- * The largest value representable as `NegativeSafeInt`.
88
+ * The largest value representable as `NegativeSafeInt` (the upper saturation
89
+ * target of `fromNumber`).
88
90
  */
89
91
  MAX_VALUE,
90
92
 
@@ -115,13 +117,17 @@ export const NegativeSafeInt = {
115
117
  max: max_,
116
118
 
117
119
  /**
118
- * Clamps a `number` into the `NegativeSafeInt` range, rounding to the nearest
119
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
120
+ * Converts an arbitrary `number` into a `NegativeSafeInt`, 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 `NegativeSafeInt`
124
+ * Unlike `asNegativeSafeInt`, this is total: out-of-range inputs are clamped
125
+ * to the nearest representable `NegativeSafeInt` instead of throwing.
126
+ *
127
+ * @param value - The value to convert
128
+ * @returns The value as a `NegativeSafeInt`
123
129
  */
124
- clamp,
130
+ fromNumber,
125
131
 
126
132
  /**
127
133
  * Generates a random `NegativeSafeInt` within the given range.
@@ -86,13 +86,13 @@ describe('NegativeSafeInt test', () => {
86
86
  });
87
87
  });
88
88
 
89
- describe('NegativeSafeInt.clamp', () => {
89
+ describe('NegativeSafeInt.fromNumber', () => {
90
90
  test('clamps to the valid range', () => {
91
- expect(NegativeSafeInt.clamp(-5)).toBe(-5);
91
+ expect(NegativeSafeInt.fromNumber(-5)).toBe(-5);
92
92
 
93
- expect(NegativeSafeInt.clamp(0)).toBe(-1);
93
+ expect(NegativeSafeInt.fromNumber(0)).toBe(-1);
94
94
 
95
- expect(NegativeSafeInt.clamp(Number.MIN_SAFE_INTEGER - 100)).toBe(
95
+ expect(NegativeSafeInt.fromNumber(Number.MIN_SAFE_INTEGER - 100)).toBe(
96
96
  Number.MIN_SAFE_INTEGER,
97
97
  );
98
98
  });
@@ -15,8 +15,8 @@ const {
15
15
  MIN_VALUE,
16
16
  add,
17
17
  castType,
18
- clamp,
19
18
  div,
19
+ fromNumber,
20
20
  is,
21
21
  max: max_,
22
22
  min: min_,
@@ -96,7 +96,8 @@ export const NonNegativeFiniteNumber = {
96
96
  is,
97
97
 
98
98
  /**
99
- * The smallest value representable as `NonNegativeFiniteNumber`.
99
+ * The smallest value representable as `NonNegativeFiniteNumber` (the lower
100
+ * saturation target of `fromNumber`).
100
101
  */
101
102
  MIN_VALUE,
102
103
 
@@ -117,13 +118,17 @@ export const NonNegativeFiniteNumber = {
117
118
  max: max_,
118
119
 
119
120
  /**
120
- * Clamps a `number` into the `NonNegativeFiniteNumber` range `[MIN_VALUE,
121
- * MAX_VALUE]`.
121
+ * Converts an arbitrary `number` into a `NonNegativeFiniteNumber`, saturating
122
+ * it into the range `[MIN_VALUE, MAX_VALUE]`.
122
123
  *
123
- * @param value - The value to clamp
124
- * @returns The clamped value as a `NonNegativeFiniteNumber`
124
+ * Unlike `asNonNegativeFiniteNumber`, this is total: out-of-range inputs are
125
+ * clamped to the nearest representable `NonNegativeFiniteNumber` instead of
126
+ * throwing.
127
+ *
128
+ * @param value - The value to convert
129
+ * @returns The value as a `NonNegativeFiniteNumber`
125
130
  */
126
- clamp,
131
+ fromNumber,
127
132
 
128
133
  /**
129
134
  * Returns the greatest integer less than or equal to a non-negative finite
@@ -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 NonNegativeInt16 = {
74
74
  is,
75
75
 
76
76
  /**
77
- * The smallest value representable as `NonNegativeInt16`.
77
+ * The smallest value representable as `NonNegativeInt16` (the lower
78
+ * saturation target of `fromNumber`).
78
79
  */
79
80
  MIN_VALUE,
80
81
 
81
82
  /**
82
- * The largest value representable as `NonNegativeInt16`.
83
+ * The largest value representable as `NonNegativeInt16` (the upper saturation
84
+ * target of `fromNumber`).
83
85
  */
84
86
  MAX_VALUE,
85
87
 
@@ -100,13 +102,17 @@ export const NonNegativeInt16 = {
100
102
  max: max_,
101
103
 
102
104
  /**
103
- * Clamps a `number` into the `NonNegativeInt16` range, rounding to the
104
- * nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
105
+ * Converts an arbitrary `number` into a `NonNegativeInt16`, 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 `NonNegativeInt16`
109
+ * Unlike `asNonNegativeInt16`, this is total: out-of-range inputs are clamped
110
+ * to the nearest representable `NonNegativeInt16` instead of throwing.
111
+ *
112
+ * @param value - The value to convert
113
+ * @returns The value as a `NonNegativeInt16`
108
114
  */
109
- clamp,
115
+ fromNumber,
110
116
 
111
117
  /**
112
118
  * Generates a random `NonNegativeInt16` 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 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.