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
|
@@ -38,8 +38,10 @@ const {
|
|
|
38
38
|
} as const);
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* Type guard that checks if a value is a positive safe integer.
|
|
42
|
+
*
|
|
43
|
+
* Returns `true` for a positive safe integer — a value with no fractional
|
|
44
|
+
* component.
|
|
43
45
|
*
|
|
44
46
|
* @example
|
|
45
47
|
*
|
|
@@ -53,13 +55,16 @@ const {
|
|
|
53
55
|
* assert.isTrue(PositiveSafeInt.is(42));
|
|
54
56
|
* ```
|
|
55
57
|
*
|
|
56
|
-
* @param value The value to check
|
|
57
|
-
* @returns `true` if the value is a
|
|
58
|
+
* @param value - The value to check
|
|
59
|
+
* @returns `true` if the value is a positive safe integer, `false` otherwise
|
|
58
60
|
*/
|
|
59
61
|
export const isPositiveSafeInt = is;
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
|
-
* Casts a number to
|
|
64
|
+
* Casts a `number` to the `PositiveSafeInt` branded type.
|
|
65
|
+
*
|
|
66
|
+
* Validates that the value is a positive safe integer and returns it with the
|
|
67
|
+
* `PositiveSafeInt` brand. Throws a `TypeError` otherwise.
|
|
63
68
|
*
|
|
64
69
|
* @example
|
|
65
70
|
*
|
|
@@ -71,24 +76,22 @@ export const isPositiveSafeInt = is;
|
|
|
71
76
|
* assert.isTrue(PositiveSafeInt.is(branded));
|
|
72
77
|
* ```
|
|
73
78
|
*
|
|
74
|
-
* @param value The value to cast
|
|
75
|
-
* @returns The value as a PositiveSafeInt
|
|
76
|
-
* @throws {TypeError} If the value is not a positive safe integer
|
|
79
|
+
* @param value - The value to cast
|
|
80
|
+
* @returns The value as a `PositiveSafeInt`
|
|
81
|
+
* @throws {TypeError} If the value is not a positive safe integer
|
|
77
82
|
*/
|
|
78
83
|
export const asPositiveSafeInt = castType;
|
|
79
84
|
|
|
80
85
|
/**
|
|
81
|
-
* Namespace providing type-safe
|
|
82
|
-
*
|
|
86
|
+
* Namespace providing type-safe operations for the `PositiveSafeInt` branded
|
|
87
|
+
* type.
|
|
83
88
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* positive constraint and IEEE 754 precision guarantees, preventing precision
|
|
87
|
-
* loss and ensuring results are always positive.
|
|
89
|
+
* The `PositiveSafeInt` type represents a positive safe integer. Division
|
|
90
|
+
* (`div`) uses floor division.
|
|
88
91
|
*/
|
|
89
92
|
export const PositiveSafeInt = {
|
|
90
93
|
/**
|
|
91
|
-
* Type guard
|
|
94
|
+
* Type guard that checks if a value is a positive safe integer.
|
|
92
95
|
*
|
|
93
96
|
* @example
|
|
94
97
|
*
|
|
@@ -102,28 +105,24 @@ export const PositiveSafeInt = {
|
|
|
102
105
|
* assert.isTrue(PositiveSafeInt.is(42));
|
|
103
106
|
* ```
|
|
104
107
|
*
|
|
105
|
-
* @param value The value to check
|
|
106
|
-
* @returns `true` if the value is a positive safe integer, `false` otherwise
|
|
108
|
+
* @param value - The value to check
|
|
109
|
+
* @returns `true` if the value is a positive safe integer, `false` otherwise
|
|
107
110
|
* @see {@link isPositiveSafeInt} for usage examples
|
|
108
111
|
*/
|
|
109
112
|
is,
|
|
110
113
|
|
|
111
114
|
/**
|
|
112
|
-
* The
|
|
113
|
-
*
|
|
114
|
-
* @readonly
|
|
115
|
+
* The smallest value representable as `PositiveSafeInt`.
|
|
115
116
|
*/
|
|
116
117
|
MIN_VALUE,
|
|
117
118
|
|
|
118
119
|
/**
|
|
119
|
-
* The
|
|
120
|
-
*
|
|
121
|
-
* @readonly
|
|
120
|
+
* The largest value representable as `PositiveSafeInt`.
|
|
122
121
|
*/
|
|
123
122
|
MAX_VALUE,
|
|
124
123
|
|
|
125
124
|
/**
|
|
126
|
-
* Returns the
|
|
125
|
+
* Returns the smallest of the given positive safe integers.
|
|
127
126
|
*
|
|
128
127
|
* @example
|
|
129
128
|
*
|
|
@@ -136,14 +135,13 @@ export const PositiveSafeInt = {
|
|
|
136
135
|
* assert.isTrue(smallest === 5);
|
|
137
136
|
* ```
|
|
138
137
|
*
|
|
139
|
-
* @param
|
|
140
|
-
* @
|
|
141
|
-
* @returns The minimum value as a PositiveSafeInt.
|
|
138
|
+
* @param values - The positive safe integers to compare (at least one required)
|
|
139
|
+
* @returns The smallest value as a `PositiveSafeInt`
|
|
142
140
|
*/
|
|
143
141
|
min: min_,
|
|
144
142
|
|
|
145
143
|
/**
|
|
146
|
-
* Returns the
|
|
144
|
+
* Returns the largest of the given positive safe integers.
|
|
147
145
|
*
|
|
148
146
|
* @example
|
|
149
147
|
*
|
|
@@ -156,14 +154,14 @@ export const PositiveSafeInt = {
|
|
|
156
154
|
* assert.isTrue(largest === 10);
|
|
157
155
|
* ```
|
|
158
156
|
*
|
|
159
|
-
* @param
|
|
160
|
-
* @
|
|
161
|
-
* @returns The maximum value as a PositiveSafeInt.
|
|
157
|
+
* @param values - The positive safe integers to compare (at least one required)
|
|
158
|
+
* @returns The largest value as a `PositiveSafeInt`
|
|
162
159
|
*/
|
|
163
160
|
max: max_,
|
|
164
161
|
|
|
165
162
|
/**
|
|
166
|
-
* Clamps a number
|
|
163
|
+
* Clamps a `number` into the `PositiveSafeInt` range, rounding to the nearest
|
|
164
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
167
165
|
*
|
|
168
166
|
* @example
|
|
169
167
|
*
|
|
@@ -181,13 +179,15 @@ export const PositiveSafeInt = {
|
|
|
181
179
|
* assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
|
|
182
180
|
* ```
|
|
183
181
|
*
|
|
184
|
-
* @param value The
|
|
185
|
-
* @returns The
|
|
182
|
+
* @param value - The value to clamp
|
|
183
|
+
* @returns The clamped value as a `PositiveSafeInt`
|
|
186
184
|
*/
|
|
187
185
|
clamp,
|
|
188
186
|
|
|
189
187
|
/**
|
|
190
|
-
* Generates a random PositiveSafeInt
|
|
188
|
+
* Generates a random `PositiveSafeInt` within the given range.
|
|
189
|
+
*
|
|
190
|
+
* The range is inclusive on both ends.
|
|
191
191
|
*
|
|
192
192
|
* @example
|
|
193
193
|
*
|
|
@@ -203,12 +203,15 @@ export const PositiveSafeInt = {
|
|
|
203
203
|
* assert.isTrue(randomValue >= 1 && randomValue <= 6);
|
|
204
204
|
* ```
|
|
205
205
|
*
|
|
206
|
-
* @
|
|
206
|
+
* @param min - The minimum value (inclusive)
|
|
207
|
+
* @param max - The maximum value (inclusive)
|
|
208
|
+
* @returns A random `PositiveSafeInt` in `[min, max]`
|
|
207
209
|
*/
|
|
208
210
|
random,
|
|
209
211
|
|
|
210
212
|
/**
|
|
211
|
-
* Raises a
|
|
213
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `PositiveSafeInt`
|
|
214
|
+
* (floored to an integer).
|
|
212
215
|
*
|
|
213
216
|
* @example
|
|
214
217
|
*
|
|
@@ -222,14 +225,14 @@ export const PositiveSafeInt = {
|
|
|
222
225
|
* assert.isTrue(power === 27);
|
|
223
226
|
* ```
|
|
224
227
|
*
|
|
225
|
-
* @param a The base
|
|
226
|
-
* @param b The exponent
|
|
227
|
-
* @returns `a ** b`
|
|
228
|
+
* @param a - The base positive safe integer
|
|
229
|
+
* @param b - The exponent positive safe integer
|
|
230
|
+
* @returns `a ** b` as a `PositiveSafeInt`
|
|
228
231
|
*/
|
|
229
232
|
pow,
|
|
230
233
|
|
|
231
234
|
/**
|
|
232
|
-
* Adds two PositiveSafeInt
|
|
235
|
+
* Adds two positive safe integers, returning `a + b` as a `PositiveSafeInt`.
|
|
233
236
|
*
|
|
234
237
|
* @example
|
|
235
238
|
*
|
|
@@ -244,14 +247,15 @@ export const PositiveSafeInt = {
|
|
|
244
247
|
* assert.isTrue(PositiveSafeInt.is(sum));
|
|
245
248
|
* ```
|
|
246
249
|
*
|
|
247
|
-
* @param a The first
|
|
248
|
-
* @param b The second
|
|
249
|
-
* @returns `a
|
|
250
|
+
* @param a - The first positive safe integer
|
|
251
|
+
* @param b - The second positive safe integer
|
|
252
|
+
* @returns The sum of `a` and `b` as a `PositiveSafeInt`
|
|
250
253
|
*/
|
|
251
254
|
add,
|
|
252
255
|
|
|
253
256
|
/**
|
|
254
|
-
* Subtracts
|
|
257
|
+
* Subtracts two positive safe integers, returning `a - b` as a
|
|
258
|
+
* `PositiveSafeInt`.
|
|
255
259
|
*
|
|
256
260
|
* @example
|
|
257
261
|
*
|
|
@@ -266,15 +270,15 @@ export const PositiveSafeInt = {
|
|
|
266
270
|
* assert.isTrue(PositiveSafeInt.is(difference));
|
|
267
271
|
* ```
|
|
268
272
|
*
|
|
269
|
-
* @param a The
|
|
270
|
-
* @param b The
|
|
271
|
-
* @returns `a
|
|
272
|
-
* (minimum 1).
|
|
273
|
+
* @param a - The first positive safe integer
|
|
274
|
+
* @param b - The second positive safe integer
|
|
275
|
+
* @returns The difference of `a` and `b` as a `PositiveSafeInt`
|
|
273
276
|
*/
|
|
274
277
|
sub,
|
|
275
278
|
|
|
276
279
|
/**
|
|
277
|
-
* Multiplies two
|
|
280
|
+
* Multiplies two positive safe integers, returning `a * b` as a
|
|
281
|
+
* `PositiveSafeInt`.
|
|
278
282
|
*
|
|
279
283
|
* @example
|
|
280
284
|
*
|
|
@@ -289,14 +293,15 @@ export const PositiveSafeInt = {
|
|
|
289
293
|
* assert.isTrue(PositiveSafeInt.is(product));
|
|
290
294
|
* ```
|
|
291
295
|
*
|
|
292
|
-
* @param a The first
|
|
293
|
-
* @param b The second
|
|
294
|
-
* @returns `a
|
|
296
|
+
* @param a - The first positive safe integer
|
|
297
|
+
* @param b - The second positive safe integer
|
|
298
|
+
* @returns The product of `a` and `b` as a `PositiveSafeInt`
|
|
295
299
|
*/
|
|
296
300
|
mul,
|
|
297
301
|
|
|
298
302
|
/**
|
|
299
|
-
* Divides
|
|
303
|
+
* Divides two positive safe integers using floor division (`⌊a / b⌋`): the
|
|
304
|
+
* result is `a / b` rounded toward negative infinity, as a `PositiveSafeInt`.
|
|
300
305
|
*
|
|
301
306
|
* @example
|
|
302
307
|
*
|
|
@@ -316,9 +321,9 @@ export const PositiveSafeInt = {
|
|
|
316
321
|
* assert.isTrue(clamped === 1);
|
|
317
322
|
* ```
|
|
318
323
|
*
|
|
319
|
-
* @param a The dividend
|
|
320
|
-
* @param b The divisor
|
|
321
|
-
* @returns
|
|
324
|
+
* @param a - The dividend
|
|
325
|
+
* @param b - The divisor (must be non-zero)
|
|
326
|
+
* @returns The floored quotient as a `PositiveSafeInt`
|
|
322
327
|
*/
|
|
323
328
|
div,
|
|
324
329
|
} as const;
|
|
@@ -34,131 +34,135 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* the range [1, 2^16)).
|
|
37
|
+
* Type guard that checks if a value is a positive integer in [1, 2^16).
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a positive integer in [1, 2^16) — a value with no
|
|
40
|
+
* fractional component.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check
|
|
43
|
+
* @returns `true` if the value is a positive integer in [1, 2^16), `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isPositiveUint16 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `PositiveUint16` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a positive integer in [1, 2^16) and returns it
|
|
51
|
+
* with the `PositiveUint16` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as a PositiveUint16
|
|
50
|
-
* @throws {TypeError} If the value is not a positive integer in [1, 2^16)
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as a `PositiveUint16`
|
|
55
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^16)
|
|
51
56
|
*/
|
|
52
57
|
export const asPositiveUint16 = castType;
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
|
-
* Namespace providing type-safe
|
|
56
|
-
*
|
|
60
|
+
* Namespace providing type-safe operations for the `PositiveUint16` branded
|
|
61
|
+
* type.
|
|
57
62
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* unsigned integer constraint, with results below 1 clamped to MIN_VALUE and
|
|
61
|
-
* overflow results clamped to MAX_VALUE.
|
|
63
|
+
* The `PositiveUint16` type represents a positive integer in [1, 2^16).
|
|
64
|
+
* Division (`div`) uses floor division.
|
|
62
65
|
*/
|
|
63
66
|
export const PositiveUint16 = {
|
|
64
67
|
/**
|
|
65
|
-
* Type guard
|
|
68
|
+
* Type guard that checks if a value is a positive integer in [1, 2^16).
|
|
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 positive integer in [1, 2^16), `false` otherwise
|
|
72
|
+
* @see {@link isPositiveUint16} for usage examples
|
|
70
73
|
*/
|
|
71
74
|
is,
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
+
* The smallest value representable as `PositiveUint16`.
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
83
|
-
* @readonly
|
|
82
|
+
* The largest value representable as `PositiveUint16`.
|
|
84
83
|
*/
|
|
85
84
|
MAX_VALUE,
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
|
-
* Returns the
|
|
87
|
+
* Returns the smallest of the given positive integers.
|
|
89
88
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @
|
|
92
|
-
* @returns The minimum value as a PositiveUint16.
|
|
89
|
+
* @param values - The positive integers to compare (at least one required)
|
|
90
|
+
* @returns The smallest value as a `PositiveUint16`
|
|
93
91
|
*/
|
|
94
92
|
min: min_,
|
|
95
93
|
|
|
96
94
|
/**
|
|
97
|
-
* Returns the
|
|
95
|
+
* Returns the largest of the given positive integers.
|
|
98
96
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @
|
|
101
|
-
* @returns The maximum value as a PositiveUint16.
|
|
97
|
+
* @param values - The positive integers to compare (at least one required)
|
|
98
|
+
* @returns The largest value as a `PositiveUint16`
|
|
102
99
|
*/
|
|
103
100
|
max: max_,
|
|
104
101
|
|
|
105
102
|
/**
|
|
106
|
-
* Clamps a number
|
|
103
|
+
* Clamps a `number` into the `PositiveUint16` range, rounding to the nearest
|
|
104
|
+
* 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 `PositiveUint16`
|
|
110
108
|
*/
|
|
111
109
|
clamp,
|
|
112
110
|
|
|
113
111
|
/**
|
|
114
|
-
* Generates a random PositiveUint16
|
|
112
|
+
* Generates a random `PositiveUint16` 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 `PositiveUint16` 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 `PositiveUint16`
|
|
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 positive integer
|
|
127
|
+
* @param b - The exponent positive integer
|
|
128
|
+
* @returns `a ** b` as a `PositiveUint16`
|
|
126
129
|
*/
|
|
127
130
|
pow,
|
|
128
131
|
|
|
129
132
|
/**
|
|
130
|
-
* Adds two PositiveUint16
|
|
133
|
+
* Adds two positive integers, returning `a + b` as a `PositiveUint16`.
|
|
131
134
|
*
|
|
132
|
-
* @param a The first
|
|
133
|
-
* @param b The second
|
|
134
|
-
* @returns `a
|
|
135
|
+
* @param a - The first positive integer
|
|
136
|
+
* @param b - The second positive integer
|
|
137
|
+
* @returns The sum of `a` and `b` as a `PositiveUint16`
|
|
135
138
|
*/
|
|
136
139
|
add,
|
|
137
140
|
|
|
138
141
|
/**
|
|
139
|
-
* Subtracts
|
|
142
|
+
* Subtracts two positive integers, returning `a - b` as a `PositiveUint16`.
|
|
140
143
|
*
|
|
141
|
-
* @param a The
|
|
142
|
-
* @param b The
|
|
143
|
-
* @returns `a
|
|
144
|
+
* @param a - The first positive integer
|
|
145
|
+
* @param b - The second positive integer
|
|
146
|
+
* @returns The difference of `a` and `b` as a `PositiveUint16`
|
|
144
147
|
*/
|
|
145
148
|
sub,
|
|
146
149
|
|
|
147
150
|
/**
|
|
148
|
-
* Multiplies two PositiveUint16
|
|
151
|
+
* Multiplies two positive integers, returning `a * b` as a `PositiveUint16`.
|
|
149
152
|
*
|
|
150
|
-
* @param a The first
|
|
151
|
-
* @param b The second
|
|
152
|
-
* @returns `a
|
|
153
|
+
* @param a - The first positive integer
|
|
154
|
+
* @param b - The second positive integer
|
|
155
|
+
* @returns The product of `a` and `b` as a `PositiveUint16`
|
|
153
156
|
*/
|
|
154
157
|
mul,
|
|
155
158
|
|
|
156
159
|
/**
|
|
157
|
-
* Divides
|
|
160
|
+
* Divides two positive integers using floor division (`⌊a / b⌋`): the result
|
|
161
|
+
* is `a / b` rounded toward negative infinity, as a `PositiveUint16`.
|
|
158
162
|
*
|
|
159
|
-
* @param a The dividend
|
|
160
|
-
* @param b The divisor
|
|
161
|
-
* @returns
|
|
163
|
+
* @param a - The dividend
|
|
164
|
+
* @param b - The divisor (must be non-zero)
|
|
165
|
+
* @returns The floored quotient as a `PositiveUint16`
|
|
162
166
|
*/
|
|
163
167
|
div,
|
|
164
168
|
} as const;
|
|
@@ -34,132 +34,135 @@ const {
|
|
|
34
34
|
} as const);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* the range [1, 2^32)).
|
|
37
|
+
* Type guard that checks if a value is a positive integer in [1, 2^32).
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Returns `true` for a positive integer in [1, 2^32) — a value with no
|
|
40
|
+
* fractional component.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check
|
|
43
|
+
* @returns `true` if the value is a positive integer in [1, 2^32), `false` otherwise
|
|
42
44
|
*/
|
|
43
45
|
export const isPositiveUint32 = is;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
* Casts a number to
|
|
48
|
+
* Casts a `number` to the `PositiveUint32` branded type.
|
|
49
|
+
*
|
|
50
|
+
* Validates that the value is a positive integer in [1, 2^32) and returns it
|
|
51
|
+
* with the `PositiveUint32` brand. Throws a `TypeError` otherwise.
|
|
47
52
|
*
|
|
48
|
-
* @param value The value to cast
|
|
49
|
-
* @returns The value as a PositiveUint32
|
|
50
|
-
* @throws {TypeError} If the value is not a positive integer in [1, 2^32)
|
|
53
|
+
* @param value - The value to cast
|
|
54
|
+
* @returns The value as a `PositiveUint32`
|
|
55
|
+
* @throws {TypeError} If the value is not a positive integer in [1, 2^32)
|
|
51
56
|
*/
|
|
52
57
|
export const asPositiveUint32 = castType;
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
|
-
* Namespace providing type-safe
|
|
56
|
-
*
|
|
60
|
+
* Namespace providing type-safe operations for the `PositiveUint32` branded
|
|
61
|
+
* type.
|
|
57
62
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* positive unsigned integer constraint, with results below 1 clamped to
|
|
61
|
-
* MIN_VALUE and overflow results clamped to MAX_VALUE.
|
|
63
|
+
* The `PositiveUint32` type represents a positive integer in [1, 2^32).
|
|
64
|
+
* Division (`div`) uses floor division.
|
|
62
65
|
*/
|
|
63
66
|
export const PositiveUint32 = {
|
|
64
67
|
/**
|
|
65
|
-
* Type guard
|
|
68
|
+
* Type guard that checks if a value is a positive integer in [1, 2^32).
|
|
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 positive integer in [1, 2^32), `false` otherwise
|
|
72
|
+
* @see {@link isPositiveUint32} for usage examples
|
|
70
73
|
*/
|
|
71
74
|
is,
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
+
* The smallest value representable as `PositiveUint32`.
|
|
77
78
|
*/
|
|
78
79
|
MIN_VALUE,
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
83
|
-
* @readonly
|
|
82
|
+
* The largest value representable as `PositiveUint32`.
|
|
84
83
|
*/
|
|
85
84
|
MAX_VALUE,
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
|
-
* Returns the
|
|
87
|
+
* Returns the smallest of the given positive integers.
|
|
89
88
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @
|
|
92
|
-
* @returns The minimum value as a PositiveUint32.
|
|
89
|
+
* @param values - The positive integers to compare (at least one required)
|
|
90
|
+
* @returns The smallest value as a `PositiveUint32`
|
|
93
91
|
*/
|
|
94
92
|
min: min_,
|
|
95
93
|
|
|
96
94
|
/**
|
|
97
|
-
* Returns the
|
|
95
|
+
* Returns the largest of the given positive integers.
|
|
98
96
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @
|
|
101
|
-
* @returns The maximum value as a PositiveUint32.
|
|
97
|
+
* @param values - The positive integers to compare (at least one required)
|
|
98
|
+
* @returns The largest value as a `PositiveUint32`
|
|
102
99
|
*/
|
|
103
100
|
max: max_,
|
|
104
101
|
|
|
105
102
|
/**
|
|
106
|
-
* Clamps a number
|
|
103
|
+
* Clamps a `number` into the `PositiveUint32` range, rounding to the nearest
|
|
104
|
+
* 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 `PositiveUint32`
|
|
110
108
|
*/
|
|
111
109
|
clamp,
|
|
112
110
|
|
|
113
111
|
/**
|
|
114
|
-
* Generates a random PositiveUint32
|
|
112
|
+
* Generates a random `PositiveUint32` 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 `PositiveUint32` 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 `PositiveUint32`
|
|
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 positive integer
|
|
127
|
+
* @param b - The exponent positive integer
|
|
128
|
+
* @returns `a ** b` as a `PositiveUint32`
|
|
126
129
|
*/
|
|
127
130
|
pow,
|
|
128
131
|
|
|
129
132
|
/**
|
|
130
|
-
* Adds two PositiveUint32
|
|
133
|
+
* Adds two positive integers, returning `a + b` as a `PositiveUint32`.
|
|
131
134
|
*
|
|
132
|
-
* @param a The first
|
|
133
|
-
* @param b The second
|
|
134
|
-
* @returns `a
|
|
135
|
+
* @param a - The first positive integer
|
|
136
|
+
* @param b - The second positive integer
|
|
137
|
+
* @returns The sum of `a` and `b` as a `PositiveUint32`
|
|
135
138
|
*/
|
|
136
139
|
add,
|
|
137
140
|
|
|
138
141
|
/**
|
|
139
|
-
* Subtracts
|
|
142
|
+
* Subtracts two positive integers, returning `a - b` as a `PositiveUint32`.
|
|
140
143
|
*
|
|
141
|
-
* @param a The
|
|
142
|
-
* @param b The
|
|
143
|
-
* @returns `a
|
|
144
|
-
* 1).
|
|
144
|
+
* @param a - The first positive integer
|
|
145
|
+
* @param b - The second positive integer
|
|
146
|
+
* @returns The difference of `a` and `b` as a `PositiveUint32`
|
|
145
147
|
*/
|
|
146
148
|
sub,
|
|
147
149
|
|
|
148
150
|
/**
|
|
149
|
-
* Multiplies two PositiveUint32
|
|
151
|
+
* Multiplies two positive integers, returning `a * b` as a `PositiveUint32`.
|
|
150
152
|
*
|
|
151
|
-
* @param a The first
|
|
152
|
-
* @param b The second
|
|
153
|
-
* @returns `a
|
|
153
|
+
* @param a - The first positive integer
|
|
154
|
+
* @param b - The second positive integer
|
|
155
|
+
* @returns The product of `a` and `b` as a `PositiveUint32`
|
|
154
156
|
*/
|
|
155
157
|
mul,
|
|
156
158
|
|
|
157
159
|
/**
|
|
158
|
-
* Divides
|
|
160
|
+
* Divides two positive integers using floor division (`⌊a / b⌋`): the result
|
|
161
|
+
* is `a / b` rounded toward negative infinity, as a `PositiveUint32`.
|
|
159
162
|
*
|
|
160
|
-
* @param a The dividend
|
|
161
|
-
* @param b The divisor
|
|
162
|
-
* @returns
|
|
163
|
+
* @param a - The dividend
|
|
164
|
+
* @param b - The divisor (must be non-zero)
|
|
165
|
+
* @returns The floored quotient as a `PositiveUint32`
|
|
163
166
|
*/
|
|
164
167
|
div,
|
|
165
168
|
} as const;
|