ts-data-forge 11.0.0 → 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/finite-number.d.mts +47 -61
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +37 -41
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +40 -46
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +29 -31
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +71 -59
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +56 -47
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +71 -59
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +56 -47
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +76 -60
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +62 -49
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +66 -49
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +48 -39
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +64 -57
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +49 -44
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +80 -65
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +65 -53
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +71 -58
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +55 -45
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +71 -59
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +55 -46
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +70 -55
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +55 -43
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +46 -146
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +33 -108
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +62 -54
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +46 -41
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +51 -38
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +31 -27
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +59 -54
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +44 -41
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +59 -55
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +44 -42
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +60 -55
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +44 -42
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +82 -64
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +67 -52
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +53 -70
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +42 -52
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +68 -58
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +52 -45
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +68 -58
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +52 -45
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +72 -61
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +56 -48
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +68 -58
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +52 -45
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +68 -59
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +52 -46
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +52 -66
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +45 -47
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +68 -58
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +53 -46
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +72 -55
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +52 -45
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +66 -59
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +51 -45
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +66 -57
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +50 -45
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +62 -66
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +57 -51
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +66 -59
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +57 -51
- 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 +2 -1
- package/src/number/branded-types/finite-number.mts +47 -61
- package/src/number/branded-types/int.mts +40 -46
- package/src/number/branded-types/int16.mts +72 -60
- package/src/number/branded-types/int32.mts +72 -60
- package/src/number/branded-types/negative-finite-number.mts +78 -71
- package/src/number/branded-types/negative-finite-number.test.mts +4 -4
- package/src/number/branded-types/negative-int.mts +68 -60
- package/src/number/branded-types/negative-int.test.mts +5 -5
- package/src/number/branded-types/negative-safe-int.mts +66 -68
- package/src/number/branded-types/negative-safe-int.test.mts +4 -4
- package/src/number/branded-types/non-negative-finite-number.mts +81 -66
- package/src/number/branded-types/non-negative-int16.mts +72 -59
- package/src/number/branded-types/non-negative-int32.mts +72 -60
- package/src/number/branded-types/non-positive-finite-number.mts +71 -56
- package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
- package/src/number/branded-types/non-positive-int.mts +47 -147
- package/src/number/branded-types/non-positive-int.test.mts +7 -7
- package/src/number/branded-types/non-positive-safe-int.mts +63 -55
- package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
- package/src/number/branded-types/non-zero-finite-number.mts +62 -51
- package/src/number/branded-types/non-zero-int.mts +51 -38
- package/src/number/branded-types/non-zero-int16.mts +60 -55
- package/src/number/branded-types/non-zero-int32.mts +60 -56
- package/src/number/branded-types/non-zero-safe-int.mts +61 -56
- package/src/number/branded-types/non-zero-uint16.mts +60 -55
- package/src/number/branded-types/non-zero-uint32.mts +60 -55
- package/src/number/branded-types/positive-finite-number.mts +83 -65
- package/src/number/branded-types/positive-int.mts +54 -71
- package/src/number/branded-types/positive-int16.mts +69 -59
- package/src/number/branded-types/positive-int32.mts +69 -59
- package/src/number/branded-types/positive-safe-int.mts +73 -62
- package/src/number/branded-types/positive-uint16.mts +69 -59
- package/src/number/branded-types/positive-uint32.mts +69 -60
- package/src/number/branded-types/safe-int.mts +53 -67
- package/src/number/branded-types/safe-uint.mts +69 -59
- package/src/number/branded-types/uint.mts +73 -56
- package/src/number/branded-types/uint16.mts +67 -60
- package/src/number/branded-types/uint32.mts +67 -58
- package/src/number/enum/int8.mts +70 -73
- package/src/number/enum/int8.test.mts +7 -4
- package/src/number/enum/uint8.mts +74 -66
- 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_,
|
|
@@ -34,131 +34,144 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* in the range [0, 2^15)).
|
|
37
|
+
* Type guard that checks if a value is a non-negative integer in [0, 2^15).
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a non-negative integer in [0, 2^15) — a value with no
|
|
40
|
+
* fractional component.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check
|
|
43
|
+
* @returns `true` if the value is a non-negative integer in [0, 2^15), `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isNonNegativeInt16 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `NonNegativeInt16` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a non-negative integer in [0, 2^15) and returns
|
|
51
|
+
* it with the `NonNegativeInt16` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as a NonNegativeInt16
|
|
50
|
-
* @throws {TypeError} If the value is not a non-negative integer in [0, 2^15)
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as a `NonNegativeInt16`
|
|
55
|
+
* @throws {TypeError} If the value is not a non-negative integer in [0, 2^15)
|
|
51
56
|
*/
|
|
52
57
|
export const asNonNegativeInt16 = castType;
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
|
-
* Namespace providing type-safe
|
|
56
|
-
*
|
|
60
|
+
* Namespace providing type-safe operations for the `NonNegativeInt16` branded
|
|
61
|
+
* type.
|
|
57
62
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* non-negative integer constraint, with negative results clamped to 0 and
|
|
61
|
-
* overflow results clamped to MAX_VALUE.
|
|
63
|
+
* The `NonNegativeInt16` type represents a non-negative integer in [0, 2^15).
|
|
64
|
+
* Division (`div`) uses floor division.
|
|
62
65
|
*/
|
|
63
66
|
export const NonNegativeInt16 = {
|
|
64
67
|
/**
|
|
65
|
-
* Type guard
|
|
68
|
+
* Type guard that checks if a value is a non-negative integer in [0, 2^15).
|
|
66
69
|
*
|
|
67
|
-
* @param value The value to check
|
|
68
|
-
* @returns `true` if the value is a
|
|
69
|
-
*
|
|
70
|
+
* @param value - The value to check
|
|
71
|
+
* @returns `true` if the value is a non-negative integer in [0, 2^15), `false` otherwise
|
|
72
|
+
* @see {@link isNonNegativeInt16} for usage examples
|
|
70
73
|
*/
|
|
71
74
|
is,
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
+
* The smallest value representable as `NonNegativeInt16` (the lower
|
|
78
|
+
* saturation target of `fromNumber`).
|
|
77
79
|
*/
|
|
78
80
|
MIN_VALUE,
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
83
|
-
* @readonly
|
|
83
|
+
* The largest value representable as `NonNegativeInt16` (the upper saturation
|
|
84
|
+
* target of `fromNumber`).
|
|
84
85
|
*/
|
|
85
86
|
MAX_VALUE,
|
|
86
87
|
|
|
87
88
|
/**
|
|
88
|
-
* Returns the
|
|
89
|
+
* Returns the smallest of the given non-negative integers.
|
|
89
90
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @
|
|
92
|
-
* @returns The minimum value as a NonNegativeInt16.
|
|
91
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
92
|
+
* @returns The smallest value as a `NonNegativeInt16`
|
|
93
93
|
*/
|
|
94
94
|
min: min_,
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
* Returns the
|
|
97
|
+
* Returns the largest of the given non-negative integers.
|
|
98
98
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @
|
|
101
|
-
* @returns The maximum value as a NonNegativeInt16.
|
|
99
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
100
|
+
* @returns The largest value as a `NonNegativeInt16`
|
|
102
101
|
*/
|
|
103
102
|
max: max_,
|
|
104
103
|
|
|
105
104
|
/**
|
|
106
|
-
*
|
|
105
|
+
* Converts an arbitrary `number` into a `NonNegativeInt16`, rounding to the
|
|
106
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
107
|
+
* MAX_VALUE]`.
|
|
108
|
+
*
|
|
109
|
+
* Unlike `asNonNegativeInt16`, this is total: out-of-range inputs are clamped
|
|
110
|
+
* to the nearest representable `NonNegativeInt16` instead of throwing.
|
|
107
111
|
*
|
|
108
|
-
* @param value The
|
|
109
|
-
* @returns The value
|
|
112
|
+
* @param value - The value to convert
|
|
113
|
+
* @returns The value as a `NonNegativeInt16`
|
|
110
114
|
*/
|
|
111
|
-
|
|
115
|
+
fromNumber,
|
|
112
116
|
|
|
113
117
|
/**
|
|
114
|
-
* Generates a random NonNegativeInt16
|
|
118
|
+
* Generates a random `NonNegativeInt16` within the given range.
|
|
119
|
+
*
|
|
120
|
+
* The range is inclusive on both ends.
|
|
115
121
|
*
|
|
116
|
-
* @
|
|
122
|
+
* @param min - The minimum value (inclusive)
|
|
123
|
+
* @param max - The maximum value (inclusive)
|
|
124
|
+
* @returns A random `NonNegativeInt16` in `[min, max]`
|
|
117
125
|
*/
|
|
118
126
|
random,
|
|
119
127
|
|
|
120
128
|
/**
|
|
121
|
-
* Raises a
|
|
129
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonNegativeInt16`
|
|
130
|
+
* (floored to an integer).
|
|
122
131
|
*
|
|
123
|
-
* @param a The base
|
|
124
|
-
* @param b The exponent
|
|
125
|
-
* @returns `a ** b`
|
|
132
|
+
* @param a - The base non-negative integer
|
|
133
|
+
* @param b - The exponent non-negative integer
|
|
134
|
+
* @returns `a ** b` as a `NonNegativeInt16`
|
|
126
135
|
*/
|
|
127
136
|
pow,
|
|
128
137
|
|
|
129
138
|
/**
|
|
130
|
-
* Adds two NonNegativeInt16
|
|
139
|
+
* Adds two non-negative integers, returning `a + b` as a `NonNegativeInt16`.
|
|
131
140
|
*
|
|
132
|
-
* @param a The first
|
|
133
|
-
* @param b The second
|
|
134
|
-
* @returns `a
|
|
141
|
+
* @param a - The first non-negative integer
|
|
142
|
+
* @param b - The second non-negative integer
|
|
143
|
+
* @returns The sum of `a` and `b` as a `NonNegativeInt16`
|
|
135
144
|
*/
|
|
136
145
|
add,
|
|
137
146
|
|
|
138
147
|
/**
|
|
139
|
-
* Subtracts
|
|
148
|
+
* Subtracts two non-negative integers, returning `a - b` as a
|
|
149
|
+
* `NonNegativeInt16`.
|
|
140
150
|
*
|
|
141
|
-
* @param a The
|
|
142
|
-
* @param b The
|
|
143
|
-
* @returns `a
|
|
151
|
+
* @param a - The first non-negative integer
|
|
152
|
+
* @param b - The second non-negative integer
|
|
153
|
+
* @returns The difference of `a` and `b` as a `NonNegativeInt16`
|
|
144
154
|
*/
|
|
145
155
|
sub,
|
|
146
156
|
|
|
147
157
|
/**
|
|
148
|
-
* Multiplies two
|
|
158
|
+
* Multiplies two non-negative integers, returning `a * b` as a
|
|
159
|
+
* `NonNegativeInt16`.
|
|
149
160
|
*
|
|
150
|
-
* @param a The first
|
|
151
|
-
* @param b The second
|
|
152
|
-
* @returns `a
|
|
161
|
+
* @param a - The first non-negative integer
|
|
162
|
+
* @param b - The second non-negative integer
|
|
163
|
+
* @returns The product of `a` and `b` as a `NonNegativeInt16`
|
|
153
164
|
*/
|
|
154
165
|
mul,
|
|
155
166
|
|
|
156
167
|
/**
|
|
157
|
-
* Divides
|
|
168
|
+
* Divides two non-negative integers using floor division (`⌊a / b⌋`): the
|
|
169
|
+
* result is `a / b` rounded toward negative infinity, as a
|
|
170
|
+
* `NonNegativeInt16`.
|
|
158
171
|
*
|
|
159
|
-
* @param a The dividend
|
|
160
|
-
* @param b The divisor
|
|
161
|
-
* @returns
|
|
172
|
+
* @param a - The dividend
|
|
173
|
+
* @param b - The divisor (must be non-zero)
|
|
174
|
+
* @returns The floored quotient as a `NonNegativeInt16`
|
|
162
175
|
*/
|
|
163
176
|
div,
|
|
164
177
|
} as const;
|
|
@@ -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_,
|
|
@@ -34,132 +34,144 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* in the range [0, 2^31)).
|
|
37
|
+
* Type guard that checks if a value is a non-negative integer in [0, 2^31).
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a non-negative integer in [0, 2^31) — a value with no
|
|
40
|
+
* fractional component.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check
|
|
43
|
+
* @returns `true` if the value is a non-negative integer in [0, 2^31), `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isNonNegativeInt32 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `NonNegativeInt32` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a non-negative integer in [0, 2^31) and returns
|
|
51
|
+
* it with the `NonNegativeInt32` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as a NonNegativeInt32
|
|
50
|
-
* @throws {TypeError} If the value is not a non-negative integer in [0, 2^31)
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as a `NonNegativeInt32`
|
|
55
|
+
* @throws {TypeError} If the value is not a non-negative integer in [0, 2^31)
|
|
51
56
|
*/
|
|
52
57
|
export const asNonNegativeInt32 = castType;
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
|
-
* Namespace providing type-safe
|
|
56
|
-
*
|
|
60
|
+
* Namespace providing type-safe operations for the `NonNegativeInt32` branded
|
|
61
|
+
* type.
|
|
57
62
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* non-negative integer constraint, with negative results clamped to 0 and
|
|
61
|
-
* overflow results clamped to MAX_VALUE.
|
|
63
|
+
* The `NonNegativeInt32` type represents a non-negative integer in [0, 2^31).
|
|
64
|
+
* Division (`div`) uses floor division.
|
|
62
65
|
*/
|
|
63
66
|
export const NonNegativeInt32 = {
|
|
64
67
|
/**
|
|
65
|
-
* Type guard
|
|
68
|
+
* Type guard that checks if a value is a non-negative integer in [0, 2^31).
|
|
66
69
|
*
|
|
67
|
-
* @param value The value to check
|
|
68
|
-
* @returns `true` if the value is a
|
|
69
|
-
*
|
|
70
|
+
* @param value - The value to check
|
|
71
|
+
* @returns `true` if the value is a non-negative integer in [0, 2^31), `false` otherwise
|
|
72
|
+
* @see {@link isNonNegativeInt32} for usage examples
|
|
70
73
|
*/
|
|
71
74
|
is,
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
+
* The smallest value representable as `NonNegativeInt32` (the lower
|
|
78
|
+
* saturation target of `fromNumber`).
|
|
77
79
|
*/
|
|
78
80
|
MIN_VALUE,
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
83
|
-
* @readonly
|
|
83
|
+
* The largest value representable as `NonNegativeInt32` (the upper saturation
|
|
84
|
+
* target of `fromNumber`).
|
|
84
85
|
*/
|
|
85
86
|
MAX_VALUE,
|
|
86
87
|
|
|
87
88
|
/**
|
|
88
|
-
* Returns the
|
|
89
|
+
* Returns the smallest of the given non-negative integers.
|
|
89
90
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @
|
|
92
|
-
* @returns The minimum value as a NonNegativeInt32.
|
|
91
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
92
|
+
* @returns The smallest value as a `NonNegativeInt32`
|
|
93
93
|
*/
|
|
94
94
|
min: min_,
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
* Returns the
|
|
97
|
+
* Returns the largest of the given non-negative integers.
|
|
98
98
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @
|
|
101
|
-
* @returns The maximum value as a NonNegativeInt32.
|
|
99
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
100
|
+
* @returns The largest value as a `NonNegativeInt32`
|
|
102
101
|
*/
|
|
103
102
|
max: max_,
|
|
104
103
|
|
|
105
104
|
/**
|
|
106
|
-
*
|
|
105
|
+
* Converts an arbitrary `number` into a `NonNegativeInt32`, rounding to the
|
|
106
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
107
|
+
* MAX_VALUE]`.
|
|
108
|
+
*
|
|
109
|
+
* Unlike `asNonNegativeInt32`, this is total: out-of-range inputs are clamped
|
|
110
|
+
* to the nearest representable `NonNegativeInt32` instead of throwing.
|
|
107
111
|
*
|
|
108
|
-
* @param value The
|
|
109
|
-
* @returns The value
|
|
112
|
+
* @param value - The value to convert
|
|
113
|
+
* @returns The value as a `NonNegativeInt32`
|
|
110
114
|
*/
|
|
111
|
-
|
|
115
|
+
fromNumber,
|
|
112
116
|
|
|
113
117
|
/**
|
|
114
|
-
* Generates a random NonNegativeInt32
|
|
118
|
+
* Generates a random `NonNegativeInt32` within the given range.
|
|
119
|
+
*
|
|
120
|
+
* The range is inclusive on both ends.
|
|
115
121
|
*
|
|
116
|
-
* @
|
|
122
|
+
* @param min - The minimum value (inclusive)
|
|
123
|
+
* @param max - The maximum value (inclusive)
|
|
124
|
+
* @returns A random `NonNegativeInt32` in `[min, max]`
|
|
117
125
|
*/
|
|
118
126
|
random,
|
|
119
127
|
|
|
120
128
|
/**
|
|
121
|
-
* Raises a
|
|
129
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonNegativeInt32`
|
|
130
|
+
* (floored to an integer).
|
|
122
131
|
*
|
|
123
|
-
* @param a The base
|
|
124
|
-
* @param b The exponent
|
|
125
|
-
* @returns `a ** b`
|
|
132
|
+
* @param a - The base non-negative integer
|
|
133
|
+
* @param b - The exponent non-negative integer
|
|
134
|
+
* @returns `a ** b` as a `NonNegativeInt32`
|
|
126
135
|
*/
|
|
127
136
|
pow,
|
|
128
137
|
|
|
129
138
|
/**
|
|
130
|
-
* Adds two NonNegativeInt32
|
|
139
|
+
* Adds two non-negative integers, returning `a + b` as a `NonNegativeInt32`.
|
|
131
140
|
*
|
|
132
|
-
* @param a The first
|
|
133
|
-
* @param b The second
|
|
134
|
-
* @returns `a
|
|
141
|
+
* @param a - The first non-negative integer
|
|
142
|
+
* @param b - The second non-negative integer
|
|
143
|
+
* @returns The sum of `a` and `b` as a `NonNegativeInt32`
|
|
135
144
|
*/
|
|
136
145
|
add,
|
|
137
146
|
|
|
138
147
|
/**
|
|
139
|
-
* Subtracts
|
|
148
|
+
* Subtracts two non-negative integers, returning `a - b` as a
|
|
149
|
+
* `NonNegativeInt32`.
|
|
140
150
|
*
|
|
141
|
-
* @param a The
|
|
142
|
-
* @param b The
|
|
143
|
-
* @returns `a
|
|
144
|
-
* 0).
|
|
151
|
+
* @param a - The first non-negative integer
|
|
152
|
+
* @param b - The second non-negative integer
|
|
153
|
+
* @returns The difference of `a` and `b` as a `NonNegativeInt32`
|
|
145
154
|
*/
|
|
146
155
|
sub,
|
|
147
156
|
|
|
148
157
|
/**
|
|
149
|
-
* Multiplies two
|
|
158
|
+
* Multiplies two non-negative integers, returning `a * b` as a
|
|
159
|
+
* `NonNegativeInt32`.
|
|
150
160
|
*
|
|
151
|
-
* @param a The first
|
|
152
|
-
* @param b The second
|
|
153
|
-
* @returns `a
|
|
161
|
+
* @param a - The first non-negative integer
|
|
162
|
+
* @param b - The second non-negative integer
|
|
163
|
+
* @returns The product of `a` and `b` as a `NonNegativeInt32`
|
|
154
164
|
*/
|
|
155
165
|
mul,
|
|
156
166
|
|
|
157
167
|
/**
|
|
158
|
-
* Divides
|
|
168
|
+
* Divides two non-negative integers using floor division (`⌊a / b⌋`): the
|
|
169
|
+
* result is `a / b` rounded toward negative infinity, as a
|
|
170
|
+
* `NonNegativeInt32`.
|
|
159
171
|
*
|
|
160
|
-
* @param a The dividend
|
|
161
|
-
* @param b The divisor
|
|
162
|
-
* @returns
|
|
172
|
+
* @param a - The dividend
|
|
173
|
+
* @param b - The divisor (must be non-zero)
|
|
174
|
+
* @returns The floored quotient as a `NonNegativeInt32`
|
|
163
175
|
*/
|
|
164
176
|
div,
|
|
165
177
|
} as const;
|
|
@@ -11,7 +11,7 @@ const {
|
|
|
11
11
|
MAX_VALUE,
|
|
12
12
|
add,
|
|
13
13
|
castType,
|
|
14
|
-
|
|
14
|
+
fromNumber,
|
|
15
15
|
is,
|
|
16
16
|
max: max_,
|
|
17
17
|
min: min_,
|
|
@@ -63,129 +63,144 @@ const round = (
|
|
|
63
63
|
>;
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
66
|
+
* Type guard that checks if a value is a non-positive finite number.
|
|
67
67
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
68
|
+
* Returns `true` only for a finite value — never `NaN`, `Infinity`, or
|
|
69
|
+
* `-Infinity`.
|
|
70
|
+
*
|
|
71
|
+
* @param value - The value to check
|
|
72
|
+
* @returns `true` if the value is a non-positive finite number, `false` otherwise
|
|
70
73
|
*/
|
|
71
74
|
export const isNonPositiveFiniteNumber = is;
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* Casts a number to
|
|
77
|
+
* Casts a `number` to the `NonPositiveFiniteNumber` branded type.
|
|
78
|
+
*
|
|
79
|
+
* Validates that the value is a non-positive finite number and returns it with
|
|
80
|
+
* the `NonPositiveFiniteNumber` brand. Throws a `TypeError` otherwise.
|
|
75
81
|
*
|
|
76
|
-
* @param value The value to cast
|
|
77
|
-
* @returns The value as a NonPositiveFiniteNumber
|
|
78
|
-
* @throws {TypeError} If the value is not a non-positive finite number
|
|
82
|
+
* @param value - The value to cast
|
|
83
|
+
* @returns The value as a `NonPositiveFiniteNumber`
|
|
84
|
+
* @throws {TypeError} If the value is not a non-positive finite number
|
|
79
85
|
*/
|
|
80
86
|
export const asNonPositiveFiniteNumber = castType;
|
|
81
87
|
|
|
82
88
|
/**
|
|
83
|
-
* Namespace providing type-safe
|
|
84
|
-
*
|
|
89
|
+
* Namespace providing type-safe operations for the `NonPositiveFiniteNumber`
|
|
90
|
+
* branded type.
|
|
85
91
|
*
|
|
86
|
-
*
|
|
87
|
-
* results to MAX_VALUE (0), while ensuring results remain finite (excluding NaN
|
|
88
|
-
* and Infinity). This type is useful for representing quantities that must
|
|
89
|
-
* always be non-positive, such as debts, penalties, and negative offsets.
|
|
92
|
+
* The `NonPositiveFiniteNumber` type represents a non-positive finite number.
|
|
90
93
|
*/
|
|
91
94
|
export const NonPositiveFiniteNumber = {
|
|
92
95
|
/**
|
|
93
|
-
* Type guard
|
|
96
|
+
* Type guard that checks if a value is a non-positive finite number.
|
|
94
97
|
*
|
|
95
|
-
* @param value The value to check
|
|
96
|
-
* @returns `true` if the value is a non-positive finite number, `false`
|
|
97
|
-
*
|
|
98
|
+
* @param value - The value to check
|
|
99
|
+
* @returns `true` if the value is a non-positive finite number, `false` otherwise
|
|
100
|
+
* @see {@link isNonPositiveFiniteNumber} for usage examples
|
|
98
101
|
*/
|
|
99
102
|
is,
|
|
100
103
|
|
|
101
104
|
/**
|
|
102
|
-
* The
|
|
103
|
-
*
|
|
104
|
-
* @readonly
|
|
105
|
+
* The largest value representable as `NonPositiveFiniteNumber` (the upper
|
|
106
|
+
* saturation target of `fromNumber`).
|
|
105
107
|
*/
|
|
106
108
|
MAX_VALUE,
|
|
107
109
|
|
|
108
110
|
/**
|
|
109
|
-
* Returns the
|
|
111
|
+
* Returns the smallest of the given non-positive finite numbers.
|
|
110
112
|
*
|
|
111
|
-
* @param
|
|
112
|
-
* @
|
|
113
|
-
* @returns The minimum value as a NonPositiveFiniteNumber.
|
|
113
|
+
* @param values - The non-positive finite numbers to compare (at least one required)
|
|
114
|
+
* @returns The smallest value as a `NonPositiveFiniteNumber`
|
|
114
115
|
*/
|
|
115
116
|
min: min_,
|
|
116
117
|
|
|
117
118
|
/**
|
|
118
|
-
* Returns the
|
|
119
|
+
* Returns the largest of the given non-positive finite numbers.
|
|
119
120
|
*
|
|
120
|
-
* @param
|
|
121
|
-
* @
|
|
122
|
-
* @returns The maximum value as a NonPositiveFiniteNumber.
|
|
121
|
+
* @param values - The non-positive finite numbers to compare (at least one required)
|
|
122
|
+
* @returns The largest value as a `NonPositiveFiniteNumber`
|
|
123
123
|
*/
|
|
124
124
|
max: max_,
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
127
|
+
* Converts an arbitrary `number` into a `NonPositiveFiniteNumber`, saturating
|
|
128
|
+
* it into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
128
129
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
130
|
+
* Unlike `asNonPositiveFiniteNumber`, this is total: out-of-range inputs are
|
|
131
|
+
* clamped to the nearest representable `NonPositiveFiniteNumber` instead of
|
|
132
|
+
* throwing.
|
|
133
|
+
*
|
|
134
|
+
* @param value - The value to convert
|
|
135
|
+
* @returns The value as a `NonPositiveFiniteNumber`
|
|
131
136
|
*/
|
|
132
|
-
|
|
137
|
+
fromNumber,
|
|
133
138
|
|
|
134
139
|
/**
|
|
135
|
-
*
|
|
140
|
+
* Returns the greatest integer less than or equal to a non-positive finite
|
|
141
|
+
* number.
|
|
136
142
|
*
|
|
137
|
-
* @param
|
|
138
|
-
* @returns The
|
|
143
|
+
* @param a - The non-positive finite number value
|
|
144
|
+
* @returns The floored value as an integer
|
|
139
145
|
*/
|
|
140
146
|
floor,
|
|
141
147
|
|
|
142
148
|
/**
|
|
143
|
-
*
|
|
149
|
+
* Returns the smallest integer greater than or equal to a non-positive finite
|
|
150
|
+
* number.
|
|
144
151
|
*
|
|
145
|
-
* @param
|
|
146
|
-
* @returns The
|
|
152
|
+
* @param a - The non-positive finite number value
|
|
153
|
+
* @returns The ceiled value as an integer
|
|
147
154
|
*/
|
|
148
155
|
ceil,
|
|
149
156
|
|
|
150
157
|
/**
|
|
151
|
-
*
|
|
158
|
+
* Returns the value of a non-positive finite number rounded to the nearest
|
|
159
|
+
* integer.
|
|
152
160
|
*
|
|
153
|
-
* @param
|
|
154
|
-
* @returns The rounded value as
|
|
161
|
+
* @param a - The non-positive finite number value
|
|
162
|
+
* @returns The rounded value as an integer
|
|
155
163
|
*/
|
|
156
164
|
round,
|
|
157
165
|
|
|
158
166
|
/**
|
|
159
|
-
* Generates a random NonPositiveFiniteNumber
|
|
167
|
+
* Generates a random `NonPositiveFiniteNumber` within the given range.
|
|
168
|
+
*
|
|
169
|
+
* The range is inclusive on both ends.
|
|
160
170
|
*
|
|
161
|
-
* @
|
|
171
|
+
* @param min - The minimum value (inclusive)
|
|
172
|
+
* @param max - The maximum value (inclusive)
|
|
173
|
+
* @returns A random `NonPositiveFiniteNumber` in `[min, max]`
|
|
162
174
|
*/
|
|
163
175
|
random,
|
|
164
176
|
|
|
165
177
|
/**
|
|
166
|
-
* Raises a
|
|
178
|
+
* Raises `a` to the power `b`, returning `a ** b` as a
|
|
179
|
+
* `NonPositiveFiniteNumber`.
|
|
167
180
|
*
|
|
168
|
-
* @param a The base
|
|
169
|
-
* @param b The exponent
|
|
170
|
-
* @returns `a ** b`
|
|
181
|
+
* @param a - The base non-positive finite number
|
|
182
|
+
* @param b - The exponent non-positive finite number
|
|
183
|
+
* @returns `a ** b` as a `NonPositiveFiniteNumber`
|
|
171
184
|
*/
|
|
172
185
|
pow,
|
|
173
186
|
|
|
174
187
|
/**
|
|
175
|
-
* Adds two
|
|
188
|
+
* Adds two non-positive finite numbers, returning `a + b` as a
|
|
189
|
+
* `NonPositiveFiniteNumber`.
|
|
176
190
|
*
|
|
177
|
-
* @param a The first
|
|
178
|
-
* @param b The second
|
|
179
|
-
* @returns `a
|
|
191
|
+
* @param a - The first non-positive finite number
|
|
192
|
+
* @param b - The second non-positive finite number
|
|
193
|
+
* @returns The sum of `a` and `b` as a `NonPositiveFiniteNumber`
|
|
180
194
|
*/
|
|
181
195
|
add,
|
|
182
196
|
|
|
183
197
|
/**
|
|
184
|
-
* Subtracts
|
|
198
|
+
* Subtracts two non-positive finite numbers, returning `a - b` as a
|
|
199
|
+
* `NonPositiveFiniteNumber`.
|
|
185
200
|
*
|
|
186
|
-
* @param a The
|
|
187
|
-
* @param b The
|
|
188
|
-
* @returns `a
|
|
201
|
+
* @param a - The first non-positive finite number
|
|
202
|
+
* @param b - The second non-positive finite number
|
|
203
|
+
* @returns The difference of `a` and `b` as a `NonPositiveFiniteNumber`
|
|
189
204
|
*/
|
|
190
205
|
sub,
|
|
191
206
|
} as const;
|