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,117 +33,116 @@ const {
|
|
|
33
33
|
} as const);
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* the range [1, 2^16)).
|
|
36
|
+
* Type guard that checks if a value is a non-zero integer in [1, 2^16).
|
|
38
37
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* Returns `true` for a non-zero integer in [1, 2^16) — a value with no
|
|
39
|
+
* fractional component.
|
|
40
|
+
*
|
|
41
|
+
* @param value - The value to check
|
|
42
|
+
* @returns `true` if the value is a non-zero integer in [1, 2^16), `false` otherwise
|
|
41
43
|
*/
|
|
42
44
|
export const isNonZeroUint16 = is;
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
|
-
* Casts a number to
|
|
47
|
+
* Casts a `number` to the `NonZeroUint16` branded type.
|
|
48
|
+
*
|
|
49
|
+
* Validates that the value is a non-zero integer in [1, 2^16) and returns it
|
|
50
|
+
* with the `NonZeroUint16` brand. Throws a `TypeError` otherwise.
|
|
46
51
|
*
|
|
47
|
-
* @param value The value to cast
|
|
48
|
-
* @returns The value as a NonZeroUint16
|
|
49
|
-
* @throws {TypeError} If the value is not a non-zero integer in [1, 2^16)
|
|
52
|
+
* @param value - The value to cast
|
|
53
|
+
* @returns The value as a `NonZeroUint16`
|
|
54
|
+
* @throws {TypeError} If the value is not a non-zero integer in [1, 2^16)
|
|
50
55
|
*/
|
|
51
56
|
export const asNonZeroUint16 = castType;
|
|
52
57
|
|
|
53
58
|
/**
|
|
54
|
-
* Namespace providing type-safe
|
|
55
|
-
*
|
|
59
|
+
* Namespace providing type-safe operations for the `NonZeroUint16` branded
|
|
60
|
+
* type.
|
|
56
61
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* unsigned integer constraint, with results below 1 clamped to MIN_VALUE and
|
|
60
|
-
* overflow results clamped to MAX_VALUE.
|
|
62
|
+
* The `NonZeroUint16` type represents a non-zero integer in [1, 2^16). Division
|
|
63
|
+
* (`div`) uses floor division.
|
|
61
64
|
*/
|
|
62
65
|
export const NonZeroUint16 = {
|
|
63
66
|
/**
|
|
64
|
-
* Type guard
|
|
67
|
+
* Type guard that checks if a value is a non-zero integer in [1, 2^16).
|
|
65
68
|
*
|
|
66
|
-
* @param value The value to check
|
|
67
|
-
* @returns `true` if the value is a
|
|
68
|
-
*
|
|
69
|
+
* @param value - The value to check
|
|
70
|
+
* @returns `true` if the value is a non-zero integer in [1, 2^16), `false` otherwise
|
|
71
|
+
* @see {@link isNonZeroUint16} for usage examples
|
|
69
72
|
*/
|
|
70
73
|
is,
|
|
71
74
|
|
|
72
75
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
75
|
-
* @readonly
|
|
76
|
+
* The smallest value representable as `NonZeroUint16`.
|
|
76
77
|
*/
|
|
77
78
|
MIN_VALUE,
|
|
78
79
|
|
|
79
80
|
/**
|
|
80
|
-
* The
|
|
81
|
-
*
|
|
82
|
-
* @readonly
|
|
81
|
+
* The largest value representable as `NonZeroUint16`.
|
|
83
82
|
*/
|
|
84
83
|
MAX_VALUE,
|
|
85
84
|
|
|
86
85
|
/**
|
|
87
|
-
* Returns the
|
|
86
|
+
* Returns the smallest of the given non-zero integers.
|
|
88
87
|
*
|
|
89
|
-
* @param
|
|
90
|
-
* @
|
|
91
|
-
* @returns The minimum value as a NonZeroUint16.
|
|
88
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
89
|
+
* @returns The smallest value as a `NonZeroUint16`
|
|
92
90
|
*/
|
|
93
91
|
min: min_,
|
|
94
92
|
|
|
95
93
|
/**
|
|
96
|
-
* Returns the
|
|
94
|
+
* Returns the largest of the given non-zero integers.
|
|
97
95
|
*
|
|
98
|
-
* @param
|
|
99
|
-
* @
|
|
100
|
-
* @returns The maximum value as a NonZeroUint16.
|
|
96
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
97
|
+
* @returns The largest value as a `NonZeroUint16`
|
|
101
98
|
*/
|
|
102
99
|
max: max_,
|
|
103
100
|
|
|
104
101
|
/**
|
|
105
|
-
* Clamps a number
|
|
102
|
+
* Clamps a `number` into the `NonZeroUint16` range, rounding to the nearest
|
|
103
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
106
104
|
*
|
|
107
|
-
* @param value The
|
|
108
|
-
* @returns The
|
|
105
|
+
* @param value - The value to clamp
|
|
106
|
+
* @returns The clamped value as a `NonZeroUint16`
|
|
109
107
|
*/
|
|
110
108
|
clamp,
|
|
111
109
|
|
|
112
110
|
/**
|
|
113
|
-
* Generates a random NonZeroUint16
|
|
111
|
+
* Generates a random `NonZeroUint16` within the given range.
|
|
112
|
+
*
|
|
113
|
+
* The range is inclusive on both ends.
|
|
114
114
|
*
|
|
115
|
-
* @
|
|
115
|
+
* @param min - The minimum value (inclusive)
|
|
116
|
+
* @param max - The maximum value (inclusive)
|
|
117
|
+
* @returns A random `NonZeroUint16` in `[min, max]`
|
|
116
118
|
*/
|
|
117
119
|
random,
|
|
118
120
|
|
|
119
121
|
/**
|
|
120
|
-
* Raises a
|
|
122
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonZeroUint16`
|
|
123
|
+
* (floored to an integer).
|
|
121
124
|
*
|
|
122
|
-
* @param a The base
|
|
123
|
-
* @param b The exponent
|
|
124
|
-
* @returns `a ** b`
|
|
125
|
+
* @param a - The base non-zero integer
|
|
126
|
+
* @param b - The exponent non-zero integer
|
|
127
|
+
* @returns `a ** b` as a `NonZeroUint16`
|
|
125
128
|
*/
|
|
126
129
|
pow,
|
|
127
130
|
|
|
128
131
|
/**
|
|
129
|
-
* Adds two NonZeroUint16
|
|
132
|
+
* Adds two non-zero integers, returning `a + b` as a `NonZeroUint16`.
|
|
130
133
|
*
|
|
131
|
-
* @param a The first
|
|
132
|
-
* @param b The second
|
|
133
|
-
* @returns `a
|
|
134
|
+
* @param a - The first non-zero integer
|
|
135
|
+
* @param b - The second non-zero integer
|
|
136
|
+
* @returns The sum of `a` and `b` as a `NonZeroUint16`
|
|
134
137
|
*/
|
|
135
138
|
add,
|
|
136
139
|
|
|
137
140
|
/**
|
|
138
|
-
* Multiplies two NonZeroUint16
|
|
139
|
-
*
|
|
140
|
-
* Both `add` and `mul` stay within `[1, 65535]`. For the non-closed
|
|
141
|
-
* operations (`sub`/`div`, whose result may be `0`) use {@link Num.sub} /
|
|
142
|
-
* {@link Num.divInt}.
|
|
141
|
+
* Multiplies two non-zero integers, returning `a * b` as a `NonZeroUint16`.
|
|
143
142
|
*
|
|
144
|
-
* @param a The first
|
|
145
|
-
* @param b The second
|
|
146
|
-
* @returns `a
|
|
143
|
+
* @param a - The first non-zero integer
|
|
144
|
+
* @param b - The second non-zero integer
|
|
145
|
+
* @returns The product of `a` and `b` as a `NonZeroUint16`
|
|
147
146
|
*/
|
|
148
147
|
mul,
|
|
149
148
|
} as const;
|
|
@@ -33,117 +33,116 @@ const {
|
|
|
33
33
|
} as const);
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* the range [1, 2^32)).
|
|
36
|
+
* Type guard that checks if a value is a non-zero integer in [1, 2^32).
|
|
38
37
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* Returns `true` for a non-zero integer in [1, 2^32) — a value with no
|
|
39
|
+
* fractional component.
|
|
40
|
+
*
|
|
41
|
+
* @param value - The value to check
|
|
42
|
+
* @returns `true` if the value is a non-zero integer in [1, 2^32), `false` otherwise
|
|
41
43
|
*/
|
|
42
44
|
export const isNonZeroUint32 = is;
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
|
-
* Casts a number to
|
|
47
|
+
* Casts a `number` to the `NonZeroUint32` branded type.
|
|
48
|
+
*
|
|
49
|
+
* Validates that the value is a non-zero integer in [1, 2^32) and returns it
|
|
50
|
+
* with the `NonZeroUint32` brand. Throws a `TypeError` otherwise.
|
|
46
51
|
*
|
|
47
|
-
* @param value The value to cast
|
|
48
|
-
* @returns The value as a NonZeroUint32
|
|
49
|
-
* @throws {TypeError} If the value is not a non-zero integer in [1, 2^32)
|
|
52
|
+
* @param value - The value to cast
|
|
53
|
+
* @returns The value as a `NonZeroUint32`
|
|
54
|
+
* @throws {TypeError} If the value is not a non-zero integer in [1, 2^32)
|
|
50
55
|
*/
|
|
51
56
|
export const asNonZeroUint32 = castType;
|
|
52
57
|
|
|
53
58
|
/**
|
|
54
|
-
* Namespace providing type-safe
|
|
55
|
-
*
|
|
59
|
+
* Namespace providing type-safe operations for the `NonZeroUint32` branded
|
|
60
|
+
* type.
|
|
56
61
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* non-zero unsigned integer constraint, with results below 1 clamped to
|
|
60
|
-
* MIN_VALUE and overflow results clamped to MAX_VALUE.
|
|
62
|
+
* The `NonZeroUint32` type represents a non-zero integer in [1, 2^32). Division
|
|
63
|
+
* (`div`) uses floor division.
|
|
61
64
|
*/
|
|
62
65
|
export const NonZeroUint32 = {
|
|
63
66
|
/**
|
|
64
|
-
* Type guard
|
|
67
|
+
* Type guard that checks if a value is a non-zero integer in [1, 2^32).
|
|
65
68
|
*
|
|
66
|
-
* @param value The value to check
|
|
67
|
-
* @returns `true` if the value is a
|
|
68
|
-
*
|
|
69
|
+
* @param value - The value to check
|
|
70
|
+
* @returns `true` if the value is a non-zero integer in [1, 2^32), `false` otherwise
|
|
71
|
+
* @see {@link isNonZeroUint32} for usage examples
|
|
69
72
|
*/
|
|
70
73
|
is,
|
|
71
74
|
|
|
72
75
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
75
|
-
* @readonly
|
|
76
|
+
* The smallest value representable as `NonZeroUint32`.
|
|
76
77
|
*/
|
|
77
78
|
MIN_VALUE,
|
|
78
79
|
|
|
79
80
|
/**
|
|
80
|
-
* The
|
|
81
|
-
*
|
|
82
|
-
* @readonly
|
|
81
|
+
* The largest value representable as `NonZeroUint32`.
|
|
83
82
|
*/
|
|
84
83
|
MAX_VALUE,
|
|
85
84
|
|
|
86
85
|
/**
|
|
87
|
-
* Returns the
|
|
86
|
+
* Returns the smallest of the given non-zero integers.
|
|
88
87
|
*
|
|
89
|
-
* @param
|
|
90
|
-
* @
|
|
91
|
-
* @returns The minimum value as a NonZeroUint32.
|
|
88
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
89
|
+
* @returns The smallest value as a `NonZeroUint32`
|
|
92
90
|
*/
|
|
93
91
|
min: min_,
|
|
94
92
|
|
|
95
93
|
/**
|
|
96
|
-
* Returns the
|
|
94
|
+
* Returns the largest of the given non-zero integers.
|
|
97
95
|
*
|
|
98
|
-
* @param
|
|
99
|
-
* @
|
|
100
|
-
* @returns The maximum value as a NonZeroUint32.
|
|
96
|
+
* @param values - The non-zero integers to compare (at least one required)
|
|
97
|
+
* @returns The largest value as a `NonZeroUint32`
|
|
101
98
|
*/
|
|
102
99
|
max: max_,
|
|
103
100
|
|
|
104
101
|
/**
|
|
105
|
-
* Clamps a number
|
|
102
|
+
* Clamps a `number` into the `NonZeroUint32` range, rounding to the nearest
|
|
103
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
106
104
|
*
|
|
107
|
-
* @param value The
|
|
108
|
-
* @returns The
|
|
105
|
+
* @param value - The value to clamp
|
|
106
|
+
* @returns The clamped value as a `NonZeroUint32`
|
|
109
107
|
*/
|
|
110
108
|
clamp,
|
|
111
109
|
|
|
112
110
|
/**
|
|
113
|
-
* Generates a random NonZeroUint32
|
|
111
|
+
* Generates a random `NonZeroUint32` within the given range.
|
|
112
|
+
*
|
|
113
|
+
* The range is inclusive on both ends.
|
|
114
114
|
*
|
|
115
|
-
* @
|
|
115
|
+
* @param min - The minimum value (inclusive)
|
|
116
|
+
* @param max - The maximum value (inclusive)
|
|
117
|
+
* @returns A random `NonZeroUint32` in `[min, max]`
|
|
116
118
|
*/
|
|
117
119
|
random,
|
|
118
120
|
|
|
119
121
|
/**
|
|
120
|
-
* Raises a
|
|
122
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonZeroUint32`
|
|
123
|
+
* (floored to an integer).
|
|
121
124
|
*
|
|
122
|
-
* @param a The base
|
|
123
|
-
* @param b The exponent
|
|
124
|
-
* @returns `a ** b`
|
|
125
|
+
* @param a - The base non-zero integer
|
|
126
|
+
* @param b - The exponent non-zero integer
|
|
127
|
+
* @returns `a ** b` as a `NonZeroUint32`
|
|
125
128
|
*/
|
|
126
129
|
pow,
|
|
127
130
|
|
|
128
131
|
/**
|
|
129
|
-
* Adds two NonZeroUint32
|
|
132
|
+
* Adds two non-zero integers, returning `a + b` as a `NonZeroUint32`.
|
|
130
133
|
*
|
|
131
|
-
* @param a The first
|
|
132
|
-
* @param b The second
|
|
133
|
-
* @returns `a
|
|
134
|
+
* @param a - The first non-zero integer
|
|
135
|
+
* @param b - The second non-zero integer
|
|
136
|
+
* @returns The sum of `a` and `b` as a `NonZeroUint32`
|
|
134
137
|
*/
|
|
135
138
|
add,
|
|
136
139
|
|
|
137
140
|
/**
|
|
138
|
-
* Multiplies two NonZeroUint32
|
|
139
|
-
*
|
|
140
|
-
* Both `add` and `mul` stay within `[1, 4294967295]`. For the non-closed
|
|
141
|
-
* operations (`sub`/`div`, whose result may be `0`) use {@link Num.sub} /
|
|
142
|
-
* {@link Num.divInt}.
|
|
141
|
+
* Multiplies two non-zero integers, returning `a * b` as a `NonZeroUint32`.
|
|
143
142
|
*
|
|
144
|
-
* @param a The first
|
|
145
|
-
* @param b The second
|
|
146
|
-
* @returns `a
|
|
143
|
+
* @param a - The first non-zero integer
|
|
144
|
+
* @param b - The second non-zero integer
|
|
145
|
+
* @returns The product of `a` and `b` as a `NonZeroUint32`
|
|
147
146
|
*/
|
|
148
147
|
mul,
|
|
149
148
|
} as const;
|
|
@@ -78,148 +78,159 @@ expectType<
|
|
|
78
78
|
>('=');
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Type guard that checks if a value is a positive finite number.
|
|
82
82
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
83
|
+
* Returns `true` only for a finite value — never `NaN`, `Infinity`, or
|
|
84
|
+
* `-Infinity`.
|
|
85
|
+
*
|
|
86
|
+
* @param value - The value to check
|
|
87
|
+
* @returns `true` if the value is a positive finite number, `false` otherwise
|
|
85
88
|
*/
|
|
86
89
|
export const isPositiveFiniteNumber = is;
|
|
87
90
|
|
|
88
91
|
/**
|
|
89
|
-
* Casts a number to
|
|
92
|
+
* Casts a `number` to the `PositiveFiniteNumber` branded type.
|
|
93
|
+
*
|
|
94
|
+
* Validates that the value is a positive finite number and returns it with the
|
|
95
|
+
* `PositiveFiniteNumber` brand. Throws a `TypeError` otherwise.
|
|
90
96
|
*
|
|
91
|
-
* @param value The value to cast
|
|
92
|
-
* @returns The value as a PositiveFiniteNumber
|
|
93
|
-
* @throws {TypeError} If the value is not a positive finite number
|
|
97
|
+
* @param value - The value to cast
|
|
98
|
+
* @returns The value as a `PositiveFiniteNumber`
|
|
99
|
+
* @throws {TypeError} If the value is not a positive finite number
|
|
94
100
|
*/
|
|
95
101
|
export const asPositiveFiniteNumber = castType;
|
|
96
102
|
|
|
97
103
|
/**
|
|
98
|
-
* Namespace providing type-safe
|
|
99
|
-
*
|
|
104
|
+
* Namespace providing type-safe operations for the `PositiveFiniteNumber`
|
|
105
|
+
* branded type.
|
|
100
106
|
*
|
|
101
|
-
*
|
|
102
|
-
* results to MIN_VALUE, while ensuring results remain finite (excluding NaN and
|
|
103
|
-
* Infinity). This type is useful for representing quantities that must always
|
|
104
|
-
* be positive, such as probabilities, magnitudes, and physical measurements.
|
|
107
|
+
* The `PositiveFiniteNumber` type represents a positive finite number.
|
|
105
108
|
*/
|
|
106
109
|
export const PositiveFiniteNumber = {
|
|
107
110
|
/**
|
|
108
|
-
* Type guard
|
|
111
|
+
* Type guard that checks if a value is a positive finite number.
|
|
109
112
|
*
|
|
110
|
-
* @param value The value to check
|
|
111
|
-
* @returns `true` if the value is a positive finite number, `false`
|
|
112
|
-
*
|
|
113
|
+
* @param value - The value to check
|
|
114
|
+
* @returns `true` if the value is a positive finite number, `false` otherwise
|
|
115
|
+
* @see {@link isPositiveFiniteNumber} for usage examples
|
|
113
116
|
*/
|
|
114
117
|
is,
|
|
115
118
|
|
|
116
119
|
/**
|
|
117
|
-
* The
|
|
118
|
-
*
|
|
119
|
-
* @readonly
|
|
120
|
+
* The smallest value representable as `PositiveFiniteNumber`.
|
|
120
121
|
*/
|
|
121
122
|
MIN_VALUE,
|
|
122
123
|
|
|
123
124
|
/**
|
|
124
|
-
* Returns the
|
|
125
|
+
* Returns the smallest of the given positive finite numbers.
|
|
125
126
|
*
|
|
126
|
-
* @param
|
|
127
|
-
* @
|
|
128
|
-
* @returns The minimum value as a PositiveFiniteNumber.
|
|
127
|
+
* @param values - The positive finite numbers to compare (at least one required)
|
|
128
|
+
* @returns The smallest value as a `PositiveFiniteNumber`
|
|
129
129
|
*/
|
|
130
130
|
min: min_,
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
* Returns the
|
|
133
|
+
* Returns the largest of the given positive finite numbers.
|
|
134
134
|
*
|
|
135
|
-
* @param
|
|
136
|
-
* @
|
|
137
|
-
* @returns The maximum value as a PositiveFiniteNumber.
|
|
135
|
+
* @param values - The positive finite numbers to compare (at least one required)
|
|
136
|
+
* @returns The largest value as a `PositiveFiniteNumber`
|
|
138
137
|
*/
|
|
139
138
|
max: max_,
|
|
140
139
|
|
|
141
140
|
/**
|
|
142
|
-
* Clamps a number
|
|
141
|
+
* Clamps a `number` into the `PositiveFiniteNumber` range `[MIN_VALUE,
|
|
142
|
+
* MAX_VALUE]`.
|
|
143
143
|
*
|
|
144
|
-
* @param value The
|
|
145
|
-
* @returns The
|
|
144
|
+
* @param value - The value to clamp
|
|
145
|
+
* @returns The clamped value as a `PositiveFiniteNumber`
|
|
146
146
|
*/
|
|
147
147
|
clamp,
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
150
|
+
* Returns the greatest integer less than or equal to a positive finite
|
|
151
|
+
* number.
|
|
151
152
|
*
|
|
152
|
-
* @param
|
|
153
|
-
* @returns The
|
|
153
|
+
* @param a - The positive finite number value
|
|
154
|
+
* @returns The floored value as an integer
|
|
154
155
|
*/
|
|
155
156
|
floor,
|
|
156
157
|
|
|
157
158
|
/**
|
|
158
|
-
*
|
|
159
|
+
* Returns the smallest integer greater than or equal to a positive finite
|
|
160
|
+
* number.
|
|
159
161
|
*
|
|
160
|
-
* @param
|
|
161
|
-
* @returns The
|
|
162
|
+
* @param a - The positive finite number value
|
|
163
|
+
* @returns The ceiled value as an integer
|
|
162
164
|
*/
|
|
163
165
|
ceil,
|
|
164
166
|
|
|
165
167
|
/**
|
|
166
|
-
*
|
|
168
|
+
* Returns the value of a positive finite number rounded to the nearest
|
|
169
|
+
* integer.
|
|
167
170
|
*
|
|
168
|
-
* @param
|
|
169
|
-
* @returns The rounded value as
|
|
171
|
+
* @param a - The positive finite number value
|
|
172
|
+
* @returns The rounded value as an integer
|
|
170
173
|
*/
|
|
171
174
|
round,
|
|
172
175
|
|
|
173
176
|
/**
|
|
174
|
-
* Generates a random PositiveFiniteNumber
|
|
177
|
+
* Generates a random `PositiveFiniteNumber` within the given range.
|
|
178
|
+
*
|
|
179
|
+
* The range is inclusive on both ends.
|
|
175
180
|
*
|
|
176
|
-
* @
|
|
181
|
+
* @param min - The minimum value (inclusive)
|
|
182
|
+
* @param max - The maximum value (inclusive)
|
|
183
|
+
* @returns A random `PositiveFiniteNumber` in `[min, max]`
|
|
177
184
|
*/
|
|
178
185
|
random,
|
|
179
186
|
|
|
180
187
|
/**
|
|
181
|
-
* Raises a
|
|
188
|
+
* Raises `a` to the power `b`, returning `a ** b` as a
|
|
189
|
+
* `PositiveFiniteNumber`.
|
|
182
190
|
*
|
|
183
|
-
* @param a The base
|
|
184
|
-
* @param b The exponent
|
|
185
|
-
* @returns `a ** b`
|
|
191
|
+
* @param a - The base positive finite number
|
|
192
|
+
* @param b - The exponent positive finite number
|
|
193
|
+
* @returns `a ** b` as a `PositiveFiniteNumber`
|
|
186
194
|
*/
|
|
187
195
|
pow,
|
|
188
196
|
|
|
189
197
|
/**
|
|
190
|
-
* Adds two
|
|
198
|
+
* Adds two positive finite numbers, returning `a + b` as a
|
|
199
|
+
* `PositiveFiniteNumber`.
|
|
191
200
|
*
|
|
192
|
-
* @param a The first
|
|
193
|
-
* @param b The second
|
|
194
|
-
* @returns `a
|
|
201
|
+
* @param a - The first positive finite number
|
|
202
|
+
* @param b - The second positive finite number
|
|
203
|
+
* @returns The sum of `a` and `b` as a `PositiveFiniteNumber`
|
|
195
204
|
*/
|
|
196
205
|
add,
|
|
197
206
|
|
|
198
207
|
/**
|
|
199
|
-
* Subtracts
|
|
208
|
+
* Subtracts two positive finite numbers, returning `a - b` as a
|
|
209
|
+
* `PositiveFiniteNumber`.
|
|
200
210
|
*
|
|
201
|
-
* @param a The
|
|
202
|
-
* @param b The
|
|
203
|
-
* @returns `a
|
|
204
|
-
* MIN_VALUE).
|
|
211
|
+
* @param a - The first positive finite number
|
|
212
|
+
* @param b - The second positive finite number
|
|
213
|
+
* @returns The difference of `a` and `b` as a `PositiveFiniteNumber`
|
|
205
214
|
*/
|
|
206
215
|
sub,
|
|
207
216
|
|
|
208
217
|
/**
|
|
209
|
-
* Multiplies two
|
|
218
|
+
* Multiplies two positive finite numbers, returning `a * b` as a
|
|
219
|
+
* `PositiveFiniteNumber`.
|
|
210
220
|
*
|
|
211
|
-
* @param a The first
|
|
212
|
-
* @param b The second
|
|
213
|
-
* @returns `a
|
|
221
|
+
* @param a - The first positive finite number
|
|
222
|
+
* @param b - The second positive finite number
|
|
223
|
+
* @returns The product of `a` and `b` as a `PositiveFiniteNumber`
|
|
214
224
|
*/
|
|
215
225
|
mul,
|
|
216
226
|
|
|
217
227
|
/**
|
|
218
|
-
* Divides
|
|
228
|
+
* Divides two positive finite numbers, returning `a / b` as a
|
|
229
|
+
* `PositiveFiniteNumber`.
|
|
219
230
|
*
|
|
220
|
-
* @param a The dividend
|
|
221
|
-
* @param b The divisor
|
|
222
|
-
* @returns `a / b`
|
|
231
|
+
* @param a - The dividend
|
|
232
|
+
* @param b - The divisor (must be non-zero)
|
|
233
|
+
* @returns `a / b` as a `PositiveFiniteNumber`
|
|
223
234
|
*/
|
|
224
235
|
div,
|
|
225
236
|
} as const;
|