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
@@ -52,7 +52,10 @@ export declare const NegativeFiniteNumber: {
52
52
  */
53
53
  readonly is: (a: number) => a is TtfImported_NegativeFiniteNumber;
54
54
  /**
55
- * The largest value representable as `NegativeFiniteNumber`.
55
+ * The largest value representable as `NegativeFiniteNumber` (the upper
56
+ * saturation target of `fromNumber`). The domain is open at `0` (excluded),
57
+ * so this is `-Number.MIN_VALUE` — the negative double closest to `0` —
58
+ * rather than `0`.
56
59
  */
57
60
  readonly MAX_VALUE: number;
58
61
  /**
@@ -79,13 +82,17 @@ export declare const NegativeFiniteNumber: {
79
82
  */
80
83
  readonly max: (...values: readonly TtfImported_NegativeFiniteNumber[]) => TtfImported_NegativeFiniteNumber;
81
84
  /**
82
- * Clamps a `number` into the `NegativeFiniteNumber` range `[MIN_VALUE,
83
- * MAX_VALUE]`.
85
+ * Converts an arbitrary `number` into a `NegativeFiniteNumber`, saturating it
86
+ * into the range `[MIN_VALUE, MAX_VALUE]`.
84
87
  *
85
- * @param value - The value to clamp
86
- * @returns The clamped value as a `NegativeFiniteNumber`
88
+ * Unlike `asNegativeFiniteNumber`, this is total: out-of-range inputs are
89
+ * clamped to the nearest representable `NegativeFiniteNumber` instead of
90
+ * throwing.
91
+ *
92
+ * @param value - The value to convert
93
+ * @returns The value as a `NegativeFiniteNumber`
87
94
  */
88
- readonly clamp: (x: number) => TtfImported_NegativeFiniteNumber;
95
+ readonly fromNumber: (x: number) => TtfImported_NegativeFiniteNumber;
89
96
  /**
90
97
  * Returns the greatest integer less than or equal to a negative finite
91
98
  * number.
@@ -1 +1 @@
1
- {"version":3,"file":"negative-finite-number.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,IAAI,gCAAgC,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,MAAM,MAAM,oBAAoB,GAAG,gCAAgC,CAAC;AAEpE,KAAK,WAAW,GAAG,oBAAoB,CAAC;AAyDxC;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,sDAAK,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;MAAW,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;;;;;;OAOG;sBAlFW,WAAW,KAAG,oBAAoB;IAqFhD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;wBAhHA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IAkH3D;;;;;;OAMG;uBAnHA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,qBAAqB,CAC9D,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAC3D;IAmHC;;;;;;OAMG;wBAlHA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,qBAAqB,CAC9D,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAC3D;IAkHC;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
1
+ {"version":3,"file":"negative-finite-number.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,IAAI,gCAAgC,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,MAAM,MAAM,oBAAoB,GAAG,gCAAgC,CAAC;AAEpE,KAAK,WAAW,GAAG,oBAAoB,CAAC;AAyDxC;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,sDAAK,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;MAAW,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;;;;;OAMG;;IAGH;;;;;OAKG;;IAGH;;;;;;;OAOG;sBArFW,WAAW,KAAG,oBAAoB;IAwFhD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;OAMG;wBAvHA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IAyH3D;;;;;;OAMG;uBA1HA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,qBAAqB,CAC9D,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAC3D;IA0HC;;;;;;OAMG;wBAzHA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,qBAAqB,CAC9D,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAC3D;IAyHC;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
@@ -6,7 +6,7 @@ const {
6
6
  MAX_VALUE,
7
7
  add,
8
8
  castType,
9
- clamp,
9
+ fromNumber,
10
10
  is,
11
11
  max: max_,
12
12
  min: min_,
@@ -19,7 +19,7 @@ const {
19
19
  MAX_VALUE: -Number.MIN_VALUE,
20
20
  typeNameInMessage
21
21
  });
22
- const abs = (x) => PositiveFiniteNumber.clamp(Math.abs(x));
22
+ const abs = (x) => PositiveFiniteNumber.fromNumber(Math.abs(x));
23
23
  const floor = (x) => (
24
24
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
25
25
  Math.floor(x)
@@ -46,7 +46,10 @@ const NegativeFiniteNumber = {
46
46
  */
47
47
  is,
48
48
  /**
49
- * The largest value representable as `NegativeFiniteNumber`.
49
+ * The largest value representable as `NegativeFiniteNumber` (the upper
50
+ * saturation target of `fromNumber`). The domain is open at `0` (excluded),
51
+ * so this is `-Number.MIN_VALUE` — the negative double closest to `0` —
52
+ * rather than `0`.
50
53
  */
51
54
  MAX_VALUE,
52
55
  /**
@@ -73,13 +76,17 @@ const NegativeFiniteNumber = {
73
76
  */
74
77
  max: max_,
75
78
  /**
76
- * Clamps a `number` into the `NegativeFiniteNumber` range `[MIN_VALUE,
77
- * MAX_VALUE]`.
79
+ * Converts an arbitrary `number` into a `NegativeFiniteNumber`, saturating it
80
+ * into the range `[MIN_VALUE, MAX_VALUE]`.
78
81
  *
79
- * @param value - The value to clamp
80
- * @returns The clamped value as a `NegativeFiniteNumber`
82
+ * Unlike `asNegativeFiniteNumber`, this is total: out-of-range inputs are
83
+ * clamped to the nearest representable `NegativeFiniteNumber` instead of
84
+ * throwing.
85
+ *
86
+ * @param value - The value to convert
87
+ * @returns The value as a `NegativeFiniteNumber`
81
88
  */
82
- clamp,
89
+ fromNumber,
83
90
  /**
84
91
  * Returns the greatest integer less than or equal to a negative finite
85
92
  * number.
@@ -1 +1 @@
1
- {"version":3,"file":"negative-finite-number.mjs","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"sourcesContent":["import { type NegativeFiniteNumber as TtfImported_NegativeFiniteNumber } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveFiniteNumber } from './positive-finite-number.mjs';\n\nexport type NegativeFiniteNumber = TtfImported_NegativeFiniteNumber;\n\ntype ElementType = NegativeFiniteNumber;\n\nconst typeNameInMessage = 'a negative finite number';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<\n ElementType,\n number,\n number\n>({\n nonZero: true,\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: -Number.MIN_VALUE,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: ElementType): PositiveFiniteNumber =>\n PositiveFiniteNumber.clamp(Math.abs(x));\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\n/**\n * Type guard that checks if a value is a negative finite number.\n *\n * Returns `true` only for a finite value — never `NaN`, `Infinity`, or\n * `-Infinity`.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative finite number, `false` otherwise\n */\nexport const isNegativeFiniteNumber = is;\n\n/**\n * Casts a `number` to the `NegativeFiniteNumber` branded type.\n *\n * Validates that the value is a negative finite number and returns it with the\n * `NegativeFiniteNumber` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeFiniteNumber`\n * @throws {TypeError} If the value is not a negative finite number\n */\nexport const asNegativeFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeFiniteNumber`\n * branded type.\n *\n * The `NegativeFiniteNumber` type represents a negative finite number.\n */\nexport const NegativeFiniteNumber = {\n /**\n * Type guard that checks if a value is a negative finite number.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative finite number, `false` otherwise\n * @see {@link isNegativeFiniteNumber} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NegativeFiniteNumber`.\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative finite number.\n *\n * The result is non-negative and keeps the `NegativeFiniteNumber` brand.\n *\n * @param a - The negative finite number value\n * @returns The absolute value as a non-negative `NegativeFiniteNumber`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative finite numbers.\n *\n * @param values - The negative finite numbers to compare (at least one required)\n * @returns The smallest value as a `NegativeFiniteNumber`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative finite numbers.\n *\n * @param values - The negative finite numbers to compare (at least one required)\n * @returns The largest value as a `NegativeFiniteNumber`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `NegativeFiniteNumber` range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `NegativeFiniteNumber`\n */\n clamp,\n\n /**\n * Returns the greatest integer less than or equal to a negative finite\n * number.\n *\n * @param a - The negative finite number value\n * @returns The floored value as an integer\n */\n floor,\n\n /**\n * Returns the smallest integer greater than or equal to a negative finite\n * number.\n *\n * @param a - The negative finite number value\n * @returns The ceiled value as an integer\n */\n ceil,\n\n /**\n * Returns the value of a negative finite number rounded to the nearest\n * integer.\n *\n * @param a - The negative finite number value\n * @returns The rounded value as an integer\n */\n round,\n\n /**\n * Generates a random `NegativeFiniteNumber` 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 `NegativeFiniteNumber` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The base negative finite number\n * @param b - The exponent negative finite number\n * @returns `a ** b` as a `NegativeFiniteNumber`\n */\n pow,\n\n /**\n * Adds two negative finite numbers, returning `a + b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The first negative finite number\n * @param b - The second negative finite number\n * @returns The sum of `a` and `b` as a `NegativeFiniteNumber`\n */\n add,\n\n /**\n * Subtracts two negative finite numbers, returning `a - b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The first negative finite number\n * @param b - The second negative finite number\n * @returns The difference of `a` and `b` as a `NegativeFiniteNumber`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;;AAQA,MAAM,iBAAA,GAAoB,0BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,iBAAA,CAI1C;AAAA,EACA,OAAA,EAAS,IAAA;AAAA,EACT,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,oBAAA,CAAqB,MAAM,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAExC,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAC;AAAA,CAAA;AAEd,MAAM,OAAO,CACX,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAK,CAAC;AAAA,CAAA;AAIb,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAaK,MAAM,sBAAA,GAAyB;AAY/B,MAAM,sBAAA,GAAyB;AAQ/B,MAAM,oBAAA,GAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlC,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;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,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,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;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
1
+ {"version":3,"file":"negative-finite-number.mjs","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"sourcesContent":["import { type NegativeFiniteNumber as TtfImported_NegativeFiniteNumber } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveFiniteNumber } from './positive-finite-number.mjs';\n\nexport type NegativeFiniteNumber = TtfImported_NegativeFiniteNumber;\n\ntype ElementType = NegativeFiniteNumber;\n\nconst typeNameInMessage = 'a negative finite number';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<\n ElementType,\n number,\n number\n>({\n nonZero: true,\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: -Number.MIN_VALUE,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: ElementType): PositiveFiniteNumber =>\n PositiveFiniteNumber.fromNumber(Math.abs(x));\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\n/**\n * Type guard that checks if a value is a negative finite number.\n *\n * Returns `true` only for a finite value — never `NaN`, `Infinity`, or\n * `-Infinity`.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative finite number, `false` otherwise\n */\nexport const isNegativeFiniteNumber = is;\n\n/**\n * Casts a `number` to the `NegativeFiniteNumber` branded type.\n *\n * Validates that the value is a negative finite number and returns it with the\n * `NegativeFiniteNumber` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeFiniteNumber`\n * @throws {TypeError} If the value is not a negative finite number\n */\nexport const asNegativeFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeFiniteNumber`\n * branded type.\n *\n * The `NegativeFiniteNumber` type represents a negative finite number.\n */\nexport const NegativeFiniteNumber = {\n /**\n * Type guard that checks if a value is a negative finite number.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative finite number, `false` otherwise\n * @see {@link isNegativeFiniteNumber} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NegativeFiniteNumber` (the upper\n * saturation target of `fromNumber`). The domain is open at `0` (excluded),\n * so this is `-Number.MIN_VALUE` — the negative double closest to `0` —\n * rather than `0`.\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative finite number.\n *\n * The result is non-negative and keeps the `NegativeFiniteNumber` brand.\n *\n * @param a - The negative finite number value\n * @returns The absolute value as a non-negative `NegativeFiniteNumber`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative finite numbers.\n *\n * @param values - The negative finite numbers to compare (at least one required)\n * @returns The smallest value as a `NegativeFiniteNumber`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative finite numbers.\n *\n * @param values - The negative finite numbers to compare (at least one required)\n * @returns The largest value as a `NegativeFiniteNumber`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NegativeFiniteNumber`, saturating it\n * into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asNegativeFiniteNumber`, this is total: out-of-range inputs are\n * clamped to the nearest representable `NegativeFiniteNumber` instead of\n * throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NegativeFiniteNumber`\n */\n fromNumber,\n\n /**\n * Returns the greatest integer less than or equal to a negative finite\n * number.\n *\n * @param a - The negative finite number value\n * @returns The floored value as an integer\n */\n floor,\n\n /**\n * Returns the smallest integer greater than or equal to a negative finite\n * number.\n *\n * @param a - The negative finite number value\n * @returns The ceiled value as an integer\n */\n ceil,\n\n /**\n * Returns the value of a negative finite number rounded to the nearest\n * integer.\n *\n * @param a - The negative finite number value\n * @returns The rounded value as an integer\n */\n round,\n\n /**\n * Generates a random `NegativeFiniteNumber` 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 `NegativeFiniteNumber` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The base negative finite number\n * @param b - The exponent negative finite number\n * @returns `a ** b` as a `NegativeFiniteNumber`\n */\n pow,\n\n /**\n * Adds two negative finite numbers, returning `a + b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The first negative finite number\n * @param b - The second negative finite number\n * @returns The sum of `a` and `b` as a `NegativeFiniteNumber`\n */\n add,\n\n /**\n * Subtracts two negative finite numbers, returning `a - b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The first negative finite number\n * @param b - The second negative finite number\n * @returns The difference of `a` and `b` as a `NegativeFiniteNumber`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;;AAQA,MAAM,iBAAA,GAAoB,0BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,iBAAA,CAI1C;AAAA,EACA,OAAA,EAAS,IAAA;AAAA,EACT,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,oBAAA,CAAqB,WAAW,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAE7C,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAC;AAAA,CAAA;AAEd,MAAM,OAAO,CACX,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAK,CAAC;AAAA,CAAA;AAIb,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAaK,MAAM,sBAAA,GAAyB;AAY/B,MAAM,sBAAA,GAAyB;AAQ/B,MAAM,oBAAA,GAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlC,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;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,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,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;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
@@ -56,7 +56,8 @@ export declare const NegativeInt: {
56
56
  */
57
57
  readonly is: (a: number) => a is TtfImported_NegativeInt;
58
58
  /**
59
- * The largest value representable as `NegativeInt`.
59
+ * The largest value representable as `NegativeInt` (the upper saturation
60
+ * target of `fromNumber`).
60
61
  */
61
62
  readonly MAX_VALUE: -1;
62
63
  /**
@@ -85,13 +86,17 @@ export declare const NegativeInt: {
85
86
  */
86
87
  readonly max: (...values: readonly WithSmallInt<TtfImported_NegativeInt>[]) => TtfImported_NegativeInt;
87
88
  /**
88
- * Clamps a `number` into the `NegativeInt` range, rounding to the nearest
89
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
89
+ * Converts an arbitrary `number` into a `NegativeInt`, rounding to the
90
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
91
+ * MAX_VALUE]`.
90
92
  *
91
- * @param value - The value to clamp
92
- * @returns The clamped value as a `NegativeInt`
93
+ * Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to
94
+ * the nearest representable `NegativeInt` instead of throwing.
95
+ *
96
+ * @param value - The value to convert
97
+ * @returns The value as a `NegativeInt`
93
98
  */
94
- readonly clamp: (x: number) => TtfImported_NegativeInt;
99
+ readonly fromNumber: (x: number) => TtfImported_NegativeInt;
95
100
  /**
96
101
  * Generates a random `NegativeInt` within the given range.
97
102
  *
@@ -1 +1 @@
1
- {"version":3,"file":"negative-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,IAAI,uBAAuB,EAC3C,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAElD,KAAK,WAAW,GAAG,WAAW,CAAC;AA8B/B;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,6CAAK,CAAC;AAEhC;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;MAAW,CAAC;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;;;;;;;;OASG;sBA5DW,YAAY,CAAC,WAAW,CAAC,KAAG,WAAW;IA+DrD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;CAEK,CAAC"}
1
+ {"version":3,"file":"negative-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,IAAI,uBAAuB,EAC3C,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAElD,KAAK,WAAW,GAAG,WAAW,CAAC;AA8B/B;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,6CAAK,CAAC;AAEhC;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;MAAW,CAAC;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;;;;;;;OASG;sBA7DW,YAAY,CAAC,WAAW,CAAC,KAAG,WAAW;IAgErD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;CAEK,CAAC"}
@@ -6,7 +6,7 @@ const {
6
6
  MAX_VALUE,
7
7
  add,
8
8
  castType,
9
- clamp,
9
+ fromNumber,
10
10
  is,
11
11
  max: max_,
12
12
  min: min_,
@@ -20,7 +20,7 @@ const {
20
20
  MAX_VALUE: -1,
21
21
  typeNameInMessage
22
22
  });
23
- const abs = (x) => PositiveInt.clamp(Math.abs(x));
23
+ const abs = (x) => PositiveInt.fromNumber(Math.abs(x));
24
24
  const isNegativeInt = is;
25
25
  const asNegativeInt = castType;
26
26
  const NegativeInt = {
@@ -33,7 +33,8 @@ const NegativeInt = {
33
33
  */
34
34
  is,
35
35
  /**
36
- * The largest value representable as `NegativeInt`.
36
+ * The largest value representable as `NegativeInt` (the upper saturation
37
+ * target of `fromNumber`).
37
38
  */
38
39
  MAX_VALUE,
39
40
  /**
@@ -62,13 +63,17 @@ const NegativeInt = {
62
63
  */
63
64
  max: max_,
64
65
  /**
65
- * Clamps a `number` into the `NegativeInt` range, rounding to the nearest
66
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
66
+ * Converts an arbitrary `number` into a `NegativeInt`, rounding to the
67
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
68
+ * MAX_VALUE]`.
67
69
  *
68
- * @param value - The value to clamp
69
- * @returns The clamped value as a `NegativeInt`
70
+ * Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to
71
+ * the nearest representable `NegativeInt` instead of throwing.
72
+ *
73
+ * @param value - The value to convert
74
+ * @returns The value as a `NegativeInt`
70
75
  */
71
- clamp,
76
+ fromNumber,
72
77
  /**
73
78
  * Generates a random `NegativeInt` within the given range.
74
79
  *
@@ -1 +1 @@
1
- {"version":3,"file":"negative-int.mjs","sources":["../../../src/number/branded-types/negative-int.mts"],"sourcesContent":["import {\n type NegativeInt as TtfImported_NegativeInt,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveInt } from './positive-int.mjs';\n\nexport type NegativeInt = TtfImported_NegativeInt;\n\ntype ElementType = NegativeInt;\n\nconst typeNameInMessage = 'a negative integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n -1\n>({\n integerOrSafeInteger: 'Integer',\n nonZero: true,\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: -1,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: WithSmallInt<ElementType>): PositiveInt =>\n PositiveInt.clamp(Math.abs(x));\n\n/**\n * Type guard that checks if a value is a negative integer.\n *\n * Returns `true` for a negative integer — a value with no fractional component,\n * including values outside the safe integer range (unlike `SafeInt`).\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative integer, `false` otherwise\n */\nexport const isNegativeInt = is;\n\n/**\n * Casts a `number` to the `NegativeInt` branded type.\n *\n * Validates that the value is a negative integer and returns it with the\n * `NegativeInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeInt`\n * @throws {TypeError} If the value is not a negative integer\n */\nexport const asNegativeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeInt` branded type.\n *\n * The `NegativeInt` type represents a negative integer. Division (`div`) uses\n * floor division.\n *\n * Unlike `SafeInt`, `NegativeInt` allows values outside the safe integer range\n * (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's\n * `number` type.\n */\nexport const NegativeInt = {\n /**\n * Type guard that checks if a value is a negative integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative integer, `false` otherwise\n * @see {@link isNegativeInt} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NegativeInt`.\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative integer.\n *\n * The result is non-negative and keeps the `NegativeInt` brand. Note that\n * `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so\n * use `SafeInt` for guaranteed precision.\n *\n * @param a - The negative integer value\n * @returns The absolute value as a non-negative `NegativeInt`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative integers.\n *\n * @param values - The negative integers to compare (at least one required)\n * @returns The smallest value as a `NegativeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative integers.\n *\n * @param values - The negative integers to compare (at least one required)\n * @returns The largest value as a `NegativeInt`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `NegativeInt` 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 `NegativeInt`\n */\n clamp,\n\n /**\n * Generates a random `NegativeInt` 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 `NegativeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored\n * to an integer).\n *\n * @param a - The base negative integer\n * @param b - The exponent negative integer\n * @returns `a ** b` as a `NegativeInt`\n */\n pow,\n\n /**\n * Adds two negative integers, returning `a + b` as a `NegativeInt`.\n *\n * @param a - The first negative integer\n * @param b - The second negative integer\n * @returns The sum of `a` and `b` as a `NegativeInt`\n */\n add,\n\n /**\n * Subtracts two negative integers, returning `a - b` as a `NegativeInt`.\n *\n * @param a - The first negative integer\n * @param b - The second negative integer\n * @returns The difference of `a` and `b` as a `NegativeInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;;AAWA,MAAM,iBAAA,GAAoB,oBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,OAAA,EAAS,IAAA;AAAA,EACT,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,EAAA;AAAA,EACX;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,WAAA,CAAY,MAAM,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAWxB,MAAM,aAAA,GAAgB;AAYtB,MAAM,aAAA,GAAgB;AAYtB,MAAM,WAAA,GAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzB,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,GAAA;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;AACF;;;;"}
1
+ {"version":3,"file":"negative-int.mjs","sources":["../../../src/number/branded-types/negative-int.mts"],"sourcesContent":["import {\n type NegativeInt as TtfImported_NegativeInt,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveInt } from './positive-int.mjs';\n\nexport type NegativeInt = TtfImported_NegativeInt;\n\ntype ElementType = NegativeInt;\n\nconst typeNameInMessage = 'a negative integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n -1\n>({\n integerOrSafeInteger: 'Integer',\n nonZero: true,\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: -1,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: WithSmallInt<ElementType>): PositiveInt =>\n PositiveInt.fromNumber(Math.abs(x));\n\n/**\n * Type guard that checks if a value is a negative integer.\n *\n * Returns `true` for a negative integer — a value with no fractional component,\n * including values outside the safe integer range (unlike `SafeInt`).\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative integer, `false` otherwise\n */\nexport const isNegativeInt = is;\n\n/**\n * Casts a `number` to the `NegativeInt` branded type.\n *\n * Validates that the value is a negative integer and returns it with the\n * `NegativeInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeInt`\n * @throws {TypeError} If the value is not a negative integer\n */\nexport const asNegativeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeInt` branded type.\n *\n * The `NegativeInt` type represents a negative integer. Division (`div`) uses\n * floor division.\n *\n * Unlike `SafeInt`, `NegativeInt` allows values outside the safe integer range\n * (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's\n * `number` type.\n */\nexport const NegativeInt = {\n /**\n * Type guard that checks if a value is a negative integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative integer, `false` otherwise\n * @see {@link isNegativeInt} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NegativeInt` (the upper saturation\n * target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative integer.\n *\n * The result is non-negative and keeps the `NegativeInt` brand. Note that\n * `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so\n * use `SafeInt` for guaranteed precision.\n *\n * @param a - The negative integer value\n * @returns The absolute value as a non-negative `NegativeInt`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative integers.\n *\n * @param values - The negative integers to compare (at least one required)\n * @returns The smallest value as a `NegativeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative integers.\n *\n * @param values - The negative integers to compare (at least one required)\n * @returns The largest value as a `NegativeInt`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NegativeInt`, rounding to the\n * nearest integer and saturating the result into the range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to\n * the nearest representable `NegativeInt` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NegativeInt`\n */\n fromNumber,\n\n /**\n * Generates a random `NegativeInt` 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 `NegativeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored\n * to an integer).\n *\n * @param a - The base negative integer\n * @param b - The exponent negative integer\n * @returns `a ** b` as a `NegativeInt`\n */\n pow,\n\n /**\n * Adds two negative integers, returning `a + b` as a `NegativeInt`.\n *\n * @param a - The first negative integer\n * @param b - The second negative integer\n * @returns The sum of `a` and `b` as a `NegativeInt`\n */\n add,\n\n /**\n * Subtracts two negative integers, returning `a - b` as a `NegativeInt`.\n *\n * @param a - The first negative integer\n * @param b - The second negative integer\n * @returns The difference of `a` and `b` as a `NegativeInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;;AAWA,MAAM,iBAAA,GAAoB,oBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,OAAA,EAAS,IAAA;AAAA,EACT,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,EAAA;AAAA,EACX;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,WAAA,CAAY,WAAW,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAW7B,MAAM,aAAA,GAAgB;AAYtB,MAAM,aAAA,GAAgB;AAYtB,MAAM,WAAA,GAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,GAAA;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;AACF;;;;"}
@@ -54,11 +54,13 @@ export declare const NegativeSafeInt: {
54
54
  */
55
55
  readonly is: (a: number) => a is TtfImported_NegativeSafeInt;
56
56
  /**
57
- * The smallest value representable as `NegativeSafeInt`.
57
+ * The smallest value representable as `NegativeSafeInt` (the lower saturation
58
+ * target of `fromNumber`).
58
59
  */
59
60
  readonly MIN_VALUE: number;
60
61
  /**
61
- * The largest value representable as `NegativeSafeInt`.
62
+ * The largest value representable as `NegativeSafeInt` (the upper saturation
63
+ * target of `fromNumber`).
62
64
  */
63
65
  readonly MAX_VALUE: -1;
64
66
  /**
@@ -85,13 +87,17 @@ export declare const NegativeSafeInt: {
85
87
  */
86
88
  readonly max: (...values: readonly WithSmallInt<TtfImported_NegativeSafeInt>[]) => TtfImported_NegativeSafeInt;
87
89
  /**
88
- * Clamps a `number` into the `NegativeSafeInt` range, rounding to the nearest
89
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
90
+ * Converts an arbitrary `number` into a `NegativeSafeInt`, rounding to the
91
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
92
+ * MAX_VALUE]`.
90
93
  *
91
- * @param value - The value to clamp
92
- * @returns The clamped value as a `NegativeSafeInt`
94
+ * Unlike `asNegativeSafeInt`, this is total: out-of-range inputs are clamped
95
+ * to the nearest representable `NegativeSafeInt` instead of throwing.
96
+ *
97
+ * @param value - The value to convert
98
+ * @returns The value as a `NegativeSafeInt`
93
99
  */
94
- readonly clamp: (x: number) => TtfImported_NegativeSafeInt;
100
+ readonly fromNumber: (x: number) => TtfImported_NegativeSafeInt;
95
101
  /**
96
102
  * Generates a random `NegativeSafeInt` within the given range.
97
103
  *
@@ -1 +1 @@
1
- {"version":3,"file":"negative-safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,IAAI,2BAA2B,EACnD,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAE1D,KAAK,WAAW,GAAG,eAAe,CAAC;AA+BnC;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,iDAAK,CAAC;AAEpC;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;MAAW,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;;;;;OAOG;sBA5DW,YAAY,CAAC,WAAW,CAAC,KAAG,eAAe;IA+DzD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
1
+ {"version":3,"file":"negative-safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,IAAI,2BAA2B,EACnD,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAE1D,KAAK,WAAW,GAAG,eAAe,CAAC;AA+BnC;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,iDAAK,CAAC;AAEpC;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;MAAW,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;;;OAOG;sBA9DW,YAAY,CAAC,WAAW,CAAC,KAAG,eAAe;IAiEzD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
@@ -7,7 +7,7 @@ const {
7
7
  MIN_VALUE,
8
8
  add,
9
9
  castType,
10
- clamp,
10
+ fromNumber,
11
11
  is,
12
12
  max: max_,
13
13
  min: min_,
@@ -21,7 +21,7 @@ const {
21
21
  MAX_VALUE: -1,
22
22
  typeNameInMessage
23
23
  });
24
- const abs = (x) => PositiveSafeInt.clamp(Math.abs(x));
24
+ const abs = (x) => PositiveSafeInt.fromNumber(Math.abs(x));
25
25
  const isNegativeSafeInt = is;
26
26
  const asNegativeSafeInt = castType;
27
27
  const NegativeSafeInt = {
@@ -34,11 +34,13 @@ const NegativeSafeInt = {
34
34
  */
35
35
  is,
36
36
  /**
37
- * The smallest value representable as `NegativeSafeInt`.
37
+ * The smallest value representable as `NegativeSafeInt` (the lower saturation
38
+ * target of `fromNumber`).
38
39
  */
39
40
  MIN_VALUE,
40
41
  /**
41
- * The largest value representable as `NegativeSafeInt`.
42
+ * The largest value representable as `NegativeSafeInt` (the upper saturation
43
+ * target of `fromNumber`).
42
44
  */
43
45
  MAX_VALUE,
44
46
  /**
@@ -65,13 +67,17 @@ const NegativeSafeInt = {
65
67
  */
66
68
  max: max_,
67
69
  /**
68
- * Clamps a `number` into the `NegativeSafeInt` range, rounding to the nearest
69
- * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
70
+ * Converts an arbitrary `number` into a `NegativeSafeInt`, rounding to the
71
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
72
+ * MAX_VALUE]`.
70
73
  *
71
- * @param value - The value to clamp
72
- * @returns The clamped value as a `NegativeSafeInt`
74
+ * Unlike `asNegativeSafeInt`, this is total: out-of-range inputs are clamped
75
+ * to the nearest representable `NegativeSafeInt` instead of throwing.
76
+ *
77
+ * @param value - The value to convert
78
+ * @returns The value as a `NegativeSafeInt`
73
79
  */
74
- clamp,
80
+ fromNumber,
75
81
  /**
76
82
  * Generates a random `NegativeSafeInt` within the given range.
77
83
  *
@@ -1 +1 @@
1
- {"version":3,"file":"negative-safe-int.mjs","sources":["../../../src/number/branded-types/negative-safe-int.mts"],"sourcesContent":["import {\n type NegativeSafeInt as TtfImported_NegativeSafeInt,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveSafeInt } from './positive-safe-int.mjs';\n\nexport type NegativeSafeInt = TtfImported_NegativeSafeInt;\n\ntype ElementType = NegativeSafeInt;\n\nconst typeNameInMessage = 'a negative safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n -1\n>({\n integerOrSafeInteger: 'SafeInteger',\n nonZero: true,\n MIN_VALUE: Number.MIN_SAFE_INTEGER,\n MAX_VALUE: -1,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: WithSmallInt<ElementType>): PositiveSafeInt =>\n PositiveSafeInt.clamp(Math.abs(x));\n\n/**\n * Type guard that checks if a value is a negative safe integer.\n *\n * Returns `true` for a negative safe integer — a value with no fractional\n * component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative safe integer, `false` otherwise\n */\nexport const isNegativeSafeInt = is;\n\n/**\n * Casts a `number` to the `NegativeSafeInt` branded type.\n *\n * Validates that the value is a negative safe integer and returns it with the\n * `NegativeSafeInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeSafeInt`\n * @throws {TypeError} If the value is not a negative safe integer\n */\nexport const asNegativeSafeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeSafeInt` branded\n * type.\n *\n * The `NegativeSafeInt` type represents a negative safe integer. Division\n * (`div`) uses floor division.\n */\nexport const NegativeSafeInt = {\n /**\n * Type guard that checks if a value is a negative safe integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative safe integer, `false` otherwise\n * @see {@link isNegativeSafeInt} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `NegativeSafeInt`.\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `NegativeSafeInt`.\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative safe integer.\n *\n * The result is non-negative and keeps the `NegativeSafeInt` brand.\n *\n * @param a - The negative safe integer value\n * @returns The absolute value as a non-negative `NegativeSafeInt`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative safe integers.\n *\n * @param values - The negative safe integers to compare (at least one required)\n * @returns The smallest value as a `NegativeSafeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative safe integers.\n *\n * @param values - The negative safe integers to compare (at least one required)\n * @returns The largest value as a `NegativeSafeInt`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `NegativeSafeInt` 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 `NegativeSafeInt`\n */\n clamp,\n\n /**\n * Generates a random `NegativeSafeInt` 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 `NegativeSafeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NegativeSafeInt`\n * (floored to an integer).\n *\n * @param a - The base negative safe integer\n * @param b - The exponent negative safe integer\n * @returns `a ** b` as a `NegativeSafeInt`\n */\n pow,\n\n /**\n * Adds two negative safe integers, returning `a + b` as a `NegativeSafeInt`.\n *\n * @param a - The first negative safe integer\n * @param b - The second negative safe integer\n * @returns The sum of `a` and `b` as a `NegativeSafeInt`\n */\n add,\n\n /**\n * Subtracts two negative safe integers, returning `a - b` as a\n * `NegativeSafeInt`.\n *\n * @param a - The first negative safe integer\n * @param b - The second negative safe integer\n * @returns The difference of `a` and `b` as a `NegativeSafeInt`\n */\n sub,\n} as const;\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,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,OAAA,EAAS,IAAA;AAAA,EACT,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB,SAAA,EAAW,EAAA;AAAA,EACX;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,eAAA,CAAgB,MAAM,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAW5B,MAAM,iBAAA,GAAoB;AAY1B,MAAM,iBAAA,GAAoB;AAS1B,MAAM,eAAA,GAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7B,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;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;AAAA,EAUA;AACF;;;;"}
1
+ {"version":3,"file":"negative-safe-int.mjs","sources":["../../../src/number/branded-types/negative-safe-int.mts"],"sourcesContent":["import {\n type NegativeSafeInt as TtfImported_NegativeSafeInt,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveSafeInt } from './positive-safe-int.mjs';\n\nexport type NegativeSafeInt = TtfImported_NegativeSafeInt;\n\ntype ElementType = NegativeSafeInt;\n\nconst typeNameInMessage = 'a negative safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n -1\n>({\n integerOrSafeInteger: 'SafeInteger',\n nonZero: true,\n MIN_VALUE: Number.MIN_SAFE_INTEGER,\n MAX_VALUE: -1,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: WithSmallInt<ElementType>): PositiveSafeInt =>\n PositiveSafeInt.fromNumber(Math.abs(x));\n\n/**\n * Type guard that checks if a value is a negative safe integer.\n *\n * Returns `true` for a negative safe integer — a value with no fractional\n * component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative safe integer, `false` otherwise\n */\nexport const isNegativeSafeInt = is;\n\n/**\n * Casts a `number` to the `NegativeSafeInt` branded type.\n *\n * Validates that the value is a negative safe integer and returns it with the\n * `NegativeSafeInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeSafeInt`\n * @throws {TypeError} If the value is not a negative safe integer\n */\nexport const asNegativeSafeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeSafeInt` branded\n * type.\n *\n * The `NegativeSafeInt` type represents a negative safe integer. Division\n * (`div`) uses floor division.\n */\nexport const NegativeSafeInt = {\n /**\n * Type guard that checks if a value is a negative safe integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative safe integer, `false` otherwise\n * @see {@link isNegativeSafeInt} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `NegativeSafeInt` (the lower saturation\n * target of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `NegativeSafeInt` (the upper saturation\n * target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative safe integer.\n *\n * The result is non-negative and keeps the `NegativeSafeInt` brand.\n *\n * @param a - The negative safe integer value\n * @returns The absolute value as a non-negative `NegativeSafeInt`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative safe integers.\n *\n * @param values - The negative safe integers to compare (at least one required)\n * @returns The smallest value as a `NegativeSafeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative safe integers.\n *\n * @param values - The negative safe integers to compare (at least one required)\n * @returns The largest value as a `NegativeSafeInt`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NegativeSafeInt`, rounding to the\n * nearest integer and saturating the result into the range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * Unlike `asNegativeSafeInt`, this is total: out-of-range inputs are clamped\n * to the nearest representable `NegativeSafeInt` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NegativeSafeInt`\n */\n fromNumber,\n\n /**\n * Generates a random `NegativeSafeInt` 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 `NegativeSafeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NegativeSafeInt`\n * (floored to an integer).\n *\n * @param a - The base negative safe integer\n * @param b - The exponent negative safe integer\n * @returns `a ** b` as a `NegativeSafeInt`\n */\n pow,\n\n /**\n * Adds two negative safe integers, returning `a + b` as a `NegativeSafeInt`.\n *\n * @param a - The first negative safe integer\n * @param b - The second negative safe integer\n * @returns The sum of `a` and `b` as a `NegativeSafeInt`\n */\n add,\n\n /**\n * Subtracts two negative safe integers, returning `a - b` as a\n * `NegativeSafeInt`.\n *\n * @param a - The first negative safe integer\n * @param b - The second negative safe integer\n * @returns The difference of `a` and `b` as a `NegativeSafeInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;;AAWA,MAAM,iBAAA,GAAoB,yBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,OAAA,EAAS,IAAA;AAAA,EACT,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB,SAAA,EAAW,EAAA;AAAA,EACX;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,eAAA,CAAgB,WAAW,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAWjC,MAAM,iBAAA,GAAoB;AAY1B,MAAM,iBAAA,GAAoB;AAS1B,MAAM,eAAA,GAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;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;AAAA,EAUA;AACF;;;;"}
@@ -49,7 +49,8 @@ export declare const NonNegativeFiniteNumber: {
49
49
  */
50
50
  readonly is: (a: number) => a is TtfImported_NonNegativeFiniteNumber;
51
51
  /**
52
- * The smallest value representable as `NonNegativeFiniteNumber`.
52
+ * The smallest value representable as `NonNegativeFiniteNumber` (the lower
53
+ * saturation target of `fromNumber`).
53
54
  */
54
55
  readonly MIN_VALUE: 0;
55
56
  /**
@@ -67,13 +68,17 @@ export declare const NonNegativeFiniteNumber: {
67
68
  */
68
69
  readonly max: (...values: readonly TtfImported_NonNegativeFiniteNumber[]) => TtfImported_NonNegativeFiniteNumber;
69
70
  /**
70
- * Clamps a `number` into the `NonNegativeFiniteNumber` range `[MIN_VALUE,
71
- * MAX_VALUE]`.
71
+ * Converts an arbitrary `number` into a `NonNegativeFiniteNumber`, saturating
72
+ * it into the range `[MIN_VALUE, MAX_VALUE]`.
72
73
  *
73
- * @param value - The value to clamp
74
- * @returns The clamped value as a `NonNegativeFiniteNumber`
74
+ * Unlike `asNonNegativeFiniteNumber`, this is total: out-of-range inputs are
75
+ * clamped to the nearest representable `NonNegativeFiniteNumber` instead of
76
+ * throwing.
77
+ *
78
+ * @param value - The value to convert
79
+ * @returns The value as a `NonNegativeFiniteNumber`
75
80
  */
76
- readonly clamp: (x: number) => TtfImported_NonNegativeFiniteNumber;
81
+ readonly fromNumber: (x: number) => TtfImported_NonNegativeFiniteNumber;
77
82
  /**
78
83
  * Returns the greatest integer less than or equal to a non-negative finite
79
84
  * number.
@@ -1 +1 @@
1
- {"version":3,"file":"non-negative-finite-number.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-negative-finite-number.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,uBAAuB,IAAI,mCAAmC,EAEpE,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,MAAM,uBAAuB,GAAG,mCAAmC,CAAC;AAE1E,KAAK,WAAW,GAAG,uBAAuB,CAAC;AAiD3C;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,yDAAK,CAAC;AAE5C;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;MAAW,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;IAClC;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;wBAhGA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IAkG3D;;;;;;OAMG;uBAnGA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IAqG3D;;;;;;OAMG;wBAtGA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IAwG3D;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;CAEK,CAAC"}
1
+ {"version":3,"file":"non-negative-finite-number.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-negative-finite-number.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,uBAAuB,IAAI,mCAAmC,EAEpE,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,MAAM,uBAAuB,GAAG,mCAAmC,CAAC;AAE1E,KAAK,WAAW,GAAG,uBAAuB,CAAC;AAiD3C;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,yDAAK,CAAC;AAE5C;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;MAAW,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;IAClC;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;OAMG;wBArGA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IAuG3D;;;;;;OAMG;uBAxGA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IA0G3D;;;;;;OAMG;wBA3GA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IA6G3D;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;CAEK,CAAC"}
@@ -5,8 +5,8 @@ const {
5
5
  MIN_VALUE,
6
6
  add,
7
7
  castType,
8
- clamp,
9
8
  div,
9
+ fromNumber,
10
10
  is,
11
11
  max: max_,
12
12
  min: min_,
@@ -43,7 +43,8 @@ const NonNegativeFiniteNumber = {
43
43
  */
44
44
  is,
45
45
  /**
46
- * The smallest value representable as `NonNegativeFiniteNumber`.
46
+ * The smallest value representable as `NonNegativeFiniteNumber` (the lower
47
+ * saturation target of `fromNumber`).
47
48
  */
48
49
  MIN_VALUE,
49
50
  /**
@@ -61,13 +62,17 @@ const NonNegativeFiniteNumber = {
61
62
  */
62
63
  max: max_,
63
64
  /**
64
- * Clamps a `number` into the `NonNegativeFiniteNumber` range `[MIN_VALUE,
65
- * MAX_VALUE]`.
65
+ * Converts an arbitrary `number` into a `NonNegativeFiniteNumber`, saturating
66
+ * it into the range `[MIN_VALUE, MAX_VALUE]`.
66
67
  *
67
- * @param value - The value to clamp
68
- * @returns The clamped value as a `NonNegativeFiniteNumber`
68
+ * Unlike `asNonNegativeFiniteNumber`, this is total: out-of-range inputs are
69
+ * clamped to the nearest representable `NonNegativeFiniteNumber` instead of
70
+ * throwing.
71
+ *
72
+ * @param value - The value to convert
73
+ * @returns The value as a `NonNegativeFiniteNumber`
69
74
  */
70
- clamp,
75
+ fromNumber,
71
76
  /**
72
77
  * Returns the greatest integer less than or equal to a non-negative finite
73
78
  * number.
@@ -1 +1 @@
1
- {"version":3,"file":"non-negative-finite-number.mjs","sources":["../../../src/number/branded-types/non-negative-finite-number.mts"],"sourcesContent":["import {\n type NonNegativeFiniteNumber as TtfImported_NonNegativeFiniteNumber,\n type Uint,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonNegativeFiniteNumber = TtfImported_NonNegativeFiniteNumber;\n\ntype ElementType = NonNegativeFiniteNumber;\n\nconst typeNameInMessage = 'a non-negative finite number';\n\nconst {\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.operatorsForFloat<\n ElementType,\n 0,\n number\n>({\n MIN_VALUE: 0,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nexpectType<TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>, Uint>(\n '=',\n);\n\n/**\n * Type guard that checks if a value is a non-negative finite number.\n *\n * Returns `true` only for a finite value — never `NaN`, `Infinity`, or\n * `-Infinity`.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative finite number, `false` otherwise\n */\nexport const isNonNegativeFiniteNumber = is;\n\n/**\n * Casts a `number` to the `NonNegativeFiniteNumber` branded type.\n *\n * Validates that the value is a non-negative finite number and returns it with\n * the `NonNegativeFiniteNumber` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NonNegativeFiniteNumber`\n * @throws {TypeError} If the value is not a non-negative finite number\n */\nexport const asNonNegativeFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe operations for the `NonNegativeFiniteNumber`\n * branded type.\n *\n * The `NonNegativeFiniteNumber` type represents a non-negative finite number.\n */\nexport const NonNegativeFiniteNumber = {\n /**\n * Type guard that checks if a value is a non-negative finite number.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative finite number, `false` otherwise\n * @see {@link isNonNegativeFiniteNumber} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `NonNegativeFiniteNumber`.\n */\n MIN_VALUE,\n\n /**\n * Returns the smallest of the given non-negative finite numbers.\n *\n * @param values - The non-negative finite numbers to compare (at least one required)\n * @returns The smallest value as a `NonNegativeFiniteNumber`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-negative finite numbers.\n *\n * @param values - The non-negative finite numbers to compare (at least one required)\n * @returns The largest value as a `NonNegativeFiniteNumber`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `NonNegativeFiniteNumber` range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `NonNegativeFiniteNumber`\n */\n clamp,\n\n /**\n * Returns the greatest integer less than or equal to a non-negative finite\n * number.\n *\n * @param a - The non-negative finite number value\n * @returns The floored value as an integer\n */\n floor,\n\n /**\n * Returns the smallest integer greater than or equal to a non-negative finite\n * number.\n *\n * @param a - The non-negative finite number value\n * @returns The ceiled value as an integer\n */\n ceil,\n\n /**\n * Returns the value of a non-negative finite number rounded to the nearest\n * integer.\n *\n * @param a - The non-negative finite number value\n * @returns The rounded value as an integer\n */\n round,\n\n /**\n * Generates a random `NonNegativeFiniteNumber` 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 `NonNegativeFiniteNumber` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The base non-negative finite number\n * @param b - The exponent non-negative finite number\n * @returns `a ** b` as a `NonNegativeFiniteNumber`\n */\n pow,\n\n /**\n * Adds two non-negative finite numbers, returning `a + b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The first non-negative finite number\n * @param b - The second non-negative finite number\n * @returns The sum of `a` and `b` as a `NonNegativeFiniteNumber`\n */\n add,\n\n /**\n * Subtracts two non-negative finite numbers, returning `a - b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The first non-negative finite number\n * @param b - The second non-negative finite number\n * @returns The difference of `a` and `b` as a `NonNegativeFiniteNumber`\n */\n sub,\n\n /**\n * Multiplies two non-negative finite numbers, returning `a * b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The first non-negative finite number\n * @param b - The second non-negative finite number\n * @returns The product of `a` and `b` as a `NonNegativeFiniteNumber`\n */\n mul,\n\n /**\n * Divides two non-negative finite numbers, returning `a / b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns `a / b` as a `NonNegativeFiniteNumber`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof NonNegativeFiniteNumber,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'non-negative'\n >\n>('=');\n\nexpectType<\n typeof NonNegativeFiniteNumber,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'non-negative'\n >\n>('<=');\n"],"names":[],"mappings":";;AAWA,MAAM,iBAAA,GAAoB,8BAAA;AAE1B,MAAM;AAAA,EACJ,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,iBAAA,CAI1C;AAAA,EACA,SAAA,EAAW,CAAA;AAAA,EACX,WAAW,MAAA,CAAO,SAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAEV,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAC;AAAA,CAAA;AAEd,MAAM,OAAO,CACX,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,KAAK,CAAC;AAAA,CAAA;AAEb,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAC;AAAA,CAAA;AAeP,MAAM,yBAAA,GAA4B;AAYlC,MAAM,yBAAA,GAA4B;AAQlC,MAAM,uBAAA,GAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQrC,EAAA;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,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,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;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
1
+ {"version":3,"file":"non-negative-finite-number.mjs","sources":["../../../src/number/branded-types/non-negative-finite-number.mts"],"sourcesContent":["import {\n type NonNegativeFiniteNumber as TtfImported_NonNegativeFiniteNumber,\n type Uint,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonNegativeFiniteNumber = TtfImported_NonNegativeFiniteNumber;\n\ntype ElementType = NonNegativeFiniteNumber;\n\nconst typeNameInMessage = 'a non-negative finite number';\n\nconst {\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.operatorsForFloat<\n ElementType,\n 0,\n number\n>({\n MIN_VALUE: 0,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nexpectType<TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>, Uint>(\n '=',\n);\n\n/**\n * Type guard that checks if a value is a non-negative finite number.\n *\n * Returns `true` only for a finite value — never `NaN`, `Infinity`, or\n * `-Infinity`.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative finite number, `false` otherwise\n */\nexport const isNonNegativeFiniteNumber = is;\n\n/**\n * Casts a `number` to the `NonNegativeFiniteNumber` branded type.\n *\n * Validates that the value is a non-negative finite number and returns it with\n * the `NonNegativeFiniteNumber` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NonNegativeFiniteNumber`\n * @throws {TypeError} If the value is not a non-negative finite number\n */\nexport const asNonNegativeFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe operations for the `NonNegativeFiniteNumber`\n * branded type.\n *\n * The `NonNegativeFiniteNumber` type represents a non-negative finite number.\n */\nexport const NonNegativeFiniteNumber = {\n /**\n * Type guard that checks if a value is a non-negative finite number.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative finite number, `false` otherwise\n * @see {@link isNonNegativeFiniteNumber} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `NonNegativeFiniteNumber` (the lower\n * saturation target of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * Returns the smallest of the given non-negative finite numbers.\n *\n * @param values - The non-negative finite numbers to compare (at least one required)\n * @returns The smallest value as a `NonNegativeFiniteNumber`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-negative finite numbers.\n *\n * @param values - The non-negative finite numbers to compare (at least one required)\n * @returns The largest value as a `NonNegativeFiniteNumber`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NonNegativeFiniteNumber`, saturating\n * it into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asNonNegativeFiniteNumber`, this is total: out-of-range inputs are\n * clamped to the nearest representable `NonNegativeFiniteNumber` instead of\n * throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NonNegativeFiniteNumber`\n */\n fromNumber,\n\n /**\n * Returns the greatest integer less than or equal to a non-negative finite\n * number.\n *\n * @param a - The non-negative finite number value\n * @returns The floored value as an integer\n */\n floor,\n\n /**\n * Returns the smallest integer greater than or equal to a non-negative finite\n * number.\n *\n * @param a - The non-negative finite number value\n * @returns The ceiled value as an integer\n */\n ceil,\n\n /**\n * Returns the value of a non-negative finite number rounded to the nearest\n * integer.\n *\n * @param a - The non-negative finite number value\n * @returns The rounded value as an integer\n */\n round,\n\n /**\n * Generates a random `NonNegativeFiniteNumber` 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 `NonNegativeFiniteNumber` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The base non-negative finite number\n * @param b - The exponent non-negative finite number\n * @returns `a ** b` as a `NonNegativeFiniteNumber`\n */\n pow,\n\n /**\n * Adds two non-negative finite numbers, returning `a + b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The first non-negative finite number\n * @param b - The second non-negative finite number\n * @returns The sum of `a` and `b` as a `NonNegativeFiniteNumber`\n */\n add,\n\n /**\n * Subtracts two non-negative finite numbers, returning `a - b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The first non-negative finite number\n * @param b - The second non-negative finite number\n * @returns The difference of `a` and `b` as a `NonNegativeFiniteNumber`\n */\n sub,\n\n /**\n * Multiplies two non-negative finite numbers, returning `a * b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The first non-negative finite number\n * @param b - The second non-negative finite number\n * @returns The product of `a` and `b` as a `NonNegativeFiniteNumber`\n */\n mul,\n\n /**\n * Divides two non-negative finite numbers, returning `a / b` as a\n * `NonNegativeFiniteNumber`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns `a / b` as a `NonNegativeFiniteNumber`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof NonNegativeFiniteNumber,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'non-negative'\n >\n>('=');\n\nexpectType<\n typeof NonNegativeFiniteNumber,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'non-negative'\n >\n>('<=');\n"],"names":[],"mappings":";;AAWA,MAAM,iBAAA,GAAoB,8BAAA;AAE1B,MAAM;AAAA,EACJ,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,iBAAA,CAI1C;AAAA,EACA,SAAA,EAAW,CAAA;AAAA,EACX,WAAW,MAAA,CAAO,SAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAEV,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAC;AAAA,CAAA;AAEd,MAAM,OAAO,CACX,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,KAAK,CAAC;AAAA,CAAA;AAEb,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAC;AAAA,CAAA;AAeP,MAAM,yBAAA,GAA4B;AAYlC,MAAM,yBAAA,GAA4B;AAQlC,MAAM,uBAAA,GAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQrC,EAAA;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,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,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;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
@@ -54,11 +54,13 @@ export declare const NonNegativeInt16: {
54
54
  */
55
55
  readonly is: (a: number) => a is TtfImported_NonNegativeInt16;
56
56
  /**
57
- * The smallest value representable as `NonNegativeInt16`.
57
+ * The smallest value representable as `NonNegativeInt16` (the lower
58
+ * saturation target of `fromNumber`).
58
59
  */
59
60
  readonly MIN_VALUE: 0;
60
61
  /**
61
- * The largest value representable as `NonNegativeInt16`.
62
+ * The largest value representable as `NonNegativeInt16` (the upper saturation
63
+ * target of `fromNumber`).
62
64
  */
63
65
  readonly MAX_VALUE: number;
64
66
  /**
@@ -76,13 +78,17 @@ export declare const NonNegativeInt16: {
76
78
  */
77
79
  readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_NonNegativeInt16>[]) => TtfImported_NonNegativeInt16;
78
80
  /**
79
- * Clamps a `number` into the `NonNegativeInt16` range, rounding to the
80
- * nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
81
+ * Converts an arbitrary `number` into a `NonNegativeInt16`, rounding to the
82
+ * nearest integer and saturating the result into the range `[MIN_VALUE,
83
+ * MAX_VALUE]`.
81
84
  *
82
- * @param value - The value to clamp
83
- * @returns The clamped value as a `NonNegativeInt16`
85
+ * Unlike `asNonNegativeInt16`, this is total: out-of-range inputs are clamped
86
+ * to the nearest representable `NonNegativeInt16` instead of throwing.
87
+ *
88
+ * @param value - The value to convert
89
+ * @returns The value as a `NonNegativeInt16`
84
90
  */
85
- readonly clamp: (x: number) => TtfImported_NonNegativeInt16;
91
+ readonly fromNumber: (x: number) => TtfImported_NonNegativeInt16;
86
92
  /**
87
93
  * Generates a random `NonNegativeInt16` within the given range.
88
94
  *
@@ -1 +1 @@
1
- {"version":3,"file":"non-negative-int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-negative-int16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,IAAI,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAItF,MAAM,MAAM,gBAAgB,GAAG,4BAA4B,CAAC;AA+B5D;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,kDAAK,CAAC;AAErC;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;MAAW,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;;OAQG;;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
1
+ {"version":3,"file":"non-negative-int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-negative-int16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,IAAI,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAItF,MAAM,MAAM,gBAAgB,GAAG,4BAA4B,CAAC;AA+B5D;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,kDAAK,CAAC;AAErC;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;MAAW,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;;OAQG;;;;;;;;;;;;;;;;;;;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 NonNegativeInt16 = {
33
33
  */
34
34
  is,
35
35
  /**
36
- * The smallest value representable as `NonNegativeInt16`.
36
+ * The smallest value representable as `NonNegativeInt16` (the lower
37
+ * saturation target of `fromNumber`).
37
38
  */
38
39
  MIN_VALUE,
39
40
  /**
40
- * The largest value representable as `NonNegativeInt16`.
41
+ * The largest value representable as `NonNegativeInt16` (the upper saturation
42
+ * target of `fromNumber`).
41
43
  */
42
44
  MAX_VALUE,
43
45
  /**
@@ -55,13 +57,17 @@ const NonNegativeInt16 = {
55
57
  */
56
58
  max: max_,
57
59
  /**
58
- * Clamps a `number` into the `NonNegativeInt16` range, rounding to the
59
- * nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
60
+ * Converts an arbitrary `number` into a `NonNegativeInt16`, 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 `NonNegativeInt16`
64
+ * Unlike `asNonNegativeInt16`, this is total: out-of-range inputs are clamped
65
+ * to the nearest representable `NonNegativeInt16` instead of throwing.
66
+ *
67
+ * @param value - The value to convert
68
+ * @returns The value as a `NonNegativeInt16`
63
69
  */
64
- clamp,
70
+ fromNumber,
65
71
  /**
66
72
  * Generates a random `NonNegativeInt16` within the given range.
67
73
  *