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.
- package/README.md +2 -2
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +65 -5
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +69 -27
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/index.mjs +1 -1
- 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/dist/string/str.d.mts +70 -5
- package/dist/string/str.d.mts.map +1 -1
- package/dist/string/str.mjs +72 -26
- package/dist/string/str.mjs.map +1 -1
- package/package.json +1 -1
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +204 -39
- package/src/array/impl/array-utils-length-bounded-array-cast.test.mts +126 -0
- 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
- package/src/string/str.mts +201 -39
- package/src/string/str.test.mts +76 -0
|
@@ -17,7 +17,7 @@ const {
|
|
|
17
17
|
MIN_VALUE,
|
|
18
18
|
abs,
|
|
19
19
|
castType,
|
|
20
|
-
|
|
20
|
+
fromNumber,
|
|
21
21
|
is,
|
|
22
22
|
max: max_,
|
|
23
23
|
min: min_,
|
|
@@ -79,12 +79,14 @@ export const NonZeroSafeInt = {
|
|
|
79
79
|
is,
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* The smallest value representable as `NonZeroSafeInt
|
|
82
|
+
* The smallest value representable as `NonZeroSafeInt` (the lower saturation
|
|
83
|
+
* target of `fromNumber`).
|
|
83
84
|
*/
|
|
84
85
|
MIN_VALUE,
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
|
-
* The largest value representable as `NonZeroSafeInt
|
|
88
|
+
* The largest value representable as `NonZeroSafeInt` (the upper saturation
|
|
89
|
+
* target of `fromNumber`).
|
|
88
90
|
*/
|
|
89
91
|
MAX_VALUE,
|
|
90
92
|
|
|
@@ -115,13 +117,17 @@ export const NonZeroSafeInt = {
|
|
|
115
117
|
max: max_,
|
|
116
118
|
|
|
117
119
|
/**
|
|
118
|
-
*
|
|
119
|
-
* integer and
|
|
120
|
+
* Converts an arbitrary `number` into a `NonZeroSafeInt`, rounding to the
|
|
121
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
122
|
+
* MAX_VALUE]`.
|
|
120
123
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
124
|
+
* Unlike `asNonZeroSafeInt`, this is total: out-of-range inputs are clamped
|
|
125
|
+
* to the nearest representable `NonZeroSafeInt` instead of throwing.
|
|
126
|
+
*
|
|
127
|
+
* @param value - The value to convert
|
|
128
|
+
* @returns The value as a `NonZeroSafeInt`
|
|
123
129
|
*/
|
|
124
|
-
|
|
130
|
+
fromNumber,
|
|
125
131
|
|
|
126
132
|
/**
|
|
127
133
|
* Generates a random `NonZeroSafeInt` within the given range.
|
|
@@ -13,7 +13,7 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
add,
|
|
15
15
|
castType,
|
|
16
|
-
|
|
16
|
+
fromNumber,
|
|
17
17
|
is,
|
|
18
18
|
max: max_,
|
|
19
19
|
min: min_,
|
|
@@ -73,12 +73,14 @@ export const NonZeroUint16 = {
|
|
|
73
73
|
is,
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* The smallest value representable as `NonZeroUint16
|
|
76
|
+
* The smallest value representable as `NonZeroUint16` (the lower saturation
|
|
77
|
+
* target of `fromNumber`).
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The largest value representable as `NonZeroUint16
|
|
82
|
+
* The largest value representable as `NonZeroUint16` (the upper saturation
|
|
83
|
+
* target of `fromNumber`).
|
|
82
84
|
*/
|
|
83
85
|
MAX_VALUE,
|
|
84
86
|
|
|
@@ -99,13 +101,17 @@ export const NonZeroUint16 = {
|
|
|
99
101
|
max: max_,
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
|
-
*
|
|
103
|
-
* integer and
|
|
104
|
+
* Converts an arbitrary `number` into a `NonZeroUint16`, rounding to the
|
|
105
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
106
|
+
* MAX_VALUE]`.
|
|
104
107
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
108
|
+
* Unlike `asNonZeroUint16`, this is total: out-of-range inputs are clamped to
|
|
109
|
+
* the nearest representable `NonZeroUint16` instead of throwing.
|
|
110
|
+
*
|
|
111
|
+
* @param value - The value to convert
|
|
112
|
+
* @returns The value as a `NonZeroUint16`
|
|
107
113
|
*/
|
|
108
|
-
|
|
114
|
+
fromNumber,
|
|
109
115
|
|
|
110
116
|
/**
|
|
111
117
|
* Generates a random `NonZeroUint16` within the given range.
|
|
@@ -13,7 +13,7 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
add,
|
|
15
15
|
castType,
|
|
16
|
-
|
|
16
|
+
fromNumber,
|
|
17
17
|
is,
|
|
18
18
|
max: max_,
|
|
19
19
|
min: min_,
|
|
@@ -73,12 +73,14 @@ export const NonZeroUint32 = {
|
|
|
73
73
|
is,
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* The smallest value representable as `NonZeroUint32
|
|
76
|
+
* The smallest value representable as `NonZeroUint32` (the lower saturation
|
|
77
|
+
* target of `fromNumber`).
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The largest value representable as `NonZeroUint32
|
|
82
|
+
* The largest value representable as `NonZeroUint32` (the upper saturation
|
|
83
|
+
* target of `fromNumber`).
|
|
82
84
|
*/
|
|
83
85
|
MAX_VALUE,
|
|
84
86
|
|
|
@@ -99,13 +101,17 @@ export const NonZeroUint32 = {
|
|
|
99
101
|
max: max_,
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
|
-
*
|
|
103
|
-
* integer and
|
|
104
|
+
* Converts an arbitrary `number` into a `NonZeroUint32`, rounding to the
|
|
105
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
106
|
+
* MAX_VALUE]`.
|
|
104
107
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
108
|
+
* Unlike `asNonZeroUint32`, this is total: out-of-range inputs are clamped to
|
|
109
|
+
* the nearest representable `NonZeroUint32` instead of throwing.
|
|
110
|
+
*
|
|
111
|
+
* @param value - The value to convert
|
|
112
|
+
* @returns The value as a `NonZeroUint32`
|
|
107
113
|
*/
|
|
108
|
-
|
|
114
|
+
fromNumber,
|
|
109
115
|
|
|
110
116
|
/**
|
|
111
117
|
* Generates a random `NonZeroUint32` within the given range.
|
|
@@ -16,8 +16,8 @@ const {
|
|
|
16
16
|
MIN_VALUE,
|
|
17
17
|
add,
|
|
18
18
|
castType,
|
|
19
|
-
clamp,
|
|
20
19
|
div,
|
|
20
|
+
fromNumber,
|
|
21
21
|
is,
|
|
22
22
|
max: max_,
|
|
23
23
|
min: min_,
|
|
@@ -117,7 +117,10 @@ export const PositiveFiniteNumber = {
|
|
|
117
117
|
is,
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* The smallest value representable as `PositiveFiniteNumber
|
|
120
|
+
* The smallest value representable as `PositiveFiniteNumber` (the lower
|
|
121
|
+
* saturation target of `fromNumber`). The domain is open at `0` (excluded),
|
|
122
|
+
* so this is `Number.MIN_VALUE` — the smallest positive double — rather than
|
|
123
|
+
* `0`.
|
|
121
124
|
*/
|
|
122
125
|
MIN_VALUE,
|
|
123
126
|
|
|
@@ -138,13 +141,17 @@ export const PositiveFiniteNumber = {
|
|
|
138
141
|
max: max_,
|
|
139
142
|
|
|
140
143
|
/**
|
|
141
|
-
*
|
|
142
|
-
* MAX_VALUE]`.
|
|
144
|
+
* Converts an arbitrary `number` into a `PositiveFiniteNumber`, saturating it
|
|
145
|
+
* into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
143
146
|
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
147
|
+
* Unlike `asPositiveFiniteNumber`, this is total: out-of-range inputs are
|
|
148
|
+
* clamped to the nearest representable `PositiveFiniteNumber` instead of
|
|
149
|
+
* throwing.
|
|
150
|
+
*
|
|
151
|
+
* @param value - The value to convert
|
|
152
|
+
* @returns The value as a `PositiveFiniteNumber`
|
|
146
153
|
*/
|
|
147
|
-
|
|
154
|
+
fromNumber,
|
|
148
155
|
|
|
149
156
|
/**
|
|
150
157
|
* Returns the greatest integer less than or equal to a positive finite
|
|
@@ -12,8 +12,8 @@ const {
|
|
|
12
12
|
MIN_VALUE,
|
|
13
13
|
add,
|
|
14
14
|
castType,
|
|
15
|
-
clamp,
|
|
16
15
|
div,
|
|
16
|
+
fromNumber,
|
|
17
17
|
is,
|
|
18
18
|
max: max_,
|
|
19
19
|
min: min_,
|
|
@@ -106,7 +106,8 @@ export const PositiveInt = {
|
|
|
106
106
|
is,
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
* The smallest value representable as `PositiveInt
|
|
109
|
+
* The smallest value representable as `PositiveInt` (the lower saturation
|
|
110
|
+
* target of `fromNumber`).
|
|
110
111
|
*/
|
|
111
112
|
MIN_VALUE,
|
|
112
113
|
|
|
@@ -151,25 +152,29 @@ export const PositiveInt = {
|
|
|
151
152
|
max: max_,
|
|
152
153
|
|
|
153
154
|
/**
|
|
154
|
-
*
|
|
155
|
-
* integer and
|
|
155
|
+
* Converts an arbitrary `number` into a `PositiveInt`, rounding to the
|
|
156
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
157
|
+
* MAX_VALUE]`.
|
|
158
|
+
*
|
|
159
|
+
* Unlike `asPositiveInt`, this is total: out-of-range inputs are clamped to
|
|
160
|
+
* the nearest representable `PositiveInt` instead of throwing.
|
|
156
161
|
*
|
|
157
162
|
* @example
|
|
158
163
|
*
|
|
159
164
|
* ```ts
|
|
160
|
-
* const belowRange = PositiveInt.
|
|
165
|
+
* const belowRange = PositiveInt.fromNumber(0);
|
|
161
166
|
*
|
|
162
|
-
* const withinRange = PositiveInt.
|
|
167
|
+
* const withinRange = PositiveInt.fromNumber(10);
|
|
163
168
|
*
|
|
164
169
|
* assert.isTrue(belowRange === 1);
|
|
165
170
|
*
|
|
166
171
|
* assert.isTrue(withinRange === 10);
|
|
167
172
|
* ```
|
|
168
173
|
*
|
|
169
|
-
* @param value - The value to
|
|
170
|
-
* @returns The
|
|
174
|
+
* @param value - The value to convert
|
|
175
|
+
* @returns The value as a `PositiveInt`
|
|
171
176
|
*/
|
|
172
|
-
|
|
177
|
+
fromNumber,
|
|
173
178
|
|
|
174
179
|
/**
|
|
175
180
|
* Generates a random `PositiveInt` 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 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.
|