ts-data-forge 1.0.0 → 1.0.2
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 +18 -16
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is a PositiveUint16 (16-bit positive unsigned integer in the range [1, 2^16)).
|
|
3
|
+
* @param value The value to check.
|
|
4
|
+
* @returns `true` if the value is a PositiveUint16, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isPositiveUint16: (a: number) => a is PositiveUint16;
|
|
7
|
+
/**
|
|
8
|
+
* Casts a number to a PositiveUint16 type.
|
|
9
|
+
* @param value The value to cast.
|
|
10
|
+
* @returns The value as a PositiveUint16 type.
|
|
11
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^16).
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const x = asPositiveUint16(1000); // PositiveUint16
|
|
15
|
+
* const y = asPositiveUint16(65535); // PositiveUint16
|
|
16
|
+
* // asPositiveUint16(0); // throws TypeError
|
|
17
|
+
* // asPositiveUint16(-1); // throws TypeError
|
|
18
|
+
* // asPositiveUint16(65536); // throws TypeError
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const asPositiveUint16: <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^16": true;
|
|
30
|
+
readonly "< 2^31": true;
|
|
31
|
+
readonly "< 2^32": true;
|
|
32
|
+
readonly Finite: true;
|
|
33
|
+
readonly Int: true;
|
|
34
|
+
readonly SafeInt: true;
|
|
35
|
+
} & Readonly<{
|
|
36
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
37
|
+
}> & N;
|
|
38
|
+
/**
|
|
39
|
+
* Namespace providing type-safe arithmetic operations for 16-bit positive unsigned integers.
|
|
40
|
+
*
|
|
41
|
+
* All operations automatically clamp results to the valid PositiveUint16 range [1, 65535].
|
|
42
|
+
* This ensures that all arithmetic maintains the 16-bit positive unsigned integer constraint,
|
|
43
|
+
* with results below 1 clamped to MIN_VALUE and overflow results clamped to MAX_VALUE.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const a = asPositiveUint16(60000);
|
|
48
|
+
* const b = asPositiveUint16(10000);
|
|
49
|
+
*
|
|
50
|
+
* // Arithmetic operations with automatic clamping and positive constraint
|
|
51
|
+
* const sum = PositiveUint16.add(a, b); // PositiveUint16 (65535 - clamped to MAX_VALUE)
|
|
52
|
+
* const diff = PositiveUint16.sub(a, b); // PositiveUint16 (50000)
|
|
53
|
+
* const reverseDiff = PositiveUint16.sub(b, a); // PositiveUint16 (1 - clamped to MIN_VALUE)
|
|
54
|
+
* const product = PositiveUint16.mul(a, b); // PositiveUint16 (65535 - clamped due to overflow)
|
|
55
|
+
*
|
|
56
|
+
* // Range operations (maintaining positive constraint)
|
|
57
|
+
* const clamped = PositiveUint16.clamp(-100); // PositiveUint16 (1)
|
|
58
|
+
* const minimum = PositiveUint16.min(a, b); // PositiveUint16 (10000)
|
|
59
|
+
* const maximum = PositiveUint16.max(a, b); // PositiveUint16 (60000)
|
|
60
|
+
*
|
|
61
|
+
* // Utility operations
|
|
62
|
+
* const random = PositiveUint16.random(); // PositiveUint16 (random value in [1, 65535])
|
|
63
|
+
* const power = PositiveUint16.pow(asPositiveUint16(2), asPositiveUint16(10)); // PositiveUint16 (1024)
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare const PositiveUint16: {
|
|
67
|
+
/**
|
|
68
|
+
* Type guard to check if a value is a PositiveUint16.
|
|
69
|
+
* @param value The value to check.
|
|
70
|
+
* @returns `true` if the value is a 16-bit positive unsigned integer, `false` otherwise.
|
|
71
|
+
*/
|
|
72
|
+
readonly is: (a: number) => a is PositiveUint16;
|
|
73
|
+
/**
|
|
74
|
+
* The minimum value for a 16-bit positive unsigned integer.
|
|
75
|
+
* @readonly
|
|
76
|
+
*/
|
|
77
|
+
readonly MIN_VALUE: 1;
|
|
78
|
+
/**
|
|
79
|
+
* The maximum value for a 16-bit positive unsigned integer.
|
|
80
|
+
* @readonly
|
|
81
|
+
*/
|
|
82
|
+
readonly MAX_VALUE: number;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the smaller of two PositiveUint16 values.
|
|
85
|
+
* @param a The first PositiveUint16.
|
|
86
|
+
* @param b The second PositiveUint16.
|
|
87
|
+
* @returns The minimum value as a PositiveUint16.
|
|
88
|
+
*/
|
|
89
|
+
readonly min: (...values: readonly WithSmallInt<PositiveUint16, 40>[]) => PositiveUint16;
|
|
90
|
+
/**
|
|
91
|
+
* Returns the larger of two PositiveUint16 values.
|
|
92
|
+
* @param a The first PositiveUint16.
|
|
93
|
+
* @param b The second PositiveUint16.
|
|
94
|
+
* @returns The maximum value as a PositiveUint16.
|
|
95
|
+
*/
|
|
96
|
+
readonly max: (...values: readonly WithSmallInt<PositiveUint16, 40>[]) => PositiveUint16;
|
|
97
|
+
/**
|
|
98
|
+
* Clamps a number to the PositiveUint16 range.
|
|
99
|
+
* @param value The number to clamp.
|
|
100
|
+
* @returns The value clamped to [1, 65535] as a PositiveUint16.
|
|
101
|
+
*/
|
|
102
|
+
readonly clamp: (x: number) => PositiveUint16;
|
|
103
|
+
/**
|
|
104
|
+
* Generates a random PositiveUint16 value within the valid range.
|
|
105
|
+
* @returns A random PositiveUint16 between 1 and 65535.
|
|
106
|
+
*/
|
|
107
|
+
readonly random: (min: WithSmallInt<PositiveUint16, 40>, max: WithSmallInt<PositiveUint16, 40>) => PositiveUint16;
|
|
108
|
+
/**
|
|
109
|
+
* Raises a PositiveUint16 to the power of another PositiveUint16.
|
|
110
|
+
* @param a The base PositiveUint16.
|
|
111
|
+
* @param b The exponent PositiveUint16.
|
|
112
|
+
* @returns `a ** b` clamped to [1, 65535] as a PositiveUint16.
|
|
113
|
+
*/
|
|
114
|
+
readonly pow: (x: WithSmallInt<PositiveUint16, 40>, y: WithSmallInt<PositiveUint16, 40>) => PositiveUint16;
|
|
115
|
+
/**
|
|
116
|
+
* Adds two PositiveUint16 values.
|
|
117
|
+
* @param a The first PositiveUint16.
|
|
118
|
+
* @param b The second PositiveUint16.
|
|
119
|
+
* @returns `a + b` clamped to [1, 65535] as a PositiveUint16.
|
|
120
|
+
*/
|
|
121
|
+
readonly add: (x: WithSmallInt<PositiveUint16, 40>, y: WithSmallInt<PositiveUint16, 40>) => PositiveUint16;
|
|
122
|
+
/**
|
|
123
|
+
* Subtracts one PositiveUint16 from another.
|
|
124
|
+
* @param a The minuend PositiveUint16.
|
|
125
|
+
* @param b The subtrahend PositiveUint16.
|
|
126
|
+
* @returns `a - b` clamped to [1, 65535] as a PositiveUint16 (minimum 1).
|
|
127
|
+
*/
|
|
128
|
+
readonly sub: (x: WithSmallInt<PositiveUint16, 40>, y: WithSmallInt<PositiveUint16, 40>) => PositiveUint16;
|
|
129
|
+
/**
|
|
130
|
+
* Multiplies two PositiveUint16 values.
|
|
131
|
+
* @param a The first PositiveUint16.
|
|
132
|
+
* @param b The second PositiveUint16.
|
|
133
|
+
* @returns `a * b` clamped to [1, 65535] as a PositiveUint16.
|
|
134
|
+
*/
|
|
135
|
+
readonly mul: (x: WithSmallInt<PositiveUint16, 40>, y: WithSmallInt<PositiveUint16, 40>) => PositiveUint16;
|
|
136
|
+
/**
|
|
137
|
+
* Divides one PositiveUint16 by another using floor division.
|
|
138
|
+
* @param a The dividend PositiveUint16.
|
|
139
|
+
* @param b The divisor PositiveUint16.
|
|
140
|
+
* @returns `⌊a / b⌋` clamped to [1, 65535] as a PositiveUint16.
|
|
141
|
+
*/
|
|
142
|
+
readonly div: (x: WithSmallInt<PositiveUint16, 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 & {
|
|
143
|
+
readonly NaNValue: false;
|
|
144
|
+
readonly "!=0": true;
|
|
145
|
+
readonly "> -2^16": true;
|
|
146
|
+
readonly "> -2^32": true;
|
|
147
|
+
readonly ">= -2^15": true;
|
|
148
|
+
readonly ">= -2^31": true;
|
|
149
|
+
readonly ">=0": true;
|
|
150
|
+
readonly "< 2^16": true;
|
|
151
|
+
readonly "< 2^31": true;
|
|
152
|
+
readonly "< 2^32": true;
|
|
153
|
+
readonly Finite: true;
|
|
154
|
+
readonly Int: true;
|
|
155
|
+
readonly SafeInt: true;
|
|
156
|
+
} & Readonly<{
|
|
157
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
158
|
+
}>>) => PositiveUint16;
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=positive-uint16.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positive-uint16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-uint16.mts"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,oCAAK,CAAC;AAEnC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;MAAW,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,cAAc;IACzB;;;;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^16)';
|
|
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 ** 16 - 1,
|
|
8
|
+
typeNameInMessage,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a number is a PositiveUint16 (16-bit positive unsigned integer in the range [1, 2^16)).
|
|
12
|
+
* @param value The value to check.
|
|
13
|
+
* @returns `true` if the value is a PositiveUint16, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
const isPositiveUint16 = is;
|
|
16
|
+
/**
|
|
17
|
+
* Casts a number to a PositiveUint16 type.
|
|
18
|
+
* @param value The value to cast.
|
|
19
|
+
* @returns The value as a PositiveUint16 type.
|
|
20
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^16).
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const x = asPositiveUint16(1000); // PositiveUint16
|
|
24
|
+
* const y = asPositiveUint16(65535); // PositiveUint16
|
|
25
|
+
* // asPositiveUint16(0); // throws TypeError
|
|
26
|
+
* // asPositiveUint16(-1); // throws TypeError
|
|
27
|
+
* // asPositiveUint16(65536); // throws TypeError
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const asPositiveUint16 = castType;
|
|
31
|
+
/**
|
|
32
|
+
* Namespace providing type-safe arithmetic operations for 16-bit positive unsigned integers.
|
|
33
|
+
*
|
|
34
|
+
* All operations automatically clamp results to the valid PositiveUint16 range [1, 65535].
|
|
35
|
+
* This ensures that all arithmetic maintains the 16-bit positive unsigned 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 = asPositiveUint16(60000);
|
|
41
|
+
* const b = asPositiveUint16(10000);
|
|
42
|
+
*
|
|
43
|
+
* // Arithmetic operations with automatic clamping and positive constraint
|
|
44
|
+
* const sum = PositiveUint16.add(a, b); // PositiveUint16 (65535 - clamped to MAX_VALUE)
|
|
45
|
+
* const diff = PositiveUint16.sub(a, b); // PositiveUint16 (50000)
|
|
46
|
+
* const reverseDiff = PositiveUint16.sub(b, a); // PositiveUint16 (1 - clamped to MIN_VALUE)
|
|
47
|
+
* const product = PositiveUint16.mul(a, b); // PositiveUint16 (65535 - clamped due to overflow)
|
|
48
|
+
*
|
|
49
|
+
* // Range operations (maintaining positive constraint)
|
|
50
|
+
* const clamped = PositiveUint16.clamp(-100); // PositiveUint16 (1)
|
|
51
|
+
* const minimum = PositiveUint16.min(a, b); // PositiveUint16 (10000)
|
|
52
|
+
* const maximum = PositiveUint16.max(a, b); // PositiveUint16 (60000)
|
|
53
|
+
*
|
|
54
|
+
* // Utility operations
|
|
55
|
+
* const random = PositiveUint16.random(); // PositiveUint16 (random value in [1, 65535])
|
|
56
|
+
* const power = PositiveUint16.pow(asPositiveUint16(2), asPositiveUint16(10)); // PositiveUint16 (1024)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
const PositiveUint16 = {
|
|
60
|
+
/**
|
|
61
|
+
* Type guard to check if a value is a PositiveUint16.
|
|
62
|
+
* @param value The value to check.
|
|
63
|
+
* @returns `true` if the value is a 16-bit positive unsigned integer, `false` otherwise.
|
|
64
|
+
*/
|
|
65
|
+
is,
|
|
66
|
+
/**
|
|
67
|
+
* The minimum value for a 16-bit positive unsigned integer.
|
|
68
|
+
* @readonly
|
|
69
|
+
*/
|
|
70
|
+
MIN_VALUE,
|
|
71
|
+
/**
|
|
72
|
+
* The maximum value for a 16-bit positive unsigned integer.
|
|
73
|
+
* @readonly
|
|
74
|
+
*/
|
|
75
|
+
MAX_VALUE,
|
|
76
|
+
/**
|
|
77
|
+
* Returns the smaller of two PositiveUint16 values.
|
|
78
|
+
* @param a The first PositiveUint16.
|
|
79
|
+
* @param b The second PositiveUint16.
|
|
80
|
+
* @returns The minimum value as a PositiveUint16.
|
|
81
|
+
*/
|
|
82
|
+
min: min_,
|
|
83
|
+
/**
|
|
84
|
+
* Returns the larger of two PositiveUint16 values.
|
|
85
|
+
* @param a The first PositiveUint16.
|
|
86
|
+
* @param b The second PositiveUint16.
|
|
87
|
+
* @returns The maximum value as a PositiveUint16.
|
|
88
|
+
*/
|
|
89
|
+
max: max_,
|
|
90
|
+
/**
|
|
91
|
+
* Clamps a number to the PositiveUint16 range.
|
|
92
|
+
* @param value The number to clamp.
|
|
93
|
+
* @returns The value clamped to [1, 65535] as a PositiveUint16.
|
|
94
|
+
*/
|
|
95
|
+
clamp,
|
|
96
|
+
/**
|
|
97
|
+
* Generates a random PositiveUint16 value within the valid range.
|
|
98
|
+
* @returns A random PositiveUint16 between 1 and 65535.
|
|
99
|
+
*/
|
|
100
|
+
random,
|
|
101
|
+
/**
|
|
102
|
+
* Raises a PositiveUint16 to the power of another PositiveUint16.
|
|
103
|
+
* @param a The base PositiveUint16.
|
|
104
|
+
* @param b The exponent PositiveUint16.
|
|
105
|
+
* @returns `a ** b` clamped to [1, 65535] as a PositiveUint16.
|
|
106
|
+
*/
|
|
107
|
+
pow,
|
|
108
|
+
/**
|
|
109
|
+
* Adds two PositiveUint16 values.
|
|
110
|
+
* @param a The first PositiveUint16.
|
|
111
|
+
* @param b The second PositiveUint16.
|
|
112
|
+
* @returns `a + b` clamped to [1, 65535] as a PositiveUint16.
|
|
113
|
+
*/
|
|
114
|
+
add,
|
|
115
|
+
/**
|
|
116
|
+
* Subtracts one PositiveUint16 from another.
|
|
117
|
+
* @param a The minuend PositiveUint16.
|
|
118
|
+
* @param b The subtrahend PositiveUint16.
|
|
119
|
+
* @returns `a - b` clamped to [1, 65535] as a PositiveUint16 (minimum 1).
|
|
120
|
+
*/
|
|
121
|
+
sub,
|
|
122
|
+
/**
|
|
123
|
+
* Multiplies two PositiveUint16 values.
|
|
124
|
+
* @param a The first PositiveUint16.
|
|
125
|
+
* @param b The second PositiveUint16.
|
|
126
|
+
* @returns `a * b` clamped to [1, 65535] as a PositiveUint16.
|
|
127
|
+
*/
|
|
128
|
+
mul,
|
|
129
|
+
/**
|
|
130
|
+
* Divides one PositiveUint16 by another using floor division.
|
|
131
|
+
* @param a The dividend PositiveUint16.
|
|
132
|
+
* @param b The divisor PositiveUint16.
|
|
133
|
+
* @returns `⌊a / b⌋` clamped to [1, 65535] as a PositiveUint16.
|
|
134
|
+
*/
|
|
135
|
+
div,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export { PositiveUint16, asPositiveUint16, isPositiveUint16 };
|
|
139
|
+
//# sourceMappingURL=positive-uint16.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positive-uint16.mjs","sources":["../../../src/number/branded-types/positive-uint16.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,gBAAgB,GAAG;AAEhC;;;;;;;;;;;;;AAaG;AACI,MAAM,gBAAgB,GAAG;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACI,MAAM,cAAc,GAAG;AAC5B;;;;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,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is a PositiveUint32 (32-bit positive unsigned integer in the range [1, 2^32)).
|
|
3
|
+
* @param value The value to check.
|
|
4
|
+
* @returns `true` if the value is a PositiveUint32, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isPositiveUint32: (a: number) => a is PositiveUint32;
|
|
7
|
+
/**
|
|
8
|
+
* Casts a number to a PositiveUint32 type.
|
|
9
|
+
* @param value The value to cast.
|
|
10
|
+
* @returns The value as a PositiveUint32 type.
|
|
11
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^32).
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const x = asPositiveUint32(1000); // PositiveUint32
|
|
15
|
+
* const y = asPositiveUint32(4294967295); // PositiveUint32
|
|
16
|
+
* // asPositiveUint32(0); // throws TypeError
|
|
17
|
+
* // asPositiveUint32(-1); // throws TypeError
|
|
18
|
+
* // asPositiveUint32(4294967296); // throws TypeError
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const asPositiveUint32: <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^32": true;
|
|
30
|
+
readonly Finite: true;
|
|
31
|
+
readonly Int: true;
|
|
32
|
+
readonly SafeInt: true;
|
|
33
|
+
} & Readonly<{
|
|
34
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
35
|
+
}> & N;
|
|
36
|
+
/**
|
|
37
|
+
* Namespace providing type-safe arithmetic operations for 32-bit positive unsigned integers.
|
|
38
|
+
*
|
|
39
|
+
* All operations automatically clamp results to the valid PositiveUint32 range [1, 4294967295].
|
|
40
|
+
* This ensures that all arithmetic maintains the 32-bit positive unsigned integer constraint,
|
|
41
|
+
* with results below 1 clamped to MIN_VALUE and overflow results clamped to MAX_VALUE.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const a = asPositiveUint32(4000000000);
|
|
46
|
+
* const b = asPositiveUint32(1000000000);
|
|
47
|
+
*
|
|
48
|
+
* // Arithmetic operations with automatic clamping and positive constraint
|
|
49
|
+
* const sum = PositiveUint32.add(a, b); // PositiveUint32 (4294967295 - clamped to MAX_VALUE)
|
|
50
|
+
* const diff = PositiveUint32.sub(a, b); // PositiveUint32 (3000000000)
|
|
51
|
+
* const reverseDiff = PositiveUint32.sub(b, a); // PositiveUint32 (1 - clamped to MIN_VALUE)
|
|
52
|
+
* const product = PositiveUint32.mul(a, b); // PositiveUint32 (4294967295 - clamped due to overflow)
|
|
53
|
+
*
|
|
54
|
+
* // Range operations (maintaining positive constraint)
|
|
55
|
+
* const clamped = PositiveUint32.clamp(-100); // PositiveUint32 (1)
|
|
56
|
+
* const minimum = PositiveUint32.min(a, b); // PositiveUint32 (1000000000)
|
|
57
|
+
* const maximum = PositiveUint32.max(a, b); // PositiveUint32 (4000000000)
|
|
58
|
+
*
|
|
59
|
+
* // Utility operations
|
|
60
|
+
* const random = PositiveUint32.random(); // PositiveUint32 (random value in [1, 4294967295])
|
|
61
|
+
* const power = PositiveUint32.pow(asPositiveUint32(2), asPositiveUint32(20)); // PositiveUint32 (1048576)
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const PositiveUint32: {
|
|
65
|
+
/**
|
|
66
|
+
* Type guard to check if a value is a PositiveUint32.
|
|
67
|
+
* @param value The value to check.
|
|
68
|
+
* @returns `true` if the value is a 32-bit positive unsigned integer, `false` otherwise.
|
|
69
|
+
*/
|
|
70
|
+
readonly is: (a: number) => a is PositiveUint32;
|
|
71
|
+
/**
|
|
72
|
+
* The minimum value for a 32-bit positive unsigned integer.
|
|
73
|
+
* @readonly
|
|
74
|
+
*/
|
|
75
|
+
readonly MIN_VALUE: 1;
|
|
76
|
+
/**
|
|
77
|
+
* The maximum value for a 32-bit positive unsigned integer.
|
|
78
|
+
* @readonly
|
|
79
|
+
*/
|
|
80
|
+
readonly MAX_VALUE: number;
|
|
81
|
+
/**
|
|
82
|
+
* Returns the smaller of two PositiveUint32 values.
|
|
83
|
+
* @param a The first PositiveUint32.
|
|
84
|
+
* @param b The second PositiveUint32.
|
|
85
|
+
* @returns The minimum value as a PositiveUint32.
|
|
86
|
+
*/
|
|
87
|
+
readonly min: (...values: readonly WithSmallInt<PositiveUint32, 40>[]) => PositiveUint32;
|
|
88
|
+
/**
|
|
89
|
+
* Returns the larger of two PositiveUint32 values.
|
|
90
|
+
* @param a The first PositiveUint32.
|
|
91
|
+
* @param b The second PositiveUint32.
|
|
92
|
+
* @returns The maximum value as a PositiveUint32.
|
|
93
|
+
*/
|
|
94
|
+
readonly max: (...values: readonly WithSmallInt<PositiveUint32, 40>[]) => PositiveUint32;
|
|
95
|
+
/**
|
|
96
|
+
* Clamps a number to the PositiveUint32 range.
|
|
97
|
+
* @param value The number to clamp.
|
|
98
|
+
* @returns The value clamped to [1, 4294967295] as a PositiveUint32.
|
|
99
|
+
*/
|
|
100
|
+
readonly clamp: (x: number) => PositiveUint32;
|
|
101
|
+
/**
|
|
102
|
+
* Generates a random PositiveUint32 value within the valid range.
|
|
103
|
+
* @returns A random PositiveUint32 between 1 and 4294967295.
|
|
104
|
+
*/
|
|
105
|
+
readonly random: (min: WithSmallInt<PositiveUint32, 40>, max: WithSmallInt<PositiveUint32, 40>) => PositiveUint32;
|
|
106
|
+
/**
|
|
107
|
+
* Raises a PositiveUint32 to the power of another PositiveUint32.
|
|
108
|
+
* @param a The base PositiveUint32.
|
|
109
|
+
* @param b The exponent PositiveUint32.
|
|
110
|
+
* @returns `a ** b` clamped to [1, 4294967295] as a PositiveUint32.
|
|
111
|
+
*/
|
|
112
|
+
readonly pow: (x: WithSmallInt<PositiveUint32, 40>, y: WithSmallInt<PositiveUint32, 40>) => PositiveUint32;
|
|
113
|
+
/**
|
|
114
|
+
* Adds two PositiveUint32 values.
|
|
115
|
+
* @param a The first PositiveUint32.
|
|
116
|
+
* @param b The second PositiveUint32.
|
|
117
|
+
* @returns `a + b` clamped to [1, 4294967295] as a PositiveUint32.
|
|
118
|
+
*/
|
|
119
|
+
readonly add: (x: WithSmallInt<PositiveUint32, 40>, y: WithSmallInt<PositiveUint32, 40>) => PositiveUint32;
|
|
120
|
+
/**
|
|
121
|
+
* Subtracts one PositiveUint32 from another.
|
|
122
|
+
* @param a The minuend PositiveUint32.
|
|
123
|
+
* @param b The subtrahend PositiveUint32.
|
|
124
|
+
* @returns `a - b` clamped to [1, 4294967295] as a PositiveUint32 (minimum 1).
|
|
125
|
+
*/
|
|
126
|
+
readonly sub: (x: WithSmallInt<PositiveUint32, 40>, y: WithSmallInt<PositiveUint32, 40>) => PositiveUint32;
|
|
127
|
+
/**
|
|
128
|
+
* Multiplies two PositiveUint32 values.
|
|
129
|
+
* @param a The first PositiveUint32.
|
|
130
|
+
* @param b The second PositiveUint32.
|
|
131
|
+
* @returns `a * b` clamped to [1, 4294967295] as a PositiveUint32.
|
|
132
|
+
*/
|
|
133
|
+
readonly mul: (x: WithSmallInt<PositiveUint32, 40>, y: WithSmallInt<PositiveUint32, 40>) => PositiveUint32;
|
|
134
|
+
/**
|
|
135
|
+
* Divides one PositiveUint32 by another using floor division.
|
|
136
|
+
* @param a The dividend PositiveUint32.
|
|
137
|
+
* @param b The divisor PositiveUint32.
|
|
138
|
+
* @returns `⌊a / b⌋` clamped to [1, 4294967295] as a PositiveUint32.
|
|
139
|
+
*/
|
|
140
|
+
readonly div: (x: WithSmallInt<PositiveUint32, 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 & {
|
|
141
|
+
readonly NaNValue: false;
|
|
142
|
+
readonly "!=0": true;
|
|
143
|
+
readonly "> -2^16": true;
|
|
144
|
+
readonly "> -2^32": true;
|
|
145
|
+
readonly ">= -2^15": true;
|
|
146
|
+
readonly ">= -2^31": true;
|
|
147
|
+
readonly ">=0": true;
|
|
148
|
+
readonly "< 2^32": true;
|
|
149
|
+
readonly Finite: true;
|
|
150
|
+
readonly Int: true;
|
|
151
|
+
readonly SafeInt: true;
|
|
152
|
+
} & Readonly<{
|
|
153
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
154
|
+
}>>) => PositiveUint32;
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=positive-uint32.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positive-uint32.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/positive-uint32.mts"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,oCAAK,CAAC;AAEnC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;MAAW,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,cAAc;IACzB;;;;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^32)';
|
|
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 ** 32 - 1,
|
|
8
|
+
typeNameInMessage,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a number is a PositiveUint32 (32-bit positive unsigned integer in the range [1, 2^32)).
|
|
12
|
+
* @param value The value to check.
|
|
13
|
+
* @returns `true` if the value is a PositiveUint32, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
const isPositiveUint32 = is;
|
|
16
|
+
/**
|
|
17
|
+
* Casts a number to a PositiveUint32 type.
|
|
18
|
+
* @param value The value to cast.
|
|
19
|
+
* @returns The value as a PositiveUint32 type.
|
|
20
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^32).
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const x = asPositiveUint32(1000); // PositiveUint32
|
|
24
|
+
* const y = asPositiveUint32(4294967295); // PositiveUint32
|
|
25
|
+
* // asPositiveUint32(0); // throws TypeError
|
|
26
|
+
* // asPositiveUint32(-1); // throws TypeError
|
|
27
|
+
* // asPositiveUint32(4294967296); // throws TypeError
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const asPositiveUint32 = castType;
|
|
31
|
+
/**
|
|
32
|
+
* Namespace providing type-safe arithmetic operations for 32-bit positive unsigned integers.
|
|
33
|
+
*
|
|
34
|
+
* All operations automatically clamp results to the valid PositiveUint32 range [1, 4294967295].
|
|
35
|
+
* This ensures that all arithmetic maintains the 32-bit positive unsigned 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 = asPositiveUint32(4000000000);
|
|
41
|
+
* const b = asPositiveUint32(1000000000);
|
|
42
|
+
*
|
|
43
|
+
* // Arithmetic operations with automatic clamping and positive constraint
|
|
44
|
+
* const sum = PositiveUint32.add(a, b); // PositiveUint32 (4294967295 - clamped to MAX_VALUE)
|
|
45
|
+
* const diff = PositiveUint32.sub(a, b); // PositiveUint32 (3000000000)
|
|
46
|
+
* const reverseDiff = PositiveUint32.sub(b, a); // PositiveUint32 (1 - clamped to MIN_VALUE)
|
|
47
|
+
* const product = PositiveUint32.mul(a, b); // PositiveUint32 (4294967295 - clamped due to overflow)
|
|
48
|
+
*
|
|
49
|
+
* // Range operations (maintaining positive constraint)
|
|
50
|
+
* const clamped = PositiveUint32.clamp(-100); // PositiveUint32 (1)
|
|
51
|
+
* const minimum = PositiveUint32.min(a, b); // PositiveUint32 (1000000000)
|
|
52
|
+
* const maximum = PositiveUint32.max(a, b); // PositiveUint32 (4000000000)
|
|
53
|
+
*
|
|
54
|
+
* // Utility operations
|
|
55
|
+
* const random = PositiveUint32.random(); // PositiveUint32 (random value in [1, 4294967295])
|
|
56
|
+
* const power = PositiveUint32.pow(asPositiveUint32(2), asPositiveUint32(20)); // PositiveUint32 (1048576)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
const PositiveUint32 = {
|
|
60
|
+
/**
|
|
61
|
+
* Type guard to check if a value is a PositiveUint32.
|
|
62
|
+
* @param value The value to check.
|
|
63
|
+
* @returns `true` if the value is a 32-bit positive unsigned integer, `false` otherwise.
|
|
64
|
+
*/
|
|
65
|
+
is,
|
|
66
|
+
/**
|
|
67
|
+
* The minimum value for a 32-bit positive unsigned integer.
|
|
68
|
+
* @readonly
|
|
69
|
+
*/
|
|
70
|
+
MIN_VALUE,
|
|
71
|
+
/**
|
|
72
|
+
* The maximum value for a 32-bit positive unsigned integer.
|
|
73
|
+
* @readonly
|
|
74
|
+
*/
|
|
75
|
+
MAX_VALUE,
|
|
76
|
+
/**
|
|
77
|
+
* Returns the smaller of two PositiveUint32 values.
|
|
78
|
+
* @param a The first PositiveUint32.
|
|
79
|
+
* @param b The second PositiveUint32.
|
|
80
|
+
* @returns The minimum value as a PositiveUint32.
|
|
81
|
+
*/
|
|
82
|
+
min: min_,
|
|
83
|
+
/**
|
|
84
|
+
* Returns the larger of two PositiveUint32 values.
|
|
85
|
+
* @param a The first PositiveUint32.
|
|
86
|
+
* @param b The second PositiveUint32.
|
|
87
|
+
* @returns The maximum value as a PositiveUint32.
|
|
88
|
+
*/
|
|
89
|
+
max: max_,
|
|
90
|
+
/**
|
|
91
|
+
* Clamps a number to the PositiveUint32 range.
|
|
92
|
+
* @param value The number to clamp.
|
|
93
|
+
* @returns The value clamped to [1, 4294967295] as a PositiveUint32.
|
|
94
|
+
*/
|
|
95
|
+
clamp,
|
|
96
|
+
/**
|
|
97
|
+
* Generates a random PositiveUint32 value within the valid range.
|
|
98
|
+
* @returns A random PositiveUint32 between 1 and 4294967295.
|
|
99
|
+
*/
|
|
100
|
+
random,
|
|
101
|
+
/**
|
|
102
|
+
* Raises a PositiveUint32 to the power of another PositiveUint32.
|
|
103
|
+
* @param a The base PositiveUint32.
|
|
104
|
+
* @param b The exponent PositiveUint32.
|
|
105
|
+
* @returns `a ** b` clamped to [1, 4294967295] as a PositiveUint32.
|
|
106
|
+
*/
|
|
107
|
+
pow,
|
|
108
|
+
/**
|
|
109
|
+
* Adds two PositiveUint32 values.
|
|
110
|
+
* @param a The first PositiveUint32.
|
|
111
|
+
* @param b The second PositiveUint32.
|
|
112
|
+
* @returns `a + b` clamped to [1, 4294967295] as a PositiveUint32.
|
|
113
|
+
*/
|
|
114
|
+
add,
|
|
115
|
+
/**
|
|
116
|
+
* Subtracts one PositiveUint32 from another.
|
|
117
|
+
* @param a The minuend PositiveUint32.
|
|
118
|
+
* @param b The subtrahend PositiveUint32.
|
|
119
|
+
* @returns `a - b` clamped to [1, 4294967295] as a PositiveUint32 (minimum 1).
|
|
120
|
+
*/
|
|
121
|
+
sub,
|
|
122
|
+
/**
|
|
123
|
+
* Multiplies two PositiveUint32 values.
|
|
124
|
+
* @param a The first PositiveUint32.
|
|
125
|
+
* @param b The second PositiveUint32.
|
|
126
|
+
* @returns `a * b` clamped to [1, 4294967295] as a PositiveUint32.
|
|
127
|
+
*/
|
|
128
|
+
mul,
|
|
129
|
+
/**
|
|
130
|
+
* Divides one PositiveUint32 by another using floor division.
|
|
131
|
+
* @param a The dividend PositiveUint32.
|
|
132
|
+
* @param b The divisor PositiveUint32.
|
|
133
|
+
* @returns `⌊a / b⌋` clamped to [1, 4294967295] as a PositiveUint32.
|
|
134
|
+
*/
|
|
135
|
+
div,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export { PositiveUint32, asPositiveUint32, isPositiveUint32 };
|
|
139
|
+
//# sourceMappingURL=positive-uint32.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positive-uint32.mjs","sources":["../../../src/number/branded-types/positive-uint32.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,gBAAgB,GAAG;AAEhC;;;;;;;;;;;;;AAaG;AACI,MAAM,gBAAgB,GAAG;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACI,MAAM,cAAc,GAAG;AAC5B;;;;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;;;;;"}
|