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
|
@@ -3,8 +3,8 @@ export type PositiveInt = TtfImported_PositiveInt;
|
|
|
3
3
|
/**
|
|
4
4
|
* Type guard that checks if a value is a positive integer.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Returns `true` for a positive integer — a value with no fractional component,
|
|
7
|
+
* including values outside the safe integer range (unlike `SafeInt`).
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
*
|
|
@@ -21,11 +21,10 @@ export type PositiveInt = TtfImported_PositiveInt;
|
|
|
21
21
|
*/
|
|
22
22
|
export declare const isPositiveInt: (a: number) => a is TtfImported_PositiveInt;
|
|
23
23
|
/**
|
|
24
|
-
* Casts a number to
|
|
24
|
+
* Casts a `number` to the `PositiveInt` branded type.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* operations that require strictly positive integer values.
|
|
26
|
+
* Validates that the value is a positive integer and returns it with the
|
|
27
|
+
* `PositiveInt` brand. Throws a `TypeError` otherwise.
|
|
29
28
|
*
|
|
30
29
|
* @example
|
|
31
30
|
*
|
|
@@ -38,7 +37,7 @@ export declare const isPositiveInt: (a: number) => a is TtfImported_PositiveInt;
|
|
|
38
37
|
* ```
|
|
39
38
|
*
|
|
40
39
|
* @param value - The value to cast
|
|
41
|
-
* @returns The value as a PositiveInt
|
|
40
|
+
* @returns The value as a `PositiveInt`
|
|
42
41
|
* @throws {TypeError} If the value is not a positive integer
|
|
43
42
|
*/
|
|
44
43
|
export declare const asPositiveInt: <N extends number>(x: N) => number & {
|
|
@@ -56,20 +55,14 @@ export declare const asPositiveInt: <N extends number>(x: N) => number & {
|
|
|
56
55
|
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
57
56
|
}> & N;
|
|
58
57
|
/**
|
|
59
|
-
* Namespace providing type-safe operations for PositiveInt branded
|
|
58
|
+
* Namespace providing type-safe operations for the `PositiveInt` branded type.
|
|
60
59
|
*
|
|
61
|
-
* PositiveInt represents
|
|
62
|
-
*
|
|
63
|
-
* constraint, ensuring that arithmetic operations never produce zero or
|
|
64
|
-
* negative values.
|
|
60
|
+
* The `PositiveInt` type represents a positive integer. Division (`div`) uses
|
|
61
|
+
* floor division.
|
|
65
62
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* - Counts and quantities that must be positive
|
|
70
|
-
* - Denominators in division operations
|
|
71
|
-
* - Loop counters and iteration counts
|
|
72
|
-
* - Database primary keys and IDs
|
|
63
|
+
* Unlike `SafeInt`, `PositiveInt` allows values outside the safe integer range
|
|
64
|
+
* (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's
|
|
65
|
+
* `number` type.
|
|
73
66
|
*/
|
|
74
67
|
export declare const PositiveInt: {
|
|
75
68
|
/**
|
|
@@ -91,16 +84,11 @@ export declare const PositiveInt: {
|
|
|
91
84
|
*/
|
|
92
85
|
readonly is: (a: number) => a is TtfImported_PositiveInt;
|
|
93
86
|
/**
|
|
94
|
-
* The
|
|
95
|
-
*
|
|
96
|
-
* @readonly
|
|
87
|
+
* The smallest value representable as `PositiveInt`.
|
|
97
88
|
*/
|
|
98
89
|
readonly MIN_VALUE: 1;
|
|
99
90
|
/**
|
|
100
|
-
* Returns the
|
|
101
|
-
*
|
|
102
|
-
* Since all inputs are guaranteed to be >= 1, the result is also guaranteed
|
|
103
|
-
* to be a positive integer.
|
|
91
|
+
* Returns the smallest of the given positive integers.
|
|
104
92
|
*
|
|
105
93
|
* @example
|
|
106
94
|
*
|
|
@@ -115,11 +103,11 @@ export declare const PositiveInt: {
|
|
|
115
103
|
* ```
|
|
116
104
|
*
|
|
117
105
|
* @param values - The positive integers to compare (at least one required)
|
|
118
|
-
* @returns The smallest value as a PositiveInt
|
|
106
|
+
* @returns The smallest value as a `PositiveInt`
|
|
119
107
|
*/
|
|
120
108
|
readonly min: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>[]) => TtfImported_PositiveInt;
|
|
121
109
|
/**
|
|
122
|
-
* Returns the
|
|
110
|
+
* Returns the largest of the given positive integers.
|
|
123
111
|
*
|
|
124
112
|
* @example
|
|
125
113
|
*
|
|
@@ -134,14 +122,12 @@ export declare const PositiveInt: {
|
|
|
134
122
|
* ```
|
|
135
123
|
*
|
|
136
124
|
* @param values - The positive integers to compare (at least one required)
|
|
137
|
-
* @returns The largest value as a PositiveInt
|
|
125
|
+
* @returns The largest value as a `PositiveInt`
|
|
138
126
|
*/
|
|
139
127
|
readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>[]) => TtfImported_PositiveInt;
|
|
140
128
|
/**
|
|
141
|
-
* Clamps a number
|
|
142
|
-
*
|
|
143
|
-
* Since PositiveInt has a minimum value of 1, this function ensures that any
|
|
144
|
-
* input less than 1 is clamped to 1.
|
|
129
|
+
* Clamps a `number` into the `PositiveInt` range, rounding to the nearest
|
|
130
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
145
131
|
*
|
|
146
132
|
* @example
|
|
147
133
|
*
|
|
@@ -155,15 +141,14 @@ export declare const PositiveInt: {
|
|
|
155
141
|
* assert.isTrue(withinRange === 10);
|
|
156
142
|
* ```
|
|
157
143
|
*
|
|
158
|
-
* @param value - The
|
|
159
|
-
* @returns The
|
|
144
|
+
* @param value - The value to clamp
|
|
145
|
+
* @returns The clamped value as a `PositiveInt`
|
|
160
146
|
*/
|
|
161
147
|
readonly clamp: (x: number) => TtfImported_PositiveInt;
|
|
162
148
|
/**
|
|
163
|
-
* Generates a random
|
|
149
|
+
* Generates a random `PositiveInt` within the given range.
|
|
164
150
|
*
|
|
165
|
-
*
|
|
166
|
-
* If min > max, they are automatically swapped.
|
|
151
|
+
* The range is inclusive on both ends.
|
|
167
152
|
*
|
|
168
153
|
* @example
|
|
169
154
|
*
|
|
@@ -179,14 +164,14 @@ export declare const PositiveInt: {
|
|
|
179
164
|
* assert.isTrue(randomValue >= 3 && randomValue <= 6);
|
|
180
165
|
* ```
|
|
181
166
|
*
|
|
182
|
-
* @param min - The minimum value (inclusive
|
|
183
|
-
* @param max - The maximum value (inclusive
|
|
184
|
-
* @returns A random PositiveInt in
|
|
167
|
+
* @param min - The minimum value (inclusive)
|
|
168
|
+
* @param max - The maximum value (inclusive)
|
|
169
|
+
* @returns A random `PositiveInt` in `[min, max]`
|
|
185
170
|
*/
|
|
186
171
|
readonly random: (min?: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt> | undefined, max?: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt> | undefined) => TtfImported_PositiveInt;
|
|
187
172
|
/**
|
|
188
|
-
* Raises a
|
|
189
|
-
*
|
|
173
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `PositiveInt` (floored
|
|
174
|
+
* to an integer).
|
|
190
175
|
*
|
|
191
176
|
* @example
|
|
192
177
|
*
|
|
@@ -202,11 +187,11 @@ export declare const PositiveInt: {
|
|
|
202
187
|
*
|
|
203
188
|
* @param a - The base positive integer
|
|
204
189
|
* @param b - The exponent positive integer
|
|
205
|
-
* @returns `a ** b` as a PositiveInt
|
|
190
|
+
* @returns `a ** b` as a `PositiveInt`
|
|
206
191
|
*/
|
|
207
192
|
readonly pow: (x: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>) => TtfImported_PositiveInt;
|
|
208
193
|
/**
|
|
209
|
-
* Adds two positive integers,
|
|
194
|
+
* Adds two positive integers, returning `a + b` as a `PositiveInt`.
|
|
210
195
|
*
|
|
211
196
|
* @example
|
|
212
197
|
*
|
|
@@ -216,16 +201,13 @@ export declare const PositiveInt: {
|
|
|
216
201
|
* assert.isTrue(sum === 9);
|
|
217
202
|
* ```
|
|
218
203
|
*
|
|
219
|
-
* @param a -
|
|
220
|
-
* @param b -
|
|
221
|
-
* @returns `a
|
|
204
|
+
* @param a - The first positive integer
|
|
205
|
+
* @param b - The second positive integer
|
|
206
|
+
* @returns The sum of `a` and `b` as a `PositiveInt`
|
|
222
207
|
*/
|
|
223
208
|
readonly add: (x: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>) => TtfImported_PositiveInt;
|
|
224
209
|
/**
|
|
225
|
-
* Subtracts two positive integers,
|
|
226
|
-
*
|
|
227
|
-
* If the mathematical result would be <= 0, it is clamped to 1 to maintain
|
|
228
|
-
* the positive integer constraint.
|
|
210
|
+
* Subtracts two positive integers, returning `a - b` as a `PositiveInt`.
|
|
229
211
|
*
|
|
230
212
|
* @example
|
|
231
213
|
*
|
|
@@ -235,13 +217,13 @@ export declare const PositiveInt: {
|
|
|
235
217
|
* assert.isTrue(difference === 1);
|
|
236
218
|
* ```
|
|
237
219
|
*
|
|
238
|
-
* @param a - The
|
|
239
|
-
* @param b - The
|
|
240
|
-
* @returns `
|
|
220
|
+
* @param a - The first positive integer
|
|
221
|
+
* @param b - The second positive integer
|
|
222
|
+
* @returns The difference of `a` and `b` as a `PositiveInt`
|
|
241
223
|
*/
|
|
242
224
|
readonly sub: (x: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>) => TtfImported_PositiveInt;
|
|
243
225
|
/**
|
|
244
|
-
* Multiplies two positive integers,
|
|
226
|
+
* Multiplies two positive integers, returning `a * b` as a `PositiveInt`.
|
|
245
227
|
*
|
|
246
228
|
* @example
|
|
247
229
|
*
|
|
@@ -251,18 +233,14 @@ export declare const PositiveInt: {
|
|
|
251
233
|
* assert.isTrue(product === 21);
|
|
252
234
|
* ```
|
|
253
235
|
*
|
|
254
|
-
* @param a -
|
|
255
|
-
* @param b -
|
|
256
|
-
* @returns `a
|
|
236
|
+
* @param a - The first positive integer
|
|
237
|
+
* @param b - The second positive integer
|
|
238
|
+
* @returns The product of `a` and `b` as a `PositiveInt`
|
|
257
239
|
*/
|
|
258
240
|
readonly mul: (x: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>) => TtfImported_PositiveInt;
|
|
259
241
|
/**
|
|
260
|
-
* Divides two positive integers using floor division
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* Performs mathematical floor division: `⌊a / b⌋`. If the result would be 0
|
|
264
|
-
* (when a < b), it is clamped to 1 to maintain the positive integer
|
|
265
|
-
* constraint.
|
|
242
|
+
* Divides two positive integers using floor division (`⌊a / b⌋`): the result
|
|
243
|
+
* is `a / b` rounded toward negative infinity, as a `PositiveInt`.
|
|
266
244
|
*
|
|
267
245
|
* @example
|
|
268
246
|
*
|
|
@@ -276,9 +254,9 @@ export declare const PositiveInt: {
|
|
|
276
254
|
* assert.isTrue(clamped === 1);
|
|
277
255
|
* ```
|
|
278
256
|
*
|
|
279
|
-
* @param a - The dividend
|
|
280
|
-
* @param b - The divisor (
|
|
281
|
-
* @returns
|
|
257
|
+
* @param a - The dividend
|
|
258
|
+
* @param b - The divisor (must be non-zero)
|
|
259
|
+
* @returns The floored quotient as a `PositiveInt`
|
|
282
260
|
*/
|
|
283
261
|
readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>, y: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | import("ts-type-forge").NormalizeBrandUnion<number & {
|
|
284
262
|
readonly "!=0": true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"positive-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-int.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,IAAI,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAI5E,MAAM,MAAM,WAAW,GAAG,uBAAuB,CAAC;AA8BlD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,6CAAK,CAAC;AAEhC
|
|
1
|
+
{"version":3,"file":"positive-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-int.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,IAAI,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAI5E,MAAM,MAAM,WAAW,GAAG,uBAAuB,CAAC;AA8BlD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,6CAAK,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;MAAW,CAAC;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;;;;;;;;;;;OAgBG;;IAGH;;OAEG;;IAGH;;;;;;;;;;;;;;;;;OAiBG;;IAGH;;;;;;;;;;;;;;;;;OAiBG;;IAGH;;;;;;;;;;;;;;;;;;OAkBG;;IAGH;;;;;;;;;;;;;;;;;;;;;;OAsBG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;IAGH;;;;;;;;;;;;;;OAcG;;IAGH;;;;;;;;;;;;;;OAcG;;IAGH;;;;;;;;;;;;;;OAcG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -42,16 +42,11 @@ const PositiveInt = {
|
|
|
42
42
|
*/
|
|
43
43
|
is,
|
|
44
44
|
/**
|
|
45
|
-
* The
|
|
46
|
-
*
|
|
47
|
-
* @readonly
|
|
45
|
+
* The smallest value representable as `PositiveInt`.
|
|
48
46
|
*/
|
|
49
47
|
MIN_VALUE,
|
|
50
48
|
/**
|
|
51
|
-
* Returns the
|
|
52
|
-
*
|
|
53
|
-
* Since all inputs are guaranteed to be >= 1, the result is also guaranteed
|
|
54
|
-
* to be a positive integer.
|
|
49
|
+
* Returns the smallest of the given positive integers.
|
|
55
50
|
*
|
|
56
51
|
* @example
|
|
57
52
|
*
|
|
@@ -66,11 +61,11 @@ const PositiveInt = {
|
|
|
66
61
|
* ```
|
|
67
62
|
*
|
|
68
63
|
* @param values - The positive integers to compare (at least one required)
|
|
69
|
-
* @returns The smallest value as a PositiveInt
|
|
64
|
+
* @returns The smallest value as a `PositiveInt`
|
|
70
65
|
*/
|
|
71
66
|
min: min_,
|
|
72
67
|
/**
|
|
73
|
-
* Returns the
|
|
68
|
+
* Returns the largest of the given positive integers.
|
|
74
69
|
*
|
|
75
70
|
* @example
|
|
76
71
|
*
|
|
@@ -85,14 +80,12 @@ const PositiveInt = {
|
|
|
85
80
|
* ```
|
|
86
81
|
*
|
|
87
82
|
* @param values - The positive integers to compare (at least one required)
|
|
88
|
-
* @returns The largest value as a PositiveInt
|
|
83
|
+
* @returns The largest value as a `PositiveInt`
|
|
89
84
|
*/
|
|
90
85
|
max: max_,
|
|
91
86
|
/**
|
|
92
|
-
* Clamps a number
|
|
93
|
-
*
|
|
94
|
-
* Since PositiveInt has a minimum value of 1, this function ensures that any
|
|
95
|
-
* input less than 1 is clamped to 1.
|
|
87
|
+
* Clamps a `number` into the `PositiveInt` range, rounding to the nearest
|
|
88
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
96
89
|
*
|
|
97
90
|
* @example
|
|
98
91
|
*
|
|
@@ -106,15 +99,14 @@ const PositiveInt = {
|
|
|
106
99
|
* assert.isTrue(withinRange === 10);
|
|
107
100
|
* ```
|
|
108
101
|
*
|
|
109
|
-
* @param value - The
|
|
110
|
-
* @returns The
|
|
102
|
+
* @param value - The value to clamp
|
|
103
|
+
* @returns The clamped value as a `PositiveInt`
|
|
111
104
|
*/
|
|
112
105
|
clamp,
|
|
113
106
|
/**
|
|
114
|
-
* Generates a random
|
|
107
|
+
* Generates a random `PositiveInt` within the given range.
|
|
115
108
|
*
|
|
116
|
-
*
|
|
117
|
-
* If min > max, they are automatically swapped.
|
|
109
|
+
* The range is inclusive on both ends.
|
|
118
110
|
*
|
|
119
111
|
* @example
|
|
120
112
|
*
|
|
@@ -130,14 +122,14 @@ const PositiveInt = {
|
|
|
130
122
|
* assert.isTrue(randomValue >= 3 && randomValue <= 6);
|
|
131
123
|
* ```
|
|
132
124
|
*
|
|
133
|
-
* @param min - The minimum value (inclusive
|
|
134
|
-
* @param max - The maximum value (inclusive
|
|
135
|
-
* @returns A random PositiveInt in
|
|
125
|
+
* @param min - The minimum value (inclusive)
|
|
126
|
+
* @param max - The maximum value (inclusive)
|
|
127
|
+
* @returns A random `PositiveInt` in `[min, max]`
|
|
136
128
|
*/
|
|
137
129
|
random,
|
|
138
130
|
/**
|
|
139
|
-
* Raises a
|
|
140
|
-
*
|
|
131
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `PositiveInt` (floored
|
|
132
|
+
* to an integer).
|
|
141
133
|
*
|
|
142
134
|
* @example
|
|
143
135
|
*
|
|
@@ -153,11 +145,11 @@ const PositiveInt = {
|
|
|
153
145
|
*
|
|
154
146
|
* @param a - The base positive integer
|
|
155
147
|
* @param b - The exponent positive integer
|
|
156
|
-
* @returns `a ** b` as a PositiveInt
|
|
148
|
+
* @returns `a ** b` as a `PositiveInt`
|
|
157
149
|
*/
|
|
158
150
|
pow,
|
|
159
151
|
/**
|
|
160
|
-
* Adds two positive integers,
|
|
152
|
+
* Adds two positive integers, returning `a + b` as a `PositiveInt`.
|
|
161
153
|
*
|
|
162
154
|
* @example
|
|
163
155
|
*
|
|
@@ -167,16 +159,13 @@ const PositiveInt = {
|
|
|
167
159
|
* assert.isTrue(sum === 9);
|
|
168
160
|
* ```
|
|
169
161
|
*
|
|
170
|
-
* @param a -
|
|
171
|
-
* @param b -
|
|
172
|
-
* @returns `a
|
|
162
|
+
* @param a - The first positive integer
|
|
163
|
+
* @param b - The second positive integer
|
|
164
|
+
* @returns The sum of `a` and `b` as a `PositiveInt`
|
|
173
165
|
*/
|
|
174
166
|
add,
|
|
175
167
|
/**
|
|
176
|
-
* Subtracts two positive integers,
|
|
177
|
-
*
|
|
178
|
-
* If the mathematical result would be <= 0, it is clamped to 1 to maintain
|
|
179
|
-
* the positive integer constraint.
|
|
168
|
+
* Subtracts two positive integers, returning `a - b` as a `PositiveInt`.
|
|
180
169
|
*
|
|
181
170
|
* @example
|
|
182
171
|
*
|
|
@@ -186,13 +175,13 @@ const PositiveInt = {
|
|
|
186
175
|
* assert.isTrue(difference === 1);
|
|
187
176
|
* ```
|
|
188
177
|
*
|
|
189
|
-
* @param a - The
|
|
190
|
-
* @param b - The
|
|
191
|
-
* @returns `
|
|
178
|
+
* @param a - The first positive integer
|
|
179
|
+
* @param b - The second positive integer
|
|
180
|
+
* @returns The difference of `a` and `b` as a `PositiveInt`
|
|
192
181
|
*/
|
|
193
182
|
sub,
|
|
194
183
|
/**
|
|
195
|
-
* Multiplies two positive integers,
|
|
184
|
+
* Multiplies two positive integers, returning `a * b` as a `PositiveInt`.
|
|
196
185
|
*
|
|
197
186
|
* @example
|
|
198
187
|
*
|
|
@@ -202,18 +191,14 @@ const PositiveInt = {
|
|
|
202
191
|
* assert.isTrue(product === 21);
|
|
203
192
|
* ```
|
|
204
193
|
*
|
|
205
|
-
* @param a -
|
|
206
|
-
* @param b -
|
|
207
|
-
* @returns `a
|
|
194
|
+
* @param a - The first positive integer
|
|
195
|
+
* @param b - The second positive integer
|
|
196
|
+
* @returns The product of `a` and `b` as a `PositiveInt`
|
|
208
197
|
*/
|
|
209
198
|
mul,
|
|
210
199
|
/**
|
|
211
|
-
* Divides two positive integers using floor division
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* Performs mathematical floor division: `⌊a / b⌋`. If the result would be 0
|
|
215
|
-
* (when a < b), it is clamped to 1 to maintain the positive integer
|
|
216
|
-
* constraint.
|
|
200
|
+
* Divides two positive integers using floor division (`⌊a / b⌋`): the result
|
|
201
|
+
* is `a / b` rounded toward negative infinity, as a `PositiveInt`.
|
|
217
202
|
*
|
|
218
203
|
* @example
|
|
219
204
|
*
|
|
@@ -227,9 +212,9 @@ const PositiveInt = {
|
|
|
227
212
|
* assert.isTrue(clamped === 1);
|
|
228
213
|
* ```
|
|
229
214
|
*
|
|
230
|
-
* @param a - The dividend
|
|
231
|
-
* @param b - The divisor (
|
|
232
|
-
* @returns
|
|
215
|
+
* @param a - The dividend
|
|
216
|
+
* @param b - The divisor (must be non-zero)
|
|
217
|
+
* @returns The floored quotient as a `PositiveInt`
|
|
233
218
|
*/
|
|
234
219
|
div
|
|
235
220
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"positive-int.mjs","sources":["../../../src/number/branded-types/positive-int.mts"],"sourcesContent":["import { type PositiveInt as TtfImported_PositiveInt } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveInt = TtfImported_PositiveInt;\n\ntype ElementType = PositiveInt;\n\nconst typeNameInMessage = 'a positive integer';\n\nconst {\n MIN_VALUE,\n add,\n castType,\n clamp,\n div,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 1,\n number\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: 1,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a positive integer.\n *\n * A positive integer is any integer greater than zero (>= 1). This excludes\n * zero, negative numbers, and non-integers.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isPositiveInt(5));\n *\n * assert.isFalse(isPositiveInt(0));\n *\n * assert.isTrue(PositiveInt.is(10));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer, `false` otherwise\n */\nexport const isPositiveInt = is;\n\n/**\n * Casts a number to a PositiveInt branded type.\n *\n * This function validates that the input is a positive integer (>= 1) and\n * returns it with the PositiveInt brand. This ensures type safety for\n * operations that require strictly positive integer values.\n *\n * @example\n *\n * ```ts\n * const branded = asPositiveInt(7);\n *\n * assert.isTrue(branded === 7);\n *\n * assert.isTrue(PositiveInt.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as a PositiveInt branded type\n * @throws {TypeError} If the value is not a positive integer\n */\nexport const asPositiveInt = castType;\n\n/**\n * Namespace providing type-safe operations for PositiveInt branded types.\n *\n * PositiveInt represents integers that are strictly greater than zero (>= 1).\n * All operations automatically clamp results to maintain the positive\n * constraint, ensuring that arithmetic operations never produce zero or\n * negative values.\n *\n * This type is essential for:\n *\n * - Array lengths and sizes (length >= 1)\n * - Counts and quantities that must be positive\n * - Denominators in division operations\n * - Loop counters and iteration counts\n * - Database primary keys and IDs\n */\nexport const PositiveInt = {\n /**\n * Type guard that checks if a value is a positive integer.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isPositiveInt(5));\n *\n * assert.isFalse(isPositiveInt(0));\n *\n * assert.isTrue(PositiveInt.is(10));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer, `false` otherwise\n * @see {@link isPositiveInt} for usage examples\n */\n is,\n\n /**\n * The minimum value for a PositiveInt.\n *\n * @readonly\n */\n MIN_VALUE,\n\n /**\n * Returns the minimum value from a list of positive integers.\n *\n * Since all inputs are guaranteed to be >= 1, the result is also guaranteed\n * to be a positive integer.\n *\n * @example\n *\n * ```ts\n * const smallest = PositiveInt.min(\n * asPositiveInt(9),\n * asPositiveInt(3),\n * asPositiveInt(12),\n * );\n *\n * assert.isTrue(smallest === 3);\n * ```\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The smallest value as a PositiveInt\n */\n min: min_,\n\n /**\n * Returns the maximum value from a list of positive integers.\n *\n * @example\n *\n * ```ts\n * const largest = PositiveInt.max(\n * asPositiveInt(9),\n * asPositiveInt(3),\n * asPositiveInt(12),\n * );\n *\n * assert.isTrue(largest === 12);\n * ```\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The largest value as a PositiveInt\n */\n max: max_,\n\n /**\n * Clamps a number to the positive integer range.\n *\n * Since PositiveInt has a minimum value of 1, this function ensures that any\n * input less than 1 is clamped to 1.\n *\n * @example\n *\n * ```ts\n * const belowRange = PositiveInt.clamp(0);\n *\n * const withinRange = PositiveInt.clamp(10);\n *\n * assert.isTrue(belowRange === 1);\n *\n * assert.isTrue(withinRange === 10);\n * ```\n *\n * @param value - The number to clamp\n * @returns The value clamped to >= 1 as a PositiveInt\n */\n clamp,\n\n /**\n * Generates a random positive integer within the specified range (inclusive).\n *\n * Both bounds are inclusive, and both min and max must be positive integers.\n * If min > max, they are automatically swapped.\n *\n * @example\n *\n * ```ts\n * const min = asPositiveInt(3);\n *\n * const max = asPositiveInt(6);\n *\n * const randomValue = PositiveInt.random(min, max);\n *\n * assert.isTrue(PositiveInt.is(randomValue));\n *\n * assert.isTrue(randomValue >= 3 && randomValue <= 6);\n * ```\n *\n * @param min - The minimum value (inclusive, must be >= 1)\n * @param max - The maximum value (inclusive, must be >= min)\n * @returns A random PositiveInt in the range [min, max]\n */\n random,\n\n /**\n * Raises a positive integer to a power, ensuring the result is never less\n * than 1.\n *\n * @example\n *\n * ```ts\n * const base = asPositiveInt(2);\n *\n * const exponent = asPositiveInt(4);\n *\n * const power = PositiveInt.pow(base, exponent);\n *\n * assert.isTrue(power === 16);\n * ```\n *\n * @param a - The base positive integer\n * @param b - The exponent positive integer\n * @returns `a ** b` as a PositiveInt, but never less than 1\n */\n pow,\n\n /**\n * Adds two positive integers, ensuring the result is never less than 1.\n *\n * @example\n *\n * ```ts\n * const sum = PositiveInt.add(asPositiveInt(4), asPositiveInt(5));\n *\n * assert.isTrue(sum === 9);\n * ```\n *\n * @param a - First positive integer\n * @param b - Second positive integer\n * @returns `a + b` as a PositiveInt, but never less than 1\n */\n add,\n\n /**\n * Subtracts two positive integers, clamping the result to remain positive.\n *\n * If the mathematical result would be <= 0, it is clamped to 1 to maintain\n * the positive integer constraint.\n *\n * @example\n *\n * ```ts\n * const difference = PositiveInt.sub(asPositiveInt(5), asPositiveInt(7));\n *\n * assert.isTrue(difference === 1);\n * ```\n *\n * @param a - The minuend (positive integer)\n * @param b - The subtrahend (positive integer)\n * @returns `max(1, a - b)` as a PositiveInt\n */\n sub,\n\n /**\n * Multiplies two positive integers, ensuring the result is never less than 1.\n *\n * @example\n *\n * ```ts\n * const product = PositiveInt.mul(asPositiveInt(3), asPositiveInt(7));\n *\n * assert.isTrue(product === 21);\n * ```\n *\n * @param a - First positive integer\n * @param b - Second positive integer\n * @returns `a * b` as a PositiveInt, but never less than 1\n */\n mul,\n\n /**\n * Divides two positive integers using floor division, clamping to remain\n * positive.\n *\n * Performs mathematical floor division: `⌊a / b⌋`. If the result would be 0\n * (when a < b), it is clamped to 1 to maintain the positive integer\n * constraint.\n *\n * @example\n *\n * ```ts\n * const quotient = PositiveInt.div(asPositiveInt(9), asPositiveInt(2));\n *\n * const clamped = PositiveInt.div(asPositiveInt(3), asPositiveInt(10));\n *\n * assert.isTrue(quotient === 4);\n *\n * assert.isTrue(clamped === 1);\n * ```\n *\n * @param a - The dividend (positive integer)\n * @param b - The divisor (positive integer, guaranteed non-zero)\n * @returns `max(1, ⌊a / b⌋)` as a PositiveInt\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof PositiveInt,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive'\n >\n>('=');\n\nexpectType<\n typeof PositiveInt,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,oBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,GAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA,EACX,WAAW,MAAA,CAAO,SAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAqBH,MAAM,aAAA,GAAgB;AAuBtB,MAAM,aAAA,GAAgB;AAkBtB,MAAM,WAAA,GAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBzB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"positive-int.mjs","sources":["../../../src/number/branded-types/positive-int.mts"],"sourcesContent":["import { type PositiveInt as TtfImported_PositiveInt } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveInt = TtfImported_PositiveInt;\n\ntype ElementType = PositiveInt;\n\nconst typeNameInMessage = 'a positive integer';\n\nconst {\n MIN_VALUE,\n add,\n castType,\n clamp,\n div,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n 1,\n number\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: 1,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a positive integer.\n *\n * Returns `true` for a positive integer — a value with no fractional component,\n * including values outside the safe integer range (unlike `SafeInt`).\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isPositiveInt(5));\n *\n * assert.isFalse(isPositiveInt(0));\n *\n * assert.isTrue(PositiveInt.is(10));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer, `false` otherwise\n */\nexport const isPositiveInt = is;\n\n/**\n * Casts a `number` to the `PositiveInt` branded type.\n *\n * Validates that the value is a positive integer and returns it with the\n * `PositiveInt` brand. Throws a `TypeError` otherwise.\n *\n * @example\n *\n * ```ts\n * const branded = asPositiveInt(7);\n *\n * assert.isTrue(branded === 7);\n *\n * assert.isTrue(PositiveInt.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as a `PositiveInt`\n * @throws {TypeError} If the value is not a positive integer\n */\nexport const asPositiveInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `PositiveInt` branded type.\n *\n * The `PositiveInt` type represents a positive integer. Division (`div`) uses\n * floor division.\n *\n * Unlike `SafeInt`, `PositiveInt` allows values outside the safe integer range\n * (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's\n * `number` type.\n */\nexport const PositiveInt = {\n /**\n * Type guard that checks if a value is a positive integer.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isPositiveInt(5));\n *\n * assert.isFalse(isPositiveInt(0));\n *\n * assert.isTrue(PositiveInt.is(10));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive integer, `false` otherwise\n * @see {@link isPositiveInt} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `PositiveInt`.\n */\n MIN_VALUE,\n\n /**\n * Returns the smallest of the given positive integers.\n *\n * @example\n *\n * ```ts\n * const smallest = PositiveInt.min(\n * asPositiveInt(9),\n * asPositiveInt(3),\n * asPositiveInt(12),\n * );\n *\n * assert.isTrue(smallest === 3);\n * ```\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The smallest value as a `PositiveInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given positive integers.\n *\n * @example\n *\n * ```ts\n * const largest = PositiveInt.max(\n * asPositiveInt(9),\n * asPositiveInt(3),\n * asPositiveInt(12),\n * );\n *\n * assert.isTrue(largest === 12);\n * ```\n *\n * @param values - The positive integers to compare (at least one required)\n * @returns The largest value as a `PositiveInt`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `PositiveInt` range, rounding to the nearest\n * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @example\n *\n * ```ts\n * const belowRange = PositiveInt.clamp(0);\n *\n * const withinRange = PositiveInt.clamp(10);\n *\n * assert.isTrue(belowRange === 1);\n *\n * assert.isTrue(withinRange === 10);\n * ```\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `PositiveInt`\n */\n clamp,\n\n /**\n * Generates a random `PositiveInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @example\n *\n * ```ts\n * const min = asPositiveInt(3);\n *\n * const max = asPositiveInt(6);\n *\n * const randomValue = PositiveInt.random(min, max);\n *\n * assert.isTrue(PositiveInt.is(randomValue));\n *\n * assert.isTrue(randomValue >= 3 && randomValue <= 6);\n * ```\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `PositiveInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `PositiveInt` (floored\n * to an integer).\n *\n * @example\n *\n * ```ts\n * const base = asPositiveInt(2);\n *\n * const exponent = asPositiveInt(4);\n *\n * const power = PositiveInt.pow(base, exponent);\n *\n * assert.isTrue(power === 16);\n * ```\n *\n * @param a - The base positive integer\n * @param b - The exponent positive integer\n * @returns `a ** b` as a `PositiveInt`\n */\n pow,\n\n /**\n * Adds two positive integers, returning `a + b` as a `PositiveInt`.\n *\n * @example\n *\n * ```ts\n * const sum = PositiveInt.add(asPositiveInt(4), asPositiveInt(5));\n *\n * assert.isTrue(sum === 9);\n * ```\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The sum of `a` and `b` as a `PositiveInt`\n */\n add,\n\n /**\n * Subtracts two positive integers, returning `a - b` as a `PositiveInt`.\n *\n * @example\n *\n * ```ts\n * const difference = PositiveInt.sub(asPositiveInt(5), asPositiveInt(7));\n *\n * assert.isTrue(difference === 1);\n * ```\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The difference of `a` and `b` as a `PositiveInt`\n */\n sub,\n\n /**\n * Multiplies two positive integers, returning `a * b` as a `PositiveInt`.\n *\n * @example\n *\n * ```ts\n * const product = PositiveInt.mul(asPositiveInt(3), asPositiveInt(7));\n *\n * assert.isTrue(product === 21);\n * ```\n *\n * @param a - The first positive integer\n * @param b - The second positive integer\n * @returns The product of `a` and `b` as a `PositiveInt`\n */\n mul,\n\n /**\n * Divides two positive integers using floor division (`⌊a / b⌋`): the result\n * is `a / b` rounded toward negative infinity, as a `PositiveInt`.\n *\n * @example\n *\n * ```ts\n * const quotient = PositiveInt.div(asPositiveInt(9), asPositiveInt(2));\n *\n * const clamped = PositiveInt.div(asPositiveInt(3), asPositiveInt(10));\n *\n * assert.isTrue(quotient === 4);\n *\n * assert.isTrue(clamped === 1);\n * ```\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `PositiveInt`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof PositiveInt,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive'\n >\n>('=');\n\nexpectType<\n typeof PositiveInt,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'positive'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,oBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,GAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA,EACX,WAAW,MAAA,CAAO,SAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAqBH,MAAM,aAAA,GAAgB;AAsBtB,MAAM,aAAA,GAAgB;AAYtB,MAAM,WAAA,GAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBzB,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA;AACF;;;;"}
|