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