ts-data-forge 11.0.1 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/number/branded-types/int16.d.mts +12 -7
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +13 -8
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +12 -7
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +13 -8
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +13 -6
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +15 -8
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +11 -6
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +13 -8
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +13 -7
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +15 -9
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +11 -6
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +12 -7
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +13 -7
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +14 -8
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +13 -7
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +14 -8
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +11 -6
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +12 -7
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +11 -6
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +12 -7
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +14 -7
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +15 -8
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +13 -7
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +14 -8
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +13 -7
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +14 -8
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +13 -7
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +14 -8
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +13 -7
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +14 -8
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +13 -7
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +14 -8
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +13 -6
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +14 -7
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +13 -8
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +14 -9
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +13 -7
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +14 -8
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +13 -7
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +14 -8
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +16 -10
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +17 -11
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +13 -7
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +14 -8
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +13 -7
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +14 -8
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +15 -10
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +16 -11
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +12 -7
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +13 -8
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +14 -10
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +15 -11
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +12 -7
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +13 -8
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +12 -7
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +13 -8
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +12 -7
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +19 -14
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +12 -7
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +19 -14
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +9 -9
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +7 -7
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/package.json +1 -1
- package/src/number/branded-types/int16.mts +13 -8
- package/src/number/branded-types/int32.mts +13 -8
- package/src/number/branded-types/negative-finite-number.mts +15 -8
- package/src/number/branded-types/negative-finite-number.test.mts +4 -4
- package/src/number/branded-types/negative-int.mts +13 -8
- package/src/number/branded-types/negative-int.test.mts +5 -5
- package/src/number/branded-types/negative-safe-int.mts +15 -9
- package/src/number/branded-types/negative-safe-int.test.mts +4 -4
- package/src/number/branded-types/non-negative-finite-number.mts +12 -7
- package/src/number/branded-types/non-negative-int16.mts +14 -8
- package/src/number/branded-types/non-negative-int32.mts +14 -8
- package/src/number/branded-types/non-positive-finite-number.mts +12 -7
- package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
- package/src/number/branded-types/non-positive-int.mts +12 -7
- package/src/number/branded-types/non-positive-int.test.mts +7 -7
- package/src/number/branded-types/non-positive-safe-int.mts +15 -8
- package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
- package/src/number/branded-types/non-zero-int16.mts +14 -8
- package/src/number/branded-types/non-zero-int32.mts +14 -8
- package/src/number/branded-types/non-zero-safe-int.mts +14 -8
- package/src/number/branded-types/non-zero-uint16.mts +14 -8
- package/src/number/branded-types/non-zero-uint32.mts +14 -8
- package/src/number/branded-types/positive-finite-number.mts +14 -7
- package/src/number/branded-types/positive-int.mts +14 -9
- package/src/number/branded-types/positive-int16.mts +14 -8
- package/src/number/branded-types/positive-int32.mts +14 -8
- package/src/number/branded-types/positive-safe-int.mts +17 -11
- package/src/number/branded-types/positive-uint16.mts +14 -8
- package/src/number/branded-types/positive-uint32.mts +14 -8
- package/src/number/branded-types/safe-int.mts +16 -11
- package/src/number/branded-types/safe-uint.mts +13 -8
- package/src/number/branded-types/uint.mts +15 -11
- package/src/number/branded-types/uint16.mts +13 -8
- package/src/number/branded-types/uint32.mts +13 -8
- package/src/number/enum/int8.mts +20 -14
- package/src/number/enum/int8.test.mts +7 -4
- package/src/number/enum/uint8.mts +20 -14
- package/src/number/enum/uint8.test.mts +7 -4
- package/src/number/refined-number-utils.mts +22 -19
|
@@ -13,8 +13,8 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
add,
|
|
15
15
|
castType,
|
|
16
|
-
clamp,
|
|
17
16
|
div,
|
|
17
|
+
fromNumber,
|
|
18
18
|
is,
|
|
19
19
|
max: max_,
|
|
20
20
|
min: min_,
|
|
@@ -74,12 +74,14 @@ export const PositiveInt16 = {
|
|
|
74
74
|
is,
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
* The smallest value representable as `PositiveInt16
|
|
77
|
+
* The smallest value representable as `PositiveInt16` (the lower saturation
|
|
78
|
+
* target of `fromNumber`).
|
|
78
79
|
*/
|
|
79
80
|
MIN_VALUE,
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
|
-
* The largest value representable as `PositiveInt16
|
|
83
|
+
* The largest value representable as `PositiveInt16` (the upper saturation
|
|
84
|
+
* target of `fromNumber`).
|
|
83
85
|
*/
|
|
84
86
|
MAX_VALUE,
|
|
85
87
|
|
|
@@ -100,13 +102,17 @@ export const PositiveInt16 = {
|
|
|
100
102
|
max: max_,
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
|
-
*
|
|
104
|
-
* integer and
|
|
105
|
+
* Converts an arbitrary `number` into a `PositiveInt16`, rounding to the
|
|
106
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
107
|
+
* MAX_VALUE]`.
|
|
105
108
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
109
|
+
* Unlike `asPositiveInt16`, this is total: out-of-range inputs are clamped to
|
|
110
|
+
* the nearest representable `PositiveInt16` instead of throwing.
|
|
111
|
+
*
|
|
112
|
+
* @param value - The value to convert
|
|
113
|
+
* @returns The value as a `PositiveInt16`
|
|
108
114
|
*/
|
|
109
|
-
|
|
115
|
+
fromNumber,
|
|
110
116
|
|
|
111
117
|
/**
|
|
112
118
|
* Generates a random `PositiveInt16` within the given range.
|
|
@@ -13,8 +13,8 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
add,
|
|
15
15
|
castType,
|
|
16
|
-
clamp,
|
|
17
16
|
div,
|
|
17
|
+
fromNumber,
|
|
18
18
|
is,
|
|
19
19
|
max: max_,
|
|
20
20
|
min: min_,
|
|
@@ -74,12 +74,14 @@ export const PositiveInt32 = {
|
|
|
74
74
|
is,
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
* The smallest value representable as `PositiveInt32
|
|
77
|
+
* The smallest value representable as `PositiveInt32` (the lower saturation
|
|
78
|
+
* target of `fromNumber`).
|
|
78
79
|
*/
|
|
79
80
|
MIN_VALUE,
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
|
-
* The largest value representable as `PositiveInt32
|
|
83
|
+
* The largest value representable as `PositiveInt32` (the upper saturation
|
|
84
|
+
* target of `fromNumber`).
|
|
83
85
|
*/
|
|
84
86
|
MAX_VALUE,
|
|
85
87
|
|
|
@@ -100,13 +102,17 @@ export const PositiveInt32 = {
|
|
|
100
102
|
max: max_,
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
|
-
*
|
|
104
|
-
* integer and
|
|
105
|
+
* Converts an arbitrary `number` into a `PositiveInt32`, rounding to the
|
|
106
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
107
|
+
* MAX_VALUE]`.
|
|
105
108
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
109
|
+
* Unlike `asPositiveInt32`, this is total: out-of-range inputs are clamped to
|
|
110
|
+
* the nearest representable `PositiveInt32` instead of throwing.
|
|
111
|
+
*
|
|
112
|
+
* @param value - The value to convert
|
|
113
|
+
* @returns The value as a `PositiveInt32`
|
|
108
114
|
*/
|
|
109
|
-
|
|
115
|
+
fromNumber,
|
|
110
116
|
|
|
111
117
|
/**
|
|
112
118
|
* Generates a random `PositiveInt32` within the given range.
|
|
@@ -16,8 +16,8 @@ const {
|
|
|
16
16
|
MIN_VALUE,
|
|
17
17
|
add,
|
|
18
18
|
castType,
|
|
19
|
-
clamp,
|
|
20
19
|
div,
|
|
20
|
+
fromNumber,
|
|
21
21
|
is,
|
|
22
22
|
max: max_,
|
|
23
23
|
min: min_,
|
|
@@ -112,12 +112,14 @@ export const PositiveSafeInt = {
|
|
|
112
112
|
is,
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
|
-
* The smallest value representable as `PositiveSafeInt
|
|
115
|
+
* The smallest value representable as `PositiveSafeInt` (the lower saturation
|
|
116
|
+
* target of `fromNumber`).
|
|
116
117
|
*/
|
|
117
118
|
MIN_VALUE,
|
|
118
119
|
|
|
119
120
|
/**
|
|
120
|
-
* The largest value representable as `PositiveSafeInt
|
|
121
|
+
* The largest value representable as `PositiveSafeInt` (the upper saturation
|
|
122
|
+
* target of `fromNumber`).
|
|
121
123
|
*/
|
|
122
124
|
MAX_VALUE,
|
|
123
125
|
|
|
@@ -160,17 +162,21 @@ export const PositiveSafeInt = {
|
|
|
160
162
|
max: max_,
|
|
161
163
|
|
|
162
164
|
/**
|
|
163
|
-
*
|
|
164
|
-
* integer and
|
|
165
|
+
* Converts an arbitrary `number` into a `PositiveSafeInt`, rounding to the
|
|
166
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
167
|
+
* MAX_VALUE]`.
|
|
168
|
+
*
|
|
169
|
+
* Unlike `asPositiveSafeInt`, this is total: out-of-range inputs are clamped
|
|
170
|
+
* to the nearest representable `PositiveSafeInt` instead of throwing.
|
|
165
171
|
*
|
|
166
172
|
* @example
|
|
167
173
|
*
|
|
168
174
|
* ```ts
|
|
169
|
-
* const belowRange = PositiveSafeInt.
|
|
175
|
+
* const belowRange = PositiveSafeInt.fromNumber(0);
|
|
170
176
|
*
|
|
171
|
-
* const withinRange = PositiveSafeInt.
|
|
177
|
+
* const withinRange = PositiveSafeInt.fromNumber(123);
|
|
172
178
|
*
|
|
173
|
-
* const aboveRange = PositiveSafeInt.
|
|
179
|
+
* const aboveRange = PositiveSafeInt.fromNumber(Number.MAX_SAFE_INTEGER + 10);
|
|
174
180
|
*
|
|
175
181
|
* assert.isTrue(belowRange === 1);
|
|
176
182
|
*
|
|
@@ -179,10 +185,10 @@ export const PositiveSafeInt = {
|
|
|
179
185
|
* assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
|
|
180
186
|
* ```
|
|
181
187
|
*
|
|
182
|
-
* @param value - The value to
|
|
183
|
-
* @returns The
|
|
188
|
+
* @param value - The value to convert
|
|
189
|
+
* @returns The value as a `PositiveSafeInt`
|
|
184
190
|
*/
|
|
185
|
-
|
|
191
|
+
fromNumber,
|
|
186
192
|
|
|
187
193
|
/**
|
|
188
194
|
* Generates a random `PositiveSafeInt` within the given range.
|
|
@@ -13,8 +13,8 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
add,
|
|
15
15
|
castType,
|
|
16
|
-
clamp,
|
|
17
16
|
div,
|
|
17
|
+
fromNumber,
|
|
18
18
|
is,
|
|
19
19
|
max: max_,
|
|
20
20
|
min: min_,
|
|
@@ -74,12 +74,14 @@ export const PositiveUint16 = {
|
|
|
74
74
|
is,
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
* The smallest value representable as `PositiveUint16
|
|
77
|
+
* The smallest value representable as `PositiveUint16` (the lower saturation
|
|
78
|
+
* target of `fromNumber`).
|
|
78
79
|
*/
|
|
79
80
|
MIN_VALUE,
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
|
-
* The largest value representable as `PositiveUint16
|
|
83
|
+
* The largest value representable as `PositiveUint16` (the upper saturation
|
|
84
|
+
* target of `fromNumber`).
|
|
83
85
|
*/
|
|
84
86
|
MAX_VALUE,
|
|
85
87
|
|
|
@@ -100,13 +102,17 @@ export const PositiveUint16 = {
|
|
|
100
102
|
max: max_,
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
|
-
*
|
|
104
|
-
* integer and
|
|
105
|
+
* Converts an arbitrary `number` into a `PositiveUint16`, rounding to the
|
|
106
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
107
|
+
* MAX_VALUE]`.
|
|
105
108
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
109
|
+
* Unlike `asPositiveUint16`, this is total: out-of-range inputs are clamped
|
|
110
|
+
* to the nearest representable `PositiveUint16` instead of throwing.
|
|
111
|
+
*
|
|
112
|
+
* @param value - The value to convert
|
|
113
|
+
* @returns The value as a `PositiveUint16`
|
|
108
114
|
*/
|
|
109
|
-
|
|
115
|
+
fromNumber,
|
|
110
116
|
|
|
111
117
|
/**
|
|
112
118
|
* Generates a random `PositiveUint16` within the given range.
|
|
@@ -13,8 +13,8 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
add,
|
|
15
15
|
castType,
|
|
16
|
-
clamp,
|
|
17
16
|
div,
|
|
17
|
+
fromNumber,
|
|
18
18
|
is,
|
|
19
19
|
max: max_,
|
|
20
20
|
min: min_,
|
|
@@ -74,12 +74,14 @@ export const PositiveUint32 = {
|
|
|
74
74
|
is,
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
* The smallest value representable as `PositiveUint32
|
|
77
|
+
* The smallest value representable as `PositiveUint32` (the lower saturation
|
|
78
|
+
* target of `fromNumber`).
|
|
78
79
|
*/
|
|
79
80
|
MIN_VALUE,
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
|
-
* The largest value representable as `PositiveUint32
|
|
83
|
+
* The largest value representable as `PositiveUint32` (the upper saturation
|
|
84
|
+
* target of `fromNumber`).
|
|
83
85
|
*/
|
|
84
86
|
MAX_VALUE,
|
|
85
87
|
|
|
@@ -100,13 +102,17 @@ export const PositiveUint32 = {
|
|
|
100
102
|
max: max_,
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
|
-
*
|
|
104
|
-
* integer and
|
|
105
|
+
* Converts an arbitrary `number` into a `PositiveUint32`, rounding to the
|
|
106
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
107
|
+
* MAX_VALUE]`.
|
|
105
108
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
109
|
+
* Unlike `asPositiveUint32`, this is total: out-of-range inputs are clamped
|
|
110
|
+
* to the nearest representable `PositiveUint32` instead of throwing.
|
|
111
|
+
*
|
|
112
|
+
* @param value - The value to convert
|
|
113
|
+
* @returns The value as a `PositiveUint32`
|
|
108
114
|
*/
|
|
109
|
-
|
|
115
|
+
fromNumber,
|
|
110
116
|
|
|
111
117
|
/**
|
|
112
118
|
* Generates a random `PositiveUint32` within the given range.
|
|
@@ -17,8 +17,8 @@ const {
|
|
|
17
17
|
abs,
|
|
18
18
|
add,
|
|
19
19
|
castType,
|
|
20
|
-
clamp,
|
|
21
20
|
div,
|
|
21
|
+
fromNumber,
|
|
22
22
|
is,
|
|
23
23
|
max: max_,
|
|
24
24
|
min: min_,
|
|
@@ -108,12 +108,14 @@ export const SafeInt = {
|
|
|
108
108
|
is,
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* The smallest value representable as `SafeInt
|
|
111
|
+
* The smallest value representable as `SafeInt` (the lower saturation target
|
|
112
|
+
* of `fromNumber`).
|
|
112
113
|
*/
|
|
113
114
|
MIN_VALUE,
|
|
114
115
|
|
|
115
116
|
/**
|
|
116
|
-
* The largest value representable as `SafeInt
|
|
117
|
+
* The largest value representable as `SafeInt` (the upper saturation target
|
|
118
|
+
* of `fromNumber`).
|
|
117
119
|
*/
|
|
118
120
|
MAX_VALUE,
|
|
119
121
|
|
|
@@ -172,17 +174,20 @@ export const SafeInt = {
|
|
|
172
174
|
max: max_,
|
|
173
175
|
|
|
174
176
|
/**
|
|
175
|
-
*
|
|
176
|
-
* and
|
|
177
|
+
* Converts an arbitrary `number` into a `SafeInt`, rounding to the nearest
|
|
178
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
179
|
+
*
|
|
180
|
+
* Unlike `asSafeInt`, this is total: out-of-range inputs are clamped to the
|
|
181
|
+
* nearest representable `SafeInt` instead of throwing.
|
|
177
182
|
*
|
|
178
183
|
* @example
|
|
179
184
|
*
|
|
180
185
|
* ```ts
|
|
181
|
-
* const aboveRange = SafeInt.
|
|
186
|
+
* const aboveRange = SafeInt.fromNumber(1e20);
|
|
182
187
|
*
|
|
183
|
-
* const withinRange = SafeInt.
|
|
188
|
+
* const withinRange = SafeInt.fromNumber(123);
|
|
184
189
|
*
|
|
185
|
-
* const belowRange = SafeInt.
|
|
190
|
+
* const belowRange = SafeInt.fromNumber(-1e20);
|
|
186
191
|
*
|
|
187
192
|
* assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
|
|
188
193
|
*
|
|
@@ -191,10 +196,10 @@ export const SafeInt = {
|
|
|
191
196
|
* assert.isTrue(belowRange === Number.MIN_SAFE_INTEGER);
|
|
192
197
|
* ```
|
|
193
198
|
*
|
|
194
|
-
* @param value - The value to
|
|
195
|
-
* @returns The
|
|
199
|
+
* @param value - The value to convert
|
|
200
|
+
* @returns The value as a `SafeInt`
|
|
196
201
|
*/
|
|
197
|
-
|
|
202
|
+
fromNumber,
|
|
198
203
|
|
|
199
204
|
/**
|
|
200
205
|
* Generates a random `SafeInt` within the given range.
|
|
@@ -13,8 +13,8 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
add,
|
|
15
15
|
castType,
|
|
16
|
-
clamp,
|
|
17
16
|
div,
|
|
17
|
+
fromNumber,
|
|
18
18
|
is,
|
|
19
19
|
max: max_,
|
|
20
20
|
min: min_,
|
|
@@ -74,12 +74,14 @@ export const SafeUint = {
|
|
|
74
74
|
is,
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
* The smallest value representable as `SafeUint
|
|
77
|
+
* The smallest value representable as `SafeUint` (the lower saturation target
|
|
78
|
+
* of `fromNumber`).
|
|
78
79
|
*/
|
|
79
80
|
MIN_VALUE,
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
|
-
* The largest value representable as `SafeUint
|
|
83
|
+
* The largest value representable as `SafeUint` (the upper saturation target
|
|
84
|
+
* of `fromNumber`).
|
|
83
85
|
*/
|
|
84
86
|
MAX_VALUE,
|
|
85
87
|
|
|
@@ -100,13 +102,16 @@ export const SafeUint = {
|
|
|
100
102
|
max: max_,
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
|
-
*
|
|
104
|
-
* integer and
|
|
105
|
+
* Converts an arbitrary `number` into a `SafeUint`, rounding to the nearest
|
|
106
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
105
107
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
+
* Unlike `asSafeUint`, this is total: out-of-range inputs are clamped to the
|
|
109
|
+
* nearest representable `SafeUint` instead of throwing.
|
|
110
|
+
*
|
|
111
|
+
* @param value - The value to convert
|
|
112
|
+
* @returns The value as a `SafeUint`
|
|
108
113
|
*/
|
|
109
|
-
|
|
114
|
+
fromNumber,
|
|
110
115
|
|
|
111
116
|
/**
|
|
112
117
|
* Generates a random `SafeUint` within the given range.
|
|
@@ -12,8 +12,8 @@ const {
|
|
|
12
12
|
MIN_VALUE,
|
|
13
13
|
add,
|
|
14
14
|
castType,
|
|
15
|
-
clamp,
|
|
16
15
|
div,
|
|
16
|
+
fromNumber,
|
|
17
17
|
is,
|
|
18
18
|
max: max_,
|
|
19
19
|
min: min_,
|
|
@@ -107,7 +107,8 @@ export const Uint = {
|
|
|
107
107
|
is,
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
* The smallest value representable as `Uint
|
|
110
|
+
* The smallest value representable as `Uint` (the lower saturation target of
|
|
111
|
+
* `fromNumber`).
|
|
111
112
|
*/
|
|
112
113
|
MIN_VALUE,
|
|
113
114
|
|
|
@@ -144,25 +145,28 @@ export const Uint = {
|
|
|
144
145
|
max: max_,
|
|
145
146
|
|
|
146
147
|
/**
|
|
147
|
-
*
|
|
148
|
-
* and
|
|
148
|
+
* Converts an arbitrary `number` into an `Uint`, rounding to the nearest
|
|
149
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
150
|
+
*
|
|
151
|
+
* Unlike `asUint`, this is total: out-of-range inputs are clamped to the
|
|
152
|
+
* nearest representable `Uint` instead of throwing.
|
|
149
153
|
*
|
|
150
154
|
* @example
|
|
151
155
|
*
|
|
152
156
|
* ```ts
|
|
153
|
-
* const
|
|
157
|
+
* const fromNegative = Uint.fromNumber(-5);
|
|
154
158
|
*
|
|
155
|
-
* const
|
|
159
|
+
* const fromPositive = Uint.fromNumber(42);
|
|
156
160
|
*
|
|
157
|
-
* assert.isTrue(
|
|
161
|
+
* assert.isTrue(fromNegative === 0);
|
|
158
162
|
*
|
|
159
|
-
* assert.isTrue(
|
|
163
|
+
* assert.isTrue(fromPositive === 42);
|
|
160
164
|
* ```
|
|
161
165
|
*
|
|
162
|
-
* @param value - The value to
|
|
163
|
-
* @returns The
|
|
166
|
+
* @param value - The value to convert
|
|
167
|
+
* @returns The value as an `Uint`
|
|
164
168
|
*/
|
|
165
|
-
|
|
169
|
+
fromNumber,
|
|
166
170
|
|
|
167
171
|
/**
|
|
168
172
|
* Generates a random `Uint` within the given range.
|
|
@@ -13,8 +13,8 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
add,
|
|
15
15
|
castType,
|
|
16
|
-
clamp,
|
|
17
16
|
div,
|
|
17
|
+
fromNumber,
|
|
18
18
|
is,
|
|
19
19
|
max: max_,
|
|
20
20
|
min: min_,
|
|
@@ -73,12 +73,14 @@ export const Uint16 = {
|
|
|
73
73
|
is,
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* The smallest value representable as `Uint16
|
|
76
|
+
* The smallest value representable as `Uint16` (the lower saturation target
|
|
77
|
+
* of `fromNumber`).
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The largest value representable as `Uint16
|
|
82
|
+
* The largest value representable as `Uint16` (the upper saturation target of
|
|
83
|
+
* `fromNumber`).
|
|
82
84
|
*/
|
|
83
85
|
MAX_VALUE,
|
|
84
86
|
|
|
@@ -99,13 +101,16 @@ export const Uint16 = {
|
|
|
99
101
|
max: max_,
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
|
-
*
|
|
103
|
-
* and
|
|
104
|
+
* Converts an arbitrary `number` into an `Uint16`, rounding to the nearest
|
|
105
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
104
106
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
+
* Unlike `asUint16`, this is total: out-of-range inputs are clamped to the
|
|
108
|
+
* nearest representable `Uint16` instead of throwing.
|
|
109
|
+
*
|
|
110
|
+
* @param value - The value to convert
|
|
111
|
+
* @returns The value as an `Uint16`
|
|
107
112
|
*/
|
|
108
|
-
|
|
113
|
+
fromNumber,
|
|
109
114
|
|
|
110
115
|
/**
|
|
111
116
|
* Generates a random `Uint16` within the given range.
|
|
@@ -13,8 +13,8 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
add,
|
|
15
15
|
castType,
|
|
16
|
-
clamp,
|
|
17
16
|
div,
|
|
17
|
+
fromNumber,
|
|
18
18
|
is,
|
|
19
19
|
max: max_,
|
|
20
20
|
min: min_,
|
|
@@ -73,12 +73,14 @@ export const Uint32 = {
|
|
|
73
73
|
is,
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* The smallest value representable as `Uint32
|
|
76
|
+
* The smallest value representable as `Uint32` (the lower saturation target
|
|
77
|
+
* of `fromNumber`).
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The largest value representable as `Uint32
|
|
82
|
+
* The largest value representable as `Uint32` (the upper saturation target of
|
|
83
|
+
* `fromNumber`).
|
|
82
84
|
*/
|
|
83
85
|
MAX_VALUE,
|
|
84
86
|
|
|
@@ -99,13 +101,16 @@ export const Uint32 = {
|
|
|
99
101
|
max: max_,
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
|
-
*
|
|
103
|
-
* and
|
|
104
|
+
* Converts an arbitrary `number` into an `Uint32`, rounding to the nearest
|
|
105
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
104
106
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
+
* Unlike `asUint32`, this is total: out-of-range inputs are clamped to the
|
|
108
|
+
* nearest representable `Uint32` instead of throwing.
|
|
109
|
+
*
|
|
110
|
+
* @param value - The value to convert
|
|
111
|
+
* @returns The value as an `Uint32`
|
|
107
112
|
*/
|
|
108
|
-
|
|
113
|
+
fromNumber,
|
|
109
114
|
|
|
110
115
|
/**
|
|
111
116
|
* Generates a random `Uint32` within the given range.
|
package/src/number/enum/int8.mts
CHANGED
|
@@ -14,7 +14,7 @@ const {
|
|
|
14
14
|
MAX_VALUE,
|
|
15
15
|
MIN_VALUE,
|
|
16
16
|
castType: castTypeImpl,
|
|
17
|
-
|
|
17
|
+
fromNumber: fromNumberImpl,
|
|
18
18
|
is: isImpl,
|
|
19
19
|
random: randomImpl,
|
|
20
20
|
} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<
|
|
@@ -34,7 +34,7 @@ const castType = (x: number): Int8 =>
|
|
|
34
34
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
35
35
|
castTypeImpl(x) as Int8;
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const fromNumber = (a: number): Int8 => castType(fromNumberImpl(a));
|
|
38
38
|
|
|
39
39
|
const abs = <N extends Int8>(x: N): AbsoluteValue<N> =>
|
|
40
40
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
@@ -46,15 +46,16 @@ const min_ = (...values: readonly Int8[]): Int8 =>
|
|
|
46
46
|
const max_ = (...values: readonly Int8[]): Int8 =>
|
|
47
47
|
castType(Math.max(...values));
|
|
48
48
|
|
|
49
|
-
const pow = (x: Int8, y: Int8): Int8 =>
|
|
49
|
+
const pow = (x: Int8, y: Int8): Int8 => fromNumber(x ** y);
|
|
50
50
|
|
|
51
|
-
const add = (x: Int8, y: Int8): Int8 =>
|
|
51
|
+
const add = (x: Int8, y: Int8): Int8 => fromNumber(x + y);
|
|
52
52
|
|
|
53
|
-
const sub = (x: Int8, y: Int8): Int8 =>
|
|
53
|
+
const sub = (x: Int8, y: Int8): Int8 => fromNumber(x - y);
|
|
54
54
|
|
|
55
|
-
const mul = (x: Int8, y: Int8): Int8 =>
|
|
55
|
+
const mul = (x: Int8, y: Int8): Int8 => fromNumber(x * y);
|
|
56
56
|
|
|
57
|
-
const div = (x: Int8, y: Exclude<Int8, 0>): Int8 =>
|
|
57
|
+
const div = (x: Int8, y: Exclude<Int8, 0>): Int8 =>
|
|
58
|
+
fromNumber(Math.floor(x / y));
|
|
58
59
|
|
|
59
60
|
const random = (min: Int8, max: Int8): Int8 =>
|
|
60
61
|
castType(randomImpl(castTypeImpl(min), castTypeImpl(max)));
|
|
@@ -99,12 +100,14 @@ export const Int8 = {
|
|
|
99
100
|
is,
|
|
100
101
|
|
|
101
102
|
/**
|
|
102
|
-
* The smallest value representable as `Int8
|
|
103
|
+
* The smallest value representable as `Int8` (the lower saturation target of
|
|
104
|
+
* `fromNumber`).
|
|
103
105
|
*/
|
|
104
106
|
MIN_VALUE,
|
|
105
107
|
|
|
106
108
|
/**
|
|
107
|
-
* The largest value representable as `Int8
|
|
109
|
+
* The largest value representable as `Int8` (the upper saturation target of
|
|
110
|
+
* `fromNumber`).
|
|
108
111
|
*/
|
|
109
112
|
MAX_VALUE,
|
|
110
113
|
|
|
@@ -125,13 +128,16 @@ export const Int8 = {
|
|
|
125
128
|
max: max_,
|
|
126
129
|
|
|
127
130
|
/**
|
|
128
|
-
*
|
|
129
|
-
* and
|
|
131
|
+
* Converts an arbitrary `number` into an `Int8`, rounding to the nearest
|
|
132
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
130
133
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
134
|
+
* Unlike `asInt8`, this is total: out-of-range inputs are clamped to the
|
|
135
|
+
* nearest representable `Int8` instead of throwing.
|
|
136
|
+
*
|
|
137
|
+
* @param value - The value to convert
|
|
138
|
+
* @returns The value as an `Int8`
|
|
133
139
|
*/
|
|
134
|
-
|
|
140
|
+
fromNumber,
|
|
135
141
|
|
|
136
142
|
/**
|
|
137
143
|
* Returns the absolute value of an integer in [-128, 127].
|
|
@@ -61,7 +61,7 @@ describe('Int8 test', () => {
|
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
describe('Int8.
|
|
64
|
+
describe('Int8.fromNumber', () => {
|
|
65
65
|
test.each([
|
|
66
66
|
{ value: -200, expected: -128 },
|
|
67
67
|
{ value: -128, expected: -128 },
|
|
@@ -69,9 +69,12 @@ describe('Int8 test', () => {
|
|
|
69
69
|
{ value: 127, expected: 127 },
|
|
70
70
|
{ value: 200, expected: 127 },
|
|
71
71
|
{ value: 1.5, expected: 2 },
|
|
72
|
-
])(
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
])(
|
|
73
|
+
'Int8.fromNumber($value) should return $expected',
|
|
74
|
+
({ expected, value }) => {
|
|
75
|
+
expect(Int8.fromNumber(value)).toBe(expected);
|
|
76
|
+
},
|
|
77
|
+
);
|
|
75
78
|
});
|
|
76
79
|
|
|
77
80
|
describe('Int8.min', () => {
|