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
|
@@ -33,7 +33,11 @@ const {
|
|
|
33
33
|
} as const);
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Type guard that checks if a value is a non-negative integer.
|
|
37
|
+
*
|
|
38
|
+
* Returns `true` for a non-negative integer — a value with no fractional
|
|
39
|
+
* component, including values outside the safe integer range (unlike
|
|
40
|
+
* `SafeInt`).
|
|
37
41
|
*
|
|
38
42
|
* @example
|
|
39
43
|
*
|
|
@@ -45,13 +49,16 @@ const {
|
|
|
45
49
|
* assert.isTrue(Uint.is(0));
|
|
46
50
|
* ```
|
|
47
51
|
*
|
|
48
|
-
* @param value The value to check
|
|
49
|
-
* @returns `true` if the value is a
|
|
52
|
+
* @param value - The value to check
|
|
53
|
+
* @returns `true` if the value is a non-negative integer, `false` otherwise
|
|
50
54
|
*/
|
|
51
55
|
export const isUint = is;
|
|
52
56
|
|
|
53
57
|
/**
|
|
54
|
-
* Casts a number to
|
|
58
|
+
* Casts a `number` to the `Uint` branded type.
|
|
59
|
+
*
|
|
60
|
+
* Validates that the value is a non-negative integer and returns it with the
|
|
61
|
+
* `Uint` brand. Throws a `TypeError` otherwise.
|
|
55
62
|
*
|
|
56
63
|
* @example
|
|
57
64
|
*
|
|
@@ -63,22 +70,25 @@ export const isUint = is;
|
|
|
63
70
|
* assert.isTrue(Uint.is(branded));
|
|
64
71
|
* ```
|
|
65
72
|
*
|
|
66
|
-
* @param value The value to cast
|
|
67
|
-
* @returns The value as
|
|
68
|
-
* @throws {TypeError} If the value is not a non-negative integer
|
|
73
|
+
* @param value - The value to cast
|
|
74
|
+
* @returns The value as an `Uint`
|
|
75
|
+
* @throws {TypeError} If the value is not a non-negative integer
|
|
69
76
|
*/
|
|
70
77
|
export const asUint = castType;
|
|
71
78
|
|
|
72
79
|
/**
|
|
73
|
-
* Namespace providing type-safe
|
|
80
|
+
* Namespace providing type-safe operations for the `Uint` branded type.
|
|
81
|
+
*
|
|
82
|
+
* The `Uint` type represents a non-negative integer. Division (`div`) uses
|
|
83
|
+
* floor division.
|
|
74
84
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
85
|
+
* Unlike `SafeInt`, `Uint` allows values outside the safe integer range (±2^53
|
|
86
|
+
* − 1), so very large magnitudes may lose precision in JavaScript's `number`
|
|
87
|
+
* type.
|
|
78
88
|
*/
|
|
79
89
|
export const Uint = {
|
|
80
90
|
/**
|
|
81
|
-
* Type guard
|
|
91
|
+
* Type guard that checks if a value is a non-negative integer.
|
|
82
92
|
*
|
|
83
93
|
* @example
|
|
84
94
|
*
|
|
@@ -90,21 +100,19 @@ export const Uint = {
|
|
|
90
100
|
* assert.isTrue(Uint.is(0));
|
|
91
101
|
* ```
|
|
92
102
|
*
|
|
93
|
-
* @param value The value to check
|
|
94
|
-
* @returns `true` if the value is a non-negative integer, `false` otherwise
|
|
103
|
+
* @param value - The value to check
|
|
104
|
+
* @returns `true` if the value is a non-negative integer, `false` otherwise
|
|
95
105
|
* @see {@link isUint} for usage examples
|
|
96
106
|
*/
|
|
97
107
|
is,
|
|
98
108
|
|
|
99
109
|
/**
|
|
100
|
-
* The
|
|
101
|
-
*
|
|
102
|
-
* @readonly
|
|
110
|
+
* The smallest value representable as `Uint`.
|
|
103
111
|
*/
|
|
104
112
|
MIN_VALUE,
|
|
105
113
|
|
|
106
114
|
/**
|
|
107
|
-
* Returns the
|
|
115
|
+
* Returns the smallest of the given non-negative integers.
|
|
108
116
|
*
|
|
109
117
|
* @example
|
|
110
118
|
*
|
|
@@ -114,14 +122,13 @@ export const Uint = {
|
|
|
114
122
|
* assert.isTrue(smallest === 3);
|
|
115
123
|
* ```
|
|
116
124
|
*
|
|
117
|
-
* @param
|
|
118
|
-
* @
|
|
119
|
-
* @returns The minimum value as a Uint.
|
|
125
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
126
|
+
* @returns The smallest value as an `Uint`
|
|
120
127
|
*/
|
|
121
128
|
min: min_,
|
|
122
129
|
|
|
123
130
|
/**
|
|
124
|
-
* Returns the
|
|
131
|
+
* Returns the largest of the given non-negative integers.
|
|
125
132
|
*
|
|
126
133
|
* @example
|
|
127
134
|
*
|
|
@@ -131,14 +138,14 @@ export const Uint = {
|
|
|
131
138
|
* assert.isTrue(largest === 7);
|
|
132
139
|
* ```
|
|
133
140
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @
|
|
136
|
-
* @returns The maximum value as a Uint.
|
|
141
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
142
|
+
* @returns The largest value as an `Uint`
|
|
137
143
|
*/
|
|
138
144
|
max: max_,
|
|
139
145
|
|
|
140
146
|
/**
|
|
141
|
-
* Clamps a number
|
|
147
|
+
* Clamps a `number` into the `Uint` range, rounding to the nearest integer
|
|
148
|
+
* and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
142
149
|
*
|
|
143
150
|
* @example
|
|
144
151
|
*
|
|
@@ -152,13 +159,15 @@ export const Uint = {
|
|
|
152
159
|
* assert.isTrue(clampedPositive === 42);
|
|
153
160
|
* ```
|
|
154
161
|
*
|
|
155
|
-
* @param value The
|
|
156
|
-
* @returns The
|
|
162
|
+
* @param value - The value to clamp
|
|
163
|
+
* @returns The clamped value as an `Uint`
|
|
157
164
|
*/
|
|
158
165
|
clamp,
|
|
159
166
|
|
|
160
167
|
/**
|
|
161
|
-
* Generates a random Uint
|
|
168
|
+
* Generates a random `Uint` within the given range.
|
|
169
|
+
*
|
|
170
|
+
* The range is inclusive on both ends.
|
|
162
171
|
*
|
|
163
172
|
* @example
|
|
164
173
|
*
|
|
@@ -174,12 +183,15 @@ export const Uint = {
|
|
|
174
183
|
* assert.isTrue(randomValue >= 0 && randomValue <= 3);
|
|
175
184
|
* ```
|
|
176
185
|
*
|
|
177
|
-
* @
|
|
186
|
+
* @param min - The minimum value (inclusive)
|
|
187
|
+
* @param max - The maximum value (inclusive)
|
|
188
|
+
* @returns A random `Uint` in `[min, max]`
|
|
178
189
|
*/
|
|
179
190
|
random,
|
|
180
191
|
|
|
181
192
|
/**
|
|
182
|
-
* Raises a
|
|
193
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Uint` (floored to an
|
|
194
|
+
* integer).
|
|
183
195
|
*
|
|
184
196
|
* @example
|
|
185
197
|
*
|
|
@@ -193,14 +205,14 @@ export const Uint = {
|
|
|
193
205
|
* assert.isTrue(power === 32);
|
|
194
206
|
* ```
|
|
195
207
|
*
|
|
196
|
-
* @param a The base
|
|
197
|
-
* @param b The exponent
|
|
198
|
-
* @returns `a ** b`
|
|
208
|
+
* @param a - The base non-negative integer
|
|
209
|
+
* @param b - The exponent non-negative integer
|
|
210
|
+
* @returns `a ** b` as an `Uint`
|
|
199
211
|
*/
|
|
200
212
|
pow,
|
|
201
213
|
|
|
202
214
|
/**
|
|
203
|
-
* Adds two Uint
|
|
215
|
+
* Adds two non-negative integers, returning `a + b` as an `Uint`.
|
|
204
216
|
*
|
|
205
217
|
* @example
|
|
206
218
|
*
|
|
@@ -210,14 +222,14 @@ export const Uint = {
|
|
|
210
222
|
* assert.isTrue(sum === 13);
|
|
211
223
|
* ```
|
|
212
224
|
*
|
|
213
|
-
* @param a The first
|
|
214
|
-
* @param b The second
|
|
215
|
-
* @returns `a
|
|
225
|
+
* @param a - The first non-negative integer
|
|
226
|
+
* @param b - The second non-negative integer
|
|
227
|
+
* @returns The sum of `a` and `b` as an `Uint`
|
|
216
228
|
*/
|
|
217
229
|
add,
|
|
218
230
|
|
|
219
231
|
/**
|
|
220
|
-
* Subtracts
|
|
232
|
+
* Subtracts two non-negative integers, returning `a - b` as an `Uint`.
|
|
221
233
|
*
|
|
222
234
|
* @example
|
|
223
235
|
*
|
|
@@ -227,14 +239,14 @@ export const Uint = {
|
|
|
227
239
|
* assert.isTrue(difference === 0);
|
|
228
240
|
* ```
|
|
229
241
|
*
|
|
230
|
-
* @param a The
|
|
231
|
-
* @param b The
|
|
232
|
-
* @returns `a
|
|
242
|
+
* @param a - The first non-negative integer
|
|
243
|
+
* @param b - The second non-negative integer
|
|
244
|
+
* @returns The difference of `a` and `b` as an `Uint`
|
|
233
245
|
*/
|
|
234
246
|
sub,
|
|
235
247
|
|
|
236
248
|
/**
|
|
237
|
-
* Multiplies two Uint
|
|
249
|
+
* Multiplies two non-negative integers, returning `a * b` as an `Uint`.
|
|
238
250
|
*
|
|
239
251
|
* @example
|
|
240
252
|
*
|
|
@@ -244,14 +256,15 @@ export const Uint = {
|
|
|
244
256
|
* assert.isTrue(product === 42);
|
|
245
257
|
* ```
|
|
246
258
|
*
|
|
247
|
-
* @param a The first
|
|
248
|
-
* @param b The second
|
|
249
|
-
* @returns `a
|
|
259
|
+
* @param a - The first non-negative integer
|
|
260
|
+
* @param b - The second non-negative integer
|
|
261
|
+
* @returns The product of `a` and `b` as an `Uint`
|
|
250
262
|
*/
|
|
251
263
|
mul,
|
|
252
264
|
|
|
253
265
|
/**
|
|
254
|
-
* Divides
|
|
266
|
+
* Divides two non-negative integers using floor division (`⌊a / b⌋`): the
|
|
267
|
+
* result is `a / b` rounded toward negative infinity, as an `Uint`.
|
|
255
268
|
*
|
|
256
269
|
* @example
|
|
257
270
|
*
|
|
@@ -261,9 +274,9 @@ export const Uint = {
|
|
|
261
274
|
* assert.isTrue(quotient === 2);
|
|
262
275
|
* ```
|
|
263
276
|
*
|
|
264
|
-
* @param a The dividend
|
|
265
|
-
* @param b The divisor
|
|
266
|
-
* @returns
|
|
277
|
+
* @param a - The dividend
|
|
278
|
+
* @param b - The divisor (must be non-zero)
|
|
279
|
+
* @returns The floored quotient as an `Uint`
|
|
267
280
|
*/
|
|
268
281
|
div,
|
|
269
282
|
} as const;
|
|
@@ -34,132 +34,134 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* 2^16)).
|
|
37
|
+
* Type guard that checks if a value is a non-negative integer less than 2^16.
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a non-negative integer less than 2^16 — a value with no
|
|
40
|
+
* fractional component.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check
|
|
43
|
+
* @returns `true` if the value is a non-negative integer less than 2^16, `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isUint16 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `Uint16` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a non-negative integer less than 2^16 and returns
|
|
51
|
+
* it with the `Uint16` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as
|
|
50
|
-
* @throws {TypeError} If the value is not a non-negative integer less than
|
|
51
|
-
* 2^16.
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as an `Uint16`
|
|
55
|
+
* @throws {TypeError} If the value is not a non-negative integer less than 2^16
|
|
52
56
|
*/
|
|
53
57
|
export const asUint16 = castType;
|
|
54
58
|
|
|
55
59
|
/**
|
|
56
|
-
* Namespace providing type-safe
|
|
57
|
-
* integers.
|
|
60
|
+
* Namespace providing type-safe operations for the `Uint16` branded type.
|
|
58
61
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* integer constraint, with negative results clamped to 0 and overflow results
|
|
62
|
-
* clamped to MAX_VALUE.
|
|
62
|
+
* The `Uint16` type represents a non-negative integer less than 2^16. Division
|
|
63
|
+
* (`div`) uses floor division.
|
|
63
64
|
*/
|
|
64
65
|
export const Uint16 = {
|
|
65
66
|
/**
|
|
66
|
-
* Type guard
|
|
67
|
+
* Type guard that checks if a value is a non-negative integer less than 2^16.
|
|
67
68
|
*
|
|
68
|
-
* @param value The value to check
|
|
69
|
-
* @returns `true` if the value is a
|
|
70
|
-
*
|
|
69
|
+
* @param value - The value to check
|
|
70
|
+
* @returns `true` if the value is a non-negative integer less than 2^16, `false` otherwise
|
|
71
|
+
* @see {@link isUint16} for usage examples
|
|
71
72
|
*/
|
|
72
73
|
is,
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
|
-
* The
|
|
76
|
-
*
|
|
77
|
-
* @readonly
|
|
76
|
+
* The smallest value representable as `Uint16`.
|
|
78
77
|
*/
|
|
79
78
|
MIN_VALUE,
|
|
80
79
|
|
|
81
80
|
/**
|
|
82
|
-
* The
|
|
83
|
-
*
|
|
84
|
-
* @readonly
|
|
81
|
+
* The largest value representable as `Uint16`.
|
|
85
82
|
*/
|
|
86
83
|
MAX_VALUE,
|
|
87
84
|
|
|
88
85
|
/**
|
|
89
|
-
* Returns the
|
|
86
|
+
* Returns the smallest of the given non-negative integers.
|
|
90
87
|
*
|
|
91
|
-
* @param
|
|
92
|
-
* @
|
|
93
|
-
* @returns The minimum value as a Uint16.
|
|
88
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
89
|
+
* @returns The smallest value as an `Uint16`
|
|
94
90
|
*/
|
|
95
91
|
min: min_,
|
|
96
92
|
|
|
97
93
|
/**
|
|
98
|
-
* Returns the
|
|
94
|
+
* Returns the largest of the given non-negative integers.
|
|
99
95
|
*
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
102
|
-
* @returns The maximum value as a Uint16.
|
|
96
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
97
|
+
* @returns The largest value as an `Uint16`
|
|
103
98
|
*/
|
|
104
99
|
max: max_,
|
|
105
100
|
|
|
106
101
|
/**
|
|
107
|
-
* Clamps a number
|
|
102
|
+
* Clamps a `number` into the `Uint16` range, rounding to the nearest integer
|
|
103
|
+
* and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
108
104
|
*
|
|
109
|
-
* @param value The
|
|
110
|
-
* @returns The
|
|
105
|
+
* @param value - The value to clamp
|
|
106
|
+
* @returns The clamped value as an `Uint16`
|
|
111
107
|
*/
|
|
112
108
|
clamp,
|
|
113
109
|
|
|
114
110
|
/**
|
|
115
|
-
* Generates a random Uint16
|
|
111
|
+
* Generates a random `Uint16` within the given range.
|
|
112
|
+
*
|
|
113
|
+
* The range is inclusive on both ends.
|
|
116
114
|
*
|
|
117
|
-
* @
|
|
115
|
+
* @param min - The minimum value (inclusive)
|
|
116
|
+
* @param max - The maximum value (inclusive)
|
|
117
|
+
* @returns A random `Uint16` in `[min, max]`
|
|
118
118
|
*/
|
|
119
119
|
random,
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
* Raises a
|
|
122
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Uint16` (floored to
|
|
123
|
+
* an integer).
|
|
123
124
|
*
|
|
124
|
-
* @param a The base
|
|
125
|
-
* @param b The exponent
|
|
126
|
-
* @returns `a ** b`
|
|
125
|
+
* @param a - The base non-negative integer
|
|
126
|
+
* @param b - The exponent non-negative integer
|
|
127
|
+
* @returns `a ** b` as an `Uint16`
|
|
127
128
|
*/
|
|
128
129
|
pow,
|
|
129
130
|
|
|
130
131
|
/**
|
|
131
|
-
* Adds two Uint16
|
|
132
|
+
* Adds two non-negative integers, returning `a + b` as an `Uint16`.
|
|
132
133
|
*
|
|
133
|
-
* @param a The first
|
|
134
|
-
* @param b The second
|
|
135
|
-
* @returns `a
|
|
134
|
+
* @param a - The first non-negative integer
|
|
135
|
+
* @param b - The second non-negative integer
|
|
136
|
+
* @returns The sum of `a` and `b` as an `Uint16`
|
|
136
137
|
*/
|
|
137
138
|
add,
|
|
138
139
|
|
|
139
140
|
/**
|
|
140
|
-
* Subtracts
|
|
141
|
+
* Subtracts two non-negative integers, returning `a - b` as an `Uint16`.
|
|
141
142
|
*
|
|
142
|
-
* @param a The
|
|
143
|
-
* @param b The
|
|
144
|
-
* @returns `a
|
|
143
|
+
* @param a - The first non-negative integer
|
|
144
|
+
* @param b - The second non-negative integer
|
|
145
|
+
* @returns The difference of `a` and `b` as an `Uint16`
|
|
145
146
|
*/
|
|
146
147
|
sub,
|
|
147
148
|
|
|
148
149
|
/**
|
|
149
|
-
* Multiplies two Uint16
|
|
150
|
+
* Multiplies two non-negative integers, returning `a * b` as an `Uint16`.
|
|
150
151
|
*
|
|
151
|
-
* @param a The first
|
|
152
|
-
* @param b The second
|
|
153
|
-
* @returns `a
|
|
152
|
+
* @param a - The first non-negative integer
|
|
153
|
+
* @param b - The second non-negative integer
|
|
154
|
+
* @returns The product of `a` and `b` as an `Uint16`
|
|
154
155
|
*/
|
|
155
156
|
mul,
|
|
156
157
|
|
|
157
158
|
/**
|
|
158
|
-
* Divides
|
|
159
|
+
* Divides two non-negative integers using floor division (`⌊a / b⌋`): the
|
|
160
|
+
* result is `a / b` rounded toward negative infinity, as an `Uint16`.
|
|
159
161
|
*
|
|
160
|
-
* @param a The dividend
|
|
161
|
-
* @param b The divisor
|
|
162
|
-
* @returns
|
|
162
|
+
* @param a - The dividend
|
|
163
|
+
* @param b - The divisor (must be non-zero)
|
|
164
|
+
* @returns The floored quotient as an `Uint16`
|
|
163
165
|
*/
|
|
164
166
|
div,
|
|
165
167
|
} as const;
|
|
@@ -34,130 +34,134 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* 2^32)).
|
|
37
|
+
* Type guard that checks if a value is a non-negative integer less than 2^32.
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a non-negative integer less than 2^32 — a value with no
|
|
40
|
+
* fractional component.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check
|
|
43
|
+
* @returns `true` if the value is a non-negative integer less than 2^32, `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isUint32 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `Uint32` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a non-negative integer less than 2^32 and returns
|
|
51
|
+
* it with the `Uint32` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as
|
|
50
|
-
* @throws {TypeError} If the value is not a non-negative integer less than
|
|
51
|
-
* 2^32.
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as an `Uint32`
|
|
55
|
+
* @throws {TypeError} If the value is not a non-negative integer less than 2^32
|
|
52
56
|
*/
|
|
53
57
|
export const asUint32 = castType;
|
|
54
58
|
|
|
55
59
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
+
* Namespace providing type-safe operations for the `Uint32` branded type.
|
|
61
|
+
*
|
|
62
|
+
* The `Uint32` type represents a non-negative integer less than 2^32. Division
|
|
63
|
+
* (`div`) uses floor division.
|
|
60
64
|
*/
|
|
61
65
|
export const Uint32 = {
|
|
62
66
|
/**
|
|
63
|
-
* Type guard that checks if a value is a
|
|
67
|
+
* Type guard that checks if a value is a non-negative integer less than 2^32.
|
|
64
68
|
*
|
|
65
69
|
* @param value - The value to check
|
|
66
|
-
* @returns `true` if the value is
|
|
67
|
-
*
|
|
70
|
+
* @returns `true` if the value is a non-negative integer less than 2^32, `false` otherwise
|
|
71
|
+
* @see {@link isUint32} for usage examples
|
|
68
72
|
*/
|
|
69
73
|
is,
|
|
70
74
|
|
|
71
75
|
/**
|
|
72
|
-
* The
|
|
73
|
-
*
|
|
74
|
-
* @readonly
|
|
76
|
+
* The smallest value representable as `Uint32`.
|
|
75
77
|
*/
|
|
76
78
|
MIN_VALUE,
|
|
77
79
|
|
|
78
80
|
/**
|
|
79
|
-
* The
|
|
80
|
-
*
|
|
81
|
-
* @readonly
|
|
81
|
+
* The largest value representable as `Uint32`.
|
|
82
82
|
*/
|
|
83
83
|
MAX_VALUE,
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* Returns the
|
|
86
|
+
* Returns the smallest of the given non-negative integers.
|
|
87
87
|
*
|
|
88
|
-
* @param values - The
|
|
89
|
-
* @returns The smallest value as
|
|
88
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
89
|
+
* @returns The smallest value as an `Uint32`
|
|
90
90
|
*/
|
|
91
91
|
min: min_,
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
* Returns the
|
|
94
|
+
* Returns the largest of the given non-negative integers.
|
|
95
95
|
*
|
|
96
|
-
* @param values - The
|
|
97
|
-
* @returns The largest value as
|
|
96
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
97
|
+
* @returns The largest value as an `Uint32`
|
|
98
98
|
*/
|
|
99
99
|
max: max_,
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
* Clamps a Uint32
|
|
102
|
+
* Clamps a `number` into the `Uint32` range, rounding to the nearest integer
|
|
103
|
+
* and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
103
104
|
*
|
|
104
105
|
* @param value - The value to clamp
|
|
105
|
-
* @
|
|
106
|
-
* @param max - The maximum value
|
|
107
|
-
* @returns The clamped value as a Uint32
|
|
106
|
+
* @returns The clamped value as an `Uint32`
|
|
108
107
|
*/
|
|
109
108
|
clamp,
|
|
110
109
|
|
|
111
110
|
/**
|
|
112
|
-
* Generates a random Uint32
|
|
111
|
+
* Generates a random `Uint32` within the given range.
|
|
112
|
+
*
|
|
113
|
+
* The range is inclusive on both ends.
|
|
113
114
|
*
|
|
114
|
-
* @
|
|
115
|
+
* @param min - The minimum value (inclusive)
|
|
116
|
+
* @param max - The maximum value (inclusive)
|
|
117
|
+
* @returns A random `Uint32` in `[min, max]`
|
|
115
118
|
*/
|
|
116
119
|
random,
|
|
117
120
|
|
|
118
121
|
/**
|
|
119
|
-
* Raises a
|
|
122
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Uint32` (floored to
|
|
123
|
+
* an integer).
|
|
120
124
|
*
|
|
121
|
-
* @param a - The base
|
|
122
|
-
* @param b - The exponent
|
|
123
|
-
* @returns `a ** b` as
|
|
125
|
+
* @param a - The base non-negative integer
|
|
126
|
+
* @param b - The exponent non-negative integer
|
|
127
|
+
* @returns `a ** b` as an `Uint32`
|
|
124
128
|
*/
|
|
125
129
|
pow,
|
|
126
130
|
|
|
127
131
|
/**
|
|
128
|
-
* Adds two
|
|
132
|
+
* Adds two non-negative integers, returning `a + b` as an `Uint32`.
|
|
129
133
|
*
|
|
130
|
-
* @param a -
|
|
131
|
-
* @param b -
|
|
132
|
-
* @returns `a
|
|
134
|
+
* @param a - The first non-negative integer
|
|
135
|
+
* @param b - The second non-negative integer
|
|
136
|
+
* @returns The sum of `a` and `b` as an `Uint32`
|
|
133
137
|
*/
|
|
134
138
|
add,
|
|
135
139
|
|
|
136
140
|
/**
|
|
137
|
-
* Subtracts two
|
|
141
|
+
* Subtracts two non-negative integers, returning `a - b` as an `Uint32`.
|
|
138
142
|
*
|
|
139
|
-
* @param a -
|
|
140
|
-
* @param b -
|
|
141
|
-
* @returns `a
|
|
143
|
+
* @param a - The first non-negative integer
|
|
144
|
+
* @param b - The second non-negative integer
|
|
145
|
+
* @returns The difference of `a` and `b` as an `Uint32`
|
|
142
146
|
*/
|
|
143
147
|
sub,
|
|
144
148
|
|
|
145
149
|
/**
|
|
146
|
-
* Multiplies two
|
|
150
|
+
* Multiplies two non-negative integers, returning `a * b` as an `Uint32`.
|
|
147
151
|
*
|
|
148
|
-
* @param a -
|
|
149
|
-
* @param b -
|
|
150
|
-
* @returns `a
|
|
152
|
+
* @param a - The first non-negative integer
|
|
153
|
+
* @param b - The second non-negative integer
|
|
154
|
+
* @returns The product of `a` and `b` as an `Uint32`
|
|
151
155
|
*/
|
|
152
156
|
mul,
|
|
153
157
|
|
|
154
158
|
/**
|
|
155
|
-
* Divides two
|
|
156
|
-
*
|
|
159
|
+
* Divides two non-negative integers using floor division (`⌊a / b⌋`): the
|
|
160
|
+
* result is `a / b` rounded toward negative infinity, as an `Uint32`.
|
|
157
161
|
*
|
|
158
|
-
* @param a - The dividend
|
|
159
|
-
* @param b - The divisor
|
|
160
|
-
* @returns
|
|
162
|
+
* @param a - The dividend
|
|
163
|
+
* @param b - The divisor (must be non-zero)
|
|
164
|
+
* @returns The floored quotient as an `Uint32`
|
|
161
165
|
*/
|
|
162
166
|
div,
|
|
163
167
|
} as const;
|