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
|
@@ -35,139 +35,131 @@ const {
|
|
|
35
35
|
typeNameInMessage,
|
|
36
36
|
} as const);
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* Returns the absolute value of a negative safe integer.
|
|
40
|
-
*
|
|
41
|
-
* The absolute value of a negative safe integer is always a positive safe
|
|
42
|
-
* integer (`>= 1`), so the result is typed as a {@link PositiveSafeInt}.
|
|
43
|
-
*
|
|
44
|
-
* @param x - The negative safe integer.
|
|
45
|
-
* @returns `|x|` as a PositiveSafeInt.
|
|
46
|
-
*/
|
|
47
38
|
const abs = (x: WithSmallInt<ElementType>): PositiveSafeInt =>
|
|
48
39
|
PositiveSafeInt.clamp(Math.abs(x));
|
|
49
40
|
|
|
50
41
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
42
|
+
* Type guard that checks if a value is a negative safe integer.
|
|
43
|
+
*
|
|
44
|
+
* Returns `true` for a negative safe integer — a value with no fractional
|
|
45
|
+
* component.
|
|
53
46
|
*
|
|
54
|
-
* @param value The value to check
|
|
55
|
-
* @returns `true` if the value is a
|
|
47
|
+
* @param value - The value to check
|
|
48
|
+
* @returns `true` if the value is a negative safe integer, `false` otherwise
|
|
56
49
|
*/
|
|
57
50
|
export const isNegativeSafeInt = is;
|
|
58
51
|
|
|
59
52
|
/**
|
|
60
|
-
* Casts a number to
|
|
53
|
+
* Casts a `number` to the `NegativeSafeInt` branded type.
|
|
54
|
+
*
|
|
55
|
+
* Validates that the value is a negative safe integer and returns it with the
|
|
56
|
+
* `NegativeSafeInt` brand. Throws a `TypeError` otherwise.
|
|
61
57
|
*
|
|
62
|
-
* @param value The value to cast
|
|
63
|
-
* @returns The value as a NegativeSafeInt
|
|
64
|
-
* @throws {TypeError} If the value is not a negative safe integer
|
|
58
|
+
* @param value - The value to cast
|
|
59
|
+
* @returns The value as a `NegativeSafeInt`
|
|
60
|
+
* @throws {TypeError} If the value is not a negative safe integer
|
|
65
61
|
*/
|
|
66
62
|
export const asNegativeSafeInt = castType;
|
|
67
63
|
|
|
68
64
|
/**
|
|
69
|
-
* Namespace providing type-safe
|
|
70
|
-
*
|
|
65
|
+
* Namespace providing type-safe operations for the `NegativeSafeInt` branded
|
|
66
|
+
* type.
|
|
71
67
|
*
|
|
72
|
-
* NegativeSafeInt represents
|
|
73
|
-
* (`
|
|
74
|
-
* safe integers clamp their results to the valid range, while operations whose
|
|
75
|
-
* result leaves the set (`mul`, `div`, `abs`) are typed to reflect the actual
|
|
76
|
-
* sign of the result.
|
|
68
|
+
* The `NegativeSafeInt` type represents a negative safe integer. Division
|
|
69
|
+
* (`div`) uses floor division.
|
|
77
70
|
*/
|
|
78
71
|
export const NegativeSafeInt = {
|
|
79
72
|
/**
|
|
80
|
-
* Type guard
|
|
73
|
+
* Type guard that checks if a value is a negative safe integer.
|
|
81
74
|
*
|
|
82
|
-
* @param value The value to check
|
|
83
|
-
* @returns `true` if the value is a negative safe integer, `false` otherwise
|
|
75
|
+
* @param value - The value to check
|
|
76
|
+
* @returns `true` if the value is a negative safe integer, `false` otherwise
|
|
77
|
+
* @see {@link isNegativeSafeInt} for usage examples
|
|
84
78
|
*/
|
|
85
79
|
is,
|
|
86
80
|
|
|
87
81
|
/**
|
|
88
|
-
* The
|
|
89
|
-
*
|
|
90
|
-
* @readonly
|
|
82
|
+
* The smallest value representable as `NegativeSafeInt`.
|
|
91
83
|
*/
|
|
92
84
|
MIN_VALUE,
|
|
93
85
|
|
|
94
86
|
/**
|
|
95
|
-
* The
|
|
96
|
-
*
|
|
97
|
-
* @readonly
|
|
87
|
+
* The largest value representable as `NegativeSafeInt`.
|
|
98
88
|
*/
|
|
99
89
|
MAX_VALUE,
|
|
100
90
|
|
|
101
91
|
/**
|
|
102
92
|
* Returns the absolute value of a negative safe integer.
|
|
103
93
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
94
|
+
* The result is non-negative and keeps the `NegativeSafeInt` brand.
|
|
95
|
+
*
|
|
96
|
+
* @param a - The negative safe integer value
|
|
97
|
+
* @returns The absolute value as a non-negative `NegativeSafeInt`
|
|
106
98
|
*/
|
|
107
99
|
abs,
|
|
108
100
|
|
|
109
101
|
/**
|
|
110
|
-
* Returns the
|
|
102
|
+
* Returns the smallest of the given negative safe integers.
|
|
111
103
|
*
|
|
112
|
-
* @param
|
|
113
|
-
* @
|
|
114
|
-
* @returns The minimum value as a NegativeSafeInt.
|
|
104
|
+
* @param values - The negative safe integers to compare (at least one required)
|
|
105
|
+
* @returns The smallest value as a `NegativeSafeInt`
|
|
115
106
|
*/
|
|
116
107
|
min: min_,
|
|
117
108
|
|
|
118
109
|
/**
|
|
119
|
-
* Returns the
|
|
110
|
+
* Returns the largest of the given negative safe integers.
|
|
120
111
|
*
|
|
121
|
-
* @param
|
|
122
|
-
* @
|
|
123
|
-
* @returns The maximum value as a NegativeSafeInt.
|
|
112
|
+
* @param values - The negative safe integers to compare (at least one required)
|
|
113
|
+
* @returns The largest value as a `NegativeSafeInt`
|
|
124
114
|
*/
|
|
125
115
|
max: max_,
|
|
126
116
|
|
|
127
117
|
/**
|
|
128
|
-
* Clamps a number
|
|
118
|
+
* Clamps a `number` into the `NegativeSafeInt` range, rounding to the nearest
|
|
119
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
129
120
|
*
|
|
130
|
-
* @param value The
|
|
131
|
-
* @returns The value
|
|
132
|
-
* NegativeSafeInt.
|
|
121
|
+
* @param value - The value to clamp
|
|
122
|
+
* @returns The clamped value as a `NegativeSafeInt`
|
|
133
123
|
*/
|
|
134
124
|
clamp,
|
|
135
125
|
|
|
136
126
|
/**
|
|
137
|
-
* Generates a random NegativeSafeInt
|
|
127
|
+
* Generates a random `NegativeSafeInt` within the given range.
|
|
138
128
|
*
|
|
139
|
-
*
|
|
129
|
+
* The range is inclusive on both ends.
|
|
130
|
+
*
|
|
131
|
+
* @param min - The minimum value (inclusive)
|
|
132
|
+
* @param max - The maximum value (inclusive)
|
|
133
|
+
* @returns A random `NegativeSafeInt` in `[min, max]`
|
|
140
134
|
*/
|
|
141
135
|
random,
|
|
142
136
|
|
|
143
137
|
/**
|
|
144
|
-
* Raises a
|
|
145
|
-
* integer.
|
|
138
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NegativeSafeInt`
|
|
139
|
+
* (floored to an integer).
|
|
146
140
|
*
|
|
147
|
-
* @param a The base negative safe integer
|
|
148
|
-
* @param b The exponent negative safe integer
|
|
149
|
-
* @returns `a ** b`
|
|
141
|
+
* @param a - The base negative safe integer
|
|
142
|
+
* @param b - The exponent negative safe integer
|
|
143
|
+
* @returns `a ** b` as a `NegativeSafeInt`
|
|
150
144
|
*/
|
|
151
145
|
pow,
|
|
152
146
|
|
|
153
147
|
/**
|
|
154
|
-
* Adds two negative safe integers
|
|
148
|
+
* Adds two negative safe integers, returning `a + b` as a `NegativeSafeInt`.
|
|
155
149
|
*
|
|
156
|
-
* @param a The first negative safe integer
|
|
157
|
-
* @param b The second negative safe integer
|
|
158
|
-
* @returns `a
|
|
150
|
+
* @param a - The first negative safe integer
|
|
151
|
+
* @param b - The second negative safe integer
|
|
152
|
+
* @returns The sum of `a` and `b` as a `NegativeSafeInt`
|
|
159
153
|
*/
|
|
160
154
|
add,
|
|
161
155
|
|
|
162
156
|
/**
|
|
163
|
-
* Subtracts
|
|
164
|
-
*
|
|
165
|
-
* The mathematical result can be positive, so it is clamped to the
|
|
166
|
-
* NegativeSafeInt range (maximum `-1`).
|
|
157
|
+
* Subtracts two negative safe integers, returning `a - b` as a
|
|
158
|
+
* `NegativeSafeInt`.
|
|
167
159
|
*
|
|
168
|
-
* @param a The
|
|
169
|
-
* @param b The
|
|
170
|
-
* @returns `a
|
|
160
|
+
* @param a - The first negative safe integer
|
|
161
|
+
* @param b - The second negative safe integer
|
|
162
|
+
* @returns The difference of `a` and `b` as a `NegativeSafeInt`
|
|
171
163
|
*/
|
|
172
164
|
sub,
|
|
173
165
|
} as const;
|
|
@@ -57,149 +57,159 @@ expectType<TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>, Uint>(
|
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* Type guard that checks if a value is a non-negative finite number.
|
|
61
61
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
62
|
+
* Returns `true` only for a finite value — never `NaN`, `Infinity`, or
|
|
63
|
+
* `-Infinity`.
|
|
64
|
+
*
|
|
65
|
+
* @param value - The value to check
|
|
66
|
+
* @returns `true` if the value is a non-negative finite number, `false` otherwise
|
|
64
67
|
*/
|
|
65
68
|
export const isNonNegativeFiniteNumber = is;
|
|
66
69
|
|
|
67
70
|
/**
|
|
68
|
-
* Casts a number to
|
|
71
|
+
* Casts a `number` to the `NonNegativeFiniteNumber` branded type.
|
|
72
|
+
*
|
|
73
|
+
* Validates that the value is a non-negative finite number and returns it with
|
|
74
|
+
* the `NonNegativeFiniteNumber` brand. Throws a `TypeError` otherwise.
|
|
69
75
|
*
|
|
70
|
-
* @param value The value to cast
|
|
71
|
-
* @returns The value as a NonNegativeFiniteNumber
|
|
72
|
-
* @throws {TypeError} If the value is not a non-negative finite number
|
|
76
|
+
* @param value - The value to cast
|
|
77
|
+
* @returns The value as a `NonNegativeFiniteNumber`
|
|
78
|
+
* @throws {TypeError} If the value is not a non-negative finite number
|
|
73
79
|
*/
|
|
74
80
|
export const asNonNegativeFiniteNumber = castType;
|
|
75
81
|
|
|
76
82
|
/**
|
|
77
|
-
* Namespace providing type-safe
|
|
78
|
-
*
|
|
83
|
+
* Namespace providing type-safe operations for the `NonNegativeFiniteNumber`
|
|
84
|
+
* branded type.
|
|
79
85
|
*
|
|
80
|
-
*
|
|
81
|
-
* results to 0, while ensuring results remain finite (excluding NaN and
|
|
82
|
-
* Infinity). This type is useful for representing measurements, distances,
|
|
83
|
-
* weights, and other inherently non-negative values.
|
|
86
|
+
* The `NonNegativeFiniteNumber` type represents a non-negative finite number.
|
|
84
87
|
*/
|
|
85
88
|
export const NonNegativeFiniteNumber = {
|
|
86
89
|
/**
|
|
87
|
-
* Type guard
|
|
90
|
+
* Type guard that checks if a value is a non-negative finite number.
|
|
88
91
|
*
|
|
89
|
-
* @param value The value to check
|
|
90
|
-
* @returns `true` if the value is a non-negative finite number, `false`
|
|
91
|
-
*
|
|
92
|
+
* @param value - The value to check
|
|
93
|
+
* @returns `true` if the value is a non-negative finite number, `false` otherwise
|
|
94
|
+
* @see {@link isNonNegativeFiniteNumber} for usage examples
|
|
92
95
|
*/
|
|
93
96
|
is,
|
|
94
97
|
|
|
95
98
|
/**
|
|
96
|
-
* The
|
|
97
|
-
*
|
|
98
|
-
* @readonly
|
|
99
|
+
* The smallest value representable as `NonNegativeFiniteNumber`.
|
|
99
100
|
*/
|
|
100
101
|
MIN_VALUE,
|
|
101
102
|
|
|
102
103
|
/**
|
|
103
|
-
* Returns the
|
|
104
|
+
* Returns the smallest of the given non-negative finite numbers.
|
|
104
105
|
*
|
|
105
|
-
* @param
|
|
106
|
-
* @
|
|
107
|
-
* @returns The minimum value as a NonNegativeFiniteNumber.
|
|
106
|
+
* @param values - The non-negative finite numbers to compare (at least one required)
|
|
107
|
+
* @returns The smallest value as a `NonNegativeFiniteNumber`
|
|
108
108
|
*/
|
|
109
109
|
min: min_,
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
* Returns the
|
|
112
|
+
* Returns the largest of the given non-negative finite numbers.
|
|
113
113
|
*
|
|
114
|
-
* @param
|
|
115
|
-
* @
|
|
116
|
-
* @returns The maximum value as a NonNegativeFiniteNumber.
|
|
114
|
+
* @param values - The non-negative finite numbers to compare (at least one required)
|
|
115
|
+
* @returns The largest value as a `NonNegativeFiniteNumber`
|
|
117
116
|
*/
|
|
118
117
|
max: max_,
|
|
119
118
|
|
|
120
119
|
/**
|
|
121
|
-
* Clamps a number
|
|
120
|
+
* Clamps a `number` into the `NonNegativeFiniteNumber` range `[MIN_VALUE,
|
|
121
|
+
* MAX_VALUE]`.
|
|
122
122
|
*
|
|
123
|
-
* @param value The
|
|
124
|
-
* @returns The
|
|
123
|
+
* @param value - The value to clamp
|
|
124
|
+
* @returns The clamped value as a `NonNegativeFiniteNumber`
|
|
125
125
|
*/
|
|
126
126
|
clamp,
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
|
-
*
|
|
129
|
+
* Returns the greatest integer less than or equal to a non-negative finite
|
|
130
|
+
* number.
|
|
130
131
|
*
|
|
131
|
-
* @param
|
|
132
|
-
* @returns The
|
|
132
|
+
* @param a - The non-negative finite number value
|
|
133
|
+
* @returns The floored value as an integer
|
|
133
134
|
*/
|
|
134
135
|
floor,
|
|
135
136
|
|
|
136
137
|
/**
|
|
137
|
-
*
|
|
138
|
+
* Returns the smallest integer greater than or equal to a non-negative finite
|
|
139
|
+
* number.
|
|
138
140
|
*
|
|
139
|
-
* @param
|
|
140
|
-
* @returns The
|
|
141
|
+
* @param a - The non-negative finite number value
|
|
142
|
+
* @returns The ceiled value as an integer
|
|
141
143
|
*/
|
|
142
144
|
ceil,
|
|
143
145
|
|
|
144
146
|
/**
|
|
145
|
-
*
|
|
147
|
+
* Returns the value of a non-negative finite number rounded to the nearest
|
|
148
|
+
* integer.
|
|
146
149
|
*
|
|
147
|
-
* @param
|
|
148
|
-
* @returns The rounded value as
|
|
150
|
+
* @param a - The non-negative finite number value
|
|
151
|
+
* @returns The rounded value as an integer
|
|
149
152
|
*/
|
|
150
153
|
round,
|
|
151
154
|
|
|
152
155
|
/**
|
|
153
|
-
* Generates a random NonNegativeFiniteNumber
|
|
156
|
+
* Generates a random `NonNegativeFiniteNumber` within the given range.
|
|
157
|
+
*
|
|
158
|
+
* The range is inclusive on both ends.
|
|
154
159
|
*
|
|
155
|
-
* @
|
|
160
|
+
* @param min - The minimum value (inclusive)
|
|
161
|
+
* @param max - The maximum value (inclusive)
|
|
162
|
+
* @returns A random `NonNegativeFiniteNumber` in `[min, max]`
|
|
156
163
|
*/
|
|
157
164
|
random,
|
|
158
165
|
|
|
159
166
|
/**
|
|
160
|
-
* Raises a
|
|
161
|
-
* NonNegativeFiniteNumber
|
|
167
|
+
* Raises `a` to the power `b`, returning `a ** b` as a
|
|
168
|
+
* `NonNegativeFiniteNumber`.
|
|
162
169
|
*
|
|
163
|
-
* @param a The base
|
|
164
|
-
* @param b The exponent
|
|
165
|
-
* @returns `a ** b`
|
|
170
|
+
* @param a - The base non-negative finite number
|
|
171
|
+
* @param b - The exponent non-negative finite number
|
|
172
|
+
* @returns `a ** b` as a `NonNegativeFiniteNumber`
|
|
166
173
|
*/
|
|
167
174
|
pow,
|
|
168
175
|
|
|
169
176
|
/**
|
|
170
|
-
* Adds two
|
|
177
|
+
* Adds two non-negative finite numbers, returning `a + b` as a
|
|
178
|
+
* `NonNegativeFiniteNumber`.
|
|
171
179
|
*
|
|
172
|
-
* @param a The first
|
|
173
|
-
* @param b The second
|
|
174
|
-
* @returns `a
|
|
180
|
+
* @param a - The first non-negative finite number
|
|
181
|
+
* @param b - The second non-negative finite number
|
|
182
|
+
* @returns The sum of `a` and `b` as a `NonNegativeFiniteNumber`
|
|
175
183
|
*/
|
|
176
184
|
add,
|
|
177
185
|
|
|
178
186
|
/**
|
|
179
|
-
* Subtracts
|
|
187
|
+
* Subtracts two non-negative finite numbers, returning `a - b` as a
|
|
188
|
+
* `NonNegativeFiniteNumber`.
|
|
180
189
|
*
|
|
181
|
-
* @param a The
|
|
182
|
-
* @param b The
|
|
183
|
-
* @returns `a
|
|
184
|
-
* 0).
|
|
190
|
+
* @param a - The first non-negative finite number
|
|
191
|
+
* @param b - The second non-negative finite number
|
|
192
|
+
* @returns The difference of `a` and `b` as a `NonNegativeFiniteNumber`
|
|
185
193
|
*/
|
|
186
194
|
sub,
|
|
187
195
|
|
|
188
196
|
/**
|
|
189
|
-
* Multiplies two
|
|
197
|
+
* Multiplies two non-negative finite numbers, returning `a * b` as a
|
|
198
|
+
* `NonNegativeFiniteNumber`.
|
|
190
199
|
*
|
|
191
|
-
* @param a The first
|
|
192
|
-
* @param b The second
|
|
193
|
-
* @returns `a
|
|
200
|
+
* @param a - The first non-negative finite number
|
|
201
|
+
* @param b - The second non-negative finite number
|
|
202
|
+
* @returns The product of `a` and `b` as a `NonNegativeFiniteNumber`
|
|
194
203
|
*/
|
|
195
204
|
mul,
|
|
196
205
|
|
|
197
206
|
/**
|
|
198
|
-
* Divides
|
|
207
|
+
* Divides two non-negative finite numbers, returning `a / b` as a
|
|
208
|
+
* `NonNegativeFiniteNumber`.
|
|
199
209
|
*
|
|
200
|
-
* @param a The dividend
|
|
201
|
-
* @param b The divisor
|
|
202
|
-
* @returns `a / b`
|
|
210
|
+
* @param a - The dividend
|
|
211
|
+
* @param b - The divisor (must be non-zero)
|
|
212
|
+
* @returns `a / b` as a `NonNegativeFiniteNumber`
|
|
203
213
|
*/
|
|
204
214
|
div,
|
|
205
215
|
} as const;
|
|
@@ -34,131 +34,138 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* in the range [0, 2^15)).
|
|
37
|
+
* Type guard that checks if a value is a non-negative integer in [0, 2^15).
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a non-negative integer in [0, 2^15) — 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 in [0, 2^15), `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isNonNegativeInt16 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `NonNegativeInt16` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a non-negative integer in [0, 2^15) and returns
|
|
51
|
+
* it with the `NonNegativeInt16` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as a NonNegativeInt16
|
|
50
|
-
* @throws {TypeError} If the value is not a non-negative integer in [0, 2^15)
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as a `NonNegativeInt16`
|
|
55
|
+
* @throws {TypeError} If the value is not a non-negative integer in [0, 2^15)
|
|
51
56
|
*/
|
|
52
57
|
export const asNonNegativeInt16 = castType;
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
|
-
* Namespace providing type-safe
|
|
56
|
-
*
|
|
60
|
+
* Namespace providing type-safe operations for the `NonNegativeInt16` branded
|
|
61
|
+
* type.
|
|
57
62
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* non-negative integer constraint, with negative results clamped to 0 and
|
|
61
|
-
* overflow results clamped to MAX_VALUE.
|
|
63
|
+
* The `NonNegativeInt16` type represents a non-negative integer in [0, 2^15).
|
|
64
|
+
* Division (`div`) uses floor division.
|
|
62
65
|
*/
|
|
63
66
|
export const NonNegativeInt16 = {
|
|
64
67
|
/**
|
|
65
|
-
* Type guard
|
|
68
|
+
* Type guard that checks if a value is a non-negative integer in [0, 2^15).
|
|
66
69
|
*
|
|
67
|
-
* @param value The value to check
|
|
68
|
-
* @returns `true` if the value is a
|
|
69
|
-
*
|
|
70
|
+
* @param value - The value to check
|
|
71
|
+
* @returns `true` if the value is a non-negative integer in [0, 2^15), `false` otherwise
|
|
72
|
+
* @see {@link isNonNegativeInt16} for usage examples
|
|
70
73
|
*/
|
|
71
74
|
is,
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
+
* The smallest value representable as `NonNegativeInt16`.
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
83
|
-
* @readonly
|
|
82
|
+
* The largest value representable as `NonNegativeInt16`.
|
|
84
83
|
*/
|
|
85
84
|
MAX_VALUE,
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
|
-
* Returns the
|
|
87
|
+
* Returns the smallest of the given non-negative integers.
|
|
89
88
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @
|
|
92
|
-
* @returns The minimum value as a NonNegativeInt16.
|
|
89
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
90
|
+
* @returns The smallest value as a `NonNegativeInt16`
|
|
93
91
|
*/
|
|
94
92
|
min: min_,
|
|
95
93
|
|
|
96
94
|
/**
|
|
97
|
-
* Returns the
|
|
95
|
+
* Returns the largest of the given non-negative integers.
|
|
98
96
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @
|
|
101
|
-
* @returns The maximum value as a NonNegativeInt16.
|
|
97
|
+
* @param values - The non-negative integers to compare (at least one required)
|
|
98
|
+
* @returns The largest value as a `NonNegativeInt16`
|
|
102
99
|
*/
|
|
103
100
|
max: max_,
|
|
104
101
|
|
|
105
102
|
/**
|
|
106
|
-
* Clamps a number
|
|
103
|
+
* Clamps a `number` into the `NonNegativeInt16` range, rounding to the
|
|
104
|
+
* nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
107
105
|
*
|
|
108
|
-
* @param value The
|
|
109
|
-
* @returns The
|
|
106
|
+
* @param value - The value to clamp
|
|
107
|
+
* @returns The clamped value as a `NonNegativeInt16`
|
|
110
108
|
*/
|
|
111
109
|
clamp,
|
|
112
110
|
|
|
113
111
|
/**
|
|
114
|
-
* Generates a random NonNegativeInt16
|
|
112
|
+
* Generates a random `NonNegativeInt16` within the given range.
|
|
113
|
+
*
|
|
114
|
+
* The range is inclusive on both ends.
|
|
115
115
|
*
|
|
116
|
-
* @
|
|
116
|
+
* @param min - The minimum value (inclusive)
|
|
117
|
+
* @param max - The maximum value (inclusive)
|
|
118
|
+
* @returns A random `NonNegativeInt16` in `[min, max]`
|
|
117
119
|
*/
|
|
118
120
|
random,
|
|
119
121
|
|
|
120
122
|
/**
|
|
121
|
-
* Raises a
|
|
123
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonNegativeInt16`
|
|
124
|
+
* (floored to an integer).
|
|
122
125
|
*
|
|
123
|
-
* @param a The base
|
|
124
|
-
* @param b The exponent
|
|
125
|
-
* @returns `a ** b`
|
|
126
|
+
* @param a - The base non-negative integer
|
|
127
|
+
* @param b - The exponent non-negative integer
|
|
128
|
+
* @returns `a ** b` as a `NonNegativeInt16`
|
|
126
129
|
*/
|
|
127
130
|
pow,
|
|
128
131
|
|
|
129
132
|
/**
|
|
130
|
-
* Adds two NonNegativeInt16
|
|
133
|
+
* Adds two non-negative integers, returning `a + b` as a `NonNegativeInt16`.
|
|
131
134
|
*
|
|
132
|
-
* @param a The first
|
|
133
|
-
* @param b The second
|
|
134
|
-
* @returns `a
|
|
135
|
+
* @param a - The first non-negative integer
|
|
136
|
+
* @param b - The second non-negative integer
|
|
137
|
+
* @returns The sum of `a` and `b` as a `NonNegativeInt16`
|
|
135
138
|
*/
|
|
136
139
|
add,
|
|
137
140
|
|
|
138
141
|
/**
|
|
139
|
-
* Subtracts
|
|
142
|
+
* Subtracts two non-negative integers, returning `a - b` as a
|
|
143
|
+
* `NonNegativeInt16`.
|
|
140
144
|
*
|
|
141
|
-
* @param a The
|
|
142
|
-
* @param b The
|
|
143
|
-
* @returns `a
|
|
145
|
+
* @param a - The first non-negative integer
|
|
146
|
+
* @param b - The second non-negative integer
|
|
147
|
+
* @returns The difference of `a` and `b` as a `NonNegativeInt16`
|
|
144
148
|
*/
|
|
145
149
|
sub,
|
|
146
150
|
|
|
147
151
|
/**
|
|
148
|
-
* Multiplies two
|
|
152
|
+
* Multiplies two non-negative integers, returning `a * b` as a
|
|
153
|
+
* `NonNegativeInt16`.
|
|
149
154
|
*
|
|
150
|
-
* @param a The first
|
|
151
|
-
* @param b The second
|
|
152
|
-
* @returns `a
|
|
155
|
+
* @param a - The first non-negative integer
|
|
156
|
+
* @param b - The second non-negative integer
|
|
157
|
+
* @returns The product of `a` and `b` as a `NonNegativeInt16`
|
|
153
158
|
*/
|
|
154
159
|
mul,
|
|
155
160
|
|
|
156
161
|
/**
|
|
157
|
-
* Divides
|
|
162
|
+
* Divides two non-negative integers using floor division (`⌊a / b⌋`): the
|
|
163
|
+
* result is `a / b` rounded toward negative infinity, as a
|
|
164
|
+
* `NonNegativeInt16`.
|
|
158
165
|
*
|
|
159
|
-
* @param a The dividend
|
|
160
|
-
* @param b The divisor
|
|
161
|
-
* @returns
|
|
166
|
+
* @param a - The dividend
|
|
167
|
+
* @param b - The divisor (must be non-zero)
|
|
168
|
+
* @returns The floored quotient as a `NonNegativeInt16`
|
|
162
169
|
*/
|
|
163
170
|
div,
|
|
164
171
|
} as const;
|