ts-data-forge 11.0.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/number/branded-types/finite-number.d.mts +47 -61
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +37 -41
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +40 -46
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +29 -31
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +71 -59
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +56 -47
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +71 -59
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +56 -47
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +76 -60
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +62 -49
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +66 -49
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +48 -39
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +64 -57
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +49 -44
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +80 -65
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +65 -53
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +71 -58
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +55 -45
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +71 -59
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +55 -46
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +70 -55
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +55 -43
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +46 -146
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +33 -108
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +62 -54
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +46 -41
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +51 -38
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +31 -27
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +59 -54
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +44 -41
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +59 -55
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +44 -42
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +60 -55
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +44 -42
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +82 -64
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +67 -52
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +53 -70
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +42 -52
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +68 -58
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +52 -45
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +68 -58
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +52 -45
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +72 -61
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +56 -48
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +68 -58
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +52 -45
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +68 -59
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +52 -46
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +52 -66
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +45 -47
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +68 -58
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +53 -46
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +72 -55
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +52 -45
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +66 -59
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +51 -45
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +66 -57
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +50 -45
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +62 -66
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +57 -51
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +66 -59
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +57 -51
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +9 -9
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +7 -7
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/package.json +2 -1
- package/src/number/branded-types/finite-number.mts +47 -61
- package/src/number/branded-types/int.mts +40 -46
- package/src/number/branded-types/int16.mts +72 -60
- package/src/number/branded-types/int32.mts +72 -60
- package/src/number/branded-types/negative-finite-number.mts +78 -71
- package/src/number/branded-types/negative-finite-number.test.mts +4 -4
- package/src/number/branded-types/negative-int.mts +68 -60
- package/src/number/branded-types/negative-int.test.mts +5 -5
- package/src/number/branded-types/negative-safe-int.mts +66 -68
- package/src/number/branded-types/negative-safe-int.test.mts +4 -4
- package/src/number/branded-types/non-negative-finite-number.mts +81 -66
- package/src/number/branded-types/non-negative-int16.mts +72 -59
- package/src/number/branded-types/non-negative-int32.mts +72 -60
- package/src/number/branded-types/non-positive-finite-number.mts +71 -56
- package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
- package/src/number/branded-types/non-positive-int.mts +47 -147
- package/src/number/branded-types/non-positive-int.test.mts +7 -7
- package/src/number/branded-types/non-positive-safe-int.mts +63 -55
- package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
- package/src/number/branded-types/non-zero-finite-number.mts +62 -51
- package/src/number/branded-types/non-zero-int.mts +51 -38
- package/src/number/branded-types/non-zero-int16.mts +60 -55
- package/src/number/branded-types/non-zero-int32.mts +60 -56
- package/src/number/branded-types/non-zero-safe-int.mts +61 -56
- package/src/number/branded-types/non-zero-uint16.mts +60 -55
- package/src/number/branded-types/non-zero-uint32.mts +60 -55
- package/src/number/branded-types/positive-finite-number.mts +83 -65
- package/src/number/branded-types/positive-int.mts +54 -71
- package/src/number/branded-types/positive-int16.mts +69 -59
- package/src/number/branded-types/positive-int32.mts +69 -59
- package/src/number/branded-types/positive-safe-int.mts +73 -62
- package/src/number/branded-types/positive-uint16.mts +69 -59
- package/src/number/branded-types/positive-uint32.mts +69 -60
- package/src/number/branded-types/safe-int.mts +53 -67
- package/src/number/branded-types/safe-uint.mts +69 -59
- package/src/number/branded-types/uint.mts +73 -56
- package/src/number/branded-types/uint16.mts +67 -60
- package/src/number/branded-types/uint32.mts +67 -58
- package/src/number/enum/int8.mts +70 -73
- package/src/number/enum/int8.test.mts +7 -4
- package/src/number/enum/uint8.mts +74 -66
- package/src/number/enum/uint8.test.mts +7 -4
- package/src/number/refined-number-utils.mts +22 -19
|
@@ -3,43 +3,22 @@ export type NonPositiveInt = TtfImported_NonPositiveInt;
|
|
|
3
3
|
/**
|
|
4
4
|
* Type guard that checks if a value is a non-positive integer.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* assert.isTrue(isNonPositiveInt(0));
|
|
14
|
-
*
|
|
15
|
-
* assert.isTrue(isNonPositiveInt(-5));
|
|
16
|
-
*
|
|
17
|
-
* assert.isFalse(isNonPositiveInt(1));
|
|
18
|
-
* ```
|
|
6
|
+
* Returns `true` for a non-positive integer — a value with no fractional
|
|
7
|
+
* component, including values outside the safe integer range (unlike
|
|
8
|
+
* `SafeInt`).
|
|
19
9
|
*
|
|
20
10
|
* @param value - The value to check
|
|
21
11
|
* @returns `true` if the value is a non-positive integer, `false` otherwise
|
|
22
12
|
*/
|
|
23
13
|
export declare const isNonPositiveInt: (a: number) => a is TtfImported_NonPositiveInt;
|
|
24
14
|
/**
|
|
25
|
-
* Casts a number to
|
|
26
|
-
*
|
|
27
|
-
* This function validates that the input is a non-positive integer (<= 0) and
|
|
28
|
-
* returns it with the NonPositiveInt brand. This ensures type safety for
|
|
29
|
-
* operations that require non-positive integer values.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
15
|
+
* Casts a `number` to the `NonPositiveInt` branded type.
|
|
32
16
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* assert.isTrue(branded === -7);
|
|
37
|
-
*
|
|
38
|
-
* assert.isTrue(NonPositiveInt.is(branded));
|
|
39
|
-
* ```
|
|
17
|
+
* Validates that the value is a non-positive integer and returns it with the
|
|
18
|
+
* `NonPositiveInt` brand. Throws a `TypeError` otherwise.
|
|
40
19
|
*
|
|
41
20
|
* @param value - The value to cast
|
|
42
|
-
* @returns The value as a NonPositiveInt
|
|
21
|
+
* @returns The value as a `NonPositiveInt`
|
|
43
22
|
* @throws {TypeError} If the value is not a non-positive integer
|
|
44
23
|
*/
|
|
45
24
|
export declare const asNonPositiveInt: <N extends number>(x: N) => number & {
|
|
@@ -55,169 +34,90 @@ export declare const asNonPositiveInt: <N extends number>(x: N) => number & {
|
|
|
55
34
|
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
56
35
|
}> & N;
|
|
57
36
|
/**
|
|
58
|
-
* Namespace providing type-safe operations for NonPositiveInt branded
|
|
59
|
-
*
|
|
60
|
-
* NonPositiveInt represents integers that are less than or equal to zero (<= 0).
|
|
61
|
-
* All operations automatically clamp results to maintain the non-positive
|
|
62
|
-
* constraint, ensuring that arithmetic operations never produce positive values.
|
|
37
|
+
* Namespace providing type-safe operations for the `NonPositiveInt` branded
|
|
38
|
+
* type.
|
|
63
39
|
*
|
|
64
|
-
*
|
|
40
|
+
* The `NonPositiveInt` type represents a non-positive integer. Division (`div`)
|
|
41
|
+
* uses floor division.
|
|
65
42
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* - Negative counts or differences
|
|
70
|
-
* - Depth or altitude below a reference point
|
|
43
|
+
* Unlike `SafeInt`, `NonPositiveInt` allows values outside the safe integer
|
|
44
|
+
* range (±2^53 − 1), so very large magnitudes may lose precision in
|
|
45
|
+
* JavaScript's `number` type.
|
|
71
46
|
*/
|
|
72
47
|
export declare const NonPositiveInt: {
|
|
73
48
|
/**
|
|
74
49
|
* Type guard that checks if a value is a non-positive integer.
|
|
75
50
|
*
|
|
76
|
-
* @example
|
|
77
|
-
*
|
|
78
|
-
* ```ts
|
|
79
|
-
* const value: number = -42;
|
|
80
|
-
*
|
|
81
|
-
* if (NonPositiveInt.is(value)) {
|
|
82
|
-
* // value is now typed as NonPositiveInt
|
|
83
|
-
* const debt = value;
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
51
|
* @param value - The value to check
|
|
88
52
|
* @returns `true` if the value is a non-positive integer, `false` otherwise
|
|
53
|
+
* @see {@link isNonPositiveInt} for usage examples
|
|
89
54
|
*/
|
|
90
55
|
readonly is: (a: number) => a is TtfImported_NonPositiveInt;
|
|
91
56
|
/**
|
|
92
|
-
* The
|
|
93
|
-
*
|
|
94
|
-
* @readonly
|
|
57
|
+
* The largest value representable as `NonPositiveInt` (the upper saturation
|
|
58
|
+
* target of `fromNumber`).
|
|
95
59
|
*/
|
|
96
60
|
readonly MAX_VALUE: 0;
|
|
97
61
|
/**
|
|
98
|
-
* Returns the
|
|
99
|
-
*
|
|
100
|
-
* Since non-positive integers range from negative infinity to 0, the smaller
|
|
101
|
-
* value is the one further from zero (more negative).
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
*
|
|
105
|
-
* ```ts
|
|
106
|
-
* const result = NonPositiveInt.min(-5, -10);
|
|
107
|
-
*
|
|
108
|
-
* assert.strictEqual(result, -10);
|
|
109
|
-
* ```
|
|
62
|
+
* Returns the smallest of the given non-positive integers.
|
|
110
63
|
*
|
|
111
|
-
* @param
|
|
112
|
-
* @
|
|
113
|
-
* @returns The minimum value as a non-positive integer
|
|
64
|
+
* @param values - The non-positive integers to compare (at least one required)
|
|
65
|
+
* @returns The smallest value as a `NonPositiveInt`
|
|
114
66
|
*/
|
|
115
67
|
readonly min: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt>[]) => TtfImported_NonPositiveInt;
|
|
116
68
|
/**
|
|
117
|
-
* Returns the
|
|
118
|
-
*
|
|
119
|
-
* Since non-positive integers range from negative infinity to 0, the larger
|
|
120
|
-
* value is the one closer to zero (less negative).
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
*
|
|
124
|
-
* ```ts
|
|
125
|
-
* const result = NonPositiveInt.max(-5, -10);
|
|
69
|
+
* Returns the largest of the given non-positive integers.
|
|
126
70
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* @param a - The first non-positive integer
|
|
131
|
-
* @param b - The second non-positive integer
|
|
132
|
-
* @returns The maximum value as a non-positive integer
|
|
71
|
+
* @param values - The non-positive integers to compare (at least one required)
|
|
72
|
+
* @returns The largest value as a `NonPositiveInt`
|
|
133
73
|
*/
|
|
134
74
|
readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt>[]) => TtfImported_NonPositiveInt;
|
|
135
75
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* Negative values are preserved as long as they are valid integers.
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
*
|
|
143
|
-
* ```ts
|
|
144
|
-
* assert.strictEqual(NonPositiveInt.clamp(5), 0);
|
|
76
|
+
* Converts an arbitrary `number` into a `NonPositiveInt`, rounding to the
|
|
77
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
78
|
+
* MAX_VALUE]`.
|
|
145
79
|
*
|
|
146
|
-
*
|
|
80
|
+
* Unlike `asNonPositiveInt`, this is total: out-of-range inputs are clamped
|
|
81
|
+
* to the nearest representable `NonPositiveInt` instead of throwing.
|
|
147
82
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* @param value - The number to clamp
|
|
152
|
-
* @returns The value clamped to the non-positive integer range
|
|
83
|
+
* @param value - The value to convert
|
|
84
|
+
* @returns The value as a `NonPositiveInt`
|
|
153
85
|
*/
|
|
154
|
-
readonly
|
|
86
|
+
readonly fromNumber: (x: number) => TtfImported_NonPositiveInt;
|
|
155
87
|
/**
|
|
156
|
-
* Generates a random
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
*
|
|
160
|
-
* ```ts
|
|
161
|
-
* const randomValue = NonPositiveInt.random();
|
|
88
|
+
* Generates a random `NonPositiveInt` within the given range.
|
|
162
89
|
*
|
|
163
|
-
*
|
|
164
|
-
* ```
|
|
90
|
+
* The range is inclusive on both ends.
|
|
165
91
|
*
|
|
166
|
-
* @
|
|
92
|
+
* @param min - The minimum value (inclusive)
|
|
93
|
+
* @param max - The maximum value (inclusive)
|
|
94
|
+
* @returns A random `NonPositiveInt` in `[min, max]`
|
|
167
95
|
*/
|
|
168
96
|
readonly random: (min?: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt> | undefined, max?: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt> | undefined) => TtfImported_NonPositiveInt;
|
|
169
97
|
/**
|
|
170
|
-
* Raises a
|
|
171
|
-
*
|
|
172
|
-
* The result is clamped to the non-positive integer range.
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
*
|
|
176
|
-
* ```ts
|
|
177
|
-
* const result = NonPositiveInt.pow(-2, -1);
|
|
178
|
-
* ```
|
|
98
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveInt`
|
|
99
|
+
* (floored to an integer).
|
|
179
100
|
*
|
|
180
101
|
* @param a - The base non-positive integer
|
|
181
102
|
* @param b - The exponent non-positive integer
|
|
182
|
-
* @returns `a ** b`
|
|
103
|
+
* @returns `a ** b` as a `NonPositiveInt`
|
|
183
104
|
*/
|
|
184
105
|
readonly pow: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt>) => TtfImported_NonPositiveInt;
|
|
185
106
|
/**
|
|
186
|
-
* Adds two non-positive integers
|
|
187
|
-
*
|
|
188
|
-
* The result is clamped to the non-positive integer range. If the sum is
|
|
189
|
-
* positive, it is clamped to 0.
|
|
190
|
-
*
|
|
191
|
-
* @example
|
|
192
|
-
*
|
|
193
|
-
* ```ts
|
|
194
|
-
* assert.strictEqual(NonPositiveInt.add(-5, -3), -8);
|
|
195
|
-
*
|
|
196
|
-
* assert.strictEqual(NonPositiveInt.add(-5, 10), 0);
|
|
197
|
-
* ```
|
|
107
|
+
* Adds two non-positive integers, returning `a + b` as a `NonPositiveInt`.
|
|
198
108
|
*
|
|
199
109
|
* @param a - The first non-positive integer
|
|
200
110
|
* @param b - The second non-positive integer
|
|
201
|
-
* @returns `a
|
|
111
|
+
* @returns The sum of `a` and `b` as a `NonPositiveInt`
|
|
202
112
|
*/
|
|
203
113
|
readonly add: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt>) => TtfImported_NonPositiveInt;
|
|
204
114
|
/**
|
|
205
|
-
* Subtracts
|
|
206
|
-
*
|
|
207
|
-
* The result is clamped to the non-positive integer range. If the result is
|
|
208
|
-
* positive, it is clamped to 0.
|
|
115
|
+
* Subtracts two non-positive integers, returning `a - b` as a
|
|
116
|
+
* `NonPositiveInt`.
|
|
209
117
|
*
|
|
210
|
-
* @
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* assert.strictEqual(NonPositiveInt.sub(-10, -3), -7);
|
|
214
|
-
*
|
|
215
|
-
* assert.strictEqual(NonPositiveInt.sub(-10, 5), 0);
|
|
216
|
-
* ```
|
|
217
|
-
*
|
|
218
|
-
* @param a - The minuend non-positive integer
|
|
219
|
-
* @param b - The subtrahend non-positive integer
|
|
220
|
-
* @returns `a - b` clamped to the non-positive integer range
|
|
118
|
+
* @param a - The first non-positive integer
|
|
119
|
+
* @param b - The second non-positive integer
|
|
120
|
+
* @returns The difference of `a` and `b` as a `NonPositiveInt`
|
|
221
121
|
*/
|
|
222
122
|
readonly sub: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveInt>) => TtfImported_NonPositiveInt;
|
|
223
123
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-positive-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-positive-int.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,IAAI,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAGlF,MAAM,MAAM,cAAc,GAAG,0BAA0B,CAAC;AA4BxD
|
|
1
|
+
{"version":3,"file":"non-positive-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-positive-int.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,IAAI,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAGlF,MAAM,MAAM,cAAc,GAAG,0BAA0B,CAAC;AA4BxD;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,gDAAK,CAAC;AAEnC;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;MAAW,CAAC;AAEzC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc;IACzB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
|
|
@@ -5,7 +5,7 @@ const {
|
|
|
5
5
|
MAX_VALUE,
|
|
6
6
|
add,
|
|
7
7
|
castType,
|
|
8
|
-
|
|
8
|
+
fromNumber,
|
|
9
9
|
is,
|
|
10
10
|
max: max_,
|
|
11
11
|
min: min_,
|
|
@@ -24,151 +24,76 @@ const NonPositiveInt = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Type guard that checks if a value is a non-positive integer.
|
|
26
26
|
*
|
|
27
|
-
* @example
|
|
28
|
-
*
|
|
29
|
-
* ```ts
|
|
30
|
-
* const value: number = -42;
|
|
31
|
-
*
|
|
32
|
-
* if (NonPositiveInt.is(value)) {
|
|
33
|
-
* // value is now typed as NonPositiveInt
|
|
34
|
-
* const debt = value;
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
27
|
* @param value - The value to check
|
|
39
28
|
* @returns `true` if the value is a non-positive integer, `false` otherwise
|
|
29
|
+
* @see {@link isNonPositiveInt} for usage examples
|
|
40
30
|
*/
|
|
41
31
|
is,
|
|
42
32
|
/**
|
|
43
|
-
* The
|
|
44
|
-
*
|
|
45
|
-
* @readonly
|
|
33
|
+
* The largest value representable as `NonPositiveInt` (the upper saturation
|
|
34
|
+
* target of `fromNumber`).
|
|
46
35
|
*/
|
|
47
36
|
MAX_VALUE,
|
|
48
37
|
/**
|
|
49
|
-
* Returns the
|
|
50
|
-
*
|
|
51
|
-
* Since non-positive integers range from negative infinity to 0, the smaller
|
|
52
|
-
* value is the one further from zero (more negative).
|
|
38
|
+
* Returns the smallest of the given non-positive integers.
|
|
53
39
|
*
|
|
54
|
-
* @
|
|
55
|
-
*
|
|
56
|
-
* ```ts
|
|
57
|
-
* const result = NonPositiveInt.min(-5, -10);
|
|
58
|
-
*
|
|
59
|
-
* assert.strictEqual(result, -10);
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* @param a - The first non-positive integer
|
|
63
|
-
* @param b - The second non-positive integer
|
|
64
|
-
* @returns The minimum value as a non-positive integer
|
|
40
|
+
* @param values - The non-positive integers to compare (at least one required)
|
|
41
|
+
* @returns The smallest value as a `NonPositiveInt`
|
|
65
42
|
*/
|
|
66
43
|
min: min_,
|
|
67
44
|
/**
|
|
68
|
-
* Returns the
|
|
69
|
-
*
|
|
70
|
-
* Since non-positive integers range from negative infinity to 0, the larger
|
|
71
|
-
* value is the one closer to zero (less negative).
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
*
|
|
75
|
-
* ```ts
|
|
76
|
-
* const result = NonPositiveInt.max(-5, -10);
|
|
77
|
-
*
|
|
78
|
-
* assert.strictEqual(result, -5);
|
|
79
|
-
* ```
|
|
45
|
+
* Returns the largest of the given non-positive integers.
|
|
80
46
|
*
|
|
81
|
-
* @param
|
|
82
|
-
* @
|
|
83
|
-
* @returns The maximum value as a non-positive integer
|
|
47
|
+
* @param values - The non-positive integers to compare (at least one required)
|
|
48
|
+
* @returns The largest value as a `NonPositiveInt`
|
|
84
49
|
*/
|
|
85
50
|
max: max_,
|
|
86
51
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* Negative values are preserved as long as they are valid integers.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
52
|
+
* Converts an arbitrary `number` into a `NonPositiveInt`, rounding to the
|
|
53
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
54
|
+
* MAX_VALUE]`.
|
|
93
55
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
56
|
+
* Unlike `asNonPositiveInt`, this is total: out-of-range inputs are clamped
|
|
57
|
+
* to the nearest representable `NonPositiveInt` instead of throwing.
|
|
96
58
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* assert.strictEqual(NonPositiveInt.clamp(0), 0);
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
* @param value - The number to clamp
|
|
103
|
-
* @returns The value clamped to the non-positive integer range
|
|
59
|
+
* @param value - The value to convert
|
|
60
|
+
* @returns The value as a `NonPositiveInt`
|
|
104
61
|
*/
|
|
105
|
-
|
|
62
|
+
fromNumber,
|
|
106
63
|
/**
|
|
107
|
-
* Generates a random
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
64
|
+
* Generates a random `NonPositiveInt` within the given range.
|
|
110
65
|
*
|
|
111
|
-
*
|
|
112
|
-
* const randomValue = NonPositiveInt.random();
|
|
66
|
+
* The range is inclusive on both ends.
|
|
113
67
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* @returns A random non-positive integer
|
|
68
|
+
* @param min - The minimum value (inclusive)
|
|
69
|
+
* @param max - The maximum value (inclusive)
|
|
70
|
+
* @returns A random `NonPositiveInt` in `[min, max]`
|
|
118
71
|
*/
|
|
119
72
|
random,
|
|
120
73
|
/**
|
|
121
|
-
* Raises a
|
|
122
|
-
*
|
|
123
|
-
* The result is clamped to the non-positive integer range.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
*
|
|
127
|
-
* ```ts
|
|
128
|
-
* const result = NonPositiveInt.pow(-2, -1);
|
|
129
|
-
* ```
|
|
74
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveInt`
|
|
75
|
+
* (floored to an integer).
|
|
130
76
|
*
|
|
131
77
|
* @param a - The base non-positive integer
|
|
132
78
|
* @param b - The exponent non-positive integer
|
|
133
|
-
* @returns `a ** b`
|
|
79
|
+
* @returns `a ** b` as a `NonPositiveInt`
|
|
134
80
|
*/
|
|
135
81
|
pow,
|
|
136
82
|
/**
|
|
137
|
-
* Adds two non-positive integers
|
|
138
|
-
*
|
|
139
|
-
* The result is clamped to the non-positive integer range. If the sum is
|
|
140
|
-
* positive, it is clamped to 0.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
*
|
|
144
|
-
* ```ts
|
|
145
|
-
* assert.strictEqual(NonPositiveInt.add(-5, -3), -8);
|
|
146
|
-
*
|
|
147
|
-
* assert.strictEqual(NonPositiveInt.add(-5, 10), 0);
|
|
148
|
-
* ```
|
|
83
|
+
* Adds two non-positive integers, returning `a + b` as a `NonPositiveInt`.
|
|
149
84
|
*
|
|
150
85
|
* @param a - The first non-positive integer
|
|
151
86
|
* @param b - The second non-positive integer
|
|
152
|
-
* @returns `a
|
|
87
|
+
* @returns The sum of `a` and `b` as a `NonPositiveInt`
|
|
153
88
|
*/
|
|
154
89
|
add,
|
|
155
90
|
/**
|
|
156
|
-
* Subtracts
|
|
157
|
-
*
|
|
158
|
-
* The result is clamped to the non-positive integer range. If the result is
|
|
159
|
-
* positive, it is clamped to 0.
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
91
|
+
* Subtracts two non-positive integers, returning `a - b` as a
|
|
92
|
+
* `NonPositiveInt`.
|
|
162
93
|
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* assert.strictEqual(NonPositiveInt.sub(-10, 5), 0);
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
* @param a - The minuend non-positive integer
|
|
170
|
-
* @param b - The subtrahend non-positive integer
|
|
171
|
-
* @returns `a - b` clamped to the non-positive integer range
|
|
94
|
+
* @param a - The first non-positive integer
|
|
95
|
+
* @param b - The second non-positive integer
|
|
96
|
+
* @returns The difference of `a` and `b` as a `NonPositiveInt`
|
|
172
97
|
*/
|
|
173
98
|
sub
|
|
174
99
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-positive-int.mjs","sources":["../../../src/number/branded-types/non-positive-int.mts"],"sourcesContent":["import { type NonPositiveInt as TtfImported_NonPositiveInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveInt = TtfImported_NonPositiveInt;\n\ntype ElementType = NonPositiveInt;\n\nconst typeNameInMessage = 'a non-positive integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"non-positive-int.mjs","sources":["../../../src/number/branded-types/non-positive-int.mts"],"sourcesContent":["import { type NonPositiveInt as TtfImported_NonPositiveInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveInt = TtfImported_NonPositiveInt;\n\ntype ElementType = NonPositiveInt;\n\nconst typeNameInMessage = 'a non-positive integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n 0\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-positive integer.\n *\n * Returns `true` for a non-positive integer — a value with no fractional\n * component, including values outside the safe integer range (unlike\n * `SafeInt`).\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive integer, `false` otherwise\n */\nexport const isNonPositiveInt = is;\n\n/**\n * Casts a `number` to the `NonPositiveInt` branded type.\n *\n * Validates that the value is a non-positive integer and returns it with the\n * `NonPositiveInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NonPositiveInt`\n * @throws {TypeError} If the value is not a non-positive integer\n */\nexport const asNonPositiveInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NonPositiveInt` branded\n * type.\n *\n * The `NonPositiveInt` type represents a non-positive integer. Division (`div`)\n * uses floor division.\n *\n * Unlike `SafeInt`, `NonPositiveInt` allows values outside the safe integer\n * range (±2^53 − 1), so very large magnitudes may lose precision in\n * JavaScript's `number` type.\n */\nexport const NonPositiveInt = {\n /**\n * Type guard that checks if a value is a non-positive integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive integer, `false` otherwise\n * @see {@link isNonPositiveInt} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NonPositiveInt` (the upper saturation\n * target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-positive integers.\n *\n * @param values - The non-positive integers to compare (at least one required)\n * @returns The smallest value as a `NonPositiveInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-positive integers.\n *\n * @param values - The non-positive integers to compare (at least one required)\n * @returns The largest value as a `NonPositiveInt`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NonPositiveInt`, rounding to the\n * nearest integer and saturating the result into the range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * Unlike `asNonPositiveInt`, this is total: out-of-range inputs are clamped\n * to the nearest representable `NonPositiveInt` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NonPositiveInt`\n */\n fromNumber,\n\n /**\n * Generates a random `NonPositiveInt` 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 `NonPositiveInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveInt`\n * (floored to an integer).\n *\n * @param a - The base non-positive integer\n * @param b - The exponent non-positive integer\n * @returns `a ** b` as a `NonPositiveInt`\n */\n pow,\n\n /**\n * Adds two non-positive integers, returning `a + b` as a `NonPositiveInt`.\n *\n * @param a - The first non-positive integer\n * @param b - The second non-positive integer\n * @returns The sum of `a` and `b` as a `NonPositiveInt`\n */\n add,\n\n /**\n * Subtracts two non-positive integers, returning `a - b` as a\n * `NonPositiveInt`.\n *\n * @param a - The first non-positive integer\n * @param b - The second non-positive integer\n * @returns The difference of `a` and `b` as a `NonPositiveInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;AAOA,MAAM,iBAAA,GAAoB,wBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,CAAA;AAAA,EACX;AACF,CAAU,CAAA;AAYH,MAAM,gBAAA,GAAmB;AAYzB,MAAM,gBAAA,GAAmB;AAazB,MAAM,cAAA,GAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,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;AAAA;AAAA;AAAA;AAAA,EAaL,UAAA;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,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
|