ts-data-forge 11.0.0 → 11.0.1
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/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 +65 -58
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +49 -45
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +65 -58
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +49 -45
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +68 -59
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +52 -46
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +60 -48
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +40 -36
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +57 -56
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +40 -41
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +74 -64
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +58 -51
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +64 -57
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +47 -43
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +64 -58
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +47 -44
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +64 -54
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +48 -41
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +41 -146
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +27 -107
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +54 -53
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +37 -39
- 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 +52 -53
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +36 -39
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +52 -54
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +36 -40
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +53 -54
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +36 -40
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +52 -53
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +35 -39
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +52 -53
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +35 -39
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +74 -63
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +58 -50
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +46 -68
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +34 -49
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +61 -57
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +44 -43
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +61 -57
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +44 -43
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +62 -57
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +45 -43
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +61 -57
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +44 -43
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +61 -58
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +44 -44
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +43 -62
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +35 -42
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +62 -57
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +46 -44
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +63 -50
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +42 -39
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +60 -58
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +44 -43
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +59 -55
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +42 -42
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +56 -65
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +44 -43
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +60 -58
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +44 -43
- package/dist/number/enum/uint8.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 +65 -58
- package/src/number/branded-types/int32.mts +65 -58
- package/src/number/branded-types/negative-finite-number.mts +68 -68
- package/src/number/branded-types/negative-int.mts +60 -57
- package/src/number/branded-types/negative-safe-int.mts +57 -65
- package/src/number/branded-types/non-negative-finite-number.mts +74 -64
- package/src/number/branded-types/non-negative-int16.mts +64 -57
- package/src/number/branded-types/non-negative-int32.mts +64 -58
- package/src/number/branded-types/non-positive-finite-number.mts +64 -54
- package/src/number/branded-types/non-positive-int.mts +41 -146
- package/src/number/branded-types/non-positive-safe-int.mts +54 -53
- 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 +52 -53
- package/src/number/branded-types/non-zero-int32.mts +52 -54
- package/src/number/branded-types/non-zero-safe-int.mts +53 -54
- package/src/number/branded-types/non-zero-uint16.mts +52 -53
- package/src/number/branded-types/non-zero-uint32.mts +52 -53
- package/src/number/branded-types/positive-finite-number.mts +74 -63
- package/src/number/branded-types/positive-int.mts +46 -68
- package/src/number/branded-types/positive-int16.mts +61 -57
- package/src/number/branded-types/positive-int32.mts +61 -57
- package/src/number/branded-types/positive-safe-int.mts +62 -57
- package/src/number/branded-types/positive-uint16.mts +61 -57
- package/src/number/branded-types/positive-uint32.mts +61 -58
- package/src/number/branded-types/safe-int.mts +43 -62
- package/src/number/branded-types/safe-uint.mts +62 -57
- package/src/number/branded-types/uint.mts +63 -50
- package/src/number/branded-types/uint16.mts +60 -58
- package/src/number/branded-types/uint32.mts +59 -55
- package/src/number/enum/int8.mts +56 -65
- package/src/number/enum/uint8.mts +60 -58
|
@@ -33,117 +33,116 @@ const {
|
|
|
33
33
|
} as const);
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* the range [1, 2^32)).
|
|
36
|
+
* Type guard that checks if a value is a non-zero integer in [1, 2^32).
|
|
38
37
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* Returns `true` for a non-zero integer in [1, 2^32) — 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^32), `false` otherwise
|
|
41
43
|
*/
|
|
42
44
|
export const isNonZeroUint32 = is;
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
|
-
* Casts a number to
|
|
47
|
+
* Casts a `number` to the `NonZeroUint32` branded type.
|
|
48
|
+
*
|
|
49
|
+
* Validates that the value is a non-zero integer in [1, 2^32) and returns it
|
|
50
|
+
* with the `NonZeroUint32` brand. Throws a `TypeError` otherwise.
|
|
46
51
|
*
|
|
47
|
-
* @param value The value to cast
|
|
48
|
-
* @returns The value as a NonZeroUint32
|
|
49
|
-
* @throws {TypeError} If the value is not a non-zero integer in [1, 2^32)
|
|
52
|
+
* @param value - The value to cast
|
|
53
|
+
* @returns The value as a `NonZeroUint32`
|
|
54
|
+
* @throws {TypeError} If the value is not a non-zero integer in [1, 2^32)
|
|
50
55
|
*/
|
|
51
56
|
export const asNonZeroUint32 = castType;
|
|
52
57
|
|
|
53
58
|
/**
|
|
54
|
-
* Namespace providing type-safe
|
|
55
|
-
*
|
|
59
|
+
* Namespace providing type-safe operations for the `NonZeroUint32` branded
|
|
60
|
+
* type.
|
|
56
61
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* non-zero unsigned integer constraint, with results below 1 clamped to
|
|
60
|
-
* MIN_VALUE and overflow results clamped to MAX_VALUE.
|
|
62
|
+
* The `NonZeroUint32` type represents a non-zero integer in [1, 2^32). Division
|
|
63
|
+
* (`div`) uses floor division.
|
|
61
64
|
*/
|
|
62
65
|
export const NonZeroUint32 = {
|
|
63
66
|
/**
|
|
64
|
-
* Type guard
|
|
67
|
+
* Type guard that checks if a value is a non-zero integer in [1, 2^32).
|
|
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^32), `false` otherwise
|
|
71
|
+
* @see {@link isNonZeroUint32} for usage examples
|
|
69
72
|
*/
|
|
70
73
|
is,
|
|
71
74
|
|
|
72
75
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
75
|
-
* @readonly
|
|
76
|
+
* The smallest value representable as `NonZeroUint32`.
|
|
76
77
|
*/
|
|
77
78
|
MIN_VALUE,
|
|
78
79
|
|
|
79
80
|
/**
|
|
80
|
-
* The
|
|
81
|
-
*
|
|
82
|
-
* @readonly
|
|
81
|
+
* The largest value representable as `NonZeroUint32`.
|
|
83
82
|
*/
|
|
84
83
|
MAX_VALUE,
|
|
85
84
|
|
|
86
85
|
/**
|
|
87
|
-
* Returns the
|
|
86
|
+
* Returns the smallest of the given non-zero integers.
|
|
88
87
|
*
|
|
89
|
-
* @param
|
|
90
|
-
* @
|
|
91
|
-
* @returns The minimum value as a NonZeroUint32.
|
|
88
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
89
|
+
* @returns The smallest value as a `NonZeroUint32`
|
|
92
90
|
*/
|
|
93
91
|
min: min_,
|
|
94
92
|
|
|
95
93
|
/**
|
|
96
|
-
* Returns the
|
|
94
|
+
* Returns the largest of the given non-zero integers.
|
|
97
95
|
*
|
|
98
|
-
* @param
|
|
99
|
-
* @
|
|
100
|
-
* @returns The maximum value as a NonZeroUint32.
|
|
96
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
97
|
+
* @returns The largest value as a `NonZeroUint32`
|
|
101
98
|
*/
|
|
102
99
|
max: max_,
|
|
103
100
|
|
|
104
101
|
/**
|
|
105
|
-
* Clamps a number
|
|
102
|
+
* Clamps a `number` into the `NonZeroUint32` range, rounding to the nearest
|
|
103
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
106
104
|
*
|
|
107
|
-
* @param value The
|
|
108
|
-
* @returns The
|
|
105
|
+
* @param value - The value to clamp
|
|
106
|
+
* @returns The clamped value as a `NonZeroUint32`
|
|
109
107
|
*/
|
|
110
108
|
clamp,
|
|
111
109
|
|
|
112
110
|
/**
|
|
113
|
-
* Generates a random NonZeroUint32
|
|
111
|
+
* Generates a random `NonZeroUint32` within the given range.
|
|
112
|
+
*
|
|
113
|
+
* The range is inclusive on both ends.
|
|
114
114
|
*
|
|
115
|
-
* @
|
|
115
|
+
* @param min - The minimum value (inclusive)
|
|
116
|
+
* @param max - The maximum value (inclusive)
|
|
117
|
+
* @returns A random `NonZeroUint32` in `[min, max]`
|
|
116
118
|
*/
|
|
117
119
|
random,
|
|
118
120
|
|
|
119
121
|
/**
|
|
120
|
-
* Raises a
|
|
122
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonZeroUint32`
|
|
123
|
+
* (floored to an integer).
|
|
121
124
|
*
|
|
122
|
-
* @param a The base
|
|
123
|
-
* @param b The exponent
|
|
124
|
-
* @returns `a ** b`
|
|
125
|
+
* @param a - The base non-zero integer
|
|
126
|
+
* @param b - The exponent non-zero integer
|
|
127
|
+
* @returns `a ** b` as a `NonZeroUint32`
|
|
125
128
|
*/
|
|
126
129
|
pow,
|
|
127
130
|
|
|
128
131
|
/**
|
|
129
|
-
* Adds two NonZeroUint32
|
|
132
|
+
* Adds two non-zero integers, returning `a + b` as a `NonZeroUint32`.
|
|
130
133
|
*
|
|
131
|
-
* @param a The first
|
|
132
|
-
* @param b The second
|
|
133
|
-
* @returns `a
|
|
134
|
+
* @param a - The first non-zero integer
|
|
135
|
+
* @param b - The second non-zero integer
|
|
136
|
+
* @returns The sum of `a` and `b` as a `NonZeroUint32`
|
|
134
137
|
*/
|
|
135
138
|
add,
|
|
136
139
|
|
|
137
140
|
/**
|
|
138
|
-
* Multiplies two NonZeroUint32
|
|
139
|
-
*
|
|
140
|
-
* Both `add` and `mul` stay within `[1, 4294967295]`. For the non-closed
|
|
141
|
-
* operations (`sub`/`div`, whose result may be `0`) use {@link Num.sub} /
|
|
142
|
-
* {@link Num.divInt}.
|
|
141
|
+
* Multiplies two non-zero integers, returning `a * b` as a `NonZeroUint32`.
|
|
143
142
|
*
|
|
144
|
-
* @param a The first
|
|
145
|
-
* @param b The second
|
|
146
|
-
* @returns `a
|
|
143
|
+
* @param a - The first non-zero integer
|
|
144
|
+
* @param b - The second non-zero integer
|
|
145
|
+
* @returns The product of `a` and `b` as a `NonZeroUint32`
|
|
147
146
|
*/
|
|
148
147
|
mul,
|
|
149
148
|
} as const;
|
|
@@ -78,148 +78,159 @@ expectType<
|
|
|
78
78
|
>('=');
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Type guard that checks if a value is a positive finite number.
|
|
82
82
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
83
|
+
* Returns `true` only for a finite value — never `NaN`, `Infinity`, or
|
|
84
|
+
* `-Infinity`.
|
|
85
|
+
*
|
|
86
|
+
* @param value - The value to check
|
|
87
|
+
* @returns `true` if the value is a positive finite number, `false` otherwise
|
|
85
88
|
*/
|
|
86
89
|
export const isPositiveFiniteNumber = is;
|
|
87
90
|
|
|
88
91
|
/**
|
|
89
|
-
* Casts a number to
|
|
92
|
+
* Casts a `number` to the `PositiveFiniteNumber` branded type.
|
|
93
|
+
*
|
|
94
|
+
* Validates that the value is a positive finite number and returns it with the
|
|
95
|
+
* `PositiveFiniteNumber` brand. Throws a `TypeError` otherwise.
|
|
90
96
|
*
|
|
91
|
-
* @param value The value to cast
|
|
92
|
-
* @returns The value as a PositiveFiniteNumber
|
|
93
|
-
* @throws {TypeError} If the value is not a positive finite number
|
|
97
|
+
* @param value - The value to cast
|
|
98
|
+
* @returns The value as a `PositiveFiniteNumber`
|
|
99
|
+
* @throws {TypeError} If the value is not a positive finite number
|
|
94
100
|
*/
|
|
95
101
|
export const asPositiveFiniteNumber = castType;
|
|
96
102
|
|
|
97
103
|
/**
|
|
98
|
-
* Namespace providing type-safe
|
|
99
|
-
*
|
|
104
|
+
* Namespace providing type-safe operations for the `PositiveFiniteNumber`
|
|
105
|
+
* branded type.
|
|
100
106
|
*
|
|
101
|
-
*
|
|
102
|
-
* results to MIN_VALUE, while ensuring results remain finite (excluding NaN and
|
|
103
|
-
* Infinity). This type is useful for representing quantities that must always
|
|
104
|
-
* be positive, such as probabilities, magnitudes, and physical measurements.
|
|
107
|
+
* The `PositiveFiniteNumber` type represents a positive finite number.
|
|
105
108
|
*/
|
|
106
109
|
export const PositiveFiniteNumber = {
|
|
107
110
|
/**
|
|
108
|
-
* Type guard
|
|
111
|
+
* Type guard that checks if a value is a positive finite number.
|
|
109
112
|
*
|
|
110
|
-
* @param value The value to check
|
|
111
|
-
* @returns `true` if the value is a positive finite number, `false`
|
|
112
|
-
*
|
|
113
|
+
* @param value - The value to check
|
|
114
|
+
* @returns `true` if the value is a positive finite number, `false` otherwise
|
|
115
|
+
* @see {@link isPositiveFiniteNumber} for usage examples
|
|
113
116
|
*/
|
|
114
117
|
is,
|
|
115
118
|
|
|
116
119
|
/**
|
|
117
|
-
* The
|
|
118
|
-
*
|
|
119
|
-
* @readonly
|
|
120
|
+
* The smallest value representable as `PositiveFiniteNumber`.
|
|
120
121
|
*/
|
|
121
122
|
MIN_VALUE,
|
|
122
123
|
|
|
123
124
|
/**
|
|
124
|
-
* Returns the
|
|
125
|
+
* Returns the smallest of the given positive finite numbers.
|
|
125
126
|
*
|
|
126
|
-
* @param
|
|
127
|
-
* @
|
|
128
|
-
* @returns The minimum value as a PositiveFiniteNumber.
|
|
127
|
+
* @param values - The positive finite numbers to compare (at least one required)
|
|
128
|
+
* @returns The smallest value as a `PositiveFiniteNumber`
|
|
129
129
|
*/
|
|
130
130
|
min: min_,
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
* Returns the
|
|
133
|
+
* Returns the largest of the given positive finite numbers.
|
|
134
134
|
*
|
|
135
|
-
* @param
|
|
136
|
-
* @
|
|
137
|
-
* @returns The maximum value as a PositiveFiniteNumber.
|
|
135
|
+
* @param values - The positive finite numbers to compare (at least one required)
|
|
136
|
+
* @returns The largest value as a `PositiveFiniteNumber`
|
|
138
137
|
*/
|
|
139
138
|
max: max_,
|
|
140
139
|
|
|
141
140
|
/**
|
|
142
|
-
* Clamps a number
|
|
141
|
+
* Clamps a `number` into the `PositiveFiniteNumber` range `[MIN_VALUE,
|
|
142
|
+
* MAX_VALUE]`.
|
|
143
143
|
*
|
|
144
|
-
* @param value The
|
|
145
|
-
* @returns The
|
|
144
|
+
* @param value - The value to clamp
|
|
145
|
+
* @returns The clamped value as a `PositiveFiniteNumber`
|
|
146
146
|
*/
|
|
147
147
|
clamp,
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
150
|
+
* Returns the greatest integer less than or equal to a positive finite
|
|
151
|
+
* number.
|
|
151
152
|
*
|
|
152
|
-
* @param
|
|
153
|
-
* @returns The
|
|
153
|
+
* @param a - The positive finite number value
|
|
154
|
+
* @returns The floored value as an integer
|
|
154
155
|
*/
|
|
155
156
|
floor,
|
|
156
157
|
|
|
157
158
|
/**
|
|
158
|
-
*
|
|
159
|
+
* Returns the smallest integer greater than or equal to a positive finite
|
|
160
|
+
* number.
|
|
159
161
|
*
|
|
160
|
-
* @param
|
|
161
|
-
* @returns The
|
|
162
|
+
* @param a - The positive finite number value
|
|
163
|
+
* @returns The ceiled value as an integer
|
|
162
164
|
*/
|
|
163
165
|
ceil,
|
|
164
166
|
|
|
165
167
|
/**
|
|
166
|
-
*
|
|
168
|
+
* Returns the value of a positive finite number rounded to the nearest
|
|
169
|
+
* integer.
|
|
167
170
|
*
|
|
168
|
-
* @param
|
|
169
|
-
* @returns The rounded value as
|
|
171
|
+
* @param a - The positive finite number value
|
|
172
|
+
* @returns The rounded value as an integer
|
|
170
173
|
*/
|
|
171
174
|
round,
|
|
172
175
|
|
|
173
176
|
/**
|
|
174
|
-
* Generates a random PositiveFiniteNumber
|
|
177
|
+
* Generates a random `PositiveFiniteNumber` within the given range.
|
|
178
|
+
*
|
|
179
|
+
* The range is inclusive on both ends.
|
|
175
180
|
*
|
|
176
|
-
* @
|
|
181
|
+
* @param min - The minimum value (inclusive)
|
|
182
|
+
* @param max - The maximum value (inclusive)
|
|
183
|
+
* @returns A random `PositiveFiniteNumber` in `[min, max]`
|
|
177
184
|
*/
|
|
178
185
|
random,
|
|
179
186
|
|
|
180
187
|
/**
|
|
181
|
-
* Raises a
|
|
188
|
+
* Raises `a` to the power `b`, returning `a ** b` as a
|
|
189
|
+
* `PositiveFiniteNumber`.
|
|
182
190
|
*
|
|
183
|
-
* @param a The base
|
|
184
|
-
* @param b The exponent
|
|
185
|
-
* @returns `a ** b`
|
|
191
|
+
* @param a - The base positive finite number
|
|
192
|
+
* @param b - The exponent positive finite number
|
|
193
|
+
* @returns `a ** b` as a `PositiveFiniteNumber`
|
|
186
194
|
*/
|
|
187
195
|
pow,
|
|
188
196
|
|
|
189
197
|
/**
|
|
190
|
-
* Adds two
|
|
198
|
+
* Adds two positive finite numbers, returning `a + b` as a
|
|
199
|
+
* `PositiveFiniteNumber`.
|
|
191
200
|
*
|
|
192
|
-
* @param a The first
|
|
193
|
-
* @param b The second
|
|
194
|
-
* @returns `a
|
|
201
|
+
* @param a - The first positive finite number
|
|
202
|
+
* @param b - The second positive finite number
|
|
203
|
+
* @returns The sum of `a` and `b` as a `PositiveFiniteNumber`
|
|
195
204
|
*/
|
|
196
205
|
add,
|
|
197
206
|
|
|
198
207
|
/**
|
|
199
|
-
* Subtracts
|
|
208
|
+
* Subtracts two positive finite numbers, returning `a - b` as a
|
|
209
|
+
* `PositiveFiniteNumber`.
|
|
200
210
|
*
|
|
201
|
-
* @param a The
|
|
202
|
-
* @param b The
|
|
203
|
-
* @returns `a
|
|
204
|
-
* MIN_VALUE).
|
|
211
|
+
* @param a - The first positive finite number
|
|
212
|
+
* @param b - The second positive finite number
|
|
213
|
+
* @returns The difference of `a` and `b` as a `PositiveFiniteNumber`
|
|
205
214
|
*/
|
|
206
215
|
sub,
|
|
207
216
|
|
|
208
217
|
/**
|
|
209
|
-
* Multiplies two
|
|
218
|
+
* Multiplies two positive finite numbers, returning `a * b` as a
|
|
219
|
+
* `PositiveFiniteNumber`.
|
|
210
220
|
*
|
|
211
|
-
* @param a The first
|
|
212
|
-
* @param b The second
|
|
213
|
-
* @returns `a
|
|
221
|
+
* @param a - The first positive finite number
|
|
222
|
+
* @param b - The second positive finite number
|
|
223
|
+
* @returns The product of `a` and `b` as a `PositiveFiniteNumber`
|
|
214
224
|
*/
|
|
215
225
|
mul,
|
|
216
226
|
|
|
217
227
|
/**
|
|
218
|
-
* Divides
|
|
228
|
+
* Divides two positive finite numbers, returning `a / b` as a
|
|
229
|
+
* `PositiveFiniteNumber`.
|
|
219
230
|
*
|
|
220
|
-
* @param a The dividend
|
|
221
|
-
* @param b The divisor
|
|
222
|
-
* @returns `a / b`
|
|
231
|
+
* @param a - The dividend
|
|
232
|
+
* @param b - The divisor (must be non-zero)
|
|
233
|
+
* @returns `a / b` as a `PositiveFiniteNumber`
|
|
223
234
|
*/
|
|
224
235
|
div,
|
|
225
236
|
} as const;
|
|
@@ -35,8 +35,8 @@ const {
|
|
|
35
35
|
/**
|
|
36
36
|
* Type guard that checks if a value is a positive integer.
|
|
37
37
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* Returns `true` for a positive integer — a value with no fractional component,
|
|
39
|
+
* including values outside the safe integer range (unlike `SafeInt`).
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
42
|
*
|
|
@@ -54,11 +54,10 @@ const {
|
|
|
54
54
|
export const isPositiveInt = is;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Casts a number to
|
|
57
|
+
* Casts a `number` to the `PositiveInt` branded type.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* operations that require strictly positive integer values.
|
|
59
|
+
* Validates that the value is a positive integer and returns it with the
|
|
60
|
+
* `PositiveInt` brand. Throws a `TypeError` otherwise.
|
|
62
61
|
*
|
|
63
62
|
* @example
|
|
64
63
|
*
|
|
@@ -71,26 +70,20 @@ export const isPositiveInt = is;
|
|
|
71
70
|
* ```
|
|
72
71
|
*
|
|
73
72
|
* @param value - The value to cast
|
|
74
|
-
* @returns The value as a PositiveInt
|
|
73
|
+
* @returns The value as a `PositiveInt`
|
|
75
74
|
* @throws {TypeError} If the value is not a positive integer
|
|
76
75
|
*/
|
|
77
76
|
export const asPositiveInt = castType;
|
|
78
77
|
|
|
79
78
|
/**
|
|
80
|
-
* Namespace providing type-safe operations for PositiveInt branded
|
|
79
|
+
* Namespace providing type-safe operations for the `PositiveInt` branded type.
|
|
81
80
|
*
|
|
82
|
-
* PositiveInt represents
|
|
83
|
-
*
|
|
84
|
-
* constraint, ensuring that arithmetic operations never produce zero or
|
|
85
|
-
* negative values.
|
|
81
|
+
* The `PositiveInt` type represents a positive integer. Division (`div`) uses
|
|
82
|
+
* floor division.
|
|
86
83
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* - Counts and quantities that must be positive
|
|
91
|
-
* - Denominators in division operations
|
|
92
|
-
* - Loop counters and iteration counts
|
|
93
|
-
* - Database primary keys and IDs
|
|
84
|
+
* Unlike `SafeInt`, `PositiveInt` allows values outside the safe integer range
|
|
85
|
+
* (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's
|
|
86
|
+
* `number` type.
|
|
94
87
|
*/
|
|
95
88
|
export const PositiveInt = {
|
|
96
89
|
/**
|
|
@@ -113,17 +106,12 @@ export const PositiveInt = {
|
|
|
113
106
|
is,
|
|
114
107
|
|
|
115
108
|
/**
|
|
116
|
-
* The
|
|
117
|
-
*
|
|
118
|
-
* @readonly
|
|
109
|
+
* The smallest value representable as `PositiveInt`.
|
|
119
110
|
*/
|
|
120
111
|
MIN_VALUE,
|
|
121
112
|
|
|
122
113
|
/**
|
|
123
|
-
* Returns the
|
|
124
|
-
*
|
|
125
|
-
* Since all inputs are guaranteed to be >= 1, the result is also guaranteed
|
|
126
|
-
* to be a positive integer.
|
|
114
|
+
* Returns the smallest of the given positive integers.
|
|
127
115
|
*
|
|
128
116
|
* @example
|
|
129
117
|
*
|
|
@@ -138,12 +126,12 @@ export const PositiveInt = {
|
|
|
138
126
|
* ```
|
|
139
127
|
*
|
|
140
128
|
* @param values - The positive integers to compare (at least one required)
|
|
141
|
-
* @returns The smallest value as a PositiveInt
|
|
129
|
+
* @returns The smallest value as a `PositiveInt`
|
|
142
130
|
*/
|
|
143
131
|
min: min_,
|
|
144
132
|
|
|
145
133
|
/**
|
|
146
|
-
* Returns the
|
|
134
|
+
* Returns the largest of the given positive integers.
|
|
147
135
|
*
|
|
148
136
|
* @example
|
|
149
137
|
*
|
|
@@ -158,15 +146,13 @@ export const PositiveInt = {
|
|
|
158
146
|
* ```
|
|
159
147
|
*
|
|
160
148
|
* @param values - The positive integers to compare (at least one required)
|
|
161
|
-
* @returns The largest value as a PositiveInt
|
|
149
|
+
* @returns The largest value as a `PositiveInt`
|
|
162
150
|
*/
|
|
163
151
|
max: max_,
|
|
164
152
|
|
|
165
153
|
/**
|
|
166
|
-
* Clamps a number
|
|
167
|
-
*
|
|
168
|
-
* Since PositiveInt has a minimum value of 1, this function ensures that any
|
|
169
|
-
* input less than 1 is clamped to 1.
|
|
154
|
+
* Clamps a `number` into the `PositiveInt` range, rounding to the nearest
|
|
155
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
170
156
|
*
|
|
171
157
|
* @example
|
|
172
158
|
*
|
|
@@ -180,16 +166,15 @@ export const PositiveInt = {
|
|
|
180
166
|
* assert.isTrue(withinRange === 10);
|
|
181
167
|
* ```
|
|
182
168
|
*
|
|
183
|
-
* @param value - The
|
|
184
|
-
* @returns The
|
|
169
|
+
* @param value - The value to clamp
|
|
170
|
+
* @returns The clamped value as a `PositiveInt`
|
|
185
171
|
*/
|
|
186
172
|
clamp,
|
|
187
173
|
|
|
188
174
|
/**
|
|
189
|
-
* Generates a random
|
|
175
|
+
* Generates a random `PositiveInt` within the given range.
|
|
190
176
|
*
|
|
191
|
-
*
|
|
192
|
-
* If min > max, they are automatically swapped.
|
|
177
|
+
* The range is inclusive on both ends.
|
|
193
178
|
*
|
|
194
179
|
* @example
|
|
195
180
|
*
|
|
@@ -205,15 +190,15 @@ export const PositiveInt = {
|
|
|
205
190
|
* assert.isTrue(randomValue >= 3 && randomValue <= 6);
|
|
206
191
|
* ```
|
|
207
192
|
*
|
|
208
|
-
* @param min - The minimum value (inclusive
|
|
209
|
-
* @param max - The maximum value (inclusive
|
|
210
|
-
* @returns A random PositiveInt in
|
|
193
|
+
* @param min - The minimum value (inclusive)
|
|
194
|
+
* @param max - The maximum value (inclusive)
|
|
195
|
+
* @returns A random `PositiveInt` in `[min, max]`
|
|
211
196
|
*/
|
|
212
197
|
random,
|
|
213
198
|
|
|
214
199
|
/**
|
|
215
|
-
* Raises a
|
|
216
|
-
*
|
|
200
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `PositiveInt` (floored
|
|
201
|
+
* to an integer).
|
|
217
202
|
*
|
|
218
203
|
* @example
|
|
219
204
|
*
|
|
@@ -229,12 +214,12 @@ export const PositiveInt = {
|
|
|
229
214
|
*
|
|
230
215
|
* @param a - The base positive integer
|
|
231
216
|
* @param b - The exponent positive integer
|
|
232
|
-
* @returns `a ** b` as a PositiveInt
|
|
217
|
+
* @returns `a ** b` as a `PositiveInt`
|
|
233
218
|
*/
|
|
234
219
|
pow,
|
|
235
220
|
|
|
236
221
|
/**
|
|
237
|
-
* Adds two positive integers,
|
|
222
|
+
* Adds two positive integers, returning `a + b` as a `PositiveInt`.
|
|
238
223
|
*
|
|
239
224
|
* @example
|
|
240
225
|
*
|
|
@@ -244,17 +229,14 @@ export const PositiveInt = {
|
|
|
244
229
|
* assert.isTrue(sum === 9);
|
|
245
230
|
* ```
|
|
246
231
|
*
|
|
247
|
-
* @param a -
|
|
248
|
-
* @param b -
|
|
249
|
-
* @returns `a
|
|
232
|
+
* @param a - The first positive integer
|
|
233
|
+
* @param b - The second positive integer
|
|
234
|
+
* @returns The sum of `a` and `b` as a `PositiveInt`
|
|
250
235
|
*/
|
|
251
236
|
add,
|
|
252
237
|
|
|
253
238
|
/**
|
|
254
|
-
* Subtracts two positive integers,
|
|
255
|
-
*
|
|
256
|
-
* If the mathematical result would be <= 0, it is clamped to 1 to maintain
|
|
257
|
-
* the positive integer constraint.
|
|
239
|
+
* Subtracts two positive integers, returning `a - b` as a `PositiveInt`.
|
|
258
240
|
*
|
|
259
241
|
* @example
|
|
260
242
|
*
|
|
@@ -264,14 +246,14 @@ export const PositiveInt = {
|
|
|
264
246
|
* assert.isTrue(difference === 1);
|
|
265
247
|
* ```
|
|
266
248
|
*
|
|
267
|
-
* @param a - The
|
|
268
|
-
* @param b - The
|
|
269
|
-
* @returns `
|
|
249
|
+
* @param a - The first positive integer
|
|
250
|
+
* @param b - The second positive integer
|
|
251
|
+
* @returns The difference of `a` and `b` as a `PositiveInt`
|
|
270
252
|
*/
|
|
271
253
|
sub,
|
|
272
254
|
|
|
273
255
|
/**
|
|
274
|
-
* Multiplies two positive integers,
|
|
256
|
+
* Multiplies two positive integers, returning `a * b` as a `PositiveInt`.
|
|
275
257
|
*
|
|
276
258
|
* @example
|
|
277
259
|
*
|
|
@@ -281,19 +263,15 @@ export const PositiveInt = {
|
|
|
281
263
|
* assert.isTrue(product === 21);
|
|
282
264
|
* ```
|
|
283
265
|
*
|
|
284
|
-
* @param a -
|
|
285
|
-
* @param b -
|
|
286
|
-
* @returns `a
|
|
266
|
+
* @param a - The first positive integer
|
|
267
|
+
* @param b - The second positive integer
|
|
268
|
+
* @returns The product of `a` and `b` as a `PositiveInt`
|
|
287
269
|
*/
|
|
288
270
|
mul,
|
|
289
271
|
|
|
290
272
|
/**
|
|
291
|
-
* Divides two positive integers using floor division
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* Performs mathematical floor division: `⌊a / b⌋`. If the result would be 0
|
|
295
|
-
* (when a < b), it is clamped to 1 to maintain the positive integer
|
|
296
|
-
* constraint.
|
|
273
|
+
* Divides two positive integers using floor division (`⌊a / b⌋`): the result
|
|
274
|
+
* is `a / b` rounded toward negative infinity, as a `PositiveInt`.
|
|
297
275
|
*
|
|
298
276
|
* @example
|
|
299
277
|
*
|
|
@@ -307,9 +285,9 @@ export const PositiveInt = {
|
|
|
307
285
|
* assert.isTrue(clamped === 1);
|
|
308
286
|
* ```
|
|
309
287
|
*
|
|
310
|
-
* @param a - The dividend
|
|
311
|
-
* @param b - The divisor (
|
|
312
|
-
* @returns
|
|
288
|
+
* @param a - The dividend
|
|
289
|
+
* @param b - The divisor (must be non-zero)
|
|
290
|
+
* @returns The floored quotient as a `PositiveInt`
|
|
313
291
|
*/
|
|
314
292
|
div,
|
|
315
293
|
} as const;
|