ts-data-forge 10.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/array/impl/array-utils-creation.d.mts +3 -3
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +4 -4
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/{guard/as-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-cast.d.mts} +9 -9
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -0
- package/dist/{guard/as-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-cast.mjs} +2 -2
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -0
- package/dist/{guard/is-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-guard.d.mts} +13 -13
- package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -0
- package/dist/{guard/is-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-guard.mjs} +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -0
- package/dist/array/impl/array-utils-modification.d.mts +9 -9
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +9 -9
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +3 -3
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +9 -9
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +16 -10
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/index.d.mts +2 -0
- package/dist/array/impl/index.d.mts.map +1 -1
- package/dist/array/impl/index.mjs +2 -0
- package/dist/array/impl/index.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -3
- package/dist/entry-point.mjs.map +1 -1
- package/dist/guard/index.d.mts +0 -3
- package/dist/guard/index.d.mts.map +1 -1
- package/dist/guard/index.mjs +0 -3
- package/dist/guard/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- 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/dist/string/index.d.mts +2 -0
- package/dist/string/index.d.mts.map +1 -0
- package/dist/string/index.mjs +2 -0
- package/dist/string/index.mjs.map +1 -0
- package/dist/string/str.d.mts +273 -0
- package/dist/string/str.d.mts.map +1 -0
- package/dist/string/str.mjs +42 -0
- package/dist/string/str.mjs.map +1 -0
- package/package.json +31 -92
- package/src/array/impl/array-utils-creation.mts +2 -1
- package/src/array/impl/array-utils-element-access.mts +3 -3
- package/src/array/impl/array-utils-element-access.test.mts +3 -3
- package/src/{guard/as-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-cast.mts} +9 -9
- package/src/{guard/as-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-cast.test.mts} +2 -2
- package/src/{guard/is-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-guard.mts} +12 -12
- package/src/{guard/is-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-guard.test.mts} +2 -2
- package/src/array/impl/array-utils-modification.mts +9 -8
- package/src/array/impl/array-utils-modification.test.mts +6 -1
- package/src/array/impl/array-utils-reducing-value.mts +9 -9
- package/src/array/impl/array-utils-size.mts +2 -2
- package/src/array/impl/array-utils-slicing.mts +24 -13
- package/src/array/impl/array-utils-transformation.mts +18 -12
- package/src/array/impl/array-utils-transformation.test.mts +12 -12
- package/src/array/impl/index.mts +2 -0
- package/src/guard/index.mts +0 -3
- package/src/index.mts +1 -0
- 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
- package/src/string/index.mts +1 -0
- package/src/string/str.mts +371 -0
- package/src/string/str.test.mts +215 -0
- package/dist/guard/as-length-bounded-array.d.mts.map +0 -1
- package/dist/guard/as-length-bounded-array.mjs.map +0 -1
- package/dist/guard/is-length-bounded-array.d.mts.map +0 -1
- package/dist/guard/is-length-bounded-array.mjs.map +0 -1
- package/dist/guard/is-length-bounded-string.d.mts +0 -163
- package/dist/guard/is-length-bounded-string.d.mts.map +0 -1
- package/dist/guard/is-length-bounded-string.mjs +0 -7
- package/dist/guard/is-length-bounded-string.mjs.map +0 -1
- package/src/guard/is-length-bounded-string.mts +0 -199
- package/src/guard/is-length-bounded-string.test.mts +0 -170
|
@@ -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;
|
|
@@ -34,131 +34,135 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* range [1, 2^15)).
|
|
37
|
+
* Type guard that checks if a value is a positive integer in [1, 2^15).
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a positive integer in [1, 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 positive integer in [1, 2^15), `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isPositiveInt16 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `PositiveInt16` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a positive integer in [1, 2^15) and returns it
|
|
51
|
+
* with the `PositiveInt16` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as a PositiveInt16
|
|
50
|
-
* @throws {TypeError} If the value is not a positive integer in [1, 2^15)
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as a `PositiveInt16`
|
|
55
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^15)
|
|
51
56
|
*/
|
|
52
57
|
export const asPositiveInt16 = castType;
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
|
-
* Namespace providing type-safe
|
|
56
|
-
*
|
|
60
|
+
* Namespace providing type-safe operations for the `PositiveInt16` branded
|
|
61
|
+
* type.
|
|
57
62
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* integer constraint, with results below 1 clamped to MIN_VALUE and overflow
|
|
61
|
-
* results clamped to MAX_VALUE.
|
|
63
|
+
* The `PositiveInt16` type represents a positive integer in [1, 2^15). Division
|
|
64
|
+
* (`div`) uses floor division.
|
|
62
65
|
*/
|
|
63
66
|
export const PositiveInt16 = {
|
|
64
67
|
/**
|
|
65
|
-
* Type guard
|
|
68
|
+
* Type guard that checks if a value is a positive integer in [1, 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 positive integer in [1, 2^15), `false` otherwise
|
|
72
|
+
* @see {@link isPositiveInt16} for usage examples
|
|
70
73
|
*/
|
|
71
74
|
is,
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
+
* The smallest value representable as `PositiveInt16`.
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
83
|
-
* @readonly
|
|
82
|
+
* The largest value representable as `PositiveInt16`.
|
|
84
83
|
*/
|
|
85
84
|
MAX_VALUE,
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
|
-
* Returns the
|
|
87
|
+
* Returns the smallest of the given positive integers.
|
|
89
88
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @
|
|
92
|
-
* @returns The minimum value as a PositiveInt16.
|
|
89
|
+
* @param values - The positive integers to compare (at least one required)
|
|
90
|
+
* @returns The smallest value as a `PositiveInt16`
|
|
93
91
|
*/
|
|
94
92
|
min: min_,
|
|
95
93
|
|
|
96
94
|
/**
|
|
97
|
-
* Returns the
|
|
95
|
+
* Returns the largest of the given positive integers.
|
|
98
96
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @
|
|
101
|
-
* @returns The maximum value as a PositiveInt16.
|
|
97
|
+
* @param values - The positive integers to compare (at least one required)
|
|
98
|
+
* @returns The largest value as a `PositiveInt16`
|
|
102
99
|
*/
|
|
103
100
|
max: max_,
|
|
104
101
|
|
|
105
102
|
/**
|
|
106
|
-
* Clamps a number
|
|
103
|
+
* Clamps a `number` into the `PositiveInt16` range, rounding to the nearest
|
|
104
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
107
105
|
*
|
|
108
|
-
* @param value The
|
|
109
|
-
* @returns The
|
|
106
|
+
* @param value - The value to clamp
|
|
107
|
+
* @returns The clamped value as a `PositiveInt16`
|
|
110
108
|
*/
|
|
111
109
|
clamp,
|
|
112
110
|
|
|
113
111
|
/**
|
|
114
|
-
* Generates a random PositiveInt16
|
|
112
|
+
* Generates a random `PositiveInt16` within the given range.
|
|
113
|
+
*
|
|
114
|
+
* The range is inclusive on both ends.
|
|
115
115
|
*
|
|
116
|
-
* @
|
|
116
|
+
* @param min - The minimum value (inclusive)
|
|
117
|
+
* @param max - The maximum value (inclusive)
|
|
118
|
+
* @returns A random `PositiveInt16` in `[min, max]`
|
|
117
119
|
*/
|
|
118
120
|
random,
|
|
119
121
|
|
|
120
122
|
/**
|
|
121
|
-
* Raises a
|
|
123
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `PositiveInt16`
|
|
124
|
+
* (floored to an integer).
|
|
122
125
|
*
|
|
123
|
-
* @param a The base
|
|
124
|
-
* @param b The exponent
|
|
125
|
-
* @returns `a ** b`
|
|
126
|
+
* @param a - The base positive integer
|
|
127
|
+
* @param b - The exponent positive integer
|
|
128
|
+
* @returns `a ** b` as a `PositiveInt16`
|
|
126
129
|
*/
|
|
127
130
|
pow,
|
|
128
131
|
|
|
129
132
|
/**
|
|
130
|
-
* Adds two PositiveInt16
|
|
133
|
+
* Adds two positive integers, returning `a + b` as a `PositiveInt16`.
|
|
131
134
|
*
|
|
132
|
-
* @param a The first
|
|
133
|
-
* @param b The second
|
|
134
|
-
* @returns `a
|
|
135
|
+
* @param a - The first positive integer
|
|
136
|
+
* @param b - The second positive integer
|
|
137
|
+
* @returns The sum of `a` and `b` as a `PositiveInt16`
|
|
135
138
|
*/
|
|
136
139
|
add,
|
|
137
140
|
|
|
138
141
|
/**
|
|
139
|
-
* Subtracts
|
|
142
|
+
* Subtracts two positive integers, returning `a - b` as a `PositiveInt16`.
|
|
140
143
|
*
|
|
141
|
-
* @param a The
|
|
142
|
-
* @param b The
|
|
143
|
-
* @returns `a
|
|
144
|
+
* @param a - The first positive integer
|
|
145
|
+
* @param b - The second positive integer
|
|
146
|
+
* @returns The difference of `a` and `b` as a `PositiveInt16`
|
|
144
147
|
*/
|
|
145
148
|
sub,
|
|
146
149
|
|
|
147
150
|
/**
|
|
148
|
-
* Multiplies two PositiveInt16
|
|
151
|
+
* Multiplies two positive integers, returning `a * b` as a `PositiveInt16`.
|
|
149
152
|
*
|
|
150
|
-
* @param a The first
|
|
151
|
-
* @param b The second
|
|
152
|
-
* @returns `a
|
|
153
|
+
* @param a - The first positive integer
|
|
154
|
+
* @param b - The second positive integer
|
|
155
|
+
* @returns The product of `a` and `b` as a `PositiveInt16`
|
|
153
156
|
*/
|
|
154
157
|
mul,
|
|
155
158
|
|
|
156
159
|
/**
|
|
157
|
-
* Divides
|
|
160
|
+
* Divides two positive integers using floor division (`⌊a / b⌋`): the result
|
|
161
|
+
* is `a / b` rounded toward negative infinity, as a `PositiveInt16`.
|
|
158
162
|
*
|
|
159
|
-
* @param a The dividend
|
|
160
|
-
* @param b The divisor
|
|
161
|
-
* @returns
|
|
163
|
+
* @param a - The dividend
|
|
164
|
+
* @param b - The divisor (must be non-zero)
|
|
165
|
+
* @returns The floored quotient as a `PositiveInt16`
|
|
162
166
|
*/
|
|
163
167
|
div,
|
|
164
168
|
} as const;
|
|
@@ -34,131 +34,135 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* range [1, 2^31)).
|
|
37
|
+
* Type guard that checks if a value is a positive integer in [1, 2^31).
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a positive integer in [1, 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 positive integer in [1, 2^31), `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isPositiveInt32 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `PositiveInt32` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a positive integer in [1, 2^31) and returns it
|
|
51
|
+
* with the `PositiveInt32` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as a PositiveInt32
|
|
50
|
-
* @throws {TypeError} If the value is not a positive integer in [1, 2^31)
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as a `PositiveInt32`
|
|
55
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^31)
|
|
51
56
|
*/
|
|
52
57
|
export const asPositiveInt32 = castType;
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
|
-
* Namespace providing type-safe
|
|
56
|
-
*
|
|
60
|
+
* Namespace providing type-safe operations for the `PositiveInt32` branded
|
|
61
|
+
* type.
|
|
57
62
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* positive integer constraint, with results below 1 clamped to MIN_VALUE and
|
|
61
|
-
* overflow results clamped to MAX_VALUE.
|
|
63
|
+
* The `PositiveInt32` type represents a positive integer in [1, 2^31). Division
|
|
64
|
+
* (`div`) uses floor division.
|
|
62
65
|
*/
|
|
63
66
|
export const PositiveInt32 = {
|
|
64
67
|
/**
|
|
65
|
-
* Type guard
|
|
68
|
+
* Type guard that checks if a value is a positive integer in [1, 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 positive integer in [1, 2^31), `false` otherwise
|
|
72
|
+
* @see {@link isPositiveInt32} for usage examples
|
|
70
73
|
*/
|
|
71
74
|
is,
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
+
* The smallest value representable as `PositiveInt32`.
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
83
|
-
* @readonly
|
|
82
|
+
* The largest value representable as `PositiveInt32`.
|
|
84
83
|
*/
|
|
85
84
|
MAX_VALUE,
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
|
-
* Returns the
|
|
87
|
+
* Returns the smallest of the given positive integers.
|
|
89
88
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @
|
|
92
|
-
* @returns The minimum value as a PositiveInt32.
|
|
89
|
+
* @param values - The positive integers to compare (at least one required)
|
|
90
|
+
* @returns The smallest value as a `PositiveInt32`
|
|
93
91
|
*/
|
|
94
92
|
min: min_,
|
|
95
93
|
|
|
96
94
|
/**
|
|
97
|
-
* Returns the
|
|
95
|
+
* Returns the largest of the given positive integers.
|
|
98
96
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @
|
|
101
|
-
* @returns The maximum value as a PositiveInt32.
|
|
97
|
+
* @param values - The positive integers to compare (at least one required)
|
|
98
|
+
* @returns The largest value as a `PositiveInt32`
|
|
102
99
|
*/
|
|
103
100
|
max: max_,
|
|
104
101
|
|
|
105
102
|
/**
|
|
106
|
-
* Clamps a number
|
|
103
|
+
* Clamps a `number` into the `PositiveInt32` range, rounding to the nearest
|
|
104
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
107
105
|
*
|
|
108
|
-
* @param value The
|
|
109
|
-
* @returns The
|
|
106
|
+
* @param value - The value to clamp
|
|
107
|
+
* @returns The clamped value as a `PositiveInt32`
|
|
110
108
|
*/
|
|
111
109
|
clamp,
|
|
112
110
|
|
|
113
111
|
/**
|
|
114
|
-
* Generates a random PositiveInt32
|
|
112
|
+
* Generates a random `PositiveInt32` within the given range.
|
|
113
|
+
*
|
|
114
|
+
* The range is inclusive on both ends.
|
|
115
115
|
*
|
|
116
|
-
* @
|
|
116
|
+
* @param min - The minimum value (inclusive)
|
|
117
|
+
* @param max - The maximum value (inclusive)
|
|
118
|
+
* @returns A random `PositiveInt32` in `[min, max]`
|
|
117
119
|
*/
|
|
118
120
|
random,
|
|
119
121
|
|
|
120
122
|
/**
|
|
121
|
-
* Raises a
|
|
123
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `PositiveInt32`
|
|
124
|
+
* (floored to an integer).
|
|
122
125
|
*
|
|
123
|
-
* @param a The base
|
|
124
|
-
* @param b The exponent
|
|
125
|
-
* @returns `a ** b`
|
|
126
|
+
* @param a - The base positive integer
|
|
127
|
+
* @param b - The exponent positive integer
|
|
128
|
+
* @returns `a ** b` as a `PositiveInt32`
|
|
126
129
|
*/
|
|
127
130
|
pow,
|
|
128
131
|
|
|
129
132
|
/**
|
|
130
|
-
* Adds two PositiveInt32
|
|
133
|
+
* Adds two positive integers, returning `a + b` as a `PositiveInt32`.
|
|
131
134
|
*
|
|
132
|
-
* @param a The first
|
|
133
|
-
* @param b The second
|
|
134
|
-
* @returns `a
|
|
135
|
+
* @param a - The first positive integer
|
|
136
|
+
* @param b - The second positive integer
|
|
137
|
+
* @returns The sum of `a` and `b` as a `PositiveInt32`
|
|
135
138
|
*/
|
|
136
139
|
add,
|
|
137
140
|
|
|
138
141
|
/**
|
|
139
|
-
* Subtracts
|
|
142
|
+
* Subtracts two positive integers, returning `a - b` as a `PositiveInt32`.
|
|
140
143
|
*
|
|
141
|
-
* @param a The
|
|
142
|
-
* @param b The
|
|
143
|
-
* @returns `a
|
|
144
|
+
* @param a - The first positive integer
|
|
145
|
+
* @param b - The second positive integer
|
|
146
|
+
* @returns The difference of `a` and `b` as a `PositiveInt32`
|
|
144
147
|
*/
|
|
145
148
|
sub,
|
|
146
149
|
|
|
147
150
|
/**
|
|
148
|
-
* Multiplies two PositiveInt32
|
|
151
|
+
* Multiplies two positive integers, returning `a * b` as a `PositiveInt32`.
|
|
149
152
|
*
|
|
150
|
-
* @param a The first
|
|
151
|
-
* @param b The second
|
|
152
|
-
* @returns `a
|
|
153
|
+
* @param a - The first positive integer
|
|
154
|
+
* @param b - The second positive integer
|
|
155
|
+
* @returns The product of `a` and `b` as a `PositiveInt32`
|
|
153
156
|
*/
|
|
154
157
|
mul,
|
|
155
158
|
|
|
156
159
|
/**
|
|
157
|
-
* Divides
|
|
160
|
+
* Divides two positive integers using floor division (`⌊a / b⌋`): the result
|
|
161
|
+
* is `a / b` rounded toward negative infinity, as a `PositiveInt32`.
|
|
158
162
|
*
|
|
159
|
-
* @param a The dividend
|
|
160
|
-
* @param b The divisor
|
|
161
|
-
* @returns
|
|
163
|
+
* @param a - The dividend
|
|
164
|
+
* @param b - The divisor (must be non-zero)
|
|
165
|
+
* @returns The floored quotient as a `PositiveInt32`
|
|
162
166
|
*/
|
|
163
167
|
div,
|
|
164
168
|
} as const;
|