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,242 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard that checks if a value is an integer.
|
|
4
|
+
*
|
|
5
|
+
* Returns `true` if the value is any integer (positive, negative, or zero),
|
|
6
|
+
* with no fractional component. This includes values outside the safe integer
|
|
7
|
+
* range, unlike SafeInt.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The value to check
|
|
10
|
+
* @returns `true` if the value is an integer, `false` otherwise
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* isInt(5); // true
|
|
15
|
+
* isInt(-10); // true
|
|
16
|
+
* isInt(0); // true
|
|
17
|
+
* isInt(5.5); // false
|
|
18
|
+
* isInt(NaN); // false
|
|
19
|
+
* isInt(Infinity); // false
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const isInt: (a: number) => a is Int;
|
|
23
|
+
/**
|
|
24
|
+
* Casts a number to an Int branded type.
|
|
25
|
+
*
|
|
26
|
+
* This function validates that the input is an integer and returns it with
|
|
27
|
+
* the Int brand. Throws a TypeError if the value has a fractional component
|
|
28
|
+
* or is not a finite number.
|
|
29
|
+
*
|
|
30
|
+
* @param value - The value to cast
|
|
31
|
+
* @returns The value as an Int branded type
|
|
32
|
+
* @throws {TypeError} If the value is not an integer
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const x = asInt(5); // Int
|
|
37
|
+
* const y = asInt(-10); // Int
|
|
38
|
+
* const z = asInt(0); // Int
|
|
39
|
+
*
|
|
40
|
+
* // These throw TypeError:
|
|
41
|
+
* // asInt(5.5); // Not an integer
|
|
42
|
+
* // asInt(NaN); // Not a number
|
|
43
|
+
* // asInt(Infinity); // Not finite
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const asInt: <N extends number>(x: N) => number & {
|
|
47
|
+
readonly NaNValue: false;
|
|
48
|
+
readonly Finite: true;
|
|
49
|
+
readonly Int: true;
|
|
50
|
+
} & Readonly<{
|
|
51
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
52
|
+
}> & N;
|
|
53
|
+
/**
|
|
54
|
+
* Namespace providing type-safe operations for Int branded types.
|
|
55
|
+
*
|
|
56
|
+
* The Int type represents any integer value (no fractional component) without
|
|
57
|
+
* range restrictions. All operations preserve the integer constraint, using
|
|
58
|
+
* floor division for division operations.
|
|
59
|
+
*
|
|
60
|
+
* Unlike SafeInt, Int allows values outside the safe integer range
|
|
61
|
+
* (±2^53 - 1), but be aware that very large integers may lose precision
|
|
62
|
+
* in JavaScript's number type.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // Type validation
|
|
67
|
+
* Int.is(42); // true
|
|
68
|
+
* Int.is(3.14); // false
|
|
69
|
+
* Int.is(-0); // true (negative zero is an integer)
|
|
70
|
+
*
|
|
71
|
+
* // Basic arithmetic
|
|
72
|
+
* const a = asInt(10);
|
|
73
|
+
* const b = asInt(3);
|
|
74
|
+
*
|
|
75
|
+
* const sum = Int.add(a, b); // Int (13)
|
|
76
|
+
* const diff = Int.sub(a, b); // Int (7)
|
|
77
|
+
* const product = Int.mul(a, b); // Int (30)
|
|
78
|
+
* const quotient = Int.div(a, b); // Int (3) - floor division
|
|
79
|
+
* const power = Int.pow(a, b); // Int (1000)
|
|
80
|
+
*
|
|
81
|
+
* // Utility operations
|
|
82
|
+
* const absolute = Int.abs(asInt(-42)); // Int (42)
|
|
83
|
+
* const minimum = Int.min(a, b, asInt(5)); // Int (3)
|
|
84
|
+
* const maximum = Int.max(a, b, asInt(5)); // Int (10)
|
|
85
|
+
*
|
|
86
|
+
* // Random generation
|
|
87
|
+
* const die = Int.random(asInt(1), asInt(6)); // Random Int in [1, 6]
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare const Int: {
|
|
91
|
+
/**
|
|
92
|
+
* Type guard that checks if a value is an integer.
|
|
93
|
+
*
|
|
94
|
+
* @param value - The value to check
|
|
95
|
+
* @returns `true` if the value is an integer, `false` otherwise
|
|
96
|
+
*
|
|
97
|
+
* @see {@link isInt} for usage examples
|
|
98
|
+
*/
|
|
99
|
+
readonly is: (a: number) => a is Int;
|
|
100
|
+
/**
|
|
101
|
+
* Returns the absolute value of an integer.
|
|
102
|
+
*
|
|
103
|
+
* The result is always non-negative and maintains the Int brand.
|
|
104
|
+
* Note that Math.abs(Number.MIN_SAFE_INTEGER) exceeds Number.MAX_SAFE_INTEGER,
|
|
105
|
+
* so use SafeInt for guaranteed precision.
|
|
106
|
+
*
|
|
107
|
+
* @param a - The integer value
|
|
108
|
+
* @returns The absolute value as a non-negative Int
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* Int.abs(asInt(-5)); // Int (5)
|
|
113
|
+
* Int.abs(asInt(3)); // Int (3)
|
|
114
|
+
* Int.abs(asInt(-0)); // Int (0)
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
readonly abs: (x: WithSmallInt<Int, 40>) => TsVerifiedInternals.RefinedNumberUtils.ToNonNegative<Int>;
|
|
118
|
+
/**
|
|
119
|
+
* Returns the minimum value from a list of integers.
|
|
120
|
+
*
|
|
121
|
+
* @param values - The integers to compare (at least one required)
|
|
122
|
+
* @returns The smallest value as an Int
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* Int.min(asInt(5), asInt(3)); // Int (3)
|
|
127
|
+
* Int.min(asInt(-10), asInt(0), asInt(10)); // Int (-10)
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
readonly min: (...values: readonly WithSmallInt<Int, 40>[]) => Int;
|
|
131
|
+
/**
|
|
132
|
+
* Returns the maximum value from a list of integers.
|
|
133
|
+
*
|
|
134
|
+
* @param values - The integers to compare (at least one required)
|
|
135
|
+
* @returns The largest value as an Int
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* Int.max(asInt(5), asInt(3)); // Int (5)
|
|
140
|
+
* Int.max(asInt(-10), asInt(0), asInt(10)); // Int (10)
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
readonly max: (...values: readonly WithSmallInt<Int, 40>[]) => Int;
|
|
144
|
+
/**
|
|
145
|
+
* Generates a random integer within the specified range (inclusive).
|
|
146
|
+
*
|
|
147
|
+
* The range is inclusive on both ends, so random(1, 6) can return
|
|
148
|
+
* any of: 1, 2, 3, 4, 5, or 6.
|
|
149
|
+
*
|
|
150
|
+
* @param min - The minimum value (inclusive)
|
|
151
|
+
* @param max - The maximum value (inclusive)
|
|
152
|
+
* @returns A random Int in the range [min, max]
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Dice roll
|
|
157
|
+
* const d6 = Int.random(asInt(1), asInt(6));
|
|
158
|
+
*
|
|
159
|
+
* // Random array index
|
|
160
|
+
* const index = Int.random(asInt(0), asInt(array.length - 1));
|
|
161
|
+
*
|
|
162
|
+
* // Can generate negative values
|
|
163
|
+
* const temp = Int.random(asInt(-10), asInt(10));
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
readonly random: (min: WithSmallInt<Int, 40>, max: WithSmallInt<Int, 40>) => Int;
|
|
167
|
+
/**
|
|
168
|
+
* Raises an integer to a power.
|
|
169
|
+
* @param a - The base integer
|
|
170
|
+
* @param b - The exponent integer
|
|
171
|
+
* @returns `a ** b` as an Int
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* Int.pow(asInt(2), asInt(3)); // Int (8)
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
readonly pow: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => Int;
|
|
178
|
+
/**
|
|
179
|
+
* Adds two integers.
|
|
180
|
+
* @param a - First integer
|
|
181
|
+
* @param b - Second integer
|
|
182
|
+
* @returns `a + b` as an Int
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* Int.add(asInt(5), asInt(3)); // Int (8)
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
readonly add: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => Int;
|
|
189
|
+
/**
|
|
190
|
+
* Subtracts two integers.
|
|
191
|
+
* @param a - First integer
|
|
192
|
+
* @param b - Second integer
|
|
193
|
+
* @returns `a - b` as an Int
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* Int.sub(asInt(8), asInt(3)); // Int (5)
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
readonly sub: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => Int;
|
|
200
|
+
/**
|
|
201
|
+
* Multiplies two integers.
|
|
202
|
+
* @param a - First integer
|
|
203
|
+
* @param b - Second integer
|
|
204
|
+
* @returns `a * b` as an Int
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* Int.mul(asInt(4), asInt(3)); // Int (12)
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
readonly mul: (x: WithSmallInt<Int, 40>, y: WithSmallInt<Int, 40>) => Int;
|
|
211
|
+
/**
|
|
212
|
+
* Divides two integers using floor division.
|
|
213
|
+
*
|
|
214
|
+
* Performs mathematical floor division: `⌊a / b⌋`.
|
|
215
|
+
* The result is always an integer, rounding toward negative infinity.
|
|
216
|
+
*
|
|
217
|
+
* @param a - The dividend
|
|
218
|
+
* @param b - The divisor (must be non-zero)
|
|
219
|
+
* @returns The integer quotient as an Int
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // Positive division
|
|
224
|
+
* Int.div(asInt(10), asInt(3)); // Int (3)
|
|
225
|
+
* Int.div(asInt(9), asInt(3)); // Int (3)
|
|
226
|
+
*
|
|
227
|
+
* // Negative division (rounds toward -∞)
|
|
228
|
+
* Int.div(asInt(-10), asInt(3)); // Int (-4)
|
|
229
|
+
* Int.div(asInt(10), asInt(-3)); // Int (-4)
|
|
230
|
+
* Int.div(asInt(-10), asInt(-3)); // Int (3)
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
readonly div: (x: WithSmallInt<Int, 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 | -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 | -40 | NormalizeBrandUnion<number & {
|
|
234
|
+
readonly NaNValue: false;
|
|
235
|
+
readonly "!=0": true;
|
|
236
|
+
readonly Finite: true;
|
|
237
|
+
readonly Int: true;
|
|
238
|
+
} & Readonly<{
|
|
239
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
240
|
+
}>>) => Int;
|
|
241
|
+
};
|
|
242
|
+
//# sourceMappingURL=int.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AA6BlE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,KAAK,yBAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,KAAK;;;;;;MAAW,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,GAAG;IACd;;;;;;;OAOG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;OAWG;;IAGH;;;;;;;;;;;OAWG;;IAGH;;;;;;;;;;;;;;;;;;;;;OAqBG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;;;;;;;;;;;;;OAqBG;;;;;;;;;CAEK,CAAC"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
|
|
3
|
+
const typeNameInMessage = 'an integer';
|
|
4
|
+
const { abs, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, } = TsVerifiedInternals.RefinedNumberUtils.operatorsForInteger({
|
|
5
|
+
integerOrSafeInteger: 'Integer',
|
|
6
|
+
MIN_VALUE: undefined,
|
|
7
|
+
MAX_VALUE: undefined,
|
|
8
|
+
typeNameInMessage,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Type guard that checks if a value is an integer.
|
|
12
|
+
*
|
|
13
|
+
* Returns `true` if the value is any integer (positive, negative, or zero),
|
|
14
|
+
* with no fractional component. This includes values outside the safe integer
|
|
15
|
+
* range, unlike SafeInt.
|
|
16
|
+
*
|
|
17
|
+
* @param value - The value to check
|
|
18
|
+
* @returns `true` if the value is an integer, `false` otherwise
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* isInt(5); // true
|
|
23
|
+
* isInt(-10); // true
|
|
24
|
+
* isInt(0); // true
|
|
25
|
+
* isInt(5.5); // false
|
|
26
|
+
* isInt(NaN); // false
|
|
27
|
+
* isInt(Infinity); // false
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const isInt = is;
|
|
31
|
+
/**
|
|
32
|
+
* Casts a number to an Int branded type.
|
|
33
|
+
*
|
|
34
|
+
* This function validates that the input is an integer and returns it with
|
|
35
|
+
* the Int brand. Throws a TypeError if the value has a fractional component
|
|
36
|
+
* or is not a finite number.
|
|
37
|
+
*
|
|
38
|
+
* @param value - The value to cast
|
|
39
|
+
* @returns The value as an Int branded type
|
|
40
|
+
* @throws {TypeError} If the value is not an integer
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const x = asInt(5); // Int
|
|
45
|
+
* const y = asInt(-10); // Int
|
|
46
|
+
* const z = asInt(0); // Int
|
|
47
|
+
*
|
|
48
|
+
* // These throw TypeError:
|
|
49
|
+
* // asInt(5.5); // Not an integer
|
|
50
|
+
* // asInt(NaN); // Not a number
|
|
51
|
+
* // asInt(Infinity); // Not finite
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
const asInt = castType;
|
|
55
|
+
/**
|
|
56
|
+
* Namespace providing type-safe operations for Int branded types.
|
|
57
|
+
*
|
|
58
|
+
* The Int type represents any integer value (no fractional component) without
|
|
59
|
+
* range restrictions. All operations preserve the integer constraint, using
|
|
60
|
+
* floor division for division operations.
|
|
61
|
+
*
|
|
62
|
+
* Unlike SafeInt, Int allows values outside the safe integer range
|
|
63
|
+
* (±2^53 - 1), but be aware that very large integers may lose precision
|
|
64
|
+
* in JavaScript's number type.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Type validation
|
|
69
|
+
* Int.is(42); // true
|
|
70
|
+
* Int.is(3.14); // false
|
|
71
|
+
* Int.is(-0); // true (negative zero is an integer)
|
|
72
|
+
*
|
|
73
|
+
* // Basic arithmetic
|
|
74
|
+
* const a = asInt(10);
|
|
75
|
+
* const b = asInt(3);
|
|
76
|
+
*
|
|
77
|
+
* const sum = Int.add(a, b); // Int (13)
|
|
78
|
+
* const diff = Int.sub(a, b); // Int (7)
|
|
79
|
+
* const product = Int.mul(a, b); // Int (30)
|
|
80
|
+
* const quotient = Int.div(a, b); // Int (3) - floor division
|
|
81
|
+
* const power = Int.pow(a, b); // Int (1000)
|
|
82
|
+
*
|
|
83
|
+
* // Utility operations
|
|
84
|
+
* const absolute = Int.abs(asInt(-42)); // Int (42)
|
|
85
|
+
* const minimum = Int.min(a, b, asInt(5)); // Int (3)
|
|
86
|
+
* const maximum = Int.max(a, b, asInt(5)); // Int (10)
|
|
87
|
+
*
|
|
88
|
+
* // Random generation
|
|
89
|
+
* const die = Int.random(asInt(1), asInt(6)); // Random Int in [1, 6]
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
const Int = {
|
|
93
|
+
/**
|
|
94
|
+
* Type guard that checks if a value is an integer.
|
|
95
|
+
*
|
|
96
|
+
* @param value - The value to check
|
|
97
|
+
* @returns `true` if the value is an integer, `false` otherwise
|
|
98
|
+
*
|
|
99
|
+
* @see {@link isInt} for usage examples
|
|
100
|
+
*/
|
|
101
|
+
is,
|
|
102
|
+
/**
|
|
103
|
+
* Returns the absolute value of an integer.
|
|
104
|
+
*
|
|
105
|
+
* The result is always non-negative and maintains the Int brand.
|
|
106
|
+
* Note that Math.abs(Number.MIN_SAFE_INTEGER) exceeds Number.MAX_SAFE_INTEGER,
|
|
107
|
+
* so use SafeInt for guaranteed precision.
|
|
108
|
+
*
|
|
109
|
+
* @param a - The integer value
|
|
110
|
+
* @returns The absolute value as a non-negative Int
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* Int.abs(asInt(-5)); // Int (5)
|
|
115
|
+
* Int.abs(asInt(3)); // Int (3)
|
|
116
|
+
* Int.abs(asInt(-0)); // Int (0)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
abs,
|
|
120
|
+
/**
|
|
121
|
+
* Returns the minimum value from a list of integers.
|
|
122
|
+
*
|
|
123
|
+
* @param values - The integers to compare (at least one required)
|
|
124
|
+
* @returns The smallest value as an Int
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* Int.min(asInt(5), asInt(3)); // Int (3)
|
|
129
|
+
* Int.min(asInt(-10), asInt(0), asInt(10)); // Int (-10)
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
min: min_,
|
|
133
|
+
/**
|
|
134
|
+
* Returns the maximum value from a list of integers.
|
|
135
|
+
*
|
|
136
|
+
* @param values - The integers to compare (at least one required)
|
|
137
|
+
* @returns The largest value as an Int
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* Int.max(asInt(5), asInt(3)); // Int (5)
|
|
142
|
+
* Int.max(asInt(-10), asInt(0), asInt(10)); // Int (10)
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
max: max_,
|
|
146
|
+
/**
|
|
147
|
+
* Generates a random integer within the specified range (inclusive).
|
|
148
|
+
*
|
|
149
|
+
* The range is inclusive on both ends, so random(1, 6) can return
|
|
150
|
+
* any of: 1, 2, 3, 4, 5, or 6.
|
|
151
|
+
*
|
|
152
|
+
* @param min - The minimum value (inclusive)
|
|
153
|
+
* @param max - The maximum value (inclusive)
|
|
154
|
+
* @returns A random Int in the range [min, max]
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* // Dice roll
|
|
159
|
+
* const d6 = Int.random(asInt(1), asInt(6));
|
|
160
|
+
*
|
|
161
|
+
* // Random array index
|
|
162
|
+
* const index = Int.random(asInt(0), asInt(array.length - 1));
|
|
163
|
+
*
|
|
164
|
+
* // Can generate negative values
|
|
165
|
+
* const temp = Int.random(asInt(-10), asInt(10));
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
random,
|
|
169
|
+
/**
|
|
170
|
+
* Raises an integer to a power.
|
|
171
|
+
* @param a - The base integer
|
|
172
|
+
* @param b - The exponent integer
|
|
173
|
+
* @returns `a ** b` as an Int
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* Int.pow(asInt(2), asInt(3)); // Int (8)
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
pow,
|
|
180
|
+
/**
|
|
181
|
+
* Adds two integers.
|
|
182
|
+
* @param a - First integer
|
|
183
|
+
* @param b - Second integer
|
|
184
|
+
* @returns `a + b` as an Int
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* Int.add(asInt(5), asInt(3)); // Int (8)
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
add,
|
|
191
|
+
/**
|
|
192
|
+
* Subtracts two integers.
|
|
193
|
+
* @param a - First integer
|
|
194
|
+
* @param b - Second integer
|
|
195
|
+
* @returns `a - b` as an Int
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* Int.sub(asInt(8), asInt(3)); // Int (5)
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
sub,
|
|
202
|
+
/**
|
|
203
|
+
* Multiplies two integers.
|
|
204
|
+
* @param a - First integer
|
|
205
|
+
* @param b - Second integer
|
|
206
|
+
* @returns `a * b` as an Int
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* Int.mul(asInt(4), asInt(3)); // Int (12)
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
mul,
|
|
213
|
+
/**
|
|
214
|
+
* Divides two integers using floor division.
|
|
215
|
+
*
|
|
216
|
+
* Performs mathematical floor division: `⌊a / b⌋`.
|
|
217
|
+
* The result is always an integer, rounding toward negative infinity.
|
|
218
|
+
*
|
|
219
|
+
* @param a - The dividend
|
|
220
|
+
* @param b - The divisor (must be non-zero)
|
|
221
|
+
* @returns The integer quotient as an Int
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* // Positive division
|
|
226
|
+
* Int.div(asInt(10), asInt(3)); // Int (3)
|
|
227
|
+
* Int.div(asInt(9), asInt(3)); // Int (3)
|
|
228
|
+
*
|
|
229
|
+
* // Negative division (rounds toward -∞)
|
|
230
|
+
* Int.div(asInt(-10), asInt(3)); // Int (-4)
|
|
231
|
+
* Int.div(asInt(10), asInt(-3)); // Int (-4)
|
|
232
|
+
* Int.div(asInt(-10), asInt(-3)); // Int (3)
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
div,
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export { Int, asInt, isInt };
|
|
239
|
+
//# sourceMappingURL=int.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"int.mjs","sources":["../../../src/number/branded-types/int.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,YAAY;AAEtC,MAAM,EACJ,GAAG,EACH,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,GACT,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,mBAAmB,CAI5D;AACA,IAAA,oBAAoB,EAAE,SAAS;AAC/B,IAAA,SAAS,EAAE,SAAS;AACpB,IAAA,SAAS,EAAE,SAAS;IACpB,iBAAiB;AACT,CAAA,CAAC;AAEX;;;;;;;;;;;;;;;;;;;AAmBG;AACI,MAAM,KAAK,GAAG;AAErB;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACI,MAAM,KAAK,GAAG;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCG;AACI,MAAM,GAAG,GAAG;AACjB;;;;;;;AAOG;IACH,EAAE;AAEF;;;;;;;;;;;;;;;;AAgBG;IACH,GAAG;AAEH;;;;;;;;;;;AAWG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;;;;;;;AAWG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;;;;;;;;;;;;;;;;;AAqBG;IACH,MAAM;AAEN;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;;;;;;;;;;;;;AAqBG;IACH,GAAG;;;;;"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a number is an Int16 (16-bit signed integer in the range [-2^15, 2^15)).
|
|
4
|
+
* @param value The value to check.
|
|
5
|
+
* @returns `true` if the value is an Int16, `false` otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isInt16: (a: number) => a is Int16;
|
|
8
|
+
/**
|
|
9
|
+
* Casts a number to an Int16 type.
|
|
10
|
+
* @param value The value to cast.
|
|
11
|
+
* @returns The value as an Int16 type.
|
|
12
|
+
* @throws {TypeError} If the value is not an integer in [-2^15, 2^15).
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const x = asInt16(1000); // Int16
|
|
16
|
+
* const y = asInt16(-5000); // Int16
|
|
17
|
+
* // asInt16(50000); // throws TypeError
|
|
18
|
+
* // asInt16(1.5); // throws TypeError
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const asInt16: <N extends number>(x: N) => number & {
|
|
22
|
+
readonly NaNValue: false;
|
|
23
|
+
readonly "> -2^16": true;
|
|
24
|
+
readonly "> -2^32": true;
|
|
25
|
+
readonly ">= -2^15": true;
|
|
26
|
+
readonly ">= -2^31": true;
|
|
27
|
+
readonly "< 2^15": true;
|
|
28
|
+
readonly "< 2^16": 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 16-bit signed integers.
|
|
39
|
+
*
|
|
40
|
+
* All operations automatically clamp results to the valid Int16 range [-32768, 32767].
|
|
41
|
+
* This ensures that all arithmetic maintains the 16-bit signed integer constraint.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const a = asInt16(30000);
|
|
46
|
+
* const b = asInt16(5000);
|
|
47
|
+
*
|
|
48
|
+
* // Arithmetic operations with automatic clamping
|
|
49
|
+
* const sum = Int16.add(a, b); // Int16 (32767 - clamped to MAX_VALUE)
|
|
50
|
+
* const diff = Int16.sub(a, b); // Int16 (25000)
|
|
51
|
+
* const product = Int16.mul(a, b); // Int16 (32767 - clamped due to overflow)
|
|
52
|
+
*
|
|
53
|
+
* // Range operations
|
|
54
|
+
* const clamped = Int16.clamp(100000); // Int16 (32767)
|
|
55
|
+
* const minimum = Int16.min(a, b); // Int16 (5000)
|
|
56
|
+
* const maximum = Int16.max(a, b); // Int16 (30000)
|
|
57
|
+
*
|
|
58
|
+
* // Range constants
|
|
59
|
+
* const range = Int16.MAX_VALUE - Int16.MIN_VALUE + 1; // 65536
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const Int16: {
|
|
63
|
+
/**
|
|
64
|
+
* Type guard to check if a value is an Int16.
|
|
65
|
+
* @param value The value to check.
|
|
66
|
+
* @returns `true` if the value is a 16-bit signed integer, `false` otherwise.
|
|
67
|
+
*/
|
|
68
|
+
readonly is: (a: number) => a is Int16;
|
|
69
|
+
/**
|
|
70
|
+
* The minimum value for a 16-bit signed integer.
|
|
71
|
+
* @readonly
|
|
72
|
+
*/
|
|
73
|
+
readonly MIN_VALUE: number;
|
|
74
|
+
/**
|
|
75
|
+
* The maximum value for a 16-bit signed integer.
|
|
76
|
+
* @readonly
|
|
77
|
+
*/
|
|
78
|
+
readonly MAX_VALUE: number;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the absolute value of a 16-bit signed integer.
|
|
81
|
+
* @param a The Int16 value.
|
|
82
|
+
* @returns The absolute value as an Int16, clamped to valid range.
|
|
83
|
+
*/
|
|
84
|
+
readonly abs: (x: WithSmallInt<Int16, 40>) => TsVerifiedInternals.RefinedNumberUtils.ToNonNegative<Int16>;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the smaller of two Int16 values.
|
|
87
|
+
* @param a The first Int16.
|
|
88
|
+
* @param b The second Int16.
|
|
89
|
+
* @returns The minimum value as an Int16.
|
|
90
|
+
*/
|
|
91
|
+
readonly min: (...values: readonly WithSmallInt<Int16, 40>[]) => Int16;
|
|
92
|
+
/**
|
|
93
|
+
* Returns the larger of two Int16 values.
|
|
94
|
+
* @param a The first Int16.
|
|
95
|
+
* @param b The second Int16.
|
|
96
|
+
* @returns The maximum value as an Int16.
|
|
97
|
+
*/
|
|
98
|
+
readonly max: (...values: readonly WithSmallInt<Int16, 40>[]) => Int16;
|
|
99
|
+
/**
|
|
100
|
+
* Clamps a number to the Int16 range.
|
|
101
|
+
* @param value The number to clamp.
|
|
102
|
+
* @returns The value clamped to [-32768, 32767] as an Int16.
|
|
103
|
+
*/
|
|
104
|
+
readonly clamp: (x: number) => Int16;
|
|
105
|
+
/**
|
|
106
|
+
* Generates a random Int16 value within the valid range.
|
|
107
|
+
* @returns A random Int16 between MIN_VALUE and MAX_VALUE.
|
|
108
|
+
*/
|
|
109
|
+
readonly random: (min: WithSmallInt<Int16, 40>, max: WithSmallInt<Int16, 40>) => Int16;
|
|
110
|
+
/**
|
|
111
|
+
* Raises an Int16 to the power of another Int16.
|
|
112
|
+
* @param a The base Int16.
|
|
113
|
+
* @param b The exponent Int16.
|
|
114
|
+
* @returns `a ** b` clamped to [-32768, 32767] as an Int16.
|
|
115
|
+
*/
|
|
116
|
+
readonly pow: (x: WithSmallInt<Int16, 40>, y: WithSmallInt<Int16, 40>) => Int16;
|
|
117
|
+
/**
|
|
118
|
+
* Adds two Int16 values.
|
|
119
|
+
* @param a The first Int16.
|
|
120
|
+
* @param b The second Int16.
|
|
121
|
+
* @returns `a + b` clamped to [-32768, 32767] as an Int16.
|
|
122
|
+
*/
|
|
123
|
+
readonly add: (x: WithSmallInt<Int16, 40>, y: WithSmallInt<Int16, 40>) => Int16;
|
|
124
|
+
/**
|
|
125
|
+
* Subtracts one Int16 from another.
|
|
126
|
+
* @param a The minuend Int16.
|
|
127
|
+
* @param b The subtrahend Int16.
|
|
128
|
+
* @returns `a - b` clamped to [-32768, 32767] as an Int16.
|
|
129
|
+
*/
|
|
130
|
+
readonly sub: (x: WithSmallInt<Int16, 40>, y: WithSmallInt<Int16, 40>) => Int16;
|
|
131
|
+
/**
|
|
132
|
+
* Multiplies two Int16 values.
|
|
133
|
+
* @param a The first Int16.
|
|
134
|
+
* @param b The second Int16.
|
|
135
|
+
* @returns `a * b` clamped to [-32768, 32767] as an Int16.
|
|
136
|
+
*/
|
|
137
|
+
readonly mul: (x: WithSmallInt<Int16, 40>, y: WithSmallInt<Int16, 40>) => Int16;
|
|
138
|
+
/**
|
|
139
|
+
* Divides one Int16 by another using floor division.
|
|
140
|
+
* @param a The dividend Int16.
|
|
141
|
+
* @param b The divisor Int16.
|
|
142
|
+
* @returns `⌊a / b⌋` clamped to [-32768, 32767] as an Int16.
|
|
143
|
+
*/
|
|
144
|
+
readonly div: (x: WithSmallInt<Int16, 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 | -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 | -40 | NormalizeBrandUnion<number & {
|
|
145
|
+
readonly NaNValue: false;
|
|
146
|
+
readonly "!=0": true;
|
|
147
|
+
readonly "> -2^16": true;
|
|
148
|
+
readonly "> -2^32": true;
|
|
149
|
+
readonly ">= -2^15": true;
|
|
150
|
+
readonly ">= -2^31": true;
|
|
151
|
+
readonly "< 2^15": true;
|
|
152
|
+
readonly "< 2^16": true;
|
|
153
|
+
readonly "< 2^31": true;
|
|
154
|
+
readonly "< 2^32": true;
|
|
155
|
+
readonly Finite: true;
|
|
156
|
+
readonly Int: true;
|
|
157
|
+
readonly SafeInt: true;
|
|
158
|
+
} & Readonly<{
|
|
159
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
160
|
+
}>>) => Int16;
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=int16.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int16.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAgClE;;;;GAIG;AACH,eAAO,MAAM,OAAO,2BAAK,CAAC;AAE1B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;MAAW,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,KAAK;IAChB;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;OAIG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
|