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,7 +13,7 @@ const {
|
|
|
13
13
|
MIN_VALUE,
|
|
14
14
|
abs,
|
|
15
15
|
castType,
|
|
16
|
-
|
|
16
|
+
fromNumber,
|
|
17
17
|
is,
|
|
18
18
|
max: max_,
|
|
19
19
|
min: min_,
|
|
@@ -33,118 +33,122 @@ const {
|
|
|
33
33
|
} as const);
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* range [-2^31, 2^31) excluding 0).
|
|
36
|
+
* Type guard that checks if a value is a non-zero integer in [-2^31, 2^31).
|
|
38
37
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* Returns `true` for a non-zero integer in [-2^31, 2^31) — a value with no
|
|
39
|
+
* fractional component.
|
|
40
|
+
*
|
|
41
|
+
* @param value - The value to check
|
|
42
|
+
* @returns `true` if the value is a non-zero integer in [-2^31, 2^31), `false` otherwise
|
|
41
43
|
*/
|
|
42
44
|
export const isNonZeroInt32 = is;
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
|
-
* Casts a number to
|
|
47
|
+
* Casts a `number` to the `NonZeroInt32` branded type.
|
|
48
|
+
*
|
|
49
|
+
* Validates that the value is a non-zero integer in [-2^31, 2^31) and returns
|
|
50
|
+
* it with the `NonZeroInt32` brand. Throws a `TypeError` otherwise.
|
|
46
51
|
*
|
|
47
|
-
* @param value The value to cast
|
|
48
|
-
* @returns The value as a NonZeroInt32
|
|
49
|
-
* @throws {TypeError} If the value is not a non-zero integer in [-2^31, 2^31)
|
|
52
|
+
* @param value - The value to cast
|
|
53
|
+
* @returns The value as a `NonZeroInt32`
|
|
54
|
+
* @throws {TypeError} If the value is not a non-zero integer in [-2^31, 2^31)
|
|
50
55
|
*/
|
|
51
56
|
export const asNonZeroInt32 = castType;
|
|
52
57
|
|
|
53
58
|
/**
|
|
54
|
-
* Namespace providing type-safe
|
|
55
|
-
* signed integers.
|
|
59
|
+
* Namespace providing type-safe operations for the `NonZeroInt32` branded type.
|
|
56
60
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* maintains the 32-bit non-zero signed integer constraint, preventing zero
|
|
60
|
-
* results and overflow.
|
|
61
|
+
* The `NonZeroInt32` type represents a non-zero integer in [-2^31, 2^31).
|
|
62
|
+
* Division (`div`) uses floor division.
|
|
61
63
|
*/
|
|
62
64
|
export const NonZeroInt32 = {
|
|
63
65
|
/**
|
|
64
|
-
* Type guard
|
|
66
|
+
* Type guard that checks if a value is a non-zero integer in [-2^31, 2^31).
|
|
65
67
|
*
|
|
66
|
-
* @param value The value to check
|
|
67
|
-
* @returns `true` if the value is a
|
|
68
|
-
*
|
|
68
|
+
* @param value - The value to check
|
|
69
|
+
* @returns `true` if the value is a non-zero integer in [-2^31, 2^31), `false` otherwise
|
|
70
|
+
* @see {@link isNonZeroInt32} for usage examples
|
|
69
71
|
*/
|
|
70
72
|
is,
|
|
71
73
|
|
|
72
74
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
75
|
-
* @readonly
|
|
75
|
+
* The smallest value representable as `NonZeroInt32` (the lower saturation
|
|
76
|
+
* target of `fromNumber`).
|
|
76
77
|
*/
|
|
77
78
|
MIN_VALUE,
|
|
78
79
|
|
|
79
80
|
/**
|
|
80
|
-
* The
|
|
81
|
-
*
|
|
82
|
-
* @readonly
|
|
81
|
+
* The largest value representable as `NonZeroInt32` (the upper saturation
|
|
82
|
+
* target of `fromNumber`).
|
|
83
83
|
*/
|
|
84
84
|
MAX_VALUE,
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
* Returns the absolute value of a
|
|
87
|
+
* Returns the absolute value of a non-zero integer in [-2^31, 2^31).
|
|
88
88
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
89
|
+
* The result is non-negative and keeps the `NonZeroInt32` brand.
|
|
90
|
+
*
|
|
91
|
+
* @param a - The non-zero integer value
|
|
92
|
+
* @returns The absolute value as a non-negative `NonZeroInt32`
|
|
91
93
|
*/
|
|
92
94
|
abs,
|
|
93
95
|
|
|
94
96
|
/**
|
|
95
|
-
* Returns the
|
|
97
|
+
* Returns the smallest of the given non-zero integers.
|
|
96
98
|
*
|
|
97
|
-
* @param
|
|
98
|
-
* @
|
|
99
|
-
* @returns The minimum value as a NonZeroInt32.
|
|
99
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
100
|
+
* @returns The smallest value as a `NonZeroInt32`
|
|
100
101
|
*/
|
|
101
102
|
min: min_,
|
|
102
103
|
|
|
103
104
|
/**
|
|
104
|
-
* Returns the
|
|
105
|
+
* Returns the largest of the given non-zero integers.
|
|
105
106
|
*
|
|
106
|
-
* @param
|
|
107
|
-
* @
|
|
108
|
-
* @returns The maximum value as a NonZeroInt32.
|
|
107
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
108
|
+
* @returns The largest value as a `NonZeroInt32`
|
|
109
109
|
*/
|
|
110
110
|
max: max_,
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
113
|
+
* Converts an arbitrary `number` into a `NonZeroInt32`, rounding to the
|
|
114
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
115
|
+
* MAX_VALUE]`.
|
|
116
|
+
*
|
|
117
|
+
* Unlike `asNonZeroInt32`, this is total: out-of-range inputs are clamped to
|
|
118
|
+
* the nearest representable `NonZeroInt32` instead of throwing.
|
|
114
119
|
*
|
|
115
|
-
* @param value The
|
|
116
|
-
* @returns The value
|
|
117
|
-
* NonZeroInt32.
|
|
120
|
+
* @param value - The value to convert
|
|
121
|
+
* @returns The value as a `NonZeroInt32`
|
|
118
122
|
*/
|
|
119
|
-
|
|
123
|
+
fromNumber,
|
|
120
124
|
|
|
121
125
|
/**
|
|
122
|
-
* Generates a random NonZeroInt32
|
|
126
|
+
* Generates a random `NonZeroInt32` within the given range.
|
|
123
127
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
128
|
+
* The range is inclusive on both ends.
|
|
129
|
+
*
|
|
130
|
+
* @param min - The minimum value (inclusive)
|
|
131
|
+
* @param max - The maximum value (inclusive)
|
|
132
|
+
* @returns A random `NonZeroInt32` in `[min, max]`
|
|
126
133
|
*/
|
|
127
134
|
random,
|
|
128
135
|
|
|
129
136
|
/**
|
|
130
|
-
* Raises a
|
|
137
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonZeroInt32`
|
|
138
|
+
* (floored to an integer).
|
|
131
139
|
*
|
|
132
|
-
* @param a The base
|
|
133
|
-
* @param b The exponent
|
|
134
|
-
* @returns `a ** b`
|
|
140
|
+
* @param a - The base non-zero integer
|
|
141
|
+
* @param b - The exponent non-zero integer
|
|
142
|
+
* @returns `a ** b` as a `NonZeroInt32`
|
|
135
143
|
*/
|
|
136
144
|
pow,
|
|
137
145
|
|
|
138
146
|
/**
|
|
139
|
-
* Multiplies two NonZeroInt32
|
|
140
|
-
*
|
|
141
|
-
* The product of two non-zero integers is always non-zero, so this stays
|
|
142
|
-
* closed; for the non-closed operations (`add`/`sub`/`div`, whose result may
|
|
143
|
-
* be `0`) use {@link Num.add}/{@link Num.sub}/{@link Num.divInt}.
|
|
147
|
+
* Multiplies two non-zero integers, returning `a * b` as a `NonZeroInt32`.
|
|
144
148
|
*
|
|
145
|
-
* @param a The first
|
|
146
|
-
* @param b The second
|
|
147
|
-
* @returns `a
|
|
149
|
+
* @param a - The first non-zero integer
|
|
150
|
+
* @param b - The second non-zero integer
|
|
151
|
+
* @returns The product of `a` and `b` as a `NonZeroInt32`
|
|
148
152
|
*/
|
|
149
153
|
mul,
|
|
150
154
|
} as const;
|
|
@@ -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_,
|
|
@@ -39,119 +39,124 @@ const {
|
|
|
39
39
|
} as const);
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
* [MIN_SAFE_INTEGER, MAX_SAFE_INTEGER] excluding 0).
|
|
42
|
+
* Type guard that checks if a value is a non-zero safe integer.
|
|
44
43
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* Returns `true` for a non-zero safe integer — a value with no fractional
|
|
45
|
+
* component.
|
|
46
|
+
*
|
|
47
|
+
* @param value - The value to check
|
|
48
|
+
* @returns `true` if the value is a non-zero safe integer, `false` otherwise
|
|
47
49
|
*/
|
|
48
50
|
export const isNonZeroSafeInt = is;
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
|
-
* Casts a number to
|
|
53
|
+
* Casts a `number` to the `NonZeroSafeInt` branded type.
|
|
54
|
+
*
|
|
55
|
+
* Validates that the value is a non-zero safe integer and returns it with the
|
|
56
|
+
* `NonZeroSafeInt` brand. Throws a `TypeError` otherwise.
|
|
52
57
|
*
|
|
53
|
-
* @param value The value to cast
|
|
54
|
-
* @returns The value as a NonZeroSafeInt
|
|
55
|
-
* @throws {TypeError} If the value is not a non-zero safe integer
|
|
58
|
+
* @param value - The value to cast
|
|
59
|
+
* @returns The value as a `NonZeroSafeInt`
|
|
60
|
+
* @throws {TypeError} If the value is not a non-zero safe integer
|
|
56
61
|
*/
|
|
57
62
|
export const asNonZeroSafeInt = castType;
|
|
58
63
|
|
|
59
64
|
/**
|
|
60
|
-
* Namespace providing type-safe
|
|
61
|
-
*
|
|
65
|
+
* Namespace providing type-safe operations for the `NonZeroSafeInt` branded
|
|
66
|
+
* type.
|
|
62
67
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* non-zero constraint and IEEE 754 precision guarantees, preventing precision
|
|
66
|
-
* loss while ensuring results are never zero.
|
|
68
|
+
* The `NonZeroSafeInt` type represents a non-zero safe integer. Division
|
|
69
|
+
* (`div`) uses floor division.
|
|
67
70
|
*/
|
|
68
71
|
export const NonZeroSafeInt = {
|
|
69
72
|
/**
|
|
70
|
-
* Type guard
|
|
73
|
+
* Type guard that checks if a value is a non-zero safe integer.
|
|
71
74
|
*
|
|
72
|
-
* @param value The value to check
|
|
73
|
-
* @returns `true` if the value is a non-zero safe integer, `false` otherwise
|
|
75
|
+
* @param value - The value to check
|
|
76
|
+
* @returns `true` if the value is a non-zero safe integer, `false` otherwise
|
|
77
|
+
* @see {@link isNonZeroSafeInt} for usage examples
|
|
74
78
|
*/
|
|
75
79
|
is,
|
|
76
80
|
|
|
77
81
|
/**
|
|
78
|
-
* The
|
|
79
|
-
*
|
|
80
|
-
* @readonly
|
|
82
|
+
* The smallest value representable as `NonZeroSafeInt` (the lower saturation
|
|
83
|
+
* target of `fromNumber`).
|
|
81
84
|
*/
|
|
82
85
|
MIN_VALUE,
|
|
83
86
|
|
|
84
87
|
/**
|
|
85
|
-
* The
|
|
86
|
-
*
|
|
87
|
-
* @readonly
|
|
88
|
+
* The largest value representable as `NonZeroSafeInt` (the upper saturation
|
|
89
|
+
* target of `fromNumber`).
|
|
88
90
|
*/
|
|
89
91
|
MAX_VALUE,
|
|
90
92
|
|
|
91
93
|
/**
|
|
92
94
|
* Returns the absolute value of a non-zero safe integer.
|
|
93
95
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
+
* The result is non-negative and keeps the `NonZeroSafeInt` brand.
|
|
97
|
+
*
|
|
98
|
+
* @param a - The non-zero safe integer value
|
|
99
|
+
* @returns The absolute value as a non-negative `NonZeroSafeInt`
|
|
96
100
|
*/
|
|
97
101
|
abs,
|
|
98
102
|
|
|
99
103
|
/**
|
|
100
|
-
* Returns the
|
|
104
|
+
* Returns the smallest of the given non-zero safe integers.
|
|
101
105
|
*
|
|
102
|
-
* @param
|
|
103
|
-
* @
|
|
104
|
-
* @returns The minimum value as a NonZeroSafeInt.
|
|
106
|
+
* @param values - The non-zero safe integers to compare (at least one required)
|
|
107
|
+
* @returns The smallest value as a `NonZeroSafeInt`
|
|
105
108
|
*/
|
|
106
109
|
min: min_,
|
|
107
110
|
|
|
108
111
|
/**
|
|
109
|
-
* Returns the
|
|
112
|
+
* Returns the largest of the given non-zero safe integers.
|
|
110
113
|
*
|
|
111
|
-
* @param
|
|
112
|
-
* @
|
|
113
|
-
* @returns The maximum value as a NonZeroSafeInt.
|
|
114
|
+
* @param values - The non-zero safe integers to compare (at least one required)
|
|
115
|
+
* @returns The largest value as a `NonZeroSafeInt`
|
|
114
116
|
*/
|
|
115
117
|
max: max_,
|
|
116
118
|
|
|
117
119
|
/**
|
|
118
|
-
*
|
|
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]`.
|
|
123
|
+
*
|
|
124
|
+
* Unlike `asNonZeroSafeInt`, this is total: out-of-range inputs are clamped
|
|
125
|
+
* to the nearest representable `NonZeroSafeInt` instead of throwing.
|
|
119
126
|
*
|
|
120
|
-
* @param value The
|
|
121
|
-
* @returns The value
|
|
122
|
-
* a NonZeroSafeInt.
|
|
127
|
+
* @param value - The value to convert
|
|
128
|
+
* @returns The value as a `NonZeroSafeInt`
|
|
123
129
|
*/
|
|
124
|
-
|
|
130
|
+
fromNumber,
|
|
125
131
|
|
|
126
132
|
/**
|
|
127
|
-
* Generates a random NonZeroSafeInt
|
|
133
|
+
* Generates a random `NonZeroSafeInt` within the given range.
|
|
128
134
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
135
|
+
* The range is inclusive on both ends.
|
|
136
|
+
*
|
|
137
|
+
* @param min - The minimum value (inclusive)
|
|
138
|
+
* @param max - The maximum value (inclusive)
|
|
139
|
+
* @returns A random `NonZeroSafeInt` in `[min, max]`
|
|
131
140
|
*/
|
|
132
141
|
random,
|
|
133
142
|
|
|
134
143
|
/**
|
|
135
|
-
* Raises a
|
|
144
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonZeroSafeInt`
|
|
145
|
+
* (floored to an integer).
|
|
136
146
|
*
|
|
137
|
-
* @param a The base
|
|
138
|
-
* @param b The exponent
|
|
139
|
-
* @returns `a ** b`
|
|
140
|
-
* NonZeroSafeInt.
|
|
147
|
+
* @param a - The base non-zero safe integer
|
|
148
|
+
* @param b - The exponent non-zero safe integer
|
|
149
|
+
* @returns `a ** b` as a `NonZeroSafeInt`
|
|
141
150
|
*/
|
|
142
151
|
pow,
|
|
143
152
|
|
|
144
153
|
/**
|
|
145
|
-
* Multiplies two
|
|
146
|
-
*
|
|
147
|
-
* The product of two non-zero safe integers is always non-zero, so this stays
|
|
148
|
-
* closed; for the non-closed operations (`add`/`sub`/`div`, whose result may
|
|
149
|
-
* be `0`) use {@link Num.add}/{@link Num.sub}/{@link Num.divInt}.
|
|
154
|
+
* Multiplies two non-zero safe integers, returning `a * b` as a
|
|
155
|
+
* `NonZeroSafeInt`.
|
|
150
156
|
*
|
|
151
|
-
* @param a The first
|
|
152
|
-
* @param b The second
|
|
153
|
-
* @returns `a
|
|
154
|
-
* NonZeroSafeInt.
|
|
157
|
+
* @param a - The first non-zero safe integer
|
|
158
|
+
* @param b - The second non-zero safe integer
|
|
159
|
+
* @returns The product of `a` and `b` as a `NonZeroSafeInt`
|
|
155
160
|
*/
|
|
156
161
|
mul,
|
|
157
162
|
} as const;
|
|
@@ -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_,
|
|
@@ -33,117 +33,122 @@ const {
|
|
|
33
33
|
} as const);
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* the range [1, 2^16)).
|
|
36
|
+
* Type guard that checks if a value is a non-zero integer in [1, 2^16).
|
|
38
37
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* Returns `true` for a non-zero integer in [1, 2^16) — a value with no
|
|
39
|
+
* fractional component.
|
|
40
|
+
*
|
|
41
|
+
* @param value - The value to check
|
|
42
|
+
* @returns `true` if the value is a non-zero integer in [1, 2^16), `false` otherwise
|
|
41
43
|
*/
|
|
42
44
|
export const isNonZeroUint16 = is;
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
|
-
* Casts a number to
|
|
47
|
+
* Casts a `number` to the `NonZeroUint16` branded type.
|
|
48
|
+
*
|
|
49
|
+
* Validates that the value is a non-zero integer in [1, 2^16) and returns it
|
|
50
|
+
* with the `NonZeroUint16` brand. Throws a `TypeError` otherwise.
|
|
46
51
|
*
|
|
47
|
-
* @param value The value to cast
|
|
48
|
-
* @returns The value as a NonZeroUint16
|
|
49
|
-
* @throws {TypeError} If the value is not a non-zero integer in [1, 2^16)
|
|
52
|
+
* @param value - The value to cast
|
|
53
|
+
* @returns The value as a `NonZeroUint16`
|
|
54
|
+
* @throws {TypeError} If the value is not a non-zero integer in [1, 2^16)
|
|
50
55
|
*/
|
|
51
56
|
export const asNonZeroUint16 = castType;
|
|
52
57
|
|
|
53
58
|
/**
|
|
54
|
-
* Namespace providing type-safe
|
|
55
|
-
*
|
|
59
|
+
* Namespace providing type-safe operations for the `NonZeroUint16` branded
|
|
60
|
+
* type.
|
|
56
61
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* unsigned integer constraint, with results below 1 clamped to MIN_VALUE and
|
|
60
|
-
* overflow results clamped to MAX_VALUE.
|
|
62
|
+
* The `NonZeroUint16` type represents a non-zero integer in [1, 2^16). Division
|
|
63
|
+
* (`div`) uses floor division.
|
|
61
64
|
*/
|
|
62
65
|
export const NonZeroUint16 = {
|
|
63
66
|
/**
|
|
64
|
-
* Type guard
|
|
67
|
+
* Type guard that checks if a value is a non-zero integer in [1, 2^16).
|
|
65
68
|
*
|
|
66
|
-
* @param value The value to check
|
|
67
|
-
* @returns `true` if the value is a
|
|
68
|
-
*
|
|
69
|
+
* @param value - The value to check
|
|
70
|
+
* @returns `true` if the value is a non-zero integer in [1, 2^16), `false` otherwise
|
|
71
|
+
* @see {@link isNonZeroUint16} for usage examples
|
|
69
72
|
*/
|
|
70
73
|
is,
|
|
71
74
|
|
|
72
75
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
75
|
-
* @readonly
|
|
76
|
+
* The smallest value representable as `NonZeroUint16` (the lower saturation
|
|
77
|
+
* target of `fromNumber`).
|
|
76
78
|
*/
|
|
77
79
|
MIN_VALUE,
|
|
78
80
|
|
|
79
81
|
/**
|
|
80
|
-
* The
|
|
81
|
-
*
|
|
82
|
-
* @readonly
|
|
82
|
+
* The largest value representable as `NonZeroUint16` (the upper saturation
|
|
83
|
+
* target of `fromNumber`).
|
|
83
84
|
*/
|
|
84
85
|
MAX_VALUE,
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
|
-
* Returns the
|
|
88
|
+
* Returns the smallest of the given non-zero integers.
|
|
88
89
|
*
|
|
89
|
-
* @param
|
|
90
|
-
* @
|
|
91
|
-
* @returns The minimum value as a NonZeroUint16.
|
|
90
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
91
|
+
* @returns The smallest value as a `NonZeroUint16`
|
|
92
92
|
*/
|
|
93
93
|
min: min_,
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
|
-
* Returns the
|
|
96
|
+
* Returns the largest of the given non-zero integers.
|
|
97
97
|
*
|
|
98
|
-
* @param
|
|
99
|
-
* @
|
|
100
|
-
* @returns The maximum value as a NonZeroUint16.
|
|
98
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
99
|
+
* @returns The largest value as a `NonZeroUint16`
|
|
101
100
|
*/
|
|
102
101
|
max: max_,
|
|
103
102
|
|
|
104
103
|
/**
|
|
105
|
-
*
|
|
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]`.
|
|
106
107
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
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`
|
|
109
113
|
*/
|
|
110
|
-
|
|
114
|
+
fromNumber,
|
|
111
115
|
|
|
112
116
|
/**
|
|
113
|
-
* Generates a random NonZeroUint16
|
|
117
|
+
* Generates a random `NonZeroUint16` within the given range.
|
|
118
|
+
*
|
|
119
|
+
* The range is inclusive on both ends.
|
|
114
120
|
*
|
|
115
|
-
* @
|
|
121
|
+
* @param min - The minimum value (inclusive)
|
|
122
|
+
* @param max - The maximum value (inclusive)
|
|
123
|
+
* @returns A random `NonZeroUint16` in `[min, max]`
|
|
116
124
|
*/
|
|
117
125
|
random,
|
|
118
126
|
|
|
119
127
|
/**
|
|
120
|
-
* Raises a
|
|
128
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonZeroUint16`
|
|
129
|
+
* (floored to an integer).
|
|
121
130
|
*
|
|
122
|
-
* @param a The base
|
|
123
|
-
* @param b The exponent
|
|
124
|
-
* @returns `a ** b`
|
|
131
|
+
* @param a - The base non-zero integer
|
|
132
|
+
* @param b - The exponent non-zero integer
|
|
133
|
+
* @returns `a ** b` as a `NonZeroUint16`
|
|
125
134
|
*/
|
|
126
135
|
pow,
|
|
127
136
|
|
|
128
137
|
/**
|
|
129
|
-
* Adds two NonZeroUint16
|
|
138
|
+
* Adds two non-zero integers, returning `a + b` as a `NonZeroUint16`.
|
|
130
139
|
*
|
|
131
|
-
* @param a The first
|
|
132
|
-
* @param b The second
|
|
133
|
-
* @returns `a
|
|
140
|
+
* @param a - The first non-zero integer
|
|
141
|
+
* @param b - The second non-zero integer
|
|
142
|
+
* @returns The sum of `a` and `b` as a `NonZeroUint16`
|
|
134
143
|
*/
|
|
135
144
|
add,
|
|
136
145
|
|
|
137
146
|
/**
|
|
138
|
-
* Multiplies two NonZeroUint16
|
|
139
|
-
*
|
|
140
|
-
* Both `add` and `mul` stay within `[1, 65535]`. For the non-closed
|
|
141
|
-
* operations (`sub`/`div`, whose result may be `0`) use {@link Num.sub} /
|
|
142
|
-
* {@link Num.divInt}.
|
|
147
|
+
* Multiplies two non-zero integers, returning `a * b` as a `NonZeroUint16`.
|
|
143
148
|
*
|
|
144
|
-
* @param a The first
|
|
145
|
-
* @param b The second
|
|
146
|
-
* @returns `a
|
|
149
|
+
* @param a - The first non-zero integer
|
|
150
|
+
* @param b - The second non-zero integer
|
|
151
|
+
* @returns The product of `a` and `b` as a `NonZeroUint16`
|
|
147
152
|
*/
|
|
148
153
|
mul,
|
|
149
154
|
} as const;
|