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
@@ -6,8 +6,8 @@ const {
6
6
  MIN_VALUE,
7
7
  add,
8
8
  castType,
9
- clamp,
10
9
  div,
10
+ fromNumber,
11
11
  is,
12
12
  max: max_,
13
13
  min: min_,
@@ -46,11 +46,13 @@ const PositiveSafeInt = {
46
46
  */
47
47
  is,
48
48
  /**
49
- * The smallest value representable as `PositiveSafeInt`.
49
+ * The smallest value representable as `PositiveSafeInt` (the lower saturation
50
+ * target of `fromNumber`).
50
51
  */
51
52
  MIN_VALUE,
52
53
  /**
53
- * The largest value representable as `PositiveSafeInt`.
54
+ * The largest value representable as `PositiveSafeInt` (the upper saturation
55
+ * target of `fromNumber`).
54
56
  */
55
57
  MAX_VALUE,
56
58
  /**
@@ -90,17 +92,21 @@ const PositiveSafeInt = {
90
92
  */
91
93
  max: max_,
92
94
  /**
93
- * Clamps a `number` into the `PositiveSafeInt` range, rounding to the nearest
94
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
95
+ * Converts an arbitrary `number` into a `PositiveSafeInt`, rounding to the
96
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
97
+ * MAX_VALUE]`.
98
+ *
99
+ * Unlike `asPositiveSafeInt`, this is total: out-of-range inputs are clamped
100
+ * to the nearest representable `PositiveSafeInt` instead of throwing.
95
101
  *
96
102
  * @example
97
103
  *
98
104
  * ```ts
99
- * const belowRange = PositiveSafeInt.clamp(0);
105
+ * const belowRange = PositiveSafeInt.fromNumber(0);
100
106
  *
101
- * const withinRange = PositiveSafeInt.clamp(123);
107
+ * const withinRange = PositiveSafeInt.fromNumber(123);
102
108
  *
103
- * const aboveRange = PositiveSafeInt.clamp(Number.MAX_SAFE_INTEGER + 10);
109
+ * const aboveRange = PositiveSafeInt.fromNumber(Number.MAX_SAFE_INTEGER + 10);
104
110
  *
105
111
  * assert.isTrue(belowRange === 1);
106
112
  *
@@ -109,10 +115,10 @@ const PositiveSafeInt = {
109
115
  * assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
110
116
  * ```
111
117
  *
112
- * @param value - The value to clamp
113
- * @returns The clamped value as a `PositiveSafeInt`
118
+ * @param value - The value to convert
119
+ * @returns The value as a `PositiveSafeInt`
114
120
  */
115
- clamp,
121
+ fromNumber,
116
122
  /**
117
123
  * Generates a random `PositiveSafeInt` within the given range.
118
124
  *
@@ -1 +1 @@
1
- {"version":3,"file":"positive-safe-int.mjs","sources":["../../../src/number/branded-types/positive-safe-int.mts"],"sourcesContent":["import {\n type SafeUint,\n type PositiveSafeInt as TtfImported_PositiveSafeInt,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveSafeInt = TtfImported_PositiveSafeInt;\n\ntype ElementType = PositiveSafeInt;\n\nconst typeNameInMessage = 'a positive safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n clamp,\n div,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 1,\n SafeUint\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 1,\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer\n MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a positive safe integer.\n *\n * Returns `true` for a positive safe integer — a value with no fractional\n * component.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isPositiveSafeInt(1));\n *\n * assert.isTrue(isPositiveSafeInt(Number.MAX_SAFE_INTEGER));\n *\n * assert.isFalse(isPositiveSafeInt(0));\n *\n * assert.isTrue(PositiveSafeInt.is(42));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive safe integer, `false` otherwise\n */\nexport const isPositiveSafeInt = is;\n\n/**\n * Casts a `number` to the `PositiveSafeInt` branded type.\n *\n * Validates that the value is a positive safe integer and returns it with the\n * `PositiveSafeInt` brand. Throws a `TypeError` otherwise.\n *\n * @example\n *\n * ```ts\n * const branded = asPositiveSafeInt(128);\n *\n * assert.isTrue(branded === 128);\n *\n * assert.isTrue(PositiveSafeInt.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as a `PositiveSafeInt`\n * @throws {TypeError} If the value is not a positive safe integer\n */\nexport const asPositiveSafeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `PositiveSafeInt` branded\n * type.\n *\n * The `PositiveSafeInt` type represents a positive safe integer. Division\n * (`div`) uses floor division.\n */\nexport const PositiveSafeInt = {\n /**\n * Type guard that checks if a value is a positive safe integer.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isPositiveSafeInt(1));\n *\n * assert.isTrue(isPositiveSafeInt(Number.MAX_SAFE_INTEGER));\n *\n * assert.isFalse(isPositiveSafeInt(0));\n *\n * assert.isTrue(PositiveSafeInt.is(42));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive safe integer, `false` otherwise\n * @see {@link isPositiveSafeInt} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `PositiveSafeInt`.\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `PositiveSafeInt`.\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given positive safe integers.\n *\n * @example\n *\n * ```ts\n * const smallest = PositiveSafeInt.min(\n * asPositiveSafeInt(10),\n * asPositiveSafeInt(5),\n * );\n *\n * assert.isTrue(smallest === 5);\n * ```\n *\n * @param values - The positive safe integers to compare (at least one required)\n * @returns The smallest value as a `PositiveSafeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given positive safe integers.\n *\n * @example\n *\n * ```ts\n * const largest = PositiveSafeInt.max(\n * asPositiveSafeInt(10),\n * asPositiveSafeInt(5),\n * );\n *\n * assert.isTrue(largest === 10);\n * ```\n *\n * @param values - The positive safe integers to compare (at least one required)\n * @returns The largest value as a `PositiveSafeInt`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `PositiveSafeInt` range, rounding to the nearest\n * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @example\n *\n * ```ts\n * const belowRange = PositiveSafeInt.clamp(0);\n *\n * const withinRange = PositiveSafeInt.clamp(123);\n *\n * const aboveRange = PositiveSafeInt.clamp(Number.MAX_SAFE_INTEGER + 10);\n *\n * assert.isTrue(belowRange === 1);\n *\n * assert.isTrue(withinRange === 123);\n *\n * assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);\n * ```\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `PositiveSafeInt`\n */\n clamp,\n\n /**\n * Generates a random `PositiveSafeInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @example\n *\n * ```ts\n * const min = asPositiveSafeInt(1);\n *\n * const max = asPositiveSafeInt(6);\n *\n * const randomValue = PositiveSafeInt.random(min, max);\n *\n * assert.isTrue(PositiveSafeInt.is(randomValue));\n *\n * assert.isTrue(randomValue >= 1 && randomValue <= 6);\n * ```\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `PositiveSafeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `PositiveSafeInt`\n * (floored to an integer).\n *\n * @example\n *\n * ```ts\n * const base = asPositiveSafeInt(3);\n *\n * const exponent = asPositiveSafeInt(3);\n *\n * const power = PositiveSafeInt.pow(base, exponent);\n *\n * assert.isTrue(power === 27);\n * ```\n *\n * @param a - The base positive safe integer\n * @param b - The exponent positive safe integer\n * @returns `a ** b` as a `PositiveSafeInt`\n */\n pow,\n\n /**\n * Adds two positive safe integers, returning `a + b` as a `PositiveSafeInt`.\n *\n * @example\n *\n * ```ts\n * const sum = PositiveSafeInt.add(\n * asPositiveSafeInt(1000),\n * asPositiveSafeInt(2048),\n * );\n *\n * assert.isTrue(sum === 3048);\n *\n * assert.isTrue(PositiveSafeInt.is(sum));\n * ```\n *\n * @param a - The first positive safe integer\n * @param b - The second positive safe integer\n * @returns The sum of `a` and `b` as a `PositiveSafeInt`\n */\n add,\n\n /**\n * Subtracts two positive safe integers, returning `a - b` as a\n * `PositiveSafeInt`.\n *\n * @example\n *\n * ```ts\n * const difference = PositiveSafeInt.sub(\n * asPositiveSafeInt(10),\n * asPositiveSafeInt(20),\n * );\n *\n * assert.isTrue(difference === 1);\n *\n * assert.isTrue(PositiveSafeInt.is(difference));\n * ```\n *\n * @param a - The first positive safe integer\n * @param b - The second positive safe integer\n * @returns The difference of `a` and `b` as a `PositiveSafeInt`\n */\n sub,\n\n /**\n * Multiplies two positive safe integers, returning `a * b` as a\n * `PositiveSafeInt`.\n *\n * @example\n *\n * ```ts\n * const product = PositiveSafeInt.mul(\n * asPositiveSafeInt(50),\n * asPositiveSafeInt(20),\n * );\n *\n * assert.isTrue(product === 1000);\n *\n * assert.isTrue(PositiveSafeInt.is(product));\n * ```\n *\n * @param a - The first positive safe integer\n * @param b - The second positive safe integer\n * @returns The product of `a` and `b` as a `PositiveSafeInt`\n */\n mul,\n\n /**\n * Divides two positive safe integers using floor division (`⌊a / b⌋`): the\n * result is `a / b` rounded toward negative infinity, as a `PositiveSafeInt`.\n *\n * @example\n *\n * ```ts\n * const quotient = PositiveSafeInt.div(\n * asPositiveSafeInt(25),\n * asPositiveSafeInt(4),\n * );\n *\n * const clamped = PositiveSafeInt.div(\n * asPositiveSafeInt(5),\n * asPositiveSafeInt(50),\n * );\n *\n * assert.isTrue(quotient === 6);\n *\n * assert.isTrue(clamped === 1);\n * ```\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `PositiveSafeInt`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof PositiveSafeInt,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('=');\n\nexpectType<\n typeof PositiveSafeInt,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAWA,MAAM,iBAAA,GAAoB,yBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,GAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA;AAAA,EAEX,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAuBH,MAAM,iBAAA,GAAoB;AAsB1B,MAAM,iBAAA,GAAoB;AAS1B,MAAM,eAAA,GAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB7B,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA4BA;AACF;;;;"}
1
+ {"version":3,"file":"positive-safe-int.mjs","sources":["../../../src/number/branded-types/positive-safe-int.mts"],"sourcesContent":["import {\n type SafeUint,\n type PositiveSafeInt as TtfImported_PositiveSafeInt,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveSafeInt = TtfImported_PositiveSafeInt;\n\ntype ElementType = PositiveSafeInt;\n\nconst typeNameInMessage = 'a positive safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n div,\n fromNumber,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 1,\n SafeUint\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 1,\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer\n MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a positive safe integer.\n *\n * Returns `true` for a positive safe integer — a value with no fractional\n * component.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isPositiveSafeInt(1));\n *\n * assert.isTrue(isPositiveSafeInt(Number.MAX_SAFE_INTEGER));\n *\n * assert.isFalse(isPositiveSafeInt(0));\n *\n * assert.isTrue(PositiveSafeInt.is(42));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive safe integer, `false` otherwise\n */\nexport const isPositiveSafeInt = is;\n\n/**\n * Casts a `number` to the `PositiveSafeInt` branded type.\n *\n * Validates that the value is a positive safe integer and returns it with the\n * `PositiveSafeInt` brand. Throws a `TypeError` otherwise.\n *\n * @example\n *\n * ```ts\n * const branded = asPositiveSafeInt(128);\n *\n * assert.isTrue(branded === 128);\n *\n * assert.isTrue(PositiveSafeInt.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as a `PositiveSafeInt`\n * @throws {TypeError} If the value is not a positive safe integer\n */\nexport const asPositiveSafeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `PositiveSafeInt` branded\n * type.\n *\n * The `PositiveSafeInt` type represents a positive safe integer. Division\n * (`div`) uses floor division.\n */\nexport const PositiveSafeInt = {\n /**\n * Type guard that checks if a value is a positive safe integer.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isPositiveSafeInt(1));\n *\n * assert.isTrue(isPositiveSafeInt(Number.MAX_SAFE_INTEGER));\n *\n * assert.isFalse(isPositiveSafeInt(0));\n *\n * assert.isTrue(PositiveSafeInt.is(42));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive safe integer, `false` otherwise\n * @see {@link isPositiveSafeInt} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `PositiveSafeInt` (the lower saturation\n * target of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `PositiveSafeInt` (the upper saturation\n * target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given positive safe integers.\n *\n * @example\n *\n * ```ts\n * const smallest = PositiveSafeInt.min(\n * asPositiveSafeInt(10),\n * asPositiveSafeInt(5),\n * );\n *\n * assert.isTrue(smallest === 5);\n * ```\n *\n * @param values - The positive safe integers to compare (at least one required)\n * @returns The smallest value as a `PositiveSafeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given positive safe integers.\n *\n * @example\n *\n * ```ts\n * const largest = PositiveSafeInt.max(\n * asPositiveSafeInt(10),\n * asPositiveSafeInt(5),\n * );\n *\n * assert.isTrue(largest === 10);\n * ```\n *\n * @param values - The positive safe integers to compare (at least one required)\n * @returns The largest value as a `PositiveSafeInt`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `PositiveSafeInt`, rounding to the\n * nearest integer and saturating the result into the range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * Unlike `asPositiveSafeInt`, this is total: out-of-range inputs are clamped\n * to the nearest representable `PositiveSafeInt` instead of throwing.\n *\n * @example\n *\n * ```ts\n * const belowRange = PositiveSafeInt.fromNumber(0);\n *\n * const withinRange = PositiveSafeInt.fromNumber(123);\n *\n * const aboveRange = PositiveSafeInt.fromNumber(Number.MAX_SAFE_INTEGER + 10);\n *\n * assert.isTrue(belowRange === 1);\n *\n * assert.isTrue(withinRange === 123);\n *\n * assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);\n * ```\n *\n * @param value - The value to convert\n * @returns The value as a `PositiveSafeInt`\n */\n fromNumber,\n\n /**\n * Generates a random `PositiveSafeInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @example\n *\n * ```ts\n * const min = asPositiveSafeInt(1);\n *\n * const max = asPositiveSafeInt(6);\n *\n * const randomValue = PositiveSafeInt.random(min, max);\n *\n * assert.isTrue(PositiveSafeInt.is(randomValue));\n *\n * assert.isTrue(randomValue >= 1 && randomValue <= 6);\n * ```\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `PositiveSafeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `PositiveSafeInt`\n * (floored to an integer).\n *\n * @example\n *\n * ```ts\n * const base = asPositiveSafeInt(3);\n *\n * const exponent = asPositiveSafeInt(3);\n *\n * const power = PositiveSafeInt.pow(base, exponent);\n *\n * assert.isTrue(power === 27);\n * ```\n *\n * @param a - The base positive safe integer\n * @param b - The exponent positive safe integer\n * @returns `a ** b` as a `PositiveSafeInt`\n */\n pow,\n\n /**\n * Adds two positive safe integers, returning `a + b` as a `PositiveSafeInt`.\n *\n * @example\n *\n * ```ts\n * const sum = PositiveSafeInt.add(\n * asPositiveSafeInt(1000),\n * asPositiveSafeInt(2048),\n * );\n *\n * assert.isTrue(sum === 3048);\n *\n * assert.isTrue(PositiveSafeInt.is(sum));\n * ```\n *\n * @param a - The first positive safe integer\n * @param b - The second positive safe integer\n * @returns The sum of `a` and `b` as a `PositiveSafeInt`\n */\n add,\n\n /**\n * Subtracts two positive safe integers, returning `a - b` as a\n * `PositiveSafeInt`.\n *\n * @example\n *\n * ```ts\n * const difference = PositiveSafeInt.sub(\n * asPositiveSafeInt(10),\n * asPositiveSafeInt(20),\n * );\n *\n * assert.isTrue(difference === 1);\n *\n * assert.isTrue(PositiveSafeInt.is(difference));\n * ```\n *\n * @param a - The first positive safe integer\n * @param b - The second positive safe integer\n * @returns The difference of `a` and `b` as a `PositiveSafeInt`\n */\n sub,\n\n /**\n * Multiplies two positive safe integers, returning `a * b` as a\n * `PositiveSafeInt`.\n *\n * @example\n *\n * ```ts\n * const product = PositiveSafeInt.mul(\n * asPositiveSafeInt(50),\n * asPositiveSafeInt(20),\n * );\n *\n * assert.isTrue(product === 1000);\n *\n * assert.isTrue(PositiveSafeInt.is(product));\n * ```\n *\n * @param a - The first positive safe integer\n * @param b - The second positive safe integer\n * @returns The product of `a` and `b` as a `PositiveSafeInt`\n */\n mul,\n\n /**\n * Divides two positive safe integers using floor division (`⌊a / b⌋`): the\n * result is `a / b` rounded toward negative infinity, as a `PositiveSafeInt`.\n *\n * @example\n *\n * ```ts\n * const quotient = PositiveSafeInt.div(\n * asPositiveSafeInt(25),\n * asPositiveSafeInt(4),\n * );\n *\n * const clamped = PositiveSafeInt.div(\n * asPositiveSafeInt(5),\n * asPositiveSafeInt(50),\n * );\n *\n * assert.isTrue(quotient === 6);\n *\n * assert.isTrue(clamped === 1);\n * ```\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `PositiveSafeInt`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof PositiveSafeInt,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('=');\n\nexpectType<\n typeof PositiveSafeInt,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAWA,MAAM,iBAAA,GAAoB,yBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA;AAAA,EAEX,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAuBH,MAAM,iBAAA,GAAoB;AAsB1B,MAAM,iBAAA,GAAoB;AAS1B,MAAM,eAAA,GAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB7B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6BL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA4BA;AACF;;;;"}
@@ -55,11 +55,13 @@ export declare const PositiveUint16: {
55
55
  */
56
56
  readonly is: (a: number) => a is TtfImported_PositiveUint16;
57
57
  /**
58
- * The smallest value representable as `PositiveUint16`.
58
+ * The smallest value representable as `PositiveUint16` (the lower saturation
59
+ * target of `fromNumber`).
59
60
  */
60
61
  readonly MIN_VALUE: 1;
61
62
  /**
62
- * The largest value representable as `PositiveUint16`.
63
+ * The largest value representable as `PositiveUint16` (the upper saturation
64
+ * target of `fromNumber`).
63
65
  */
64
66
  readonly MAX_VALUE: number;
65
67
  /**
@@ -77,13 +79,17 @@ export declare const PositiveUint16: {
77
79
  */
78
80
  readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_PositiveUint16>[]) => TtfImported_PositiveUint16;
79
81
  /**
80
- * Clamps a `number` into the `PositiveUint16` range, rounding to the nearest
81
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
82
+ * Converts an arbitrary `number` into a `PositiveUint16`, rounding to the
83
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
84
+ * MAX_VALUE]`.
82
85
  *
83
- * @param value - The value to clamp
84
- * @returns The clamped value as a `PositiveUint16`
86
+ * Unlike `asPositiveUint16`, this is total: out-of-range inputs are clamped
87
+ * to the nearest representable `PositiveUint16` instead of throwing.
88
+ *
89
+ * @param value - The value to convert
90
+ * @returns The value as a `PositiveUint16`
85
91
  */
86
- readonly clamp: (x: number) => TtfImported_PositiveUint16;
92
+ readonly fromNumber: (x: number) => TtfImported_PositiveUint16;
87
93
  /**
88
94
  * Generates a random `PositiveUint16` within the given range.
89
95
  *
@@ -1 +1 @@
1
- {"version":3,"file":"positive-uint16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-uint16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,IAAI,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAIlF,MAAM,MAAM,cAAc,GAAG,0BAA0B,CAAC;AA+BxD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,gDAAK,CAAC;AAEnC;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;MAAW,CAAC;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;IACzB;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
1
+ {"version":3,"file":"positive-uint16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-uint16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,IAAI,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAIlF,MAAM,MAAM,cAAc,GAAG,0BAA0B,CAAC;AA+BxD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,gDAAK,CAAC;AAEnC;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;MAAW,CAAC;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;IACzB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
@@ -6,8 +6,8 @@ const {
6
6
  MIN_VALUE,
7
7
  add,
8
8
  castType,
9
- clamp,
10
9
  div,
10
+ fromNumber,
11
11
  is,
12
12
  max: max_,
13
13
  min: min_,
@@ -33,11 +33,13 @@ const PositiveUint16 = {
33
33
  */
34
34
  is,
35
35
  /**
36
- * The smallest value representable as `PositiveUint16`.
36
+ * The smallest value representable as `PositiveUint16` (the lower saturation
37
+ * target of `fromNumber`).
37
38
  */
38
39
  MIN_VALUE,
39
40
  /**
40
- * The largest value representable as `PositiveUint16`.
41
+ * The largest value representable as `PositiveUint16` (the upper saturation
42
+ * target of `fromNumber`).
41
43
  */
42
44
  MAX_VALUE,
43
45
  /**
@@ -55,13 +57,17 @@ const PositiveUint16 = {
55
57
  */
56
58
  max: max_,
57
59
  /**
58
- * Clamps a `number` into the `PositiveUint16` range, rounding to the nearest
59
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
60
+ * Converts an arbitrary `number` into a `PositiveUint16`, rounding to the
61
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
62
+ * MAX_VALUE]`.
60
63
  *
61
- * @param value - The value to clamp
62
- * @returns The clamped value as a `PositiveUint16`
64
+ * Unlike `asPositiveUint16`, this is total: out-of-range inputs are clamped
65
+ * to the nearest representable `PositiveUint16` instead of throwing.
66
+ *
67
+ * @param value - The value to convert
68
+ * @returns The value as a `PositiveUint16`
63
69
  */
64
- clamp,
70
+ fromNumber,
65
71
  /**
66
72
  * Generates a random `PositiveUint16` within the given range.
67
73
  *
@@ -1 +1 @@
1
- {"version":3,"file":"positive-uint16.mjs","sources":["../../../src/number/branded-types/positive-uint16.mts"],"sourcesContent":["import { type PositiveUint16 as TtfImported_PositiveUint16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveUint16 = TtfImported_PositiveUint16;\n\ntype ElementType = PositiveUint16;\n\nconst typeNameInMessage = 'a positive integer in [1, 2^16)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n clamp,\n div,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 1,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 1,\n MAX_VALUE: 2 ** 16 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a positive integer in [1, 2^16).\n *\n * Returns `true` for a positive integer in [1, 2^16) — a value with no\n * fractional component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer in [1, 2^16), `false` otherwise\n */\nexport const isPositiveUint16 = is;\n\n/**\n * Casts a `number` to the `PositiveUint16` branded type.\n *\n * Validates that the value is a positive integer in [1, 2^16) and returns it\n * with the `PositiveUint16` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `PositiveUint16`\n * @throws {TypeError} If the value is not a positive integer in [1, 2^16)\n */\nexport const asPositiveUint16 = castType;\n\n/**\n * Namespace providing type-safe operations for the `PositiveUint16` branded\n * type.\n *\n * The `PositiveUint16` type represents a positive integer in [1, 2^16).\n * Division (`div`) uses floor division.\n */\nexport const PositiveUint16 = {\n /**\n * Type guard that checks if a value is a positive integer in [1, 2^16).\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer in [1, 2^16), `false` otherwise\n * @see {@link isPositiveUint16} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `PositiveUint16`.\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `PositiveUint16`.\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given positive integers.\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The smallest value as a `PositiveUint16`\n */\n min: min_,\n\n /**\n * Returns the largest of the given positive integers.\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The largest value as a `PositiveUint16`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `PositiveUint16` range, rounding to the nearest\n * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `PositiveUint16`\n */\n clamp,\n\n /**\n * Generates a random `PositiveUint16` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `PositiveUint16` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `PositiveUint16`\n * (floored to an integer).\n *\n * @param a - The base positive integer\n * @param b - The exponent positive integer\n * @returns `a ** b` as a `PositiveUint16`\n */\n pow,\n\n /**\n * Adds two positive integers, returning `a + b` as a `PositiveUint16`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The sum of `a` and `b` as a `PositiveUint16`\n */\n add,\n\n /**\n * Subtracts two positive integers, returning `a - b` as a `PositiveUint16`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The difference of `a` and `b` as a `PositiveUint16`\n */\n sub,\n\n /**\n * Multiplies two positive integers, returning `a * b` as a `PositiveUint16`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The product of `a` and `b` as a `PositiveUint16`\n */\n mul,\n\n /**\n * Divides two positive integers using floor division (`⌊a / b⌋`): the result\n * is `a / b` rounded toward negative infinity, as a `PositiveUint16`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `PositiveUint16`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof PositiveUint16,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('=');\n\nexpectType<\n typeof PositiveUint16,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,iCAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,GAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA,EACX,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,gBAAA,GAAmB;AAYzB,MAAM,gBAAA,GAAmB;AASzB,MAAM,cAAA,GAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
1
+ {"version":3,"file":"positive-uint16.mjs","sources":["../../../src/number/branded-types/positive-uint16.mts"],"sourcesContent":["import { type PositiveUint16 as TtfImported_PositiveUint16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveUint16 = TtfImported_PositiveUint16;\n\ntype ElementType = PositiveUint16;\n\nconst typeNameInMessage = 'a positive integer in [1, 2^16)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n div,\n fromNumber,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 1,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 1,\n MAX_VALUE: 2 ** 16 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a positive integer in [1, 2^16).\n *\n * Returns `true` for a positive integer in [1, 2^16) — a value with no\n * fractional component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer in [1, 2^16), `false` otherwise\n */\nexport const isPositiveUint16 = is;\n\n/**\n * Casts a `number` to the `PositiveUint16` branded type.\n *\n * Validates that the value is a positive integer in [1, 2^16) and returns it\n * with the `PositiveUint16` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `PositiveUint16`\n * @throws {TypeError} If the value is not a positive integer in [1, 2^16)\n */\nexport const asPositiveUint16 = castType;\n\n/**\n * Namespace providing type-safe operations for the `PositiveUint16` branded\n * type.\n *\n * The `PositiveUint16` type represents a positive integer in [1, 2^16).\n * Division (`div`) uses floor division.\n */\nexport const PositiveUint16 = {\n /**\n * Type guard that checks if a value is a positive integer in [1, 2^16).\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer in [1, 2^16), `false` otherwise\n * @see {@link isPositiveUint16} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `PositiveUint16` (the lower saturation\n * target of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `PositiveUint16` (the upper saturation\n * target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given positive integers.\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The smallest value as a `PositiveUint16`\n */\n min: min_,\n\n /**\n * Returns the largest of the given positive integers.\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The largest value as a `PositiveUint16`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `PositiveUint16`, rounding to the\n * nearest integer and saturating the result into the range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * Unlike `asPositiveUint16`, this is total: out-of-range inputs are clamped\n * to the nearest representable `PositiveUint16` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `PositiveUint16`\n */\n fromNumber,\n\n /**\n * Generates a random `PositiveUint16` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `PositiveUint16` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `PositiveUint16`\n * (floored to an integer).\n *\n * @param a - The base positive integer\n * @param b - The exponent positive integer\n * @returns `a ** b` as a `PositiveUint16`\n */\n pow,\n\n /**\n * Adds two positive integers, returning `a + b` as a `PositiveUint16`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The sum of `a` and `b` as a `PositiveUint16`\n */\n add,\n\n /**\n * Subtracts two positive integers, returning `a - b` as a `PositiveUint16`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The difference of `a` and `b` as a `PositiveUint16`\n */\n sub,\n\n /**\n * Multiplies two positive integers, returning `a * b` as a `PositiveUint16`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The product of `a` and `b` as a `PositiveUint16`\n */\n mul,\n\n /**\n * Divides two positive integers using floor division (`⌊a / b⌋`): the result\n * is `a / b` rounded toward negative infinity, as a `PositiveUint16`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `PositiveUint16`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof PositiveUint16,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('=');\n\nexpectType<\n typeof PositiveUint16,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,iCAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA,EACX,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,gBAAA,GAAmB;AAYzB,MAAM,gBAAA,GAAmB;AASzB,MAAM,cAAA,GAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
@@ -53,11 +53,13 @@ export declare const PositiveUint32: {
53
53
  */
54
54
  readonly is: (a: number) => a is TtfImported_PositiveUint32;
55
55
  /**
56
- * The smallest value representable as `PositiveUint32`.
56
+ * The smallest value representable as `PositiveUint32` (the lower saturation
57
+ * target of `fromNumber`).
57
58
  */
58
59
  readonly MIN_VALUE: 1;
59
60
  /**
60
- * The largest value representable as `PositiveUint32`.
61
+ * The largest value representable as `PositiveUint32` (the upper saturation
62
+ * target of `fromNumber`).
61
63
  */
62
64
  readonly MAX_VALUE: number;
63
65
  /**
@@ -75,13 +77,17 @@ export declare const PositiveUint32: {
75
77
  */
76
78
  readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_PositiveUint32>[]) => TtfImported_PositiveUint32;
77
79
  /**
78
- * Clamps a `number` into the `PositiveUint32` range, rounding to the nearest
79
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
80
+ * Converts an arbitrary `number` into a `PositiveUint32`, rounding to the
81
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
82
+ * MAX_VALUE]`.
80
83
  *
81
- * @param value - The value to clamp
82
- * @returns The clamped value as a `PositiveUint32`
84
+ * Unlike `asPositiveUint32`, this is total: out-of-range inputs are clamped
85
+ * to the nearest representable `PositiveUint32` instead of throwing.
86
+ *
87
+ * @param value - The value to convert
88
+ * @returns The value as a `PositiveUint32`
83
89
  */
84
- readonly clamp: (x: number) => TtfImported_PositiveUint32;
90
+ readonly fromNumber: (x: number) => TtfImported_PositiveUint32;
85
91
  /**
86
92
  * Generates a random `PositiveUint32` within the given range.
87
93
  *
@@ -1 +1 @@
1
- {"version":3,"file":"positive-uint32.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-uint32.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,IAAI,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAIlF,MAAM,MAAM,cAAc,GAAG,0BAA0B,CAAC;AA+BxD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,gDAAK,CAAC;AAEnC;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;MAAW,CAAC;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;IACzB;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;;;CAEK,CAAC"}
1
+ {"version":3,"file":"positive-uint32.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-uint32.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,IAAI,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAIlF,MAAM,MAAM,cAAc,GAAG,0BAA0B,CAAC;AA+BxD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,gDAAK,CAAC;AAEnC;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;MAAW,CAAC;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;IACzB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;;;CAEK,CAAC"}
@@ -6,8 +6,8 @@ const {
6
6
  MIN_VALUE,
7
7
  add,
8
8
  castType,
9
- clamp,
10
9
  div,
10
+ fromNumber,
11
11
  is,
12
12
  max: max_,
13
13
  min: min_,
@@ -33,11 +33,13 @@ const PositiveUint32 = {
33
33
  */
34
34
  is,
35
35
  /**
36
- * The smallest value representable as `PositiveUint32`.
36
+ * The smallest value representable as `PositiveUint32` (the lower saturation
37
+ * target of `fromNumber`).
37
38
  */
38
39
  MIN_VALUE,
39
40
  /**
40
- * The largest value representable as `PositiveUint32`.
41
+ * The largest value representable as `PositiveUint32` (the upper saturation
42
+ * target of `fromNumber`).
41
43
  */
42
44
  MAX_VALUE,
43
45
  /**
@@ -55,13 +57,17 @@ const PositiveUint32 = {
55
57
  */
56
58
  max: max_,
57
59
  /**
58
- * Clamps a `number` into the `PositiveUint32` range, rounding to the nearest
59
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
60
+ * Converts an arbitrary `number` into a `PositiveUint32`, rounding to the
61
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
62
+ * MAX_VALUE]`.
60
63
  *
61
- * @param value - The value to clamp
62
- * @returns The clamped value as a `PositiveUint32`
64
+ * Unlike `asPositiveUint32`, this is total: out-of-range inputs are clamped
65
+ * to the nearest representable `PositiveUint32` instead of throwing.
66
+ *
67
+ * @param value - The value to convert
68
+ * @returns The value as a `PositiveUint32`
63
69
  */
64
- clamp,
70
+ fromNumber,
65
71
  /**
66
72
  * Generates a random `PositiveUint32` within the given range.
67
73
  *
@@ -1 +1 @@
1
- {"version":3,"file":"positive-uint32.mjs","sources":["../../../src/number/branded-types/positive-uint32.mts"],"sourcesContent":["import { type PositiveUint32 as TtfImported_PositiveUint32 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveUint32 = TtfImported_PositiveUint32;\n\ntype ElementType = PositiveUint32;\n\nconst typeNameInMessage = 'a positive integer in [1, 2^32)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n clamp,\n div,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 1,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 1,\n MAX_VALUE: 2 ** 32 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a positive integer in [1, 2^32).\n *\n * Returns `true` for a positive integer in [1, 2^32) — a value with no\n * fractional component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer in [1, 2^32), `false` otherwise\n */\nexport const isPositiveUint32 = is;\n\n/**\n * Casts a `number` to the `PositiveUint32` branded type.\n *\n * Validates that the value is a positive integer in [1, 2^32) and returns it\n * with the `PositiveUint32` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `PositiveUint32`\n * @throws {TypeError} If the value is not a positive integer in [1, 2^32)\n */\nexport const asPositiveUint32 = castType;\n\n/**\n * Namespace providing type-safe operations for the `PositiveUint32` branded\n * type.\n *\n * The `PositiveUint32` type represents a positive integer in [1, 2^32).\n * Division (`div`) uses floor division.\n */\nexport const PositiveUint32 = {\n /**\n * Type guard that checks if a value is a positive integer in [1, 2^32).\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer in [1, 2^32), `false` otherwise\n * @see {@link isPositiveUint32} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `PositiveUint32`.\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `PositiveUint32`.\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given positive integers.\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The smallest value as a `PositiveUint32`\n */\n min: min_,\n\n /**\n * Returns the largest of the given positive integers.\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The largest value as a `PositiveUint32`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `PositiveUint32` range, rounding to the nearest\n * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `PositiveUint32`\n */\n clamp,\n\n /**\n * Generates a random `PositiveUint32` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `PositiveUint32` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `PositiveUint32`\n * (floored to an integer).\n *\n * @param a - The base positive integer\n * @param b - The exponent positive integer\n * @returns `a ** b` as a `PositiveUint32`\n */\n pow,\n\n /**\n * Adds two positive integers, returning `a + b` as a `PositiveUint32`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The sum of `a` and `b` as a `PositiveUint32`\n */\n add,\n\n /**\n * Subtracts two positive integers, returning `a - b` as a `PositiveUint32`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The difference of `a` and `b` as a `PositiveUint32`\n */\n sub,\n\n /**\n * Multiplies two positive integers, returning `a * b` as a `PositiveUint32`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The product of `a` and `b` as a `PositiveUint32`\n */\n mul,\n\n /**\n * Divides two positive integers using floor division (`⌊a / b⌋`): the result\n * is `a / b` rounded toward negative infinity, as a `PositiveUint32`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `PositiveUint32`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof PositiveUint32,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('=');\n\nexpectType<\n typeof PositiveUint32,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,iCAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,GAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA,EACX,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,gBAAA,GAAmB;AAYzB,MAAM,gBAAA,GAAmB;AASzB,MAAM,cAAA,GAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
1
+ {"version":3,"file":"positive-uint32.mjs","sources":["../../../src/number/branded-types/positive-uint32.mts"],"sourcesContent":["import { type PositiveUint32 as TtfImported_PositiveUint32 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveUint32 = TtfImported_PositiveUint32;\n\ntype ElementType = PositiveUint32;\n\nconst typeNameInMessage = 'a positive integer in [1, 2^32)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n div,\n fromNumber,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 1,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 1,\n MAX_VALUE: 2 ** 32 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a positive integer in [1, 2^32).\n *\n * Returns `true` for a positive integer in [1, 2^32) — a value with no\n * fractional component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer in [1, 2^32), `false` otherwise\n */\nexport const isPositiveUint32 = is;\n\n/**\n * Casts a `number` to the `PositiveUint32` branded type.\n *\n * Validates that the value is a positive integer in [1, 2^32) and returns it\n * with the `PositiveUint32` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `PositiveUint32`\n * @throws {TypeError} If the value is not a positive integer in [1, 2^32)\n */\nexport const asPositiveUint32 = castType;\n\n/**\n * Namespace providing type-safe operations for the `PositiveUint32` branded\n * type.\n *\n * The `PositiveUint32` type represents a positive integer in [1, 2^32).\n * Division (`div`) uses floor division.\n */\nexport const PositiveUint32 = {\n /**\n * Type guard that checks if a value is a positive integer in [1, 2^32).\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer in [1, 2^32), `false` otherwise\n * @see {@link isPositiveUint32} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `PositiveUint32` (the lower saturation\n * target of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `PositiveUint32` (the upper saturation\n * target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given positive integers.\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The smallest value as a `PositiveUint32`\n */\n min: min_,\n\n /**\n * Returns the largest of the given positive integers.\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The largest value as a `PositiveUint32`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `PositiveUint32`, rounding to the\n * nearest integer and saturating the result into the range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * Unlike `asPositiveUint32`, this is total: out-of-range inputs are clamped\n * to the nearest representable `PositiveUint32` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `PositiveUint32`\n */\n fromNumber,\n\n /**\n * Generates a random `PositiveUint32` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `PositiveUint32` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `PositiveUint32`\n * (floored to an integer).\n *\n * @param a - The base positive integer\n * @param b - The exponent positive integer\n * @returns `a ** b` as a `PositiveUint32`\n */\n pow,\n\n /**\n * Adds two positive integers, returning `a + b` as a `PositiveUint32`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The sum of `a` and `b` as a `PositiveUint32`\n */\n add,\n\n /**\n * Subtracts two positive integers, returning `a - b` as a `PositiveUint32`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The difference of `a` and `b` as a `PositiveUint32`\n */\n sub,\n\n /**\n * Multiplies two positive integers, returning `a * b` as a `PositiveUint32`.\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The product of `a` and `b` as a `PositiveUint32`\n */\n mul,\n\n /**\n * Divides two positive integers using floor division (`⌊a / b⌋`): the result\n * is `a / b` rounded toward negative infinity, as a `PositiveUint32`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `PositiveUint32`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof PositiveUint32,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('=');\n\nexpectType<\n typeof PositiveUint32,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,iCAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA,EACX,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,gBAAA,GAAmB;AAYzB,MAAM,gBAAA,GAAmB;AASzB,MAAM,cAAA,GAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
@@ -73,11 +73,13 @@ export declare const SafeInt: {
73
73
  */
74
74
  readonly is: (a: number) => a is TtfImported_SafeInt;
75
75
  /**
76
- * The smallest value representable as `SafeInt`.
76
+ * The smallest value representable as `SafeInt` (the lower saturation target
77
+ * of `fromNumber`).
77
78
  */
78
79
  readonly MIN_VALUE: TtfImported_SafeInt;
79
80
  /**
80
- * The largest value representable as `SafeInt`.
81
+ * The largest value representable as `SafeInt` (the upper saturation target
82
+ * of `fromNumber`).
81
83
  */
82
84
  readonly MAX_VALUE: SafeUint;
83
85
  /**
@@ -132,17 +134,20 @@ export declare const SafeInt: {
132
134
  */
133
135
  readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_SafeInt>[]) => TtfImported_SafeInt;
134
136
  /**
135
- * Clamps a `number` into the `SafeInt` range, rounding to the nearest integer
136
- * and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
137
+ * Converts an arbitrary `number` into a `SafeInt`, rounding to the nearest
138
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
139
+ *
140
+ * Unlike `asSafeInt`, this is total: out-of-range inputs are clamped to the
141
+ * nearest representable `SafeInt` instead of throwing.
137
142
  *
138
143
  * @example
139
144
  *
140
145
  * ```ts
141
- * const aboveRange = SafeInt.clamp(1e20);
146
+ * const aboveRange = SafeInt.fromNumber(1e20);
142
147
  *
143
- * const withinRange = SafeInt.clamp(123);
148
+ * const withinRange = SafeInt.fromNumber(123);
144
149
  *
145
- * const belowRange = SafeInt.clamp(-1e20);
150
+ * const belowRange = SafeInt.fromNumber(-1e20);
146
151
  *
147
152
  * assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
148
153
  *
@@ -151,10 +156,10 @@ export declare const SafeInt: {
151
156
  * assert.isTrue(belowRange === Number.MIN_SAFE_INTEGER);
152
157
  * ```
153
158
  *
154
- * @param value - The value to clamp
155
- * @returns The clamped value as a `SafeInt`
159
+ * @param value - The value to convert
160
+ * @returns The value as a `SafeInt`
156
161
  */
157
- readonly clamp: (x: number) => TtfImported_SafeInt;
162
+ readonly fromNumber: (x: number) => TtfImported_SafeInt;
158
163
  /**
159
164
  * Generates a random `SafeInt` within the given range.
160
165
  *
@@ -1 +1 @@
1
- {"version":3,"file":"safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,OAAO,IAAI,mBAAmB,EACpC,MAAM,eAAe,CAAC;AAIvB,MAAM,MAAM,OAAO,GAAG,mBAAmB,CAAC;AAkC1C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,yCAAK,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,SAAS;;;;;;;MAAW,CAAC;AAElC;;;;;GAKG;AACH,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;;;;;OAgBG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;IAGH;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;;;;;;;;;;;;;;;OAsBG;;IAGH;;;;;;;;;;;;;;;;;;;;;;OAsBG;;IAGH;;;;;;;;;;;;;;;;;;;;;OAqBG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;;;OAiBG;;;;;;;;;;CAEK,CAAC"}
1
+ {"version":3,"file":"safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,OAAO,IAAI,mBAAmB,EACpC,MAAM,eAAe,CAAC;AAIvB,MAAM,MAAM,OAAO,GAAG,mBAAmB,CAAC;AAkC1C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,yCAAK,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,SAAS;;;;;;;MAAW,CAAC;AAElC;;;;;GAKG;AACH,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;IAGH;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;;IAGH;;;;;;;;;;;;;;;;;;;;;;OAsBG;;IAGH;;;;;;;;;;;;;;;;;;;;;OAqBG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;;;OAiBG;;;;;;;;;;CAEK,CAAC"}
@@ -7,8 +7,8 @@ const {
7
7
  abs,
8
8
  add,
9
9
  castType,
10
- clamp,
11
10
  div,
11
+ fromNumber,
12
12
  is,
13
13
  max: max_,
14
14
  min: min_,
@@ -46,11 +46,13 @@ const SafeInt = {
46
46
  */
47
47
  is,
48
48
  /**
49
- * The smallest value representable as `SafeInt`.
49
+ * The smallest value representable as `SafeInt` (the lower saturation target
50
+ * of `fromNumber`).
50
51
  */
51
52
  MIN_VALUE,
52
53
  /**
53
- * The largest value representable as `SafeInt`.
54
+ * The largest value representable as `SafeInt` (the upper saturation target
55
+ * of `fromNumber`).
54
56
  */
55
57
  MAX_VALUE,
56
58
  /**
@@ -105,17 +107,20 @@ const SafeInt = {
105
107
  */
106
108
  max: max_,
107
109
  /**
108
- * Clamps a `number` into the `SafeInt` range, rounding to the nearest integer
109
- * and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
110
+ * Converts an arbitrary `number` into a `SafeInt`, rounding to the nearest
111
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
112
+ *
113
+ * Unlike `asSafeInt`, this is total: out-of-range inputs are clamped to the
114
+ * nearest representable `SafeInt` instead of throwing.
110
115
  *
111
116
  * @example
112
117
  *
113
118
  * ```ts
114
- * const aboveRange = SafeInt.clamp(1e20);
119
+ * const aboveRange = SafeInt.fromNumber(1e20);
115
120
  *
116
- * const withinRange = SafeInt.clamp(123);
121
+ * const withinRange = SafeInt.fromNumber(123);
117
122
  *
118
- * const belowRange = SafeInt.clamp(-1e20);
123
+ * const belowRange = SafeInt.fromNumber(-1e20);
119
124
  *
120
125
  * assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
121
126
  *
@@ -124,10 +129,10 @@ const SafeInt = {
124
129
  * assert.isTrue(belowRange === Number.MIN_SAFE_INTEGER);
125
130
  * ```
126
131
  *
127
- * @param value - The value to clamp
128
- * @returns The clamped value as a `SafeInt`
132
+ * @param value - The value to convert
133
+ * @returns The value as a `SafeInt`
129
134
  */
130
- clamp,
135
+ fromNumber,
131
136
  /**
132
137
  * Generates a random `SafeInt` within the given range.
133
138
  *
@@ -1 +1 @@
1
- {"version":3,"file":"safe-int.mjs","sources":["../../../src/number/branded-types/safe-int.mts"],"sourcesContent":["import {\n type SafeUint,\n type SafeInt as TtfImported_SafeInt,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type SafeInt = TtfImported_SafeInt;\n\ntype ElementType = SafeInt;\n\nconst typeNameInMessage = 'a safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n abs,\n add,\n castType,\n clamp,\n div,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n SafeInt,\n SafeUint\n>({\n integerOrSafeInteger: 'SafeInteger',\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-min-safe-integer\n MIN_VALUE: Number.MIN_SAFE_INTEGER as SafeInt,\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer\n MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a safe integer.\n *\n * Returns `true` for a safe integer — a value with no fractional component.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isSafeInt(Number.MAX_SAFE_INTEGER));\n *\n * assert.isFalse(isSafeInt(Number.MAX_SAFE_INTEGER + 0.5));\n *\n * assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a safe integer, `false` otherwise\n */\nexport const isSafeInt = is;\n\n/**\n * Casts a `number` to the `SafeInt` branded type.\n *\n * Validates that the value is a safe integer and returns it with the `SafeInt`\n * brand. Throws a `TypeError` otherwise.\n *\n * @example\n *\n * ```ts\n * const branded = asSafeInt(123);\n *\n * assert.isTrue(branded === 123);\n *\n * assert.isTrue(SafeInt.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as a `SafeInt`\n * @throws {TypeError} If the value is not a safe integer\n */\nexport const asSafeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `SafeInt` branded type.\n *\n * The `SafeInt` type represents a safe integer. Division (`div`) uses floor\n * division.\n */\nexport const SafeInt = {\n /**\n * Type guard that checks if a value is a safe integer.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isSafeInt(Number.MAX_SAFE_INTEGER));\n *\n * assert.isFalse(isSafeInt(Number.MAX_SAFE_INTEGER + 0.5));\n *\n * assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a safe integer, `false` otherwise\n * @see {@link isSafeInt} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `SafeInt`.\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `SafeInt`.\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a safe integer.\n *\n * The result is non-negative and keeps the `SafeInt` brand.\n *\n * @example\n *\n * ```ts\n * const negative = asSafeInt(-900);\n *\n * const absolute = SafeInt.abs(negative);\n *\n * assert.isTrue(absolute === 900);\n *\n * assert.isTrue(SafeInt.is(absolute));\n * ```\n *\n * @param a - The safe integer value\n * @returns The absolute value as a non-negative `SafeInt`\n */\n abs,\n\n /**\n * Returns the smallest of the given safe integers.\n *\n * @example\n *\n * ```ts\n * const smallest = SafeInt.min(asSafeInt(25), asSafeInt(-14), asSafeInt(99));\n *\n * assert.isTrue(smallest === -14);\n * ```\n *\n * @param values - The safe integers to compare (at least one required)\n * @returns The smallest value as a `SafeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given safe integers.\n *\n * @example\n *\n * ```ts\n * const largest = SafeInt.max(asSafeInt(25), asSafeInt(-14), asSafeInt(99));\n *\n * assert.isTrue(largest === 99);\n * ```\n *\n * @param values - The safe integers to compare (at least one required)\n * @returns The largest value as a `SafeInt`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `SafeInt` range, rounding to the nearest integer\n * and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @example\n *\n * ```ts\n * const aboveRange = SafeInt.clamp(1e20);\n *\n * const withinRange = SafeInt.clamp(123);\n *\n * const belowRange = SafeInt.clamp(-1e20);\n *\n * assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);\n *\n * assert.isTrue(withinRange === 123);\n *\n * assert.isTrue(belowRange === Number.MIN_SAFE_INTEGER);\n * ```\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `SafeInt`\n */\n clamp,\n\n /**\n * Generates a random `SafeInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @example\n *\n * ```ts\n * const min = asSafeInt(-10);\n *\n * const max = asSafeInt(10);\n *\n * const randomValue = SafeInt.random(min, max);\n *\n * assert.isTrue(SafeInt.is(randomValue));\n *\n * assert.isTrue(randomValue >= -10 && randomValue <= 10);\n * ```\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `SafeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `SafeInt` (floored to\n * an integer).\n *\n * @example\n *\n * ```ts\n * const base = asSafeInt(3);\n *\n * const exponent = asSafeInt(5);\n *\n * const power = SafeInt.pow(base, exponent);\n *\n * assert.isTrue(power === 243);\n *\n * assert.isTrue(SafeInt.is(power));\n * ```\n *\n * @param a - The base safe integer\n * @param b - The exponent safe integer\n * @returns `a ** b` as a `SafeInt`\n */\n pow,\n\n /**\n * Adds two safe integers, returning `a + b` as a `SafeInt`.\n *\n * @example\n *\n * ```ts\n * const sum = SafeInt.add(asSafeInt(9), asSafeInt(4));\n *\n * assert.isTrue(sum === 13);\n *\n * assert.isTrue(SafeInt.is(sum));\n * ```\n *\n * @param a - The first safe integer\n * @param b - The second safe integer\n * @returns The sum of `a` and `b` as a `SafeInt`\n */\n add,\n\n /**\n * Subtracts two safe integers, returning `a - b` as a `SafeInt`.\n *\n * @example\n *\n * ```ts\n * const difference = SafeInt.sub(asSafeInt(9), asSafeInt(14));\n *\n * assert.isTrue(difference === -5);\n *\n * assert.isTrue(SafeInt.is(difference));\n * ```\n *\n * @param a - The first safe integer\n * @param b - The second safe integer\n * @returns The difference of `a` and `b` as a `SafeInt`\n */\n sub,\n\n /**\n * Multiplies two safe integers, returning `a * b` as a `SafeInt`.\n *\n * @example\n *\n * ```ts\n * const product = SafeInt.mul(asSafeInt(-8), asSafeInt(7));\n *\n * assert.isTrue(product === -56);\n *\n * assert.isTrue(SafeInt.is(product));\n * ```\n *\n * @param a - The first safe integer\n * @param b - The second safe integer\n * @returns The product of `a` and `b` as a `SafeInt`\n */\n mul,\n\n /**\n * Divides two safe integers using floor division (`⌊a / b⌋`): the result is\n * `a / b` rounded toward negative infinity, as a `SafeInt`.\n *\n * @example\n *\n * ```ts\n * const quotient = SafeInt.div(asSafeInt(-17), asSafeInt(5));\n *\n * assert.isTrue(quotient === -4);\n *\n * assert.isTrue(SafeInt.is(quotient));\n * ```\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `SafeInt`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof SafeInt,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('=');\n\nexpectType<\n typeof SafeInt,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAWA,MAAM,iBAAA,GAAoB,gBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,GAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA;AAAA,EAEtB,WAAW,MAAA,CAAO,gBAAA;AAAA;AAAA,EAElB,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAoBH,MAAM,SAAA,GAAY;AAsBlB,MAAM,SAAA,GAAY;AAQlB,MAAM,OAAA,GAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBrB,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA;AACF;;;;"}
1
+ {"version":3,"file":"safe-int.mjs","sources":["../../../src/number/branded-types/safe-int.mts"],"sourcesContent":["import {\n type SafeUint,\n type SafeInt as TtfImported_SafeInt,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type SafeInt = TtfImported_SafeInt;\n\ntype ElementType = SafeInt;\n\nconst typeNameInMessage = 'a safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n abs,\n add,\n castType,\n div,\n fromNumber,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n SafeInt,\n SafeUint\n>({\n integerOrSafeInteger: 'SafeInteger',\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-min-safe-integer\n MIN_VALUE: Number.MIN_SAFE_INTEGER as SafeInt,\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer\n MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a safe integer.\n *\n * Returns `true` for a safe integer — a value with no fractional component.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isSafeInt(Number.MAX_SAFE_INTEGER));\n *\n * assert.isFalse(isSafeInt(Number.MAX_SAFE_INTEGER + 0.5));\n *\n * assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a safe integer, `false` otherwise\n */\nexport const isSafeInt = is;\n\n/**\n * Casts a `number` to the `SafeInt` branded type.\n *\n * Validates that the value is a safe integer and returns it with the `SafeInt`\n * brand. Throws a `TypeError` otherwise.\n *\n * @example\n *\n * ```ts\n * const branded = asSafeInt(123);\n *\n * assert.isTrue(branded === 123);\n *\n * assert.isTrue(SafeInt.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as a `SafeInt`\n * @throws {TypeError} If the value is not a safe integer\n */\nexport const asSafeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `SafeInt` branded type.\n *\n * The `SafeInt` type represents a safe integer. Division (`div`) uses floor\n * division.\n */\nexport const SafeInt = {\n /**\n * Type guard that checks if a value is a safe integer.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isSafeInt(Number.MAX_SAFE_INTEGER));\n *\n * assert.isFalse(isSafeInt(Number.MAX_SAFE_INTEGER + 0.5));\n *\n * assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a safe integer, `false` otherwise\n * @see {@link isSafeInt} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `SafeInt` (the lower saturation target\n * of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `SafeInt` (the upper saturation target\n * of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a safe integer.\n *\n * The result is non-negative and keeps the `SafeInt` brand.\n *\n * @example\n *\n * ```ts\n * const negative = asSafeInt(-900);\n *\n * const absolute = SafeInt.abs(negative);\n *\n * assert.isTrue(absolute === 900);\n *\n * assert.isTrue(SafeInt.is(absolute));\n * ```\n *\n * @param a - The safe integer value\n * @returns The absolute value as a non-negative `SafeInt`\n */\n abs,\n\n /**\n * Returns the smallest of the given safe integers.\n *\n * @example\n *\n * ```ts\n * const smallest = SafeInt.min(asSafeInt(25), asSafeInt(-14), asSafeInt(99));\n *\n * assert.isTrue(smallest === -14);\n * ```\n *\n * @param values - The safe integers to compare (at least one required)\n * @returns The smallest value as a `SafeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given safe integers.\n *\n * @example\n *\n * ```ts\n * const largest = SafeInt.max(asSafeInt(25), asSafeInt(-14), asSafeInt(99));\n *\n * assert.isTrue(largest === 99);\n * ```\n *\n * @param values - The safe integers to compare (at least one required)\n * @returns The largest value as a `SafeInt`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `SafeInt`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asSafeInt`, this is total: out-of-range inputs are clamped to the\n * nearest representable `SafeInt` instead of throwing.\n *\n * @example\n *\n * ```ts\n * const aboveRange = SafeInt.fromNumber(1e20);\n *\n * const withinRange = SafeInt.fromNumber(123);\n *\n * const belowRange = SafeInt.fromNumber(-1e20);\n *\n * assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);\n *\n * assert.isTrue(withinRange === 123);\n *\n * assert.isTrue(belowRange === Number.MIN_SAFE_INTEGER);\n * ```\n *\n * @param value - The value to convert\n * @returns The value as a `SafeInt`\n */\n fromNumber,\n\n /**\n * Generates a random `SafeInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @example\n *\n * ```ts\n * const min = asSafeInt(-10);\n *\n * const max = asSafeInt(10);\n *\n * const randomValue = SafeInt.random(min, max);\n *\n * assert.isTrue(SafeInt.is(randomValue));\n *\n * assert.isTrue(randomValue >= -10 && randomValue <= 10);\n * ```\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `SafeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `SafeInt` (floored to\n * an integer).\n *\n * @example\n *\n * ```ts\n * const base = asSafeInt(3);\n *\n * const exponent = asSafeInt(5);\n *\n * const power = SafeInt.pow(base, exponent);\n *\n * assert.isTrue(power === 243);\n *\n * assert.isTrue(SafeInt.is(power));\n * ```\n *\n * @param a - The base safe integer\n * @param b - The exponent safe integer\n * @returns `a ** b` as a `SafeInt`\n */\n pow,\n\n /**\n * Adds two safe integers, returning `a + b` as a `SafeInt`.\n *\n * @example\n *\n * ```ts\n * const sum = SafeInt.add(asSafeInt(9), asSafeInt(4));\n *\n * assert.isTrue(sum === 13);\n *\n * assert.isTrue(SafeInt.is(sum));\n * ```\n *\n * @param a - The first safe integer\n * @param b - The second safe integer\n * @returns The sum of `a` and `b` as a `SafeInt`\n */\n add,\n\n /**\n * Subtracts two safe integers, returning `a - b` as a `SafeInt`.\n *\n * @example\n *\n * ```ts\n * const difference = SafeInt.sub(asSafeInt(9), asSafeInt(14));\n *\n * assert.isTrue(difference === -5);\n *\n * assert.isTrue(SafeInt.is(difference));\n * ```\n *\n * @param a - The first safe integer\n * @param b - The second safe integer\n * @returns The difference of `a` and `b` as a `SafeInt`\n */\n sub,\n\n /**\n * Multiplies two safe integers, returning `a * b` as a `SafeInt`.\n *\n * @example\n *\n * ```ts\n * const product = SafeInt.mul(asSafeInt(-8), asSafeInt(7));\n *\n * assert.isTrue(product === -56);\n *\n * assert.isTrue(SafeInt.is(product));\n * ```\n *\n * @param a - The first safe integer\n * @param b - The second safe integer\n * @returns The product of `a` and `b` as a `SafeInt`\n */\n mul,\n\n /**\n * Divides two safe integers using floor division (`⌊a / b⌋`): the result is\n * `a / b` rounded toward negative infinity, as a `SafeInt`.\n *\n * @example\n *\n * ```ts\n * const quotient = SafeInt.div(asSafeInt(-17), asSafeInt(5));\n *\n * assert.isTrue(quotient === -4);\n *\n * assert.isTrue(SafeInt.is(quotient));\n * ```\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `SafeInt`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof SafeInt,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('=');\n\nexpectType<\n typeof SafeInt,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAWA,MAAM,iBAAA,GAAoB,gBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA;AAAA,EAEtB,WAAW,MAAA,CAAO,gBAAA;AAAA;AAAA,EAElB,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAoBH,MAAM,SAAA,GAAY;AAsBlB,MAAM,SAAA,GAAY;AAQlB,MAAM,OAAA,GAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBrB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA4BL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA;AACF;;;;"}
@@ -49,11 +49,13 @@ export declare const SafeUint: {
49
49
  */
50
50
  readonly is: (a: number) => a is TtfImported_SafeUint;
51
51
  /**
52
- * The smallest value representable as `SafeUint`.
52
+ * The smallest value representable as `SafeUint` (the lower saturation target
53
+ * of `fromNumber`).
53
54
  */
54
55
  readonly MIN_VALUE: 0;
55
56
  /**
56
- * The largest value representable as `SafeUint`.
57
+ * The largest value representable as `SafeUint` (the upper saturation target
58
+ * of `fromNumber`).
57
59
  */
58
60
  readonly MAX_VALUE: TtfImported_SafeUint;
59
61
  /**
@@ -71,13 +73,16 @@ export declare const SafeUint: {
71
73
  */
72
74
  readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_SafeUint>[]) => TtfImported_SafeUint;
73
75
  /**
74
- * Clamps a `number` into the `SafeUint` range, rounding to the nearest
75
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
76
+ * Converts an arbitrary `number` into a `SafeUint`, rounding to the nearest
77
+ * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
76
78
  *
77
- * @param value - The value to clamp
78
- * @returns The clamped value as a `SafeUint`
79
+ * Unlike `asSafeUint`, this is total: out-of-range inputs are clamped to the
80
+ * nearest representable `SafeUint` instead of throwing.
81
+ *
82
+ * @param value - The value to convert
83
+ * @returns The value as a `SafeUint`
79
84
  */
80
- readonly clamp: (x: number) => TtfImported_SafeUint;
85
+ readonly fromNumber: (x: number) => TtfImported_SafeUint;
81
86
  /**
82
87
  * Generates a random `SafeUint` within the given range.
83
88
  *
@@ -1 +1 @@
1
- {"version":3,"file":"safe-uint.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/safe-uint.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,IAAI,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAItE,MAAM,MAAM,QAAQ,GAAG,oBAAoB,CAAC;AAgC5C;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,0CAAK,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;MAAW,CAAC;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,QAAQ;IACnB;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;CAEK,CAAC"}
1
+ {"version":3,"file":"safe-uint.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/safe-uint.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,IAAI,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAItE,MAAM,MAAM,QAAQ,GAAG,oBAAoB,CAAC;AAgC5C;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,0CAAK,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;MAAW,CAAC;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,QAAQ;IACnB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;CAEK,CAAC"}