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
|
@@ -39,108 +39,116 @@ const isPositiveFiniteNumber = is;
|
|
|
39
39
|
const asPositiveFiniteNumber = castType;
|
|
40
40
|
const PositiveFiniteNumber = {
|
|
41
41
|
/**
|
|
42
|
-
* Type guard
|
|
42
|
+
* Type guard that checks if a value is a positive finite number.
|
|
43
43
|
*
|
|
44
|
-
* @param value The value to check
|
|
45
|
-
* @returns `true` if the value is a positive finite number, `false`
|
|
46
|
-
*
|
|
44
|
+
* @param value - The value to check
|
|
45
|
+
* @returns `true` if the value is a positive finite number, `false` otherwise
|
|
46
|
+
* @see {@link isPositiveFiniteNumber} for usage examples
|
|
47
47
|
*/
|
|
48
48
|
is,
|
|
49
49
|
/**
|
|
50
|
-
* The
|
|
51
|
-
*
|
|
52
|
-
* @readonly
|
|
50
|
+
* The smallest value representable as `PositiveFiniteNumber`.
|
|
53
51
|
*/
|
|
54
52
|
MIN_VALUE,
|
|
55
53
|
/**
|
|
56
|
-
* Returns the
|
|
54
|
+
* Returns the smallest of the given positive finite numbers.
|
|
57
55
|
*
|
|
58
|
-
* @param
|
|
59
|
-
* @
|
|
60
|
-
* @returns The minimum value as a PositiveFiniteNumber.
|
|
56
|
+
* @param values - The positive finite numbers to compare (at least one required)
|
|
57
|
+
* @returns The smallest value as a `PositiveFiniteNumber`
|
|
61
58
|
*/
|
|
62
59
|
min: min_,
|
|
63
60
|
/**
|
|
64
|
-
* Returns the
|
|
61
|
+
* Returns the largest of the given positive finite numbers.
|
|
65
62
|
*
|
|
66
|
-
* @param
|
|
67
|
-
* @
|
|
68
|
-
* @returns The maximum value as a PositiveFiniteNumber.
|
|
63
|
+
* @param values - The positive finite numbers to compare (at least one required)
|
|
64
|
+
* @returns The largest value as a `PositiveFiniteNumber`
|
|
69
65
|
*/
|
|
70
66
|
max: max_,
|
|
71
67
|
/**
|
|
72
|
-
* Clamps a number
|
|
68
|
+
* Clamps a `number` into the `PositiveFiniteNumber` range `[MIN_VALUE,
|
|
69
|
+
* MAX_VALUE]`.
|
|
73
70
|
*
|
|
74
|
-
* @param value The
|
|
75
|
-
* @returns The
|
|
71
|
+
* @param value - The value to clamp
|
|
72
|
+
* @returns The clamped value as a `PositiveFiniteNumber`
|
|
76
73
|
*/
|
|
77
74
|
clamp,
|
|
78
75
|
/**
|
|
79
|
-
*
|
|
76
|
+
* Returns the greatest integer less than or equal to a positive finite
|
|
77
|
+
* number.
|
|
80
78
|
*
|
|
81
|
-
* @param
|
|
82
|
-
* @returns The
|
|
79
|
+
* @param a - The positive finite number value
|
|
80
|
+
* @returns The floored value as an integer
|
|
83
81
|
*/
|
|
84
82
|
floor,
|
|
85
83
|
/**
|
|
86
|
-
*
|
|
84
|
+
* Returns the smallest integer greater than or equal to a positive finite
|
|
85
|
+
* number.
|
|
87
86
|
*
|
|
88
|
-
* @param
|
|
89
|
-
* @returns The
|
|
87
|
+
* @param a - The positive finite number value
|
|
88
|
+
* @returns The ceiled value as an integer
|
|
90
89
|
*/
|
|
91
90
|
ceil,
|
|
92
91
|
/**
|
|
93
|
-
*
|
|
92
|
+
* Returns the value of a positive finite number rounded to the nearest
|
|
93
|
+
* integer.
|
|
94
94
|
*
|
|
95
|
-
* @param
|
|
96
|
-
* @returns The rounded value as
|
|
95
|
+
* @param a - The positive finite number value
|
|
96
|
+
* @returns The rounded value as an integer
|
|
97
97
|
*/
|
|
98
98
|
round,
|
|
99
99
|
/**
|
|
100
|
-
* Generates a random PositiveFiniteNumber
|
|
100
|
+
* Generates a random `PositiveFiniteNumber` within the given range.
|
|
101
|
+
*
|
|
102
|
+
* The range is inclusive on both ends.
|
|
101
103
|
*
|
|
102
|
-
* @
|
|
104
|
+
* @param min - The minimum value (inclusive)
|
|
105
|
+
* @param max - The maximum value (inclusive)
|
|
106
|
+
* @returns A random `PositiveFiniteNumber` in `[min, max]`
|
|
103
107
|
*/
|
|
104
108
|
random,
|
|
105
109
|
/**
|
|
106
|
-
* Raises a
|
|
110
|
+
* Raises `a` to the power `b`, returning `a ** b` as a
|
|
111
|
+
* `PositiveFiniteNumber`.
|
|
107
112
|
*
|
|
108
|
-
* @param a The base
|
|
109
|
-
* @param b The exponent
|
|
110
|
-
* @returns `a ** b`
|
|
113
|
+
* @param a - The base positive finite number
|
|
114
|
+
* @param b - The exponent positive finite number
|
|
115
|
+
* @returns `a ** b` as a `PositiveFiniteNumber`
|
|
111
116
|
*/
|
|
112
117
|
pow,
|
|
113
118
|
/**
|
|
114
|
-
* Adds two
|
|
119
|
+
* Adds two positive finite numbers, returning `a + b` as a
|
|
120
|
+
* `PositiveFiniteNumber`.
|
|
115
121
|
*
|
|
116
|
-
* @param a The first
|
|
117
|
-
* @param b The second
|
|
118
|
-
* @returns `a
|
|
122
|
+
* @param a - The first positive finite number
|
|
123
|
+
* @param b - The second positive finite number
|
|
124
|
+
* @returns The sum of `a` and `b` as a `PositiveFiniteNumber`
|
|
119
125
|
*/
|
|
120
126
|
add,
|
|
121
127
|
/**
|
|
122
|
-
* Subtracts
|
|
128
|
+
* Subtracts two positive finite numbers, returning `a - b` as a
|
|
129
|
+
* `PositiveFiniteNumber`.
|
|
123
130
|
*
|
|
124
|
-
* @param a The
|
|
125
|
-
* @param b The
|
|
126
|
-
* @returns `a
|
|
127
|
-
* MIN_VALUE).
|
|
131
|
+
* @param a - The first positive finite number
|
|
132
|
+
* @param b - The second positive finite number
|
|
133
|
+
* @returns The difference of `a` and `b` as a `PositiveFiniteNumber`
|
|
128
134
|
*/
|
|
129
135
|
sub,
|
|
130
136
|
/**
|
|
131
|
-
* Multiplies two
|
|
137
|
+
* Multiplies two positive finite numbers, returning `a * b` as a
|
|
138
|
+
* `PositiveFiniteNumber`.
|
|
132
139
|
*
|
|
133
|
-
* @param a The first
|
|
134
|
-
* @param b The second
|
|
135
|
-
* @returns `a
|
|
140
|
+
* @param a - The first positive finite number
|
|
141
|
+
* @param b - The second positive finite number
|
|
142
|
+
* @returns The product of `a` and `b` as a `PositiveFiniteNumber`
|
|
136
143
|
*/
|
|
137
144
|
mul,
|
|
138
145
|
/**
|
|
139
|
-
* Divides
|
|
146
|
+
* Divides two positive finite numbers, returning `a / b` as a
|
|
147
|
+
* `PositiveFiniteNumber`.
|
|
140
148
|
*
|
|
141
|
-
* @param a The dividend
|
|
142
|
-
* @param b The divisor
|
|
143
|
-
* @returns `a / b`
|
|
149
|
+
* @param a - The dividend
|
|
150
|
+
* @param b - The divisor (must be non-zero)
|
|
151
|
+
* @returns `a / b` as a `PositiveFiniteNumber`
|
|
144
152
|
*/
|
|
145
153
|
div
|
|
146
154
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"positive-finite-number.mjs","sources":["../../../src/number/branded-types/positive-finite-number.mts"],"sourcesContent":["import {\n type PositiveInt,\n type PositiveFiniteNumber as TtfImported_PositiveFiniteNumber,\n type Uint,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveFiniteNumber = TtfImported_PositiveFiniteNumber;\n\ntype ElementType = PositiveFiniteNumber;\n\nconst typeNameInMessage = 'a positive finite number';\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.operatorsForFloat<\n ElementType,\n number,\n number\n>({\n MIN_VALUE: Number.MIN_VALUE,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nexpectType<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>,\n PositiveInt\n>('=');\n\nexpectType<\n TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >,\n Uint\n>('=');\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"positive-finite-number.mjs","sources":["../../../src/number/branded-types/positive-finite-number.mts"],"sourcesContent":["import {\n type PositiveInt,\n type PositiveFiniteNumber as TtfImported_PositiveFiniteNumber,\n type Uint,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type PositiveFiniteNumber = TtfImported_PositiveFiniteNumber;\n\ntype ElementType = PositiveFiniteNumber;\n\nconst typeNameInMessage = 'a positive finite number';\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.operatorsForFloat<\n ElementType,\n number,\n number\n>({\n MIN_VALUE: Number.MIN_VALUE,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nexpectType<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>,\n PositiveInt\n>('=');\n\nexpectType<\n TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >,\n Uint\n>('=');\n\n/**\n * Type guard that checks if a value is a positive finite number.\n *\n * Returns `true` only for a finite value — never `NaN`, `Infinity`, or\n * `-Infinity`.\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive finite number, `false` otherwise\n */\nexport const isPositiveFiniteNumber = is;\n\n/**\n * Casts a `number` to the `PositiveFiniteNumber` branded type.\n *\n * Validates that the value is a positive finite number and returns it with the\n * `PositiveFiniteNumber` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `PositiveFiniteNumber`\n * @throws {TypeError} If the value is not a positive finite number\n */\nexport const asPositiveFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe operations for the `PositiveFiniteNumber`\n * branded type.\n *\n * The `PositiveFiniteNumber` type represents a positive finite number.\n */\nexport const PositiveFiniteNumber = {\n /**\n * Type guard that checks if a value is a positive finite number.\n *\n * @param value - The value to check\n * @returns `true` if the value is a positive finite number, `false` otherwise\n * @see {@link isPositiveFiniteNumber} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `PositiveFiniteNumber`.\n */\n MIN_VALUE,\n\n /**\n * Returns the smallest of the given positive finite numbers.\n *\n * @param values - The positive finite numbers to compare (at least one required)\n * @returns The smallest value as a `PositiveFiniteNumber`\n */\n min: min_,\n\n /**\n * Returns the largest of the given positive finite numbers.\n *\n * @param values - The positive finite numbers to compare (at least one required)\n * @returns The largest value as a `PositiveFiniteNumber`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `PositiveFiniteNumber` range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `PositiveFiniteNumber`\n */\n clamp,\n\n /**\n * Returns the greatest integer less than or equal to a positive finite\n * number.\n *\n * @param a - The positive finite number value\n * @returns The floored value as an integer\n */\n floor,\n\n /**\n * Returns the smallest integer greater than or equal to a positive finite\n * number.\n *\n * @param a - The positive finite number value\n * @returns The ceiled value as an integer\n */\n ceil,\n\n /**\n * Returns the value of a positive finite number rounded to the nearest\n * integer.\n *\n * @param a - The positive finite number value\n * @returns The rounded value as an integer\n */\n round,\n\n /**\n * Generates a random `PositiveFiniteNumber` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `PositiveFiniteNumber` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a\n * `PositiveFiniteNumber`.\n *\n * @param a - The base positive finite number\n * @param b - The exponent positive finite number\n * @returns `a ** b` as a `PositiveFiniteNumber`\n */\n pow,\n\n /**\n * Adds two positive finite numbers, returning `a + b` as a\n * `PositiveFiniteNumber`.\n *\n * @param a - The first positive finite number\n * @param b - The second positive finite number\n * @returns The sum of `a` and `b` as a `PositiveFiniteNumber`\n */\n add,\n\n /**\n * Subtracts two positive finite numbers, returning `a - b` as a\n * `PositiveFiniteNumber`.\n *\n * @param a - The first positive finite number\n * @param b - The second positive finite number\n * @returns The difference of `a` and `b` as a `PositiveFiniteNumber`\n */\n sub,\n\n /**\n * Multiplies two positive finite numbers, returning `a * b` as a\n * `PositiveFiniteNumber`.\n *\n * @param a - The first positive finite number\n * @param b - The second positive finite number\n * @returns The product of `a` and `b` as a `PositiveFiniteNumber`\n */\n mul,\n\n /**\n * Divides two positive finite numbers, returning `a / b` as a\n * `PositiveFiniteNumber`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns `a / b` as a `PositiveFiniteNumber`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof PositiveFiniteNumber,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'positive'\n >\n>('=');\n\nexpectType<\n typeof PositiveFiniteNumber,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<ElementType, 'positive'>\n>('<=');\n"],"names":[],"mappings":";;AAYA,MAAM,iBAAA,GAAoB,0BAAA;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,iBAAA,CAI1C;AAAA,EACA,WAAW,MAAA,CAAO,SAAA;AAAA,EAClB,WAAW,MAAA,CAAO,SAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAEV,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAIF,MAAM,OAAO,CACX,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,KAAK,CAAC;AAAA,CAAA;AAEb,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAyBK,MAAM,sBAAA,GAAyB;AAY/B,MAAM,sBAAA,GAAyB;AAQ/B,MAAM,oBAAA,GAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlC,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
|
|
@@ -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
|
};
|