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,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard that checks if a value is an 8-bit signed integer.
|
|
3
|
+
*
|
|
4
|
+
* An Int8 is a signed integer in the range [-128, 127], representing
|
|
5
|
+
* values that fit in exactly 8 bits of memory.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to check
|
|
8
|
+
* @returns `true` if the value is an Int8, `false` otherwise
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* isInt8(100); // true
|
|
13
|
+
* isInt8(-50); // true
|
|
14
|
+
* isInt8(127); // true (max value)
|
|
15
|
+
* isInt8(-128); // true (min value)
|
|
16
|
+
* isInt8(128); // false (exceeds max)
|
|
17
|
+
* isInt8(-129); // false (below min)
|
|
18
|
+
* isInt8(5.5); // false (not integer)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const isInt8: (x: number) => x is Int8;
|
|
22
|
+
/**
|
|
23
|
+
* Casts a number to an Int8 branded type.
|
|
24
|
+
*
|
|
25
|
+
* This function validates that the input is within the Int8 range [-128, 127]
|
|
26
|
+
* and is an integer, then returns it with the Int8 brand.
|
|
27
|
+
*
|
|
28
|
+
* @param value - The value to cast
|
|
29
|
+
* @returns The value as an Int8 branded type
|
|
30
|
+
* @throws {TypeError} If the value is not a valid 8-bit signed integer
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const byte = asInt8(100); // Int8
|
|
35
|
+
* const max = asInt8(127); // Int8 (maximum value)
|
|
36
|
+
* const min = asInt8(-128); // Int8 (minimum value)
|
|
37
|
+
* const zero = asInt8(0); // Int8
|
|
38
|
+
*
|
|
39
|
+
* // These throw TypeError:
|
|
40
|
+
* // asInt8(128); // Exceeds maximum (127)
|
|
41
|
+
* // asInt8(-129); // Below minimum (-128)
|
|
42
|
+
* // asInt8(1.5); // Not an integer
|
|
43
|
+
* // asInt8(NaN); // Not a number
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const asInt8: (x: number) => Int8;
|
|
47
|
+
/**
|
|
48
|
+
* Namespace providing type-safe operations for Int8 (8-bit signed integer) branded types.
|
|
49
|
+
*
|
|
50
|
+
* Int8 represents signed integers in the range [-128, 127], equivalent to a signed
|
|
51
|
+
* byte in many programming languages. All operations automatically clamp results
|
|
52
|
+
* to stay within this range, preventing overflow/underflow issues.
|
|
53
|
+
*
|
|
54
|
+
* This type is useful for:
|
|
55
|
+
* - Binary data processing (signed bytes)
|
|
56
|
+
* - Small integer values with known bounds
|
|
57
|
+
* - Embedded systems programming
|
|
58
|
+
* - Memory-efficient integer storage
|
|
59
|
+
* - Image processing (signed pixel offsets)
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // Basic usage
|
|
64
|
+
* const a = asInt8(100);
|
|
65
|
+
* const b = asInt8(50);
|
|
66
|
+
*
|
|
67
|
+
* // Arithmetic with automatic clamping
|
|
68
|
+
* const sum = Int8.add(a, b); // Int8 (127) - clamped to maximum
|
|
69
|
+
* const diff = Int8.sub(a, b); // Int8 (50)
|
|
70
|
+
* const product = Int8.mul(a, b); // Int8 (127) - clamped due to overflow
|
|
71
|
+
* const quotient = Int8.div(a, b); // Int8 (2)
|
|
72
|
+
*
|
|
73
|
+
* // Boundary handling
|
|
74
|
+
* const overflow = Int8.add(asInt8(127), asInt8(10)); // Int8 (127) - clamped
|
|
75
|
+
* const underflow = Int8.sub(asInt8(-128), asInt8(10)); // Int8 (-128) - clamped
|
|
76
|
+
*
|
|
77
|
+
* // Utility operations
|
|
78
|
+
* const clamped = Int8.clamp(200); // Int8 (127)
|
|
79
|
+
* const absolute = Int8.abs(asInt8(-100)); // Int8 (100)
|
|
80
|
+
* const minimum = Int8.min(a, b); // Int8 (50)
|
|
81
|
+
* const maximum = Int8.max(a, b); // Int8 (100)
|
|
82
|
+
*
|
|
83
|
+
* // Random generation
|
|
84
|
+
* const die = Int8.random(asInt8(1), asInt8(6)); // Random 1-6
|
|
85
|
+
* const offset = Int8.random(asInt8(-10), asInt8(10)); // Random ±10
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare const Int8: {
|
|
89
|
+
/**
|
|
90
|
+
* Type guard that checks if a value is an 8-bit signed integer.
|
|
91
|
+
*
|
|
92
|
+
* @param value - The value to check
|
|
93
|
+
* @returns `true` if the value is in range [-128, 127] and is an integer
|
|
94
|
+
*
|
|
95
|
+
* @see {@link isInt8} for usage examples
|
|
96
|
+
*/
|
|
97
|
+
readonly is: (x: number) => x is Int8;
|
|
98
|
+
/**
|
|
99
|
+
* The minimum value for an 8-bit signed integer.
|
|
100
|
+
* @readonly
|
|
101
|
+
*/
|
|
102
|
+
readonly MIN_VALUE: -128;
|
|
103
|
+
/**
|
|
104
|
+
* The maximum value for an 8-bit signed integer.
|
|
105
|
+
* @readonly
|
|
106
|
+
*/
|
|
107
|
+
readonly MAX_VALUE: 127;
|
|
108
|
+
/**
|
|
109
|
+
* Returns the minimum value from a list of Int8 values.
|
|
110
|
+
*
|
|
111
|
+
* @param values - The Int8 values to compare (at least one required)
|
|
112
|
+
* @returns The smallest value as an Int8
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* Int8.min(asInt8(50), asInt8(-30), asInt8(100)); // Int8 (-30)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
readonly min: (...values: readonly Int8[]) => Int8;
|
|
120
|
+
/**
|
|
121
|
+
* Returns the maximum value from a list of Int8 values.
|
|
122
|
+
*
|
|
123
|
+
* @param values - The Int8 values to compare (at least one required)
|
|
124
|
+
* @returns The largest value as an Int8
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* Int8.max(asInt8(50), asInt8(-30), asInt8(100)); // Int8 (100)
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
readonly max: (...values: readonly Int8[]) => Int8;
|
|
132
|
+
/**
|
|
133
|
+
* Clamps a number to the Int8 range.
|
|
134
|
+
* @param value The number to clamp.
|
|
135
|
+
* @returns The value clamped to [-128, 127] as an Int8.
|
|
136
|
+
*/
|
|
137
|
+
readonly clamp: (a: number) => Int8;
|
|
138
|
+
/**
|
|
139
|
+
* Returns the absolute value of an Int8.
|
|
140
|
+
* @param value The Int8 value.
|
|
141
|
+
* @returns The absolute value as an Int8, clamped to valid range.
|
|
142
|
+
*/
|
|
143
|
+
readonly abs: <N extends Int8>(x: N) => AbsoluteValue<N>;
|
|
144
|
+
/**
|
|
145
|
+
* Generates a random Int8 value within the specified range (inclusive).
|
|
146
|
+
*
|
|
147
|
+
* Both bounds are inclusive. If min > max, they are automatically swapped.
|
|
148
|
+
*
|
|
149
|
+
* @param min - The minimum value (inclusive)
|
|
150
|
+
* @param max - The maximum value (inclusive)
|
|
151
|
+
* @returns A random Int8 in the range [min, max]
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* // Random signed byte
|
|
156
|
+
* const randomByte = Int8.random(Int8.MIN_VALUE, Int8.MAX_VALUE);
|
|
157
|
+
*
|
|
158
|
+
* // Random small range
|
|
159
|
+
* const dice = Int8.random(asInt8(1), asInt8(6)); // 1-6
|
|
160
|
+
*
|
|
161
|
+
* // Random offset
|
|
162
|
+
* const offset = Int8.random(asInt8(-10), asInt8(10)); // -10 to 10
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
readonly random: (min: Int8, max: Int8) => Int8;
|
|
166
|
+
/**
|
|
167
|
+
* Raises an Int8 to the power of another Int8.
|
|
168
|
+
* @param a The base Int8.
|
|
169
|
+
* @param b The exponent Int8.
|
|
170
|
+
* @returns `a ** b` clamped to [-128, 127] as an Int8.
|
|
171
|
+
*/
|
|
172
|
+
readonly pow: (x: Int8, y: Int8) => Int8;
|
|
173
|
+
/**
|
|
174
|
+
* Adds two Int8 values.
|
|
175
|
+
* @param a The first Int8.
|
|
176
|
+
* @param b The second Int8.
|
|
177
|
+
* @returns `a + b` clamped to [-128, 127] as an Int8.
|
|
178
|
+
*/
|
|
179
|
+
readonly add: (x: Int8, y: Int8) => Int8;
|
|
180
|
+
/**
|
|
181
|
+
* Subtracts one Int8 from another.
|
|
182
|
+
* @param a The minuend Int8.
|
|
183
|
+
* @param b The subtrahend Int8.
|
|
184
|
+
* @returns `a - b` clamped to [-128, 127] as an Int8.
|
|
185
|
+
*/
|
|
186
|
+
readonly sub: (x: Int8, y: Int8) => Int8;
|
|
187
|
+
/**
|
|
188
|
+
* Multiplies two Int8 values.
|
|
189
|
+
* @param a The first Int8.
|
|
190
|
+
* @param b The second Int8.
|
|
191
|
+
* @returns `a * b` clamped to [-128, 127] as an Int8.
|
|
192
|
+
*/
|
|
193
|
+
readonly mul: (x: Int8, y: Int8) => Int8;
|
|
194
|
+
/**
|
|
195
|
+
* Divides one Int8 by another using floor division.
|
|
196
|
+
* @param a The dividend Int8.
|
|
197
|
+
* @param b The divisor Int8 (cannot be 0).
|
|
198
|
+
* @returns `⌊a / b⌋` clamped to [-128, 127] as an Int8.
|
|
199
|
+
*/
|
|
200
|
+
readonly div: (x: Int8, y: Exclude<Int8, 0>) => Int8;
|
|
201
|
+
};
|
|
202
|
+
//# sourceMappingURL=int8.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"int8.d.mts","sourceRoot":"","sources":["../../../src/number/enum/int8.mts"],"names":[],"mappings":"AAyHA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM,MAjHJ,MAAM,KAAG,CAAC,IAAI,IAiHL,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,MAAM,MAnIE,MAAM,KAAG,IAmIA,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,IAAI;IACf;;;;;;;OAOG;qBA9LU,MAAM,KAAG,CAAC,IAAI,IAAI;IAiM/B;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;;;;;;OAUG;8BAtLoB,SAAS,IAAI,EAAE,KAAG,IAAI;IAyL7C;;;;;;;;;;OAUG;8BA3LoB,SAAS,IAAI,EAAE,KAAG,IAAI;IA8L7C;;;;OAIG;wBA1Na,MAAM,KAAG,IAAI;IA6N7B;;;;OAIG;mBA1NQ,CAAC,SAAS,IAAI,KAAK,CAAC,KAAG,aAAa,CAAC,CAAC,CAAC;IA6NlD;;;;;;;;;;;;;;;;;;;;OAoBG;2BA/KgB,IAAI,OAAO,IAAI,KAAG,IAAI;IAkLzC;;;;;OAKG;sBA/NW,IAAI,KAAK,IAAI,KAAG,IAAI;IAkOlC;;;;;OAKG;sBA/NW,IAAI,KAAK,IAAI,KAAG,IAAI;IAkOlC;;;;;OAKG;sBA/NW,IAAI,KAAK,IAAI,KAAG,IAAI;IAkOlC;;;;;OAKG;sBA/NW,IAAI,KAAK,IAAI,KAAG,IAAI;IAkOlC;;;;;OAKG;sBA/NW,IAAI,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,KAAG,IAAI;CAiOtC,CAAC"}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
|
|
3
|
+
const typeNameInMessage = 'an integer in [-128, 127]';
|
|
4
|
+
const { MIN_VALUE, MAX_VALUE, random: randomImpl, is: isImpl, castType: castTypeImpl, clamp: clampImpl, } = TsVerifiedInternals.RefinedNumberUtils.operatorsForInteger({
|
|
5
|
+
integerOrSafeInteger: 'SafeInteger',
|
|
6
|
+
MIN_VALUE: -128,
|
|
7
|
+
MAX_VALUE: 127,
|
|
8
|
+
typeNameInMessage,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a number is a valid Int8 (integer in [-128, 127]).
|
|
12
|
+
* @param x - The number to check
|
|
13
|
+
* @returns True if x is a valid Int8
|
|
14
|
+
*/
|
|
15
|
+
const is = (x) => isImpl(x);
|
|
16
|
+
/**
|
|
17
|
+
* Converts a number to Int8, throwing an error if invalid.
|
|
18
|
+
* @param x - The number to convert
|
|
19
|
+
* @returns The number as Int8
|
|
20
|
+
* @throws TypeError if x is not a valid Int8
|
|
21
|
+
*/
|
|
22
|
+
const castType = (x) =>
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
24
|
+
castTypeImpl(x);
|
|
25
|
+
/**
|
|
26
|
+
* Clamps a number to the Int8 range [-128, 127].
|
|
27
|
+
* @param a - The number to clamp
|
|
28
|
+
* @returns The clamped value as Int8
|
|
29
|
+
*/
|
|
30
|
+
const clamp = (a) => castType(clampImpl(a));
|
|
31
|
+
/**
|
|
32
|
+
* Returns the absolute value of an Int8.
|
|
33
|
+
* @param x - The Int8 value
|
|
34
|
+
* @returns The absolute value
|
|
35
|
+
*/
|
|
36
|
+
const abs = (x) =>
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
38
|
+
Math.abs(x);
|
|
39
|
+
/**
|
|
40
|
+
* Returns the minimum of the given Int8 values.
|
|
41
|
+
* @param values - The Int8 values to compare
|
|
42
|
+
* @returns The minimum value
|
|
43
|
+
*/
|
|
44
|
+
const min_ = (...values) => castType(Math.min(...values));
|
|
45
|
+
/**
|
|
46
|
+
* Returns the maximum of the given Int8 values.
|
|
47
|
+
* @param values - The Int8 values to compare
|
|
48
|
+
* @returns The maximum value
|
|
49
|
+
*/
|
|
50
|
+
const max_ = (...values) => castType(Math.max(...values));
|
|
51
|
+
/**
|
|
52
|
+
* Raises x to the power of y, clamped to Int8 range.
|
|
53
|
+
* @param x - The base
|
|
54
|
+
* @param y - The exponent
|
|
55
|
+
* @returns x^y clamped to [-128, 127]
|
|
56
|
+
*/
|
|
57
|
+
const pow = (x, y) => clamp(x ** y);
|
|
58
|
+
/**
|
|
59
|
+
* Adds two Int8 values, clamped to Int8 range.
|
|
60
|
+
* @param x - First operand
|
|
61
|
+
* @param y - Second operand
|
|
62
|
+
* @returns x + y clamped to [-128, 127]
|
|
63
|
+
*/
|
|
64
|
+
const add = (x, y) => clamp(x + y);
|
|
65
|
+
/**
|
|
66
|
+
* Subtracts two Int8 values, clamped to Int8 range.
|
|
67
|
+
* @param x - First operand
|
|
68
|
+
* @param y - Second operand
|
|
69
|
+
* @returns x - y clamped to [-128, 127]
|
|
70
|
+
*/
|
|
71
|
+
const sub = (x, y) => clamp(x - y);
|
|
72
|
+
/**
|
|
73
|
+
* Multiplies two Int8 values, clamped to Int8 range.
|
|
74
|
+
* @param x - First operand
|
|
75
|
+
* @param y - Second operand
|
|
76
|
+
* @returns x * y clamped to [-128, 127]
|
|
77
|
+
*/
|
|
78
|
+
const mul = (x, y) => clamp(x * y);
|
|
79
|
+
/**
|
|
80
|
+
* Divides two Int8 values, clamped to Int8 range.
|
|
81
|
+
* @param x - The dividend
|
|
82
|
+
* @param y - The divisor (cannot be 0)
|
|
83
|
+
* @returns ⌊x / y⌋ clamped to [-128, 127]
|
|
84
|
+
*/
|
|
85
|
+
const div = (x, y) => clamp(Math.floor(x / y));
|
|
86
|
+
/**
|
|
87
|
+
* Generates a random Int8 value within the specified range.
|
|
88
|
+
* @param min - The minimum value (inclusive)
|
|
89
|
+
* @param max - The maximum value (inclusive)
|
|
90
|
+
* @returns A random Int8 between min and max
|
|
91
|
+
*/
|
|
92
|
+
const random = (min, max) => castType(randomImpl(castTypeImpl(min), castTypeImpl(max)));
|
|
93
|
+
/**
|
|
94
|
+
* Type guard that checks if a value is an 8-bit signed integer.
|
|
95
|
+
*
|
|
96
|
+
* An Int8 is a signed integer in the range [-128, 127], representing
|
|
97
|
+
* values that fit in exactly 8 bits of memory.
|
|
98
|
+
*
|
|
99
|
+
* @param value - The value to check
|
|
100
|
+
* @returns `true` if the value is an Int8, `false` otherwise
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* isInt8(100); // true
|
|
105
|
+
* isInt8(-50); // true
|
|
106
|
+
* isInt8(127); // true (max value)
|
|
107
|
+
* isInt8(-128); // true (min value)
|
|
108
|
+
* isInt8(128); // false (exceeds max)
|
|
109
|
+
* isInt8(-129); // false (below min)
|
|
110
|
+
* isInt8(5.5); // false (not integer)
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
const isInt8 = is;
|
|
114
|
+
/**
|
|
115
|
+
* Casts a number to an Int8 branded type.
|
|
116
|
+
*
|
|
117
|
+
* This function validates that the input is within the Int8 range [-128, 127]
|
|
118
|
+
* and is an integer, then returns it with the Int8 brand.
|
|
119
|
+
*
|
|
120
|
+
* @param value - The value to cast
|
|
121
|
+
* @returns The value as an Int8 branded type
|
|
122
|
+
* @throws {TypeError} If the value is not a valid 8-bit signed integer
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const byte = asInt8(100); // Int8
|
|
127
|
+
* const max = asInt8(127); // Int8 (maximum value)
|
|
128
|
+
* const min = asInt8(-128); // Int8 (minimum value)
|
|
129
|
+
* const zero = asInt8(0); // Int8
|
|
130
|
+
*
|
|
131
|
+
* // These throw TypeError:
|
|
132
|
+
* // asInt8(128); // Exceeds maximum (127)
|
|
133
|
+
* // asInt8(-129); // Below minimum (-128)
|
|
134
|
+
* // asInt8(1.5); // Not an integer
|
|
135
|
+
* // asInt8(NaN); // Not a number
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
const asInt8 = castType;
|
|
139
|
+
/**
|
|
140
|
+
* Namespace providing type-safe operations for Int8 (8-bit signed integer) branded types.
|
|
141
|
+
*
|
|
142
|
+
* Int8 represents signed integers in the range [-128, 127], equivalent to a signed
|
|
143
|
+
* byte in many programming languages. All operations automatically clamp results
|
|
144
|
+
* to stay within this range, preventing overflow/underflow issues.
|
|
145
|
+
*
|
|
146
|
+
* This type is useful for:
|
|
147
|
+
* - Binary data processing (signed bytes)
|
|
148
|
+
* - Small integer values with known bounds
|
|
149
|
+
* - Embedded systems programming
|
|
150
|
+
* - Memory-efficient integer storage
|
|
151
|
+
* - Image processing (signed pixel offsets)
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* // Basic usage
|
|
156
|
+
* const a = asInt8(100);
|
|
157
|
+
* const b = asInt8(50);
|
|
158
|
+
*
|
|
159
|
+
* // Arithmetic with automatic clamping
|
|
160
|
+
* const sum = Int8.add(a, b); // Int8 (127) - clamped to maximum
|
|
161
|
+
* const diff = Int8.sub(a, b); // Int8 (50)
|
|
162
|
+
* const product = Int8.mul(a, b); // Int8 (127) - clamped due to overflow
|
|
163
|
+
* const quotient = Int8.div(a, b); // Int8 (2)
|
|
164
|
+
*
|
|
165
|
+
* // Boundary handling
|
|
166
|
+
* const overflow = Int8.add(asInt8(127), asInt8(10)); // Int8 (127) - clamped
|
|
167
|
+
* const underflow = Int8.sub(asInt8(-128), asInt8(10)); // Int8 (-128) - clamped
|
|
168
|
+
*
|
|
169
|
+
* // Utility operations
|
|
170
|
+
* const clamped = Int8.clamp(200); // Int8 (127)
|
|
171
|
+
* const absolute = Int8.abs(asInt8(-100)); // Int8 (100)
|
|
172
|
+
* const minimum = Int8.min(a, b); // Int8 (50)
|
|
173
|
+
* const maximum = Int8.max(a, b); // Int8 (100)
|
|
174
|
+
*
|
|
175
|
+
* // Random generation
|
|
176
|
+
* const die = Int8.random(asInt8(1), asInt8(6)); // Random 1-6
|
|
177
|
+
* const offset = Int8.random(asInt8(-10), asInt8(10)); // Random ±10
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
const Int8 = {
|
|
181
|
+
/**
|
|
182
|
+
* Type guard that checks if a value is an 8-bit signed integer.
|
|
183
|
+
*
|
|
184
|
+
* @param value - The value to check
|
|
185
|
+
* @returns `true` if the value is in range [-128, 127] and is an integer
|
|
186
|
+
*
|
|
187
|
+
* @see {@link isInt8} for usage examples
|
|
188
|
+
*/
|
|
189
|
+
is,
|
|
190
|
+
/**
|
|
191
|
+
* The minimum value for an 8-bit signed integer.
|
|
192
|
+
* @readonly
|
|
193
|
+
*/
|
|
194
|
+
MIN_VALUE,
|
|
195
|
+
/**
|
|
196
|
+
* The maximum value for an 8-bit signed integer.
|
|
197
|
+
* @readonly
|
|
198
|
+
*/
|
|
199
|
+
MAX_VALUE,
|
|
200
|
+
/**
|
|
201
|
+
* Returns the minimum value from a list of Int8 values.
|
|
202
|
+
*
|
|
203
|
+
* @param values - The Int8 values to compare (at least one required)
|
|
204
|
+
* @returns The smallest value as an Int8
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* Int8.min(asInt8(50), asInt8(-30), asInt8(100)); // Int8 (-30)
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
min: min_,
|
|
212
|
+
/**
|
|
213
|
+
* Returns the maximum value from a list of Int8 values.
|
|
214
|
+
*
|
|
215
|
+
* @param values - The Int8 values to compare (at least one required)
|
|
216
|
+
* @returns The largest value as an Int8
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* Int8.max(asInt8(50), asInt8(-30), asInt8(100)); // Int8 (100)
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
max: max_,
|
|
224
|
+
/**
|
|
225
|
+
* Clamps a number to the Int8 range.
|
|
226
|
+
* @param value The number to clamp.
|
|
227
|
+
* @returns The value clamped to [-128, 127] as an Int8.
|
|
228
|
+
*/
|
|
229
|
+
clamp,
|
|
230
|
+
/**
|
|
231
|
+
* Returns the absolute value of an Int8.
|
|
232
|
+
* @param value The Int8 value.
|
|
233
|
+
* @returns The absolute value as an Int8, clamped to valid range.
|
|
234
|
+
*/
|
|
235
|
+
abs,
|
|
236
|
+
/**
|
|
237
|
+
* Generates a random Int8 value within the specified range (inclusive).
|
|
238
|
+
*
|
|
239
|
+
* Both bounds are inclusive. If min > max, they are automatically swapped.
|
|
240
|
+
*
|
|
241
|
+
* @param min - The minimum value (inclusive)
|
|
242
|
+
* @param max - The maximum value (inclusive)
|
|
243
|
+
* @returns A random Int8 in the range [min, max]
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* // Random signed byte
|
|
248
|
+
* const randomByte = Int8.random(Int8.MIN_VALUE, Int8.MAX_VALUE);
|
|
249
|
+
*
|
|
250
|
+
* // Random small range
|
|
251
|
+
* const dice = Int8.random(asInt8(1), asInt8(6)); // 1-6
|
|
252
|
+
*
|
|
253
|
+
* // Random offset
|
|
254
|
+
* const offset = Int8.random(asInt8(-10), asInt8(10)); // -10 to 10
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
random,
|
|
258
|
+
/**
|
|
259
|
+
* Raises an Int8 to the power of another Int8.
|
|
260
|
+
* @param a The base Int8.
|
|
261
|
+
* @param b The exponent Int8.
|
|
262
|
+
* @returns `a ** b` clamped to [-128, 127] as an Int8.
|
|
263
|
+
*/
|
|
264
|
+
pow,
|
|
265
|
+
/**
|
|
266
|
+
* Adds two Int8 values.
|
|
267
|
+
* @param a The first Int8.
|
|
268
|
+
* @param b The second Int8.
|
|
269
|
+
* @returns `a + b` clamped to [-128, 127] as an Int8.
|
|
270
|
+
*/
|
|
271
|
+
add,
|
|
272
|
+
/**
|
|
273
|
+
* Subtracts one Int8 from another.
|
|
274
|
+
* @param a The minuend Int8.
|
|
275
|
+
* @param b The subtrahend Int8.
|
|
276
|
+
* @returns `a - b` clamped to [-128, 127] as an Int8.
|
|
277
|
+
*/
|
|
278
|
+
sub,
|
|
279
|
+
/**
|
|
280
|
+
* Multiplies two Int8 values.
|
|
281
|
+
* @param a The first Int8.
|
|
282
|
+
* @param b The second Int8.
|
|
283
|
+
* @returns `a * b` clamped to [-128, 127] as an Int8.
|
|
284
|
+
*/
|
|
285
|
+
mul,
|
|
286
|
+
/**
|
|
287
|
+
* Divides one Int8 by another using floor division.
|
|
288
|
+
* @param a The dividend Int8.
|
|
289
|
+
* @param b The divisor Int8 (cannot be 0).
|
|
290
|
+
* @returns `⌊a / b⌋` clamped to [-128, 127] as an Int8.
|
|
291
|
+
*/
|
|
292
|
+
div,
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export { Int8, asInt8, isInt8 };
|
|
296
|
+
//# sourceMappingURL=int8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"int8.mjs","sources":["../../../src/number/enum/int8.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA,MAAM,iBAAiB,GAAG,2BAA2B;AAErD,MAAM,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EAAE,UAAU,EAClB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,SAAS,GACjB,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,mBAAmB,CAI5D;AACA,IAAA,oBAAoB,EAAE,aAAa;IACnC,SAAS,EAAE,IAAI;AACf,IAAA,SAAS,EAAE,GAAG;IACd,iBAAiB;AACT,CAAA,CAAC;AAEX;;;;AAIG;AACH,MAAM,EAAE,GAAG,CAAC,CAAS,KAAgB,MAAM,CAAC,CAAC,CAAC;AAE9C;;;;;AAKG;AACH,MAAM,QAAQ,GAAG,CAAC,CAAS;AACzB;AACA,YAAY,CAAC,CAAC,CAAS;AAEzB;;;;AAIG;AACH,MAAM,KAAK,GAAG,CAAC,CAAS,KAAW,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAEzD;;;;AAIG;AACH,MAAM,GAAG,GAAG,CAAiB,CAAI;AAC/B;AACA,IAAI,CAAC,GAAG,CAAC,CAAC,CAAgC;AAE5C;;;;AAIG;AACH,MAAM,IAAI,GAAG,CAAC,GAAG,MAAuB,KACtC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;AAE/B;;;;AAIG;AACH,MAAM,IAAI,GAAG,CAAC,GAAG,MAAuB,KACtC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;AAE/B;;;;;AAKG;AACH,MAAM,GAAG,GAAG,CAAC,CAAO,EAAE,CAAO,KAAW,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;AAErD;;;;;AAKG;AACH,MAAM,GAAG,GAAG,CAAC,CAAO,EAAE,CAAO,KAAW,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpD;;;;;AAKG;AACH,MAAM,GAAG,GAAG,CAAC,CAAO,EAAE,CAAO,KAAW,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpD;;;;;AAKG;AACH,MAAM,GAAG,GAAG,CAAC,CAAO,EAAE,CAAO,KAAW,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpD;;;;;AAKG;AACH,MAAM,GAAG,GAAG,CAAC,CAAO,EAAE,CAAmB,KAAW,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAE5E;;;;;AAKG;AACH,MAAM,MAAM,GAAG,CAAC,GAAS,EAAE,GAAS,KAClC,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;AAmBG;AACI,MAAM,MAAM,GAAG;AAEtB;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACI,MAAM,MAAM,GAAG;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCG;AACI,MAAM,IAAI,GAAG;AAClB;;;;;;;AAOG;IACH,EAAE;AAEF;;;AAGG;IACH,SAAS;AAET;;;AAGG;IACH,SAAS;AAET;;;;;;;;;;AAUG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;;;;;;AAUG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;AAIG;IACH,KAAK;AAEL;;;;AAIG;IACH,GAAG;AAEH;;;;;;;;;;;;;;;;;;;;AAoBG;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,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is a Uint8 (8-bit unsigned integer in the range [0, 255]).
|
|
3
|
+
* @param value The value to check.
|
|
4
|
+
* @returns `true` if the value is a Uint8, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isUint8: (x: number) => x is Uint8;
|
|
7
|
+
/**
|
|
8
|
+
* Casts a number to a Uint8 type.
|
|
9
|
+
* @param value The value to cast.
|
|
10
|
+
* @returns The value as a Uint8 type.
|
|
11
|
+
* @throws {TypeError} If the value is not a valid 8-bit unsigned integer.
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const x = asUint8(255); // Uint8
|
|
15
|
+
* const y = asUint8(0); // Uint8
|
|
16
|
+
* // asUint8(-1); // throws TypeError
|
|
17
|
+
* // asUint8(256); // throws TypeError
|
|
18
|
+
* // asUint8(1.5); // throws TypeError
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const asUint8: (x: number) => Uint8;
|
|
22
|
+
/**
|
|
23
|
+
* Namespace providing type-safe arithmetic operations for 8-bit unsigned integers.
|
|
24
|
+
*
|
|
25
|
+
* All operations automatically clamp results to the valid Uint8 range [0, 255].
|
|
26
|
+
* This ensures that all arithmetic maintains the 8-bit unsigned integer constraint,
|
|
27
|
+
* with negative results clamped to 0 and overflow results clamped to MAX_VALUE.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const a = asUint8(200);
|
|
32
|
+
* const b = asUint8(100);
|
|
33
|
+
*
|
|
34
|
+
* // Arithmetic operations with automatic clamping
|
|
35
|
+
* const sum = Uint8.add(a, b); // Uint8 (255 - clamped to MAX_VALUE)
|
|
36
|
+
* const diff = Uint8.sub(a, b); // Uint8 (100)
|
|
37
|
+
* const reverseDiff = Uint8.sub(b, a); // Uint8 (0 - clamped to MIN_VALUE)
|
|
38
|
+
* const product = Uint8.mul(a, b); // Uint8 (255 - clamped due to overflow)
|
|
39
|
+
*
|
|
40
|
+
* // Range operations
|
|
41
|
+
* const clamped = Uint8.clamp(-10); // Uint8 (0)
|
|
42
|
+
* const minimum = Uint8.min(a, b); // Uint8 (100)
|
|
43
|
+
* const maximum = Uint8.max(a, b); // Uint8 (200)
|
|
44
|
+
*
|
|
45
|
+
* // Utility operations
|
|
46
|
+
* const random = Uint8.random(asUint8(50), asUint8(150)); // Uint8 (random value in [50, 150])
|
|
47
|
+
* const power = Uint8.pow(asUint8(2), asUint8(7)); // Uint8 (128)
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const Uint8: {
|
|
51
|
+
/**
|
|
52
|
+
* Type guard to check if a value is a Uint8.
|
|
53
|
+
* @param value The value to check.
|
|
54
|
+
* @returns `true` if the value is an 8-bit unsigned integer, `false` otherwise.
|
|
55
|
+
*/
|
|
56
|
+
readonly is: (x: number) => x is Uint8;
|
|
57
|
+
/**
|
|
58
|
+
* The minimum value for an 8-bit unsigned integer.
|
|
59
|
+
* @readonly
|
|
60
|
+
*/
|
|
61
|
+
readonly MIN_VALUE: 0;
|
|
62
|
+
/**
|
|
63
|
+
* The maximum value for an 8-bit unsigned integer.
|
|
64
|
+
* @readonly
|
|
65
|
+
*/
|
|
66
|
+
readonly MAX_VALUE: 255;
|
|
67
|
+
/**
|
|
68
|
+
* Returns the larger of the given Uint8 values.
|
|
69
|
+
* @param values The Uint8 values to compare.
|
|
70
|
+
* @returns The maximum value as a Uint8.
|
|
71
|
+
*/
|
|
72
|
+
readonly max: (...values: readonly Uint8[]) => Uint8;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the smaller of the given Uint8 values.
|
|
75
|
+
* @param values The Uint8 values to compare.
|
|
76
|
+
* @returns The minimum value as a Uint8.
|
|
77
|
+
*/
|
|
78
|
+
readonly min: (...values: readonly Uint8[]) => Uint8;
|
|
79
|
+
/**
|
|
80
|
+
* Clamps a number to the Uint8 range.
|
|
81
|
+
* @param value The number to clamp.
|
|
82
|
+
* @returns The value clamped to [0, 255] as a Uint8.
|
|
83
|
+
*/
|
|
84
|
+
readonly clamp: (a: number) => Uint8;
|
|
85
|
+
/**
|
|
86
|
+
* Generates a random Uint8 value within the specified range.
|
|
87
|
+
* @param min The minimum value (inclusive).
|
|
88
|
+
* @param max The maximum value (inclusive).
|
|
89
|
+
* @returns A random Uint8 between min and max.
|
|
90
|
+
*/
|
|
91
|
+
readonly random: (min: Uint8, max: Uint8) => Uint8;
|
|
92
|
+
/**
|
|
93
|
+
* Raises a Uint8 to the power of another Uint8.
|
|
94
|
+
* @param a The base Uint8.
|
|
95
|
+
* @param b The exponent Uint8.
|
|
96
|
+
* @returns `a ** b` clamped to [0, 255] as a Uint8.
|
|
97
|
+
*/
|
|
98
|
+
readonly pow: (x: Uint8, y: Uint8) => Uint8;
|
|
99
|
+
/**
|
|
100
|
+
* Adds two Uint8 values.
|
|
101
|
+
* @param a The first Uint8.
|
|
102
|
+
* @param b The second Uint8.
|
|
103
|
+
* @returns `a + b` clamped to [0, 255] as a Uint8.
|
|
104
|
+
*/
|
|
105
|
+
readonly add: (x: Uint8, y: Uint8) => Uint8;
|
|
106
|
+
/**
|
|
107
|
+
* Subtracts one Uint8 from another.
|
|
108
|
+
* @param a The minuend Uint8.
|
|
109
|
+
* @param b The subtrahend Uint8.
|
|
110
|
+
* @returns `a - b` clamped to [0, 255] as a Uint8 (minimum 0).
|
|
111
|
+
*/
|
|
112
|
+
readonly sub: (x: Uint8, y: Uint8) => Uint8;
|
|
113
|
+
/**
|
|
114
|
+
* Multiplies two Uint8 values.
|
|
115
|
+
* @param a The first Uint8.
|
|
116
|
+
* @param b The second Uint8.
|
|
117
|
+
* @returns `a * b` clamped to [0, 255] as a Uint8.
|
|
118
|
+
*/
|
|
119
|
+
readonly mul: (x: Uint8, y: Uint8) => Uint8;
|
|
120
|
+
/**
|
|
121
|
+
* Divides one Uint8 by another using floor division.
|
|
122
|
+
* @param a The dividend Uint8.
|
|
123
|
+
* @param b The divisor Uint8 (cannot be 0).
|
|
124
|
+
* @returns `⌊a / b⌋` clamped to [0, 255] as a Uint8.
|
|
125
|
+
*/
|
|
126
|
+
readonly div: (x: Uint8, y: Exclude<Uint8, 0>) => Uint8;
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=uint8.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uint8.d.mts","sourceRoot":"","sources":["../../../src/number/enum/uint8.mts"],"names":[],"mappings":"AAiJA;;;;GAIG;AACH,eAAO,MAAM,OAAO,MAhHL,MAAM,KAAG,CAAC,IAAI,KAgHJ,CAAC;AAE1B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,OAAO,MAxGC,MAAM,KAAG,KAwGC,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,KAAK;IAChB;;;;OAIG;qBAnKU,MAAM,KAAG,CAAC,IAAI,KAAK;IAsKhC;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;OAIG;8BA/HoB,SAAS,KAAK,EAAE,KAAG,KAAK;IAkI/C;;;;OAIG;8BA9IoB,SAAS,KAAK,EAAE,KAAG,KAAK;IAiJ/C;;;;OAIG;wBAnKa,MAAM,KAAG,KAAK;IAsK9B;;;;;OAKG;2BApGgB,KAAK,OAAO,KAAK,KAAG,KAAK;IAuG5C;;;;;OAKG;sBApJW,KAAK,KAAK,KAAK,KAAG,KAAK;IAuJrC;;;;;OAKG;sBApJW,KAAK,KAAK,KAAK,KAAG,KAAK;IAuJrC;;;;;OAKG;sBApJW,KAAK,KAAK,KAAK,KAAG,KAAK;IAuJrC;;;;;OAKG;sBApJW,KAAK,KAAK,KAAK,KAAG,KAAK;IAuJrC;;;;;OAKG;sBApJW,KAAK,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,KAAG,KAAK;CAsJzC,CAAC"}
|