ts-data-forge 10.0.0 → 11.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/dist/array/impl/array-utils-creation.d.mts +3 -3
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +4 -4
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/{guard/as-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-cast.d.mts} +9 -9
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -0
- package/dist/{guard/as-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-cast.mjs} +2 -2
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -0
- package/dist/{guard/is-length-bounded-array.d.mts → array/impl/array-utils-length-bounded-array-guard.d.mts} +13 -13
- package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -0
- package/dist/{guard/is-length-bounded-array.mjs → array/impl/array-utils-length-bounded-array-guard.mjs} +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -0
- package/dist/array/impl/array-utils-modification.d.mts +9 -9
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +9 -9
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +3 -3
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +9 -9
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +16 -10
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/index.d.mts +2 -0
- package/dist/array/impl/index.d.mts.map +1 -1
- package/dist/array/impl/index.mjs +2 -0
- package/dist/array/impl/index.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -3
- package/dist/entry-point.mjs.map +1 -1
- package/dist/guard/index.d.mts +0 -3
- package/dist/guard/index.d.mts.map +1 -1
- package/dist/guard/index.mjs +0 -3
- package/dist/guard/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +47 -61
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +37 -41
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +40 -46
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +29 -31
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +65 -58
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +49 -45
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +65 -58
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +49 -45
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +68 -59
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +52 -46
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +60 -48
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +40 -36
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +57 -56
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +40 -41
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +74 -64
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +58 -51
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +64 -57
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +47 -43
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +64 -58
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +47 -44
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +64 -54
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +48 -41
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +41 -146
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +27 -107
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +54 -53
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +37 -39
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +51 -38
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +31 -27
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +52 -53
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +36 -39
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +52 -54
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +36 -40
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +53 -54
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +36 -40
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +52 -53
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +35 -39
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +52 -53
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +35 -39
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +74 -63
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +58 -50
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +46 -68
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +34 -49
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +61 -57
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +44 -43
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +61 -57
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +44 -43
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +62 -57
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +45 -43
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +61 -57
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +44 -43
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +61 -58
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +44 -44
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +43 -62
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +35 -42
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +62 -57
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +46 -44
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +63 -50
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +42 -39
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +60 -58
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +44 -43
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +59 -55
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +42 -42
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +56 -65
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +44 -43
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +60 -58
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +44 -43
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/string/index.d.mts +2 -0
- package/dist/string/index.d.mts.map +1 -0
- package/dist/string/index.mjs +2 -0
- package/dist/string/index.mjs.map +1 -0
- package/dist/string/str.d.mts +273 -0
- package/dist/string/str.d.mts.map +1 -0
- package/dist/string/str.mjs +42 -0
- package/dist/string/str.mjs.map +1 -0
- package/package.json +31 -92
- package/src/array/impl/array-utils-creation.mts +2 -1
- package/src/array/impl/array-utils-element-access.mts +3 -3
- package/src/array/impl/array-utils-element-access.test.mts +3 -3
- package/src/{guard/as-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-cast.mts} +9 -9
- package/src/{guard/as-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-cast.test.mts} +2 -2
- package/src/{guard/is-length-bounded-array.mts → array/impl/array-utils-length-bounded-array-guard.mts} +12 -12
- package/src/{guard/is-length-bounded-array.test.mts → array/impl/array-utils-length-bounded-array-guard.test.mts} +2 -2
- package/src/array/impl/array-utils-modification.mts +9 -8
- package/src/array/impl/array-utils-modification.test.mts +6 -1
- package/src/array/impl/array-utils-reducing-value.mts +9 -9
- package/src/array/impl/array-utils-size.mts +2 -2
- package/src/array/impl/array-utils-slicing.mts +24 -13
- package/src/array/impl/array-utils-transformation.mts +18 -12
- package/src/array/impl/array-utils-transformation.test.mts +12 -12
- package/src/array/impl/index.mts +2 -0
- package/src/guard/index.mts +0 -3
- package/src/index.mts +1 -0
- package/src/number/branded-types/finite-number.mts +47 -61
- package/src/number/branded-types/int.mts +40 -46
- package/src/number/branded-types/int16.mts +65 -58
- package/src/number/branded-types/int32.mts +65 -58
- package/src/number/branded-types/negative-finite-number.mts +68 -68
- package/src/number/branded-types/negative-int.mts +60 -57
- package/src/number/branded-types/negative-safe-int.mts +57 -65
- package/src/number/branded-types/non-negative-finite-number.mts +74 -64
- package/src/number/branded-types/non-negative-int16.mts +64 -57
- package/src/number/branded-types/non-negative-int32.mts +64 -58
- package/src/number/branded-types/non-positive-finite-number.mts +64 -54
- package/src/number/branded-types/non-positive-int.mts +41 -146
- package/src/number/branded-types/non-positive-safe-int.mts +54 -53
- package/src/number/branded-types/non-zero-finite-number.mts +62 -51
- package/src/number/branded-types/non-zero-int.mts +51 -38
- package/src/number/branded-types/non-zero-int16.mts +52 -53
- package/src/number/branded-types/non-zero-int32.mts +52 -54
- package/src/number/branded-types/non-zero-safe-int.mts +53 -54
- package/src/number/branded-types/non-zero-uint16.mts +52 -53
- package/src/number/branded-types/non-zero-uint32.mts +52 -53
- package/src/number/branded-types/positive-finite-number.mts +74 -63
- package/src/number/branded-types/positive-int.mts +46 -68
- package/src/number/branded-types/positive-int16.mts +61 -57
- package/src/number/branded-types/positive-int32.mts +61 -57
- package/src/number/branded-types/positive-safe-int.mts +62 -57
- package/src/number/branded-types/positive-uint16.mts +61 -57
- package/src/number/branded-types/positive-uint32.mts +61 -58
- package/src/number/branded-types/safe-int.mts +43 -62
- package/src/number/branded-types/safe-uint.mts +62 -57
- package/src/number/branded-types/uint.mts +63 -50
- package/src/number/branded-types/uint16.mts +60 -58
- package/src/number/branded-types/uint32.mts +59 -55
- package/src/number/enum/int8.mts +56 -65
- package/src/number/enum/uint8.mts +60 -58
- package/src/string/index.mts +1 -0
- package/src/string/str.mts +371 -0
- package/src/string/str.test.mts +215 -0
- package/dist/guard/as-length-bounded-array.d.mts.map +0 -1
- package/dist/guard/as-length-bounded-array.mjs.map +0 -1
- package/dist/guard/is-length-bounded-array.d.mts.map +0 -1
- package/dist/guard/is-length-bounded-array.mjs.map +0 -1
- package/dist/guard/is-length-bounded-string.d.mts +0 -163
- package/dist/guard/is-length-bounded-string.d.mts.map +0 -1
- package/dist/guard/is-length-bounded-string.mjs +0 -7
- package/dist/guard/is-length-bounded-string.mjs.map +0 -1
- package/src/guard/is-length-bounded-string.mts +0 -199
- package/src/guard/is-length-bounded-string.test.mts +0 -170
package/src/number/enum/int8.mts
CHANGED
|
@@ -60,153 +60,144 @@ const random = (min: Int8, max: Int8): Int8 =>
|
|
|
60
60
|
castType(randomImpl(castTypeImpl(min), castTypeImpl(max)));
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
* Type guard that checks if a value is an
|
|
63
|
+
* Type guard that checks if a value is an integer in [-128, 127].
|
|
64
64
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
65
|
+
* Returns `true` for an integer in [-128, 127] — a value with no fractional
|
|
66
|
+
* component.
|
|
67
67
|
*
|
|
68
68
|
* @param value - The value to check
|
|
69
|
-
* @returns `true` if the value is an
|
|
69
|
+
* @returns `true` if the value is an integer in [-128, 127], `false` otherwise
|
|
70
70
|
*/
|
|
71
71
|
export const isInt8 = is;
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* Casts a number to
|
|
74
|
+
* Casts a `number` to the `Int8` branded type.
|
|
75
75
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
76
|
+
* Validates that the value is an integer in [-128, 127] and returns it with the
|
|
77
|
+
* `Int8` brand. Throws a `TypeError` otherwise.
|
|
78
78
|
*
|
|
79
79
|
* @param value - The value to cast
|
|
80
|
-
* @returns The value as an Int8
|
|
81
|
-
* @throws {TypeError} If the value is not
|
|
80
|
+
* @returns The value as an `Int8`
|
|
81
|
+
* @throws {TypeError} If the value is not an integer in [-128, 127]
|
|
82
82
|
*/
|
|
83
83
|
export const asInt8 = castType;
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* Namespace providing type-safe operations for Int8
|
|
87
|
-
* branded types.
|
|
86
|
+
* Namespace providing type-safe operations for the `Int8` branded type.
|
|
88
87
|
*
|
|
89
|
-
* Int8 represents
|
|
90
|
-
*
|
|
91
|
-
* results to stay within this range, preventing overflow/underflow issues.
|
|
92
|
-
*
|
|
93
|
-
* This type is useful for:
|
|
94
|
-
*
|
|
95
|
-
* - Binary data processing (signed bytes)
|
|
96
|
-
* - Small integer values with known bounds
|
|
97
|
-
* - Embedded systems programming
|
|
98
|
-
* - Memory-efficient integer storage
|
|
99
|
-
* - Image processing (signed pixel offsets)
|
|
88
|
+
* The `Int8` type represents an integer in [-128, 127]. Division (`div`) uses
|
|
89
|
+
* floor division.
|
|
100
90
|
*/
|
|
101
91
|
export const Int8 = {
|
|
102
92
|
/**
|
|
103
|
-
* Type guard that checks if a value is an
|
|
93
|
+
* Type guard that checks if a value is an integer in [-128, 127].
|
|
104
94
|
*
|
|
105
95
|
* @param value - The value to check
|
|
106
|
-
* @returns `true` if the value is in
|
|
96
|
+
* @returns `true` if the value is an integer in [-128, 127], `false` otherwise
|
|
107
97
|
* @see {@link isInt8} for usage examples
|
|
108
98
|
*/
|
|
109
99
|
is,
|
|
110
100
|
|
|
111
101
|
/**
|
|
112
|
-
* The
|
|
113
|
-
*
|
|
114
|
-
* @readonly
|
|
102
|
+
* The smallest value representable as `Int8`.
|
|
115
103
|
*/
|
|
116
104
|
MIN_VALUE,
|
|
117
105
|
|
|
118
106
|
/**
|
|
119
|
-
* The
|
|
120
|
-
*
|
|
121
|
-
* @readonly
|
|
107
|
+
* The largest value representable as `Int8`.
|
|
122
108
|
*/
|
|
123
109
|
MAX_VALUE,
|
|
124
110
|
|
|
125
111
|
/**
|
|
126
|
-
* Returns the
|
|
112
|
+
* Returns the smallest of the given integers.
|
|
127
113
|
*
|
|
128
|
-
* @param values - The
|
|
129
|
-
* @returns The smallest value as an Int8
|
|
114
|
+
* @param values - The integers to compare (at least one required)
|
|
115
|
+
* @returns The smallest value as an `Int8`
|
|
130
116
|
*/
|
|
131
117
|
min: min_,
|
|
132
118
|
|
|
133
119
|
/**
|
|
134
|
-
* Returns the
|
|
120
|
+
* Returns the largest of the given integers.
|
|
135
121
|
*
|
|
136
|
-
* @param values - The
|
|
137
|
-
* @returns The largest value as an Int8
|
|
122
|
+
* @param values - The integers to compare (at least one required)
|
|
123
|
+
* @returns The largest value as an `Int8`
|
|
138
124
|
*/
|
|
139
125
|
max: max_,
|
|
140
126
|
|
|
141
127
|
/**
|
|
142
|
-
* Clamps a number
|
|
128
|
+
* Clamps a `number` into the `Int8` range, rounding to the nearest integer
|
|
129
|
+
* and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
143
130
|
*
|
|
144
|
-
* @param value The
|
|
145
|
-
* @returns The
|
|
131
|
+
* @param value - The value to clamp
|
|
132
|
+
* @returns The clamped value as an `Int8`
|
|
146
133
|
*/
|
|
147
134
|
clamp,
|
|
148
135
|
|
|
149
136
|
/**
|
|
150
|
-
* Returns the absolute value of an
|
|
137
|
+
* Returns the absolute value of an integer in [-128, 127].
|
|
138
|
+
*
|
|
139
|
+
* The result is non-negative and keeps the `Int8` brand.
|
|
151
140
|
*
|
|
152
|
-
* @param
|
|
153
|
-
* @returns The absolute value as
|
|
141
|
+
* @param a - The integer value
|
|
142
|
+
* @returns The absolute value as a non-negative `Int8`
|
|
154
143
|
*/
|
|
155
144
|
abs,
|
|
156
145
|
|
|
157
146
|
/**
|
|
158
|
-
* Generates a random Int8
|
|
147
|
+
* Generates a random `Int8` within the given range.
|
|
159
148
|
*
|
|
160
|
-
*
|
|
149
|
+
* The range is inclusive on both ends.
|
|
161
150
|
*
|
|
162
151
|
* @param min - The minimum value (inclusive)
|
|
163
152
|
* @param max - The maximum value (inclusive)
|
|
164
|
-
* @returns A random Int8 in
|
|
153
|
+
* @returns A random `Int8` in `[min, max]`
|
|
165
154
|
*/
|
|
166
155
|
random,
|
|
167
156
|
|
|
168
157
|
/**
|
|
169
|
-
* Raises
|
|
158
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Int8` (floored to an
|
|
159
|
+
* integer).
|
|
170
160
|
*
|
|
171
|
-
* @param
|
|
172
|
-
* @param
|
|
173
|
-
* @returns `
|
|
161
|
+
* @param a - The base integer
|
|
162
|
+
* @param b - The exponent integer
|
|
163
|
+
* @returns `a ** b` as an `Int8`
|
|
174
164
|
*/
|
|
175
165
|
pow,
|
|
176
166
|
|
|
177
167
|
/**
|
|
178
|
-
* Adds two
|
|
168
|
+
* Adds two integers, returning `a + b` as an `Int8`.
|
|
179
169
|
*
|
|
180
|
-
* @param
|
|
181
|
-
* @param
|
|
182
|
-
* @returns `
|
|
170
|
+
* @param a - The first integer
|
|
171
|
+
* @param b - The second integer
|
|
172
|
+
* @returns The sum of `a` and `b` as an `Int8`
|
|
183
173
|
*/
|
|
184
174
|
add,
|
|
185
175
|
|
|
186
176
|
/**
|
|
187
|
-
* Subtracts two
|
|
177
|
+
* Subtracts two integers, returning `a - b` as an `Int8`.
|
|
188
178
|
*
|
|
189
|
-
* @param
|
|
190
|
-
* @param
|
|
191
|
-
* @returns `
|
|
179
|
+
* @param a - The first integer
|
|
180
|
+
* @param b - The second integer
|
|
181
|
+
* @returns The difference of `a` and `b` as an `Int8`
|
|
192
182
|
*/
|
|
193
183
|
sub,
|
|
194
184
|
|
|
195
185
|
/**
|
|
196
|
-
* Multiplies two
|
|
186
|
+
* Multiplies two integers, returning `a * b` as an `Int8`.
|
|
197
187
|
*
|
|
198
|
-
* @param
|
|
199
|
-
* @param
|
|
200
|
-
* @returns `
|
|
188
|
+
* @param a - The first integer
|
|
189
|
+
* @param b - The second integer
|
|
190
|
+
* @returns The product of `a` and `b` as an `Int8`
|
|
201
191
|
*/
|
|
202
192
|
mul,
|
|
203
193
|
|
|
204
194
|
/**
|
|
205
|
-
* Divides two
|
|
195
|
+
* Divides two integers using floor division (`⌊a / b⌋`): the result is `a /
|
|
196
|
+
* b` rounded toward negative infinity, as an `Int8`.
|
|
206
197
|
*
|
|
207
|
-
* @param
|
|
208
|
-
* @param
|
|
209
|
-
* @returns
|
|
198
|
+
* @param a - The dividend
|
|
199
|
+
* @param b - The divisor (must be non-zero)
|
|
200
|
+
* @returns The floored quotient as an `Int8`
|
|
210
201
|
*/
|
|
211
202
|
div,
|
|
212
203
|
} as const;
|
|
@@ -50,132 +50,134 @@ const random = (min: Uint8, max: Uint8): Uint8 =>
|
|
|
50
50
|
castType(randomImpl(castTypeImpl(min), castTypeImpl(max)));
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Type guard that checks if a value is an non-negative integer less than 256.
|
|
54
54
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
55
|
+
* Returns `true` for an non-negative integer less than 256 — a value with no
|
|
56
|
+
* fractional component.
|
|
57
|
+
*
|
|
58
|
+
* @param value - The value to check
|
|
59
|
+
* @returns `true` if the value is an non-negative integer less than 256, `false` otherwise
|
|
57
60
|
*/
|
|
58
61
|
export const isUint8 = is;
|
|
59
62
|
|
|
60
63
|
/**
|
|
61
|
-
* Casts a number to
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
+
* Casts a `number` to the `Uint8` branded type.
|
|
65
|
+
*
|
|
66
|
+
* Validates that the value is an non-negative integer less than 256 and returns
|
|
67
|
+
* it with the `Uint8` brand. Throws a `TypeError` otherwise.
|
|
64
68
|
*
|
|
65
|
-
* @param value The value to cast
|
|
66
|
-
* @returns The value as
|
|
67
|
-
* @throws {TypeError} If the value is not
|
|
69
|
+
* @param value - The value to cast
|
|
70
|
+
* @returns The value as an `Uint8`
|
|
71
|
+
* @throws {TypeError} If the value is not an non-negative integer less than 256
|
|
68
72
|
*/
|
|
69
73
|
export const asUint8 = castType;
|
|
70
74
|
|
|
71
75
|
/**
|
|
72
|
-
* Namespace providing type-safe
|
|
73
|
-
* integers.
|
|
76
|
+
* Namespace providing type-safe operations for the `Uint8` branded type.
|
|
74
77
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* constraint, with negative results clamped to 0 and overflow results clamped
|
|
78
|
-
* to MAX_VALUE.
|
|
78
|
+
* The `Uint8` type represents an non-negative integer less than 256. Division
|
|
79
|
+
* (`div`) uses floor division.
|
|
79
80
|
*/
|
|
80
81
|
export const Uint8 = {
|
|
81
82
|
/**
|
|
82
|
-
* Type guard that checks if a value is an
|
|
83
|
+
* Type guard that checks if a value is an non-negative integer less than 256.
|
|
83
84
|
*
|
|
84
|
-
* @param value The value to check
|
|
85
|
-
* @returns `true` if the value is an
|
|
86
|
-
*
|
|
85
|
+
* @param value - The value to check
|
|
86
|
+
* @returns `true` if the value is an non-negative integer less than 256, `false` otherwise
|
|
87
|
+
* @see {@link isUint8} for usage examples
|
|
87
88
|
*/
|
|
88
89
|
is,
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
|
-
* The
|
|
92
|
-
*
|
|
93
|
-
* @readonly
|
|
92
|
+
* The smallest value representable as `Uint8`.
|
|
94
93
|
*/
|
|
95
94
|
MIN_VALUE,
|
|
96
95
|
|
|
97
96
|
/**
|
|
98
|
-
* The
|
|
99
|
-
*
|
|
100
|
-
* @readonly
|
|
97
|
+
* The largest value representable as `Uint8`.
|
|
101
98
|
*/
|
|
102
99
|
MAX_VALUE,
|
|
103
100
|
|
|
104
101
|
/**
|
|
105
|
-
* Returns the
|
|
102
|
+
* Returns the largest of the given non-negative integers.
|
|
106
103
|
*
|
|
107
|
-
* @param values The
|
|
108
|
-
* @returns The
|
|
104
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
105
|
+
* @returns The largest value as an `Uint8`
|
|
109
106
|
*/
|
|
110
107
|
max: max_,
|
|
111
108
|
|
|
112
109
|
/**
|
|
113
|
-
* Returns the
|
|
110
|
+
* Returns the smallest of the given non-negative integers.
|
|
114
111
|
*
|
|
115
|
-
* @param values The
|
|
116
|
-
* @returns The
|
|
112
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
113
|
+
* @returns The smallest value as an `Uint8`
|
|
117
114
|
*/
|
|
118
115
|
min: min_,
|
|
119
116
|
|
|
120
117
|
/**
|
|
121
|
-
* Clamps a number
|
|
118
|
+
* Clamps a `number` into the `Uint8` range, rounding to the nearest integer
|
|
119
|
+
* and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
122
120
|
*
|
|
123
|
-
* @param value The
|
|
124
|
-
* @returns The
|
|
121
|
+
* @param value - The value to clamp
|
|
122
|
+
* @returns The clamped value as an `Uint8`
|
|
125
123
|
*/
|
|
126
124
|
clamp,
|
|
127
125
|
|
|
128
126
|
/**
|
|
129
|
-
* Generates a random Uint8
|
|
127
|
+
* Generates a random `Uint8` within the given range.
|
|
128
|
+
*
|
|
129
|
+
* The range is inclusive on both ends.
|
|
130
130
|
*
|
|
131
|
-
* @param min The minimum value (inclusive)
|
|
132
|
-
* @param max The maximum value (inclusive)
|
|
133
|
-
* @returns A random Uint8
|
|
131
|
+
* @param min - The minimum value (inclusive)
|
|
132
|
+
* @param max - The maximum value (inclusive)
|
|
133
|
+
* @returns A random `Uint8` in `[min, max]`
|
|
134
134
|
*/
|
|
135
135
|
random,
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
|
-
* Raises
|
|
138
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Uint8` (floored to
|
|
139
|
+
* an integer).
|
|
139
140
|
*
|
|
140
|
-
* @param
|
|
141
|
-
* @param
|
|
142
|
-
* @returns `
|
|
141
|
+
* @param a - The base non-negative integer
|
|
142
|
+
* @param b - The exponent non-negative integer
|
|
143
|
+
* @returns `a ** b` as an `Uint8`
|
|
143
144
|
*/
|
|
144
145
|
pow,
|
|
145
146
|
|
|
146
147
|
/**
|
|
147
|
-
* Adds two
|
|
148
|
+
* Adds two non-negative integers, returning `a + b` as an `Uint8`.
|
|
148
149
|
*
|
|
149
|
-
* @param
|
|
150
|
-
* @param
|
|
151
|
-
* @returns `
|
|
150
|
+
* @param a - The first non-negative integer
|
|
151
|
+
* @param b - The second non-negative integer
|
|
152
|
+
* @returns The sum of `a` and `b` as an `Uint8`
|
|
152
153
|
*/
|
|
153
154
|
add,
|
|
154
155
|
|
|
155
156
|
/**
|
|
156
|
-
* Subtracts two
|
|
157
|
+
* Subtracts two non-negative integers, returning `a - b` as an `Uint8`.
|
|
157
158
|
*
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
160
|
-
* @returns `
|
|
159
|
+
* @param a - The first non-negative integer
|
|
160
|
+
* @param b - The second non-negative integer
|
|
161
|
+
* @returns The difference of `a` and `b` as an `Uint8`
|
|
161
162
|
*/
|
|
162
163
|
sub,
|
|
163
164
|
|
|
164
165
|
/**
|
|
165
|
-
* Multiplies two
|
|
166
|
+
* Multiplies two non-negative integers, returning `a * b` as an `Uint8`.
|
|
166
167
|
*
|
|
167
|
-
* @param
|
|
168
|
-
* @param
|
|
169
|
-
* @returns `
|
|
168
|
+
* @param a - The first non-negative integer
|
|
169
|
+
* @param b - The second non-negative integer
|
|
170
|
+
* @returns The product of `a` and `b` as an `Uint8`
|
|
170
171
|
*/
|
|
171
172
|
mul,
|
|
172
173
|
|
|
173
174
|
/**
|
|
174
|
-
* Divides two
|
|
175
|
+
* Divides two non-negative integers using floor division (`⌊a / b⌋`): the
|
|
176
|
+
* result is `a / b` rounded toward negative infinity, as an `Uint8`.
|
|
175
177
|
*
|
|
176
|
-
* @param
|
|
177
|
-
* @param
|
|
178
|
-
* @returns
|
|
178
|
+
* @param a - The dividend
|
|
179
|
+
* @param b - The divisor (must be non-zero)
|
|
180
|
+
* @returns The floored quotient as an `Uint8`
|
|
179
181
|
*/
|
|
180
182
|
div,
|
|
181
183
|
} as const;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './str.mjs';
|