ts-data-forge 1.0.0 → 1.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/README.md +1 -1
- package/dist/array/array-utils.d.mts +2617 -0
- package/dist/array/array-utils.d.mts.map +1 -0
- package/dist/array/array-utils.mjs +2915 -0
- package/dist/array/array-utils.mjs.map +1 -0
- package/dist/array/index.d.mts +3 -0
- package/dist/array/index.d.mts.map +1 -0
- package/dist/array/index.mjs +3 -0
- package/dist/array/index.mjs.map +1 -0
- package/dist/array/tuple-utils.d.mts +421 -0
- package/dist/array/tuple-utils.d.mts.map +1 -0
- package/dist/array/tuple-utils.mjs +391 -0
- package/dist/array/tuple-utils.mjs.map +1 -0
- package/dist/collections/imap-mapped.d.mts +445 -0
- package/dist/collections/imap-mapped.d.mts.map +1 -0
- package/dist/collections/imap-mapped.mjs +424 -0
- package/dist/collections/imap-mapped.mjs.map +1 -0
- package/dist/collections/imap.d.mts +359 -0
- package/dist/collections/imap.d.mts.map +1 -0
- package/dist/collections/imap.mjs +338 -0
- package/dist/collections/imap.mjs.map +1 -0
- package/dist/collections/index.d.mts +7 -0
- package/dist/collections/index.d.mts.map +1 -0
- package/dist/collections/index.mjs +7 -0
- package/dist/collections/index.mjs.map +1 -0
- package/dist/collections/iset-mapped.d.mts +576 -0
- package/dist/collections/iset-mapped.d.mts.map +1 -0
- package/dist/collections/iset-mapped.mjs +522 -0
- package/dist/collections/iset-mapped.mjs.map +1 -0
- package/dist/collections/iset.d.mts +426 -0
- package/dist/collections/iset.d.mts.map +1 -0
- package/dist/collections/iset.mjs +437 -0
- package/dist/collections/iset.mjs.map +1 -0
- package/dist/collections/queue.d.mts +190 -0
- package/dist/collections/queue.d.mts.map +1 -0
- package/dist/collections/queue.mjs +317 -0
- package/dist/collections/queue.mjs.map +1 -0
- package/dist/collections/stack.d.mts +210 -0
- package/dist/collections/stack.d.mts.map +1 -0
- package/dist/collections/stack.mjs +353 -0
- package/dist/collections/stack.mjs.map +1 -0
- package/dist/expect-type.d.mts +199 -0
- package/dist/expect-type.d.mts.map +1 -0
- package/dist/expect-type.mjs +201 -0
- package/dist/expect-type.mjs.map +1 -0
- package/dist/functional/index.d.mts +5 -0
- package/dist/functional/index.d.mts.map +1 -0
- package/dist/functional/index.mjs +5 -0
- package/dist/functional/index.mjs.map +1 -0
- package/dist/functional/match.d.mts +215 -0
- package/dist/functional/match.d.mts.map +1 -0
- package/dist/functional/match.mjs +139 -0
- package/dist/functional/match.mjs.map +1 -0
- package/dist/functional/optional.d.mts +517 -0
- package/dist/functional/optional.d.mts.map +1 -0
- package/dist/functional/optional.mjs +532 -0
- package/dist/functional/optional.mjs.map +1 -0
- package/dist/functional/pipe.d.mts +185 -0
- package/dist/functional/pipe.d.mts.map +1 -0
- package/dist/functional/pipe.mjs +129 -0
- package/dist/functional/pipe.mjs.map +1 -0
- package/dist/functional/result.d.mts +796 -0
- package/dist/functional/result.d.mts.map +1 -0
- package/dist/functional/result.mjs +844 -0
- package/dist/functional/result.mjs.map +1 -0
- package/dist/globals.d.mts +38 -0
- package/dist/guard/has-key.d.mts +100 -0
- package/dist/guard/has-key.d.mts.map +1 -0
- package/dist/guard/has-key.mjs +94 -0
- package/dist/guard/has-key.mjs.map +1 -0
- package/dist/guard/index.d.mts +8 -0
- package/dist/guard/index.d.mts.map +1 -0
- package/dist/guard/index.mjs +8 -0
- package/dist/guard/index.mjs.map +1 -0
- package/dist/guard/is-non-empty-string.d.mts +106 -0
- package/dist/guard/is-non-empty-string.d.mts.map +1 -0
- package/dist/guard/is-non-empty-string.mjs +108 -0
- package/dist/guard/is-non-empty-string.mjs.map +1 -0
- package/dist/guard/is-non-null-object.d.mts +105 -0
- package/dist/guard/is-non-null-object.d.mts.map +1 -0
- package/dist/guard/is-non-null-object.mjs +108 -0
- package/dist/guard/is-non-null-object.mjs.map +1 -0
- package/dist/guard/is-primitive.d.mts +146 -0
- package/dist/guard/is-primitive.d.mts.map +1 -0
- package/dist/guard/is-primitive.mjs +161 -0
- package/dist/guard/is-primitive.mjs.map +1 -0
- package/dist/guard/is-record.d.mts +151 -0
- package/dist/guard/is-record.d.mts.map +1 -0
- package/dist/guard/is-record.mjs +155 -0
- package/dist/guard/is-record.mjs.map +1 -0
- package/dist/guard/is-type.d.mts +430 -0
- package/dist/guard/is-type.d.mts.map +1 -0
- package/dist/guard/is-type.mjs +432 -0
- package/dist/guard/is-type.mjs.map +1 -0
- package/dist/guard/key-is-in.d.mts +158 -0
- package/dist/guard/key-is-in.d.mts.map +1 -0
- package/dist/guard/key-is-in.mjs +160 -0
- package/dist/guard/key-is-in.mjs.map +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +61 -0
- package/dist/index.mjs.map +1 -0
- package/dist/iterator/index.d.mts +2 -0
- package/dist/iterator/index.d.mts.map +1 -0
- package/dist/iterator/index.mjs +2 -0
- package/dist/iterator/index.mjs.map +1 -0
- package/dist/iterator/range.d.mts +97 -0
- package/dist/iterator/range.d.mts.map +1 -0
- package/dist/iterator/range.mjs +130 -0
- package/dist/iterator/range.mjs.map +1 -0
- package/dist/json/index.d.mts +2 -0
- package/dist/json/index.d.mts.map +1 -0
- package/dist/json/index.mjs +2 -0
- package/dist/json/index.mjs.map +1 -0
- package/dist/json/json.d.mts +597 -0
- package/dist/json/json.d.mts.map +1 -0
- package/dist/json/json.mjs +687 -0
- package/dist/json/json.mjs.map +1 -0
- package/dist/number/branded-types/finite-number.d.mts +291 -0
- package/dist/number/branded-types/finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/finite-number.mjs +296 -0
- package/dist/number/branded-types/finite-number.mjs.map +1 -0
- package/dist/number/branded-types/index.d.mts +27 -0
- package/dist/number/branded-types/index.d.mts.map +1 -0
- package/dist/number/branded-types/index.mjs +27 -0
- package/dist/number/branded-types/index.mjs.map +1 -0
- package/dist/number/branded-types/int.d.mts +242 -0
- package/dist/number/branded-types/int.d.mts.map +1 -0
- package/dist/number/branded-types/int.mjs +239 -0
- package/dist/number/branded-types/int.mjs.map +1 -0
- package/dist/number/branded-types/int16.d.mts +162 -0
- package/dist/number/branded-types/int16.d.mts.map +1 -0
- package/dist/number/branded-types/int16.mjs +141 -0
- package/dist/number/branded-types/int16.mjs.map +1 -0
- package/dist/number/branded-types/int32.d.mts +155 -0
- package/dist/number/branded-types/int32.d.mts.map +1 -0
- package/dist/number/branded-types/int32.mjs +142 -0
- package/dist/number/branded-types/int32.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-finite-number.d.mts +165 -0
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-finite-number.mjs +160 -0
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-int16.d.mts +160 -0
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-int16.mjs +138 -0
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-int32.d.mts +156 -0
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-int32.mjs +138 -0
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-finite-number.d.mts +154 -0
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-finite-number.mjs +160 -0
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int.d.mts +131 -0
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int.mjs +128 -0
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int16.d.mts +166 -0
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int16.mjs +145 -0
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int32.d.mts +158 -0
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int32.mjs +145 -0
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-safe-int.d.mts +148 -0
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-safe-int.mjs +145 -0
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-uint16.d.mts +160 -0
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-uint16.mjs +140 -0
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-uint32.d.mts +156 -0
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-uint32.mjs +140 -0
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -0
- package/dist/number/branded-types/positive-finite-number.d.mts +171 -0
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/positive-finite-number.mjs +165 -0
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/positive-int.d.mts +270 -0
- package/dist/number/branded-types/positive-int.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int.mjs +257 -0
- package/dist/number/branded-types/positive-int.mjs.map +1 -0
- package/dist/number/branded-types/positive-int16.d.mts +162 -0
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int16.mjs +139 -0
- package/dist/number/branded-types/positive-int16.mjs.map +1 -0
- package/dist/number/branded-types/positive-int32.d.mts +158 -0
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int32.mjs +139 -0
- package/dist/number/branded-types/positive-int32.mjs.map +1 -0
- package/dist/number/branded-types/positive-safe-int.d.mts +152 -0
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/positive-safe-int.mjs +138 -0
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -0
- package/dist/number/branded-types/positive-uint16.d.mts +160 -0
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -0
- package/dist/number/branded-types/positive-uint16.mjs +139 -0
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -0
- package/dist/number/branded-types/positive-uint32.d.mts +156 -0
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -0
- package/dist/number/branded-types/positive-uint32.mjs +139 -0
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -0
- package/dist/number/branded-types/safe-int.d.mts +243 -0
- package/dist/number/branded-types/safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/safe-int.mjs +240 -0
- package/dist/number/branded-types/safe-int.mjs.map +1 -0
- package/dist/number/branded-types/safe-uint.d.mts +151 -0
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -0
- package/dist/number/branded-types/safe-uint.mjs +138 -0
- package/dist/number/branded-types/safe-uint.mjs.map +1 -0
- package/dist/number/branded-types/uint.d.mts +144 -0
- package/dist/number/branded-types/uint.d.mts.map +1 -0
- package/dist/number/branded-types/uint.mjs +132 -0
- package/dist/number/branded-types/uint.mjs.map +1 -0
- package/dist/number/branded-types/uint16.d.mts +157 -0
- package/dist/number/branded-types/uint16.d.mts.map +1 -0
- package/dist/number/branded-types/uint16.mjs +137 -0
- package/dist/number/branded-types/uint16.mjs.map +1 -0
- package/dist/number/branded-types/uint32.d.mts +185 -0
- package/dist/number/branded-types/uint32.d.mts.map +1 -0
- package/dist/number/branded-types/uint32.mjs +169 -0
- package/dist/number/branded-types/uint32.mjs.map +1 -0
- package/dist/number/enum/index.d.mts +3 -0
- package/dist/number/enum/index.d.mts.map +1 -0
- package/dist/number/enum/index.mjs +3 -0
- package/dist/number/enum/index.mjs.map +1 -0
- package/dist/number/enum/int8.d.mts +202 -0
- package/dist/number/enum/int8.d.mts.map +1 -0
- package/dist/number/enum/int8.mjs +296 -0
- package/dist/number/enum/int8.mjs.map +1 -0
- package/dist/number/enum/uint8.d.mts +128 -0
- package/dist/number/enum/uint8.d.mts.map +1 -0
- package/dist/number/enum/uint8.mjs +251 -0
- package/dist/number/enum/uint8.mjs.map +1 -0
- package/dist/number/index.d.mts +5 -0
- package/dist/number/index.d.mts.map +1 -0
- package/dist/number/index.mjs +31 -0
- package/dist/number/index.mjs.map +1 -0
- package/dist/number/num.d.mts +515 -0
- package/dist/number/num.d.mts.map +1 -0
- package/dist/number/num.mjs +513 -0
- package/dist/number/num.mjs.map +1 -0
- package/dist/number/refined-number-utils.d.mts +191 -0
- package/dist/number/refined-number-utils.d.mts.map +1 -0
- package/dist/number/refined-number-utils.mjs +179 -0
- package/dist/number/refined-number-utils.mjs.map +1 -0
- package/dist/object/index.d.mts +2 -0
- package/dist/object/index.d.mts.map +1 -0
- package/dist/object/index.mjs +2 -0
- package/dist/object/index.mjs.map +1 -0
- package/dist/object/object.d.mts +296 -0
- package/dist/object/object.d.mts.map +1 -0
- package/dist/object/object.mjs +295 -0
- package/dist/object/object.mjs.map +1 -0
- package/dist/others/cast-mutable.d.mts +110 -0
- package/dist/others/cast-mutable.d.mts.map +1 -0
- package/dist/others/cast-mutable.mjs +114 -0
- package/dist/others/cast-mutable.mjs.map +1 -0
- package/dist/others/cast-readonly.d.mts +189 -0
- package/dist/others/cast-readonly.d.mts.map +1 -0
- package/dist/others/cast-readonly.mjs +193 -0
- package/dist/others/cast-readonly.mjs.map +1 -0
- package/dist/others/if-then.d.mts +98 -0
- package/dist/others/if-then.d.mts.map +1 -0
- package/dist/others/if-then.mjs +100 -0
- package/dist/others/if-then.mjs.map +1 -0
- package/dist/others/index.d.mts +8 -0
- package/dist/others/index.d.mts.map +1 -0
- package/dist/others/index.mjs +8 -0
- package/dist/others/index.mjs.map +1 -0
- package/dist/others/map-nullable.d.mts +151 -0
- package/dist/others/map-nullable.d.mts.map +1 -0
- package/dist/others/map-nullable.mjs +159 -0
- package/dist/others/map-nullable.mjs.map +1 -0
- package/dist/others/memoize-function.d.mts +173 -0
- package/dist/others/memoize-function.d.mts.map +1 -0
- package/dist/others/memoize-function.mjs +189 -0
- package/dist/others/memoize-function.mjs.map +1 -0
- package/dist/others/tuple.d.mts +159 -0
- package/dist/others/tuple.d.mts.map +1 -0
- package/dist/others/tuple.mjs +161 -0
- package/dist/others/tuple.mjs.map +1 -0
- package/dist/others/unknown-to-string.d.mts +180 -0
- package/dist/others/unknown-to-string.d.mts.map +1 -0
- package/dist/others/unknown-to-string.mjs +211 -0
- package/dist/others/unknown-to-string.mjs.map +1 -0
- package/dist/tsconfig.json +1 -0
- package/package.json +16 -14
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is a PositiveInt32 (32-bit positive signed integer in the range [1, 2^31)).
|
|
3
|
+
* @param value The value to check.
|
|
4
|
+
* @returns `true` if the value is a PositiveInt32, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isPositiveInt32: (a: number) => a is PositiveInt32;
|
|
7
|
+
/**
|
|
8
|
+
* Casts a number to a PositiveInt32 type.
|
|
9
|
+
* @param value The value to cast.
|
|
10
|
+
* @returns The value as a PositiveInt32 type.
|
|
11
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^31).
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const x = asPositiveInt32(1000); // PositiveInt32
|
|
15
|
+
* const y = asPositiveInt32(2147483647); // PositiveInt32
|
|
16
|
+
* // asPositiveInt32(0); // throws TypeError
|
|
17
|
+
* // asPositiveInt32(-1); // throws TypeError
|
|
18
|
+
* // asPositiveInt32(2147483648); // throws TypeError
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const asPositiveInt32: <N extends number>(x: N) => number & {
|
|
22
|
+
readonly NaNValue: false;
|
|
23
|
+
readonly "!=0": true;
|
|
24
|
+
readonly "> -2^16": true;
|
|
25
|
+
readonly "> -2^32": true;
|
|
26
|
+
readonly ">= -2^15": true;
|
|
27
|
+
readonly ">= -2^31": true;
|
|
28
|
+
readonly ">=0": true;
|
|
29
|
+
readonly "< 2^31": true;
|
|
30
|
+
readonly "< 2^32": true;
|
|
31
|
+
readonly Finite: true;
|
|
32
|
+
readonly Int: true;
|
|
33
|
+
readonly SafeInt: true;
|
|
34
|
+
} & Readonly<{
|
|
35
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
36
|
+
}> & N;
|
|
37
|
+
/**
|
|
38
|
+
* Namespace providing type-safe arithmetic operations for 32-bit positive integers.
|
|
39
|
+
*
|
|
40
|
+
* All operations automatically clamp results to the valid PositiveInt32 range [1, 2147483647].
|
|
41
|
+
* This ensures that all arithmetic maintains the 32-bit positive integer constraint,
|
|
42
|
+
* with results below 1 clamped to MIN_VALUE and overflow results clamped to MAX_VALUE.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const a = asPositiveInt32(2000000000);
|
|
47
|
+
* const b = asPositiveInt32(500000000);
|
|
48
|
+
*
|
|
49
|
+
* // Arithmetic operations with automatic clamping and positive constraint
|
|
50
|
+
* const sum = PositiveInt32.add(a, b); // PositiveInt32 (2147483647 - clamped to MAX_VALUE)
|
|
51
|
+
* const diff = PositiveInt32.sub(a, b); // PositiveInt32 (1500000000)
|
|
52
|
+
* const reverseDiff = PositiveInt32.sub(b, a); // PositiveInt32 (1 - clamped to MIN_VALUE)
|
|
53
|
+
* const product = PositiveInt32.mul(a, b); // PositiveInt32 (2147483647 - clamped due to overflow)
|
|
54
|
+
*
|
|
55
|
+
* // Range operations (maintaining positive constraint)
|
|
56
|
+
* const clamped = PositiveInt32.clamp(-1000); // PositiveInt32 (1)
|
|
57
|
+
* const minimum = PositiveInt32.min(a, b); // PositiveInt32 (500000000)
|
|
58
|
+
* const maximum = PositiveInt32.max(a, b); // PositiveInt32 (2000000000)
|
|
59
|
+
*
|
|
60
|
+
* // Utility operations
|
|
61
|
+
* const random = PositiveInt32.random(); // PositiveInt32 (random value in [1, 2147483647])
|
|
62
|
+
* const power = PositiveInt32.pow(asPositiveInt32(2), asPositiveInt32(20)); // PositiveInt32 (1048576)
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const PositiveInt32: {
|
|
66
|
+
/**
|
|
67
|
+
* Type guard to check if a value is a PositiveInt32.
|
|
68
|
+
* @param value The value to check.
|
|
69
|
+
* @returns `true` if the value is a 32-bit positive integer, `false` otherwise.
|
|
70
|
+
*/
|
|
71
|
+
readonly is: (a: number) => a is PositiveInt32;
|
|
72
|
+
/**
|
|
73
|
+
* The minimum value for a 32-bit positive integer.
|
|
74
|
+
* @readonly
|
|
75
|
+
*/
|
|
76
|
+
readonly MIN_VALUE: 1;
|
|
77
|
+
/**
|
|
78
|
+
* The maximum value for a 32-bit positive integer.
|
|
79
|
+
* @readonly
|
|
80
|
+
*/
|
|
81
|
+
readonly MAX_VALUE: number;
|
|
82
|
+
/**
|
|
83
|
+
* Returns the smaller of two PositiveInt32 values.
|
|
84
|
+
* @param a The first PositiveInt32.
|
|
85
|
+
* @param b The second PositiveInt32.
|
|
86
|
+
* @returns The minimum value as a PositiveInt32.
|
|
87
|
+
*/
|
|
88
|
+
readonly min: (...values: readonly WithSmallInt<PositiveInt32, 40>[]) => PositiveInt32;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the larger of two PositiveInt32 values.
|
|
91
|
+
* @param a The first PositiveInt32.
|
|
92
|
+
* @param b The second PositiveInt32.
|
|
93
|
+
* @returns The maximum value as a PositiveInt32.
|
|
94
|
+
*/
|
|
95
|
+
readonly max: (...values: readonly WithSmallInt<PositiveInt32, 40>[]) => PositiveInt32;
|
|
96
|
+
/**
|
|
97
|
+
* Clamps a number to the PositiveInt32 range.
|
|
98
|
+
* @param value The number to clamp.
|
|
99
|
+
* @returns The value clamped to [1, 2147483647] as a PositiveInt32.
|
|
100
|
+
*/
|
|
101
|
+
readonly clamp: (x: number) => PositiveInt32;
|
|
102
|
+
/**
|
|
103
|
+
* Generates a random PositiveInt32 value within the valid range.
|
|
104
|
+
* @returns A random PositiveInt32 between 1 and 2147483647.
|
|
105
|
+
*/
|
|
106
|
+
readonly random: (min: WithSmallInt<PositiveInt32, 40>, max: WithSmallInt<PositiveInt32, 40>) => PositiveInt32;
|
|
107
|
+
/**
|
|
108
|
+
* Raises a PositiveInt32 to the power of another PositiveInt32.
|
|
109
|
+
* @param a The base PositiveInt32.
|
|
110
|
+
* @param b The exponent PositiveInt32.
|
|
111
|
+
* @returns `a ** b` clamped to [1, 2147483647] as a PositiveInt32.
|
|
112
|
+
*/
|
|
113
|
+
readonly pow: (x: WithSmallInt<PositiveInt32, 40>, y: WithSmallInt<PositiveInt32, 40>) => PositiveInt32;
|
|
114
|
+
/**
|
|
115
|
+
* Adds two PositiveInt32 values.
|
|
116
|
+
* @param a The first PositiveInt32.
|
|
117
|
+
* @param b The second PositiveInt32.
|
|
118
|
+
* @returns `a + b` clamped to [1, 2147483647] as a PositiveInt32.
|
|
119
|
+
*/
|
|
120
|
+
readonly add: (x: WithSmallInt<PositiveInt32, 40>, y: WithSmallInt<PositiveInt32, 40>) => PositiveInt32;
|
|
121
|
+
/**
|
|
122
|
+
* Subtracts one PositiveInt32 from another.
|
|
123
|
+
* @param a The minuend PositiveInt32.
|
|
124
|
+
* @param b The subtrahend PositiveInt32.
|
|
125
|
+
* @returns `a - b` clamped to [1, 2147483647] as a PositiveInt32 (minimum 1).
|
|
126
|
+
*/
|
|
127
|
+
readonly sub: (x: WithSmallInt<PositiveInt32, 40>, y: WithSmallInt<PositiveInt32, 40>) => PositiveInt32;
|
|
128
|
+
/**
|
|
129
|
+
* Multiplies two PositiveInt32 values.
|
|
130
|
+
* @param a The first PositiveInt32.
|
|
131
|
+
* @param b The second PositiveInt32.
|
|
132
|
+
* @returns `a * b` clamped to [1, 2147483647] as a PositiveInt32.
|
|
133
|
+
*/
|
|
134
|
+
readonly mul: (x: WithSmallInt<PositiveInt32, 40>, y: WithSmallInt<PositiveInt32, 40>) => PositiveInt32;
|
|
135
|
+
/**
|
|
136
|
+
* Divides one PositiveInt32 by another using floor division.
|
|
137
|
+
* @param a The dividend PositiveInt32.
|
|
138
|
+
* @param b The divisor PositiveInt32.
|
|
139
|
+
* @returns `⌊a / b⌋` clamped to [1, 2147483647] as a PositiveInt32.
|
|
140
|
+
*/
|
|
141
|
+
readonly div: (x: WithSmallInt<PositiveInt32, 40>, y: 1 | 2 | 3 | 32 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 10 | 24 | 14 | 34 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | NormalizeBrandUnion<number & {
|
|
142
|
+
readonly NaNValue: false;
|
|
143
|
+
readonly "!=0": true;
|
|
144
|
+
readonly "> -2^16": true;
|
|
145
|
+
readonly "> -2^32": true;
|
|
146
|
+
readonly ">= -2^15": true;
|
|
147
|
+
readonly ">= -2^31": true;
|
|
148
|
+
readonly ">=0": true;
|
|
149
|
+
readonly "< 2^31": true;
|
|
150
|
+
readonly "< 2^32": true;
|
|
151
|
+
readonly Finite: true;
|
|
152
|
+
readonly Int: true;
|
|
153
|
+
readonly SafeInt: true;
|
|
154
|
+
} & Readonly<{
|
|
155
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
156
|
+
}>>) => PositiveInt32;
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=positive-int32.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positive-int32.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-int32.mts"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,eAAO,MAAM,eAAe,mCAAK,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;MAAW,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,aAAa;IACxB;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;;;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
|
|
3
|
+
const typeNameInMessage = 'a positive integer in [1, 2^31)';
|
|
4
|
+
const { MIN_VALUE, MAX_VALUE, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, clamp, } = TsVerifiedInternals.RefinedNumberUtils.operatorsForInteger({
|
|
5
|
+
integerOrSafeInteger: 'SafeInteger',
|
|
6
|
+
MIN_VALUE: 1,
|
|
7
|
+
MAX_VALUE: 2 ** 31 - 1,
|
|
8
|
+
typeNameInMessage,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a number is a PositiveInt32 (32-bit positive signed integer in the range [1, 2^31)).
|
|
12
|
+
* @param value The value to check.
|
|
13
|
+
* @returns `true` if the value is a PositiveInt32, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
const isPositiveInt32 = is;
|
|
16
|
+
/**
|
|
17
|
+
* Casts a number to a PositiveInt32 type.
|
|
18
|
+
* @param value The value to cast.
|
|
19
|
+
* @returns The value as a PositiveInt32 type.
|
|
20
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^31).
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const x = asPositiveInt32(1000); // PositiveInt32
|
|
24
|
+
* const y = asPositiveInt32(2147483647); // PositiveInt32
|
|
25
|
+
* // asPositiveInt32(0); // throws TypeError
|
|
26
|
+
* // asPositiveInt32(-1); // throws TypeError
|
|
27
|
+
* // asPositiveInt32(2147483648); // throws TypeError
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const asPositiveInt32 = castType;
|
|
31
|
+
/**
|
|
32
|
+
* Namespace providing type-safe arithmetic operations for 32-bit positive integers.
|
|
33
|
+
*
|
|
34
|
+
* All operations automatically clamp results to the valid PositiveInt32 range [1, 2147483647].
|
|
35
|
+
* This ensures that all arithmetic maintains the 32-bit positive integer constraint,
|
|
36
|
+
* with results below 1 clamped to MIN_VALUE and overflow results clamped to MAX_VALUE.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const a = asPositiveInt32(2000000000);
|
|
41
|
+
* const b = asPositiveInt32(500000000);
|
|
42
|
+
*
|
|
43
|
+
* // Arithmetic operations with automatic clamping and positive constraint
|
|
44
|
+
* const sum = PositiveInt32.add(a, b); // PositiveInt32 (2147483647 - clamped to MAX_VALUE)
|
|
45
|
+
* const diff = PositiveInt32.sub(a, b); // PositiveInt32 (1500000000)
|
|
46
|
+
* const reverseDiff = PositiveInt32.sub(b, a); // PositiveInt32 (1 - clamped to MIN_VALUE)
|
|
47
|
+
* const product = PositiveInt32.mul(a, b); // PositiveInt32 (2147483647 - clamped due to overflow)
|
|
48
|
+
*
|
|
49
|
+
* // Range operations (maintaining positive constraint)
|
|
50
|
+
* const clamped = PositiveInt32.clamp(-1000); // PositiveInt32 (1)
|
|
51
|
+
* const minimum = PositiveInt32.min(a, b); // PositiveInt32 (500000000)
|
|
52
|
+
* const maximum = PositiveInt32.max(a, b); // PositiveInt32 (2000000000)
|
|
53
|
+
*
|
|
54
|
+
* // Utility operations
|
|
55
|
+
* const random = PositiveInt32.random(); // PositiveInt32 (random value in [1, 2147483647])
|
|
56
|
+
* const power = PositiveInt32.pow(asPositiveInt32(2), asPositiveInt32(20)); // PositiveInt32 (1048576)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
const PositiveInt32 = {
|
|
60
|
+
/**
|
|
61
|
+
* Type guard to check if a value is a PositiveInt32.
|
|
62
|
+
* @param value The value to check.
|
|
63
|
+
* @returns `true` if the value is a 32-bit positive integer, `false` otherwise.
|
|
64
|
+
*/
|
|
65
|
+
is,
|
|
66
|
+
/**
|
|
67
|
+
* The minimum value for a 32-bit positive integer.
|
|
68
|
+
* @readonly
|
|
69
|
+
*/
|
|
70
|
+
MIN_VALUE,
|
|
71
|
+
/**
|
|
72
|
+
* The maximum value for a 32-bit positive integer.
|
|
73
|
+
* @readonly
|
|
74
|
+
*/
|
|
75
|
+
MAX_VALUE,
|
|
76
|
+
/**
|
|
77
|
+
* Returns the smaller of two PositiveInt32 values.
|
|
78
|
+
* @param a The first PositiveInt32.
|
|
79
|
+
* @param b The second PositiveInt32.
|
|
80
|
+
* @returns The minimum value as a PositiveInt32.
|
|
81
|
+
*/
|
|
82
|
+
min: min_,
|
|
83
|
+
/**
|
|
84
|
+
* Returns the larger of two PositiveInt32 values.
|
|
85
|
+
* @param a The first PositiveInt32.
|
|
86
|
+
* @param b The second PositiveInt32.
|
|
87
|
+
* @returns The maximum value as a PositiveInt32.
|
|
88
|
+
*/
|
|
89
|
+
max: max_,
|
|
90
|
+
/**
|
|
91
|
+
* Clamps a number to the PositiveInt32 range.
|
|
92
|
+
* @param value The number to clamp.
|
|
93
|
+
* @returns The value clamped to [1, 2147483647] as a PositiveInt32.
|
|
94
|
+
*/
|
|
95
|
+
clamp,
|
|
96
|
+
/**
|
|
97
|
+
* Generates a random PositiveInt32 value within the valid range.
|
|
98
|
+
* @returns A random PositiveInt32 between 1 and 2147483647.
|
|
99
|
+
*/
|
|
100
|
+
random,
|
|
101
|
+
/**
|
|
102
|
+
* Raises a PositiveInt32 to the power of another PositiveInt32.
|
|
103
|
+
* @param a The base PositiveInt32.
|
|
104
|
+
* @param b The exponent PositiveInt32.
|
|
105
|
+
* @returns `a ** b` clamped to [1, 2147483647] as a PositiveInt32.
|
|
106
|
+
*/
|
|
107
|
+
pow,
|
|
108
|
+
/**
|
|
109
|
+
* Adds two PositiveInt32 values.
|
|
110
|
+
* @param a The first PositiveInt32.
|
|
111
|
+
* @param b The second PositiveInt32.
|
|
112
|
+
* @returns `a + b` clamped to [1, 2147483647] as a PositiveInt32.
|
|
113
|
+
*/
|
|
114
|
+
add,
|
|
115
|
+
/**
|
|
116
|
+
* Subtracts one PositiveInt32 from another.
|
|
117
|
+
* @param a The minuend PositiveInt32.
|
|
118
|
+
* @param b The subtrahend PositiveInt32.
|
|
119
|
+
* @returns `a - b` clamped to [1, 2147483647] as a PositiveInt32 (minimum 1).
|
|
120
|
+
*/
|
|
121
|
+
sub,
|
|
122
|
+
/**
|
|
123
|
+
* Multiplies two PositiveInt32 values.
|
|
124
|
+
* @param a The first PositiveInt32.
|
|
125
|
+
* @param b The second PositiveInt32.
|
|
126
|
+
* @returns `a * b` clamped to [1, 2147483647] as a PositiveInt32.
|
|
127
|
+
*/
|
|
128
|
+
mul,
|
|
129
|
+
/**
|
|
130
|
+
* Divides one PositiveInt32 by another using floor division.
|
|
131
|
+
* @param a The dividend PositiveInt32.
|
|
132
|
+
* @param b The divisor PositiveInt32.
|
|
133
|
+
* @returns `⌊a / b⌋` clamped to [1, 2147483647] as a PositiveInt32.
|
|
134
|
+
*/
|
|
135
|
+
div,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export { PositiveInt32, asPositiveInt32, isPositiveInt32 };
|
|
139
|
+
//# sourceMappingURL=positive-int32.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positive-int32.mjs","sources":["../../../src/number/branded-types/positive-int32.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,iCAAiC;AAE3D,MAAM,EACJ,SAAS,EACT,SAAS,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,EACR,KAAK,GACN,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,mBAAmB,CAI5D;AACA,IAAA,oBAAoB,EAAE,aAAa;AACnC,IAAA,SAAS,EAAE,CAAC;AACZ,IAAA,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;IACtB,iBAAiB;AACT,CAAA,CAAC;AAEX;;;;AAIG;AACI,MAAM,eAAe,GAAG;AAE/B;;;;;;;;;;;;;AAaG;AACI,MAAM,eAAe,GAAG;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACI,MAAM,aAAa,GAAG;AAC3B;;;;AAIG;IACH,EAAE;AAEF;;;AAGG;IACH,SAAS;AAET;;;AAGG;IACH,SAAS;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;AAIG;IACH,KAAK;AAEL;;;AAGG;IACH,MAAM;AAEN;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;;;;;"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is a PositiveSafeInt (a positive safe integer in the range [1, MAX_SAFE_INTEGER]).
|
|
3
|
+
* @param value The value to check.
|
|
4
|
+
* @returns `true` if the value is a PositiveSafeInt, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isPositiveSafeInt: (a: number) => a is PositiveSafeInt;
|
|
7
|
+
/**
|
|
8
|
+
* Casts a number to a PositiveSafeInt type.
|
|
9
|
+
* @param value The value to cast.
|
|
10
|
+
* @returns The value as a PositiveSafeInt type.
|
|
11
|
+
* @throws {TypeError} If the value is not a positive safe integer.
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const x = asPositiveSafeInt(5); // PositiveSafeInt
|
|
15
|
+
* const y = asPositiveSafeInt(1000); // PositiveSafeInt
|
|
16
|
+
* // asPositiveSafeInt(0); // throws TypeError
|
|
17
|
+
* // asPositiveSafeInt(-1); // throws TypeError
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const asPositiveSafeInt: <N extends number>(x: N) => number & {
|
|
21
|
+
readonly NaNValue: false;
|
|
22
|
+
readonly "!=0": true;
|
|
23
|
+
readonly "> -2^16": true;
|
|
24
|
+
readonly "> -2^32": true;
|
|
25
|
+
readonly ">= -2^15": true;
|
|
26
|
+
readonly ">= -2^31": true;
|
|
27
|
+
readonly ">=0": true;
|
|
28
|
+
readonly Finite: true;
|
|
29
|
+
readonly Int: true;
|
|
30
|
+
readonly SafeInt: true;
|
|
31
|
+
} & Readonly<{
|
|
32
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
33
|
+
}> & N;
|
|
34
|
+
/**
|
|
35
|
+
* Namespace providing type-safe arithmetic operations for positive safe integers.
|
|
36
|
+
*
|
|
37
|
+
* All operations automatically clamp results to the positive safe integer range [1, MAX_SAFE_INTEGER].
|
|
38
|
+
* This ensures that all arithmetic maintains both the positive constraint and IEEE 754 precision guarantees,
|
|
39
|
+
* preventing precision loss and ensuring results are always positive.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const a = asPositiveSafeInt(1000000);
|
|
44
|
+
* const b = asPositiveSafeInt(2000000);
|
|
45
|
+
*
|
|
46
|
+
* // Arithmetic operations with positive safe range clamping
|
|
47
|
+
* const sum = PositiveSafeInt.add(a, b); // PositiveSafeInt (3000000)
|
|
48
|
+
* const diff = PositiveSafeInt.sub(a, b); // PositiveSafeInt (1 - clamped to MIN_VALUE)
|
|
49
|
+
* const product = PositiveSafeInt.mul(a, b); // PositiveSafeInt (2000000000000)
|
|
50
|
+
*
|
|
51
|
+
* // Range operations
|
|
52
|
+
* const clamped = PositiveSafeInt.clamp(0); // PositiveSafeInt (1)
|
|
53
|
+
* const minimum = PositiveSafeInt.min(a, b); // PositiveSafeInt (1000000)
|
|
54
|
+
* const maximum = PositiveSafeInt.max(a, b); // PositiveSafeInt (2000000)
|
|
55
|
+
*
|
|
56
|
+
* // Utility operations
|
|
57
|
+
* const random = PositiveSafeInt.random(); // PositiveSafeInt (random positive safe integer)
|
|
58
|
+
* const power = PositiveSafeInt.pow(asPositiveSafeInt(2), asPositiveSafeInt(10)); // PositiveSafeInt (1024)
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const PositiveSafeInt: {
|
|
62
|
+
/**
|
|
63
|
+
* Type guard to check if a value is a PositiveSafeInt.
|
|
64
|
+
* @param value The value to check.
|
|
65
|
+
* @returns `true` if the value is a positive safe integer, `false` otherwise.
|
|
66
|
+
*/
|
|
67
|
+
readonly is: (a: number) => a is PositiveSafeInt;
|
|
68
|
+
/**
|
|
69
|
+
* The minimum value for a positive safe integer.
|
|
70
|
+
* @readonly
|
|
71
|
+
*/
|
|
72
|
+
readonly MIN_VALUE: 1;
|
|
73
|
+
/**
|
|
74
|
+
* The maximum safe integer value (2^53 - 1).
|
|
75
|
+
* @readonly
|
|
76
|
+
*/
|
|
77
|
+
readonly MAX_VALUE: SafeUint;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the smaller of two PositiveSafeInt values.
|
|
80
|
+
* @param a The first PositiveSafeInt.
|
|
81
|
+
* @param b The second PositiveSafeInt.
|
|
82
|
+
* @returns The minimum value as a PositiveSafeInt.
|
|
83
|
+
*/
|
|
84
|
+
readonly min: (...values: readonly WithSmallInt<PositiveSafeInt, 40>[]) => PositiveSafeInt;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the larger of two PositiveSafeInt values.
|
|
87
|
+
* @param a The first PositiveSafeInt.
|
|
88
|
+
* @param b The second PositiveSafeInt.
|
|
89
|
+
* @returns The maximum value as a PositiveSafeInt.
|
|
90
|
+
*/
|
|
91
|
+
readonly max: (...values: readonly WithSmallInt<PositiveSafeInt, 40>[]) => PositiveSafeInt;
|
|
92
|
+
/**
|
|
93
|
+
* Clamps a number to the positive safe integer range.
|
|
94
|
+
* @param value The number to clamp.
|
|
95
|
+
* @returns The value clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
96
|
+
*/
|
|
97
|
+
readonly clamp: (x: number) => PositiveSafeInt;
|
|
98
|
+
/**
|
|
99
|
+
* Generates a random PositiveSafeInt value within the valid range.
|
|
100
|
+
* @returns A random PositiveSafeInt between 1 and MAX_SAFE_INTEGER.
|
|
101
|
+
*/
|
|
102
|
+
readonly random: (min: WithSmallInt<PositiveSafeInt, 40>, max: WithSmallInt<PositiveSafeInt, 40>) => PositiveSafeInt;
|
|
103
|
+
/**
|
|
104
|
+
* Raises a PositiveSafeInt to the power of another PositiveSafeInt.
|
|
105
|
+
* @param a The base PositiveSafeInt.
|
|
106
|
+
* @param b The exponent PositiveSafeInt.
|
|
107
|
+
* @returns `a ** b` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
108
|
+
*/
|
|
109
|
+
readonly pow: (x: WithSmallInt<PositiveSafeInt, 40>, y: WithSmallInt<PositiveSafeInt, 40>) => PositiveSafeInt;
|
|
110
|
+
/**
|
|
111
|
+
* Adds two PositiveSafeInt values.
|
|
112
|
+
* @param a The first PositiveSafeInt.
|
|
113
|
+
* @param b The second PositiveSafeInt.
|
|
114
|
+
* @returns `a + b` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
115
|
+
*/
|
|
116
|
+
readonly add: (x: WithSmallInt<PositiveSafeInt, 40>, y: WithSmallInt<PositiveSafeInt, 40>) => PositiveSafeInt;
|
|
117
|
+
/**
|
|
118
|
+
* Subtracts one PositiveSafeInt from another.
|
|
119
|
+
* @param a The minuend PositiveSafeInt.
|
|
120
|
+
* @param b The subtrahend PositiveSafeInt.
|
|
121
|
+
* @returns `a - b` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt (minimum 1).
|
|
122
|
+
*/
|
|
123
|
+
readonly sub: (x: WithSmallInt<PositiveSafeInt, 40>, y: WithSmallInt<PositiveSafeInt, 40>) => PositiveSafeInt;
|
|
124
|
+
/**
|
|
125
|
+
* Multiplies two PositiveSafeInt values.
|
|
126
|
+
* @param a The first PositiveSafeInt.
|
|
127
|
+
* @param b The second PositiveSafeInt.
|
|
128
|
+
* @returns `a * b` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
129
|
+
*/
|
|
130
|
+
readonly mul: (x: WithSmallInt<PositiveSafeInt, 40>, y: WithSmallInt<PositiveSafeInt, 40>) => PositiveSafeInt;
|
|
131
|
+
/**
|
|
132
|
+
* Divides one PositiveSafeInt by another using floor division.
|
|
133
|
+
* @param a The dividend PositiveSafeInt.
|
|
134
|
+
* @param b The divisor PositiveSafeInt.
|
|
135
|
+
* @returns `⌊a / b⌋` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
136
|
+
*/
|
|
137
|
+
readonly div: (x: WithSmallInt<PositiveSafeInt, 40>, y: 1 | 2 | 3 | 32 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 10 | 24 | 14 | 34 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | NormalizeBrandUnion<number & {
|
|
138
|
+
readonly NaNValue: false;
|
|
139
|
+
readonly "!=0": true;
|
|
140
|
+
readonly "> -2^16": true;
|
|
141
|
+
readonly "> -2^32": true;
|
|
142
|
+
readonly ">= -2^15": true;
|
|
143
|
+
readonly ">= -2^31": true;
|
|
144
|
+
readonly ">=0": true;
|
|
145
|
+
readonly Finite: true;
|
|
146
|
+
readonly Int: true;
|
|
147
|
+
readonly SafeInt: true;
|
|
148
|
+
} & Readonly<{
|
|
149
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
150
|
+
}>>) => PositiveSafeInt;
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=positive-safe-int.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positive-safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-safe-int.mts"],"names":[],"mappings":"AAiCA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,qCAAK,CAAC;AAEpC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;MAAW,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
|
|
3
|
+
const typeNameInMessage = 'a positive safe integer';
|
|
4
|
+
const { MIN_VALUE, MAX_VALUE, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, clamp, } = TsVerifiedInternals.RefinedNumberUtils.operatorsForInteger({
|
|
5
|
+
integerOrSafeInteger: 'SafeInteger',
|
|
6
|
+
MIN_VALUE: 1,
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
8
|
+
MAX_VALUE: Number.MAX_SAFE_INTEGER,
|
|
9
|
+
typeNameInMessage,
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a number is a PositiveSafeInt (a positive safe integer in the range [1, MAX_SAFE_INTEGER]).
|
|
13
|
+
* @param value The value to check.
|
|
14
|
+
* @returns `true` if the value is a PositiveSafeInt, `false` otherwise.
|
|
15
|
+
*/
|
|
16
|
+
const isPositiveSafeInt = is;
|
|
17
|
+
/**
|
|
18
|
+
* Casts a number to a PositiveSafeInt type.
|
|
19
|
+
* @param value The value to cast.
|
|
20
|
+
* @returns The value as a PositiveSafeInt type.
|
|
21
|
+
* @throws {TypeError} If the value is not a positive safe integer.
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const x = asPositiveSafeInt(5); // PositiveSafeInt
|
|
25
|
+
* const y = asPositiveSafeInt(1000); // PositiveSafeInt
|
|
26
|
+
* // asPositiveSafeInt(0); // throws TypeError
|
|
27
|
+
* // asPositiveSafeInt(-1); // throws TypeError
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const asPositiveSafeInt = castType;
|
|
31
|
+
/**
|
|
32
|
+
* Namespace providing type-safe arithmetic operations for positive safe integers.
|
|
33
|
+
*
|
|
34
|
+
* All operations automatically clamp results to the positive safe integer range [1, MAX_SAFE_INTEGER].
|
|
35
|
+
* This ensures that all arithmetic maintains both the positive constraint and IEEE 754 precision guarantees,
|
|
36
|
+
* preventing precision loss and ensuring results are always positive.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const a = asPositiveSafeInt(1000000);
|
|
41
|
+
* const b = asPositiveSafeInt(2000000);
|
|
42
|
+
*
|
|
43
|
+
* // Arithmetic operations with positive safe range clamping
|
|
44
|
+
* const sum = PositiveSafeInt.add(a, b); // PositiveSafeInt (3000000)
|
|
45
|
+
* const diff = PositiveSafeInt.sub(a, b); // PositiveSafeInt (1 - clamped to MIN_VALUE)
|
|
46
|
+
* const product = PositiveSafeInt.mul(a, b); // PositiveSafeInt (2000000000000)
|
|
47
|
+
*
|
|
48
|
+
* // Range operations
|
|
49
|
+
* const clamped = PositiveSafeInt.clamp(0); // PositiveSafeInt (1)
|
|
50
|
+
* const minimum = PositiveSafeInt.min(a, b); // PositiveSafeInt (1000000)
|
|
51
|
+
* const maximum = PositiveSafeInt.max(a, b); // PositiveSafeInt (2000000)
|
|
52
|
+
*
|
|
53
|
+
* // Utility operations
|
|
54
|
+
* const random = PositiveSafeInt.random(); // PositiveSafeInt (random positive safe integer)
|
|
55
|
+
* const power = PositiveSafeInt.pow(asPositiveSafeInt(2), asPositiveSafeInt(10)); // PositiveSafeInt (1024)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const PositiveSafeInt = {
|
|
59
|
+
/**
|
|
60
|
+
* Type guard to check if a value is a PositiveSafeInt.
|
|
61
|
+
* @param value The value to check.
|
|
62
|
+
* @returns `true` if the value is a positive safe integer, `false` otherwise.
|
|
63
|
+
*/
|
|
64
|
+
is,
|
|
65
|
+
/**
|
|
66
|
+
* The minimum value for a positive safe integer.
|
|
67
|
+
* @readonly
|
|
68
|
+
*/
|
|
69
|
+
MIN_VALUE,
|
|
70
|
+
/**
|
|
71
|
+
* The maximum safe integer value (2^53 - 1).
|
|
72
|
+
* @readonly
|
|
73
|
+
*/
|
|
74
|
+
MAX_VALUE,
|
|
75
|
+
/**
|
|
76
|
+
* Returns the smaller of two PositiveSafeInt values.
|
|
77
|
+
* @param a The first PositiveSafeInt.
|
|
78
|
+
* @param b The second PositiveSafeInt.
|
|
79
|
+
* @returns The minimum value as a PositiveSafeInt.
|
|
80
|
+
*/
|
|
81
|
+
min: min_,
|
|
82
|
+
/**
|
|
83
|
+
* Returns the larger of two PositiveSafeInt values.
|
|
84
|
+
* @param a The first PositiveSafeInt.
|
|
85
|
+
* @param b The second PositiveSafeInt.
|
|
86
|
+
* @returns The maximum value as a PositiveSafeInt.
|
|
87
|
+
*/
|
|
88
|
+
max: max_,
|
|
89
|
+
/**
|
|
90
|
+
* Clamps a number to the positive safe integer range.
|
|
91
|
+
* @param value The number to clamp.
|
|
92
|
+
* @returns The value clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
93
|
+
*/
|
|
94
|
+
clamp,
|
|
95
|
+
/**
|
|
96
|
+
* Generates a random PositiveSafeInt value within the valid range.
|
|
97
|
+
* @returns A random PositiveSafeInt between 1 and MAX_SAFE_INTEGER.
|
|
98
|
+
*/
|
|
99
|
+
random,
|
|
100
|
+
/**
|
|
101
|
+
* Raises a PositiveSafeInt to the power of another PositiveSafeInt.
|
|
102
|
+
* @param a The base PositiveSafeInt.
|
|
103
|
+
* @param b The exponent PositiveSafeInt.
|
|
104
|
+
* @returns `a ** b` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
105
|
+
*/
|
|
106
|
+
pow,
|
|
107
|
+
/**
|
|
108
|
+
* Adds two PositiveSafeInt values.
|
|
109
|
+
* @param a The first PositiveSafeInt.
|
|
110
|
+
* @param b The second PositiveSafeInt.
|
|
111
|
+
* @returns `a + b` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
112
|
+
*/
|
|
113
|
+
add,
|
|
114
|
+
/**
|
|
115
|
+
* Subtracts one PositiveSafeInt from another.
|
|
116
|
+
* @param a The minuend PositiveSafeInt.
|
|
117
|
+
* @param b The subtrahend PositiveSafeInt.
|
|
118
|
+
* @returns `a - b` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt (minimum 1).
|
|
119
|
+
*/
|
|
120
|
+
sub,
|
|
121
|
+
/**
|
|
122
|
+
* Multiplies two PositiveSafeInt values.
|
|
123
|
+
* @param a The first PositiveSafeInt.
|
|
124
|
+
* @param b The second PositiveSafeInt.
|
|
125
|
+
* @returns `a * b` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
126
|
+
*/
|
|
127
|
+
mul,
|
|
128
|
+
/**
|
|
129
|
+
* Divides one PositiveSafeInt by another using floor division.
|
|
130
|
+
* @param a The dividend PositiveSafeInt.
|
|
131
|
+
* @param b The divisor PositiveSafeInt.
|
|
132
|
+
* @returns `⌊a / b⌋` clamped to [1, MAX_SAFE_INTEGER] as a PositiveSafeInt.
|
|
133
|
+
*/
|
|
134
|
+
div,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export { PositiveSafeInt, asPositiveSafeInt, isPositiveSafeInt };
|
|
138
|
+
//# sourceMappingURL=positive-safe-int.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positive-safe-int.mjs","sources":["../../../src/number/branded-types/positive-safe-int.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,yBAAyB;AAEnD,MAAM,EACJ,SAAS,EACT,SAAS,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,EACR,KAAK,GACN,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,mBAAmB,CAI5D;AACA,IAAA,oBAAoB,EAAE,aAAa;AACnC,IAAA,SAAS,EAAE,CAAC;;IAEZ,SAAS,EAAE,MAAM,CAAC,gBAA4B;IAC9C,iBAAiB;AACT,CAAA,CAAC;AAEX;;;;AAIG;AACI,MAAM,iBAAiB,GAAG;AAEjC;;;;;;;;;;;;AAYG;AACI,MAAM,iBAAiB,GAAG;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACI,MAAM,eAAe,GAAG;AAC7B;;;;AAIG;IACH,EAAE;AAEF;;;AAGG;IACH,SAAS;AAET;;;AAGG;IACH,SAAS;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;AAIG;IACH,KAAK;AAEL;;;AAGG;IACH,MAAM;AAEN;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;;;;;"}
|