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
|
@@ -24,151 +24,71 @@ const NonPositiveInt = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Type guard that checks if a value is a non-positive integer.
|
|
26
26
|
*
|
|
27
|
-
* @example
|
|
28
|
-
*
|
|
29
|
-
* ```ts
|
|
30
|
-
* const value: number = -42;
|
|
31
|
-
*
|
|
32
|
-
* if (NonPositiveInt.is(value)) {
|
|
33
|
-
* // value is now typed as NonPositiveInt
|
|
34
|
-
* const debt = value;
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
27
|
* @param value - The value to check
|
|
39
28
|
* @returns `true` if the value is a non-positive integer, `false` otherwise
|
|
29
|
+
* @see {@link isNonPositiveInt} for usage examples
|
|
40
30
|
*/
|
|
41
31
|
is,
|
|
42
32
|
/**
|
|
43
|
-
* The
|
|
44
|
-
*
|
|
45
|
-
* @readonly
|
|
33
|
+
* The largest value representable as `NonPositiveInt`.
|
|
46
34
|
*/
|
|
47
35
|
MAX_VALUE,
|
|
48
36
|
/**
|
|
49
|
-
* Returns the
|
|
50
|
-
*
|
|
51
|
-
* Since non-positive integers range from negative infinity to 0, the smaller
|
|
52
|
-
* value is the one further from zero (more negative).
|
|
37
|
+
* Returns the smallest of the given non-positive integers.
|
|
53
38
|
*
|
|
54
|
-
* @
|
|
55
|
-
*
|
|
56
|
-
* ```ts
|
|
57
|
-
* const result = NonPositiveInt.min(-5, -10);
|
|
58
|
-
*
|
|
59
|
-
* assert.strictEqual(result, -10);
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* @param a - The first non-positive integer
|
|
63
|
-
* @param b - The second non-positive integer
|
|
64
|
-
* @returns The minimum value as a non-positive integer
|
|
39
|
+
* @param values - The non-positive integers to compare (at least one required)
|
|
40
|
+
* @returns The smallest value as a `NonPositiveInt`
|
|
65
41
|
*/
|
|
66
42
|
min: min_,
|
|
67
43
|
/**
|
|
68
|
-
* Returns the
|
|
69
|
-
*
|
|
70
|
-
* Since non-positive integers range from negative infinity to 0, the larger
|
|
71
|
-
* value is the one closer to zero (less negative).
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
*
|
|
75
|
-
* ```ts
|
|
76
|
-
* const result = NonPositiveInt.max(-5, -10);
|
|
77
|
-
*
|
|
78
|
-
* assert.strictEqual(result, -5);
|
|
79
|
-
* ```
|
|
44
|
+
* Returns the largest of the given non-positive integers.
|
|
80
45
|
*
|
|
81
|
-
* @param
|
|
82
|
-
* @
|
|
83
|
-
* @returns The maximum value as a non-positive integer
|
|
46
|
+
* @param values - The non-positive integers to compare (at least one required)
|
|
47
|
+
* @returns The largest value as a `NonPositiveInt`
|
|
84
48
|
*/
|
|
85
49
|
max: max_,
|
|
86
50
|
/**
|
|
87
|
-
* Clamps a number
|
|
88
|
-
*
|
|
89
|
-
* Any positive value is clamped to 0 (the maximum non-positive integer).
|
|
90
|
-
* Negative values are preserved as long as they are valid integers.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
51
|
+
* Clamps a `number` into the `NonPositiveInt` range, rounding to the nearest
|
|
52
|
+
* integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
93
53
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* assert.strictEqual(NonPositiveInt.clamp(-5), -5);
|
|
98
|
-
*
|
|
99
|
-
* assert.strictEqual(NonPositiveInt.clamp(0), 0);
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
* @param value - The number to clamp
|
|
103
|
-
* @returns The value clamped to the non-positive integer range
|
|
54
|
+
* @param value - The value to clamp
|
|
55
|
+
* @returns The clamped value as a `NonPositiveInt`
|
|
104
56
|
*/
|
|
105
57
|
clamp,
|
|
106
58
|
/**
|
|
107
|
-
* Generates a random
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
*
|
|
111
|
-
* ```ts
|
|
112
|
-
* const randomValue = NonPositiveInt.random();
|
|
59
|
+
* Generates a random `NonPositiveInt` within the given range.
|
|
113
60
|
*
|
|
114
|
-
*
|
|
115
|
-
* ```
|
|
61
|
+
* The range is inclusive on both ends.
|
|
116
62
|
*
|
|
117
|
-
* @
|
|
63
|
+
* @param min - The minimum value (inclusive)
|
|
64
|
+
* @param max - The maximum value (inclusive)
|
|
65
|
+
* @returns A random `NonPositiveInt` in `[min, max]`
|
|
118
66
|
*/
|
|
119
67
|
random,
|
|
120
68
|
/**
|
|
121
|
-
* Raises a
|
|
122
|
-
*
|
|
123
|
-
* The result is clamped to the non-positive integer range.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
*
|
|
127
|
-
* ```ts
|
|
128
|
-
* const result = NonPositiveInt.pow(-2, -1);
|
|
129
|
-
* ```
|
|
69
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveInt`
|
|
70
|
+
* (floored to an integer).
|
|
130
71
|
*
|
|
131
72
|
* @param a - The base non-positive integer
|
|
132
73
|
* @param b - The exponent non-positive integer
|
|
133
|
-
* @returns `a ** b`
|
|
74
|
+
* @returns `a ** b` as a `NonPositiveInt`
|
|
134
75
|
*/
|
|
135
76
|
pow,
|
|
136
77
|
/**
|
|
137
|
-
* Adds two non-positive integers
|
|
138
|
-
*
|
|
139
|
-
* The result is clamped to the non-positive integer range. If the sum is
|
|
140
|
-
* positive, it is clamped to 0.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
*
|
|
144
|
-
* ```ts
|
|
145
|
-
* assert.strictEqual(NonPositiveInt.add(-5, -3), -8);
|
|
146
|
-
*
|
|
147
|
-
* assert.strictEqual(NonPositiveInt.add(-5, 10), 0);
|
|
148
|
-
* ```
|
|
78
|
+
* Adds two non-positive integers, returning `a + b` as a `NonPositiveInt`.
|
|
149
79
|
*
|
|
150
80
|
* @param a - The first non-positive integer
|
|
151
81
|
* @param b - The second non-positive integer
|
|
152
|
-
* @returns `a
|
|
82
|
+
* @returns The sum of `a` and `b` as a `NonPositiveInt`
|
|
153
83
|
*/
|
|
154
84
|
add,
|
|
155
85
|
/**
|
|
156
|
-
* Subtracts
|
|
157
|
-
*
|
|
158
|
-
* The result is clamped to the non-positive integer range. If the result is
|
|
159
|
-
* positive, it is clamped to 0.
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
86
|
+
* Subtracts two non-positive integers, returning `a - b` as a
|
|
87
|
+
* `NonPositiveInt`.
|
|
162
88
|
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* assert.strictEqual(NonPositiveInt.sub(-10, 5), 0);
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
* @param a - The minuend non-positive integer
|
|
170
|
-
* @param b - The subtrahend non-positive integer
|
|
171
|
-
* @returns `a - b` clamped to the non-positive integer range
|
|
89
|
+
* @param a - The first non-positive integer
|
|
90
|
+
* @param b - The second non-positive integer
|
|
91
|
+
* @returns The difference of `a` and `b` as a `NonPositiveInt`
|
|
172
92
|
*/
|
|
173
93
|
sub
|
|
174
94
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-positive-int.mjs","sources":["../../../src/number/branded-types/non-positive-int.mts"],"sourcesContent":["import { type NonPositiveInt as TtfImported_NonPositiveInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveInt = TtfImported_NonPositiveInt;\n\ntype ElementType = NonPositiveInt;\n\nconst typeNameInMessage = 'a non-positive integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n 0\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-positive integer.\n *\n *
|
|
1
|
+
{"version":3,"file":"non-positive-int.mjs","sources":["../../../src/number/branded-types/non-positive-int.mts"],"sourcesContent":["import { type NonPositiveInt as TtfImported_NonPositiveInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveInt = TtfImported_NonPositiveInt;\n\ntype ElementType = NonPositiveInt;\n\nconst typeNameInMessage = 'a non-positive integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n 0\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-positive integer.\n *\n * Returns `true` for a non-positive integer — a value with no fractional\n * component, including values outside the safe integer range (unlike\n * `SafeInt`).\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive integer, `false` otherwise\n */\nexport const isNonPositiveInt = is;\n\n/**\n * Casts a `number` to the `NonPositiveInt` branded type.\n *\n * Validates that the value is a non-positive integer and returns it with the\n * `NonPositiveInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NonPositiveInt`\n * @throws {TypeError} If the value is not a non-positive integer\n */\nexport const asNonPositiveInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NonPositiveInt` branded\n * type.\n *\n * The `NonPositiveInt` type represents a non-positive integer. Division (`div`)\n * uses floor division.\n *\n * Unlike `SafeInt`, `NonPositiveInt` allows values outside the safe integer\n * range (±2^53 − 1), so very large magnitudes may lose precision in\n * JavaScript's `number` type.\n */\nexport const NonPositiveInt = {\n /**\n * Type guard that checks if a value is a non-positive integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive integer, `false` otherwise\n * @see {@link isNonPositiveInt} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NonPositiveInt`.\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-positive integers.\n *\n * @param values - The non-positive integers to compare (at least one required)\n * @returns The smallest value as a `NonPositiveInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-positive integers.\n *\n * @param values - The non-positive integers to compare (at least one required)\n * @returns The largest value as a `NonPositiveInt`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `NonPositiveInt` range, rounding to the nearest\n * integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `NonPositiveInt`\n */\n clamp,\n\n /**\n * Generates a random `NonPositiveInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `NonPositiveInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveInt`\n * (floored to an integer).\n *\n * @param a - The base non-positive integer\n * @param b - The exponent non-positive integer\n * @returns `a ** b` as a `NonPositiveInt`\n */\n pow,\n\n /**\n * Adds two non-positive integers, returning `a + b` as a `NonPositiveInt`.\n *\n * @param a - The first non-positive integer\n * @param b - The second non-positive integer\n * @returns The sum of `a` and `b` as a `NonPositiveInt`\n */\n add,\n\n /**\n * Subtracts two non-positive integers, returning `a - b` as a\n * `NonPositiveInt`.\n *\n * @param a - The first non-positive integer\n * @param b - The second non-positive integer\n * @returns The difference of `a` and `b` as a `NonPositiveInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;AAOA,MAAM,iBAAA,GAAoB,wBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,SAAA;AAAA,EACtB,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,CAAA;AAAA,EACX;AACF,CAAU,CAAA;AAYH,MAAM,gBAAA,GAAmB;AAYzB,MAAM,gBAAA,GAAmB;AAazB,MAAM,cAAA,GAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { type NonPositiveSafeInt as TtfImported_NonPositiveSafeInt } from 'ts-type-forge';
|
|
2
2
|
export type NonPositiveSafeInt = TtfImported_NonPositiveSafeInt;
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* range [Number.MIN_SAFE_INTEGER, 0]).
|
|
4
|
+
* Type guard that checks if a value is a non-positive safe integer.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Returns `true` for a non-positive safe integer — a value with no fractional
|
|
7
|
+
* component.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The value to check
|
|
10
|
+
* @returns `true` if the value is a non-positive safe integer, `false` otherwise
|
|
9
11
|
*/
|
|
10
12
|
export declare const isNonPositiveSafeInt: (a: number) => a is TtfImported_NonPositiveSafeInt;
|
|
11
13
|
/**
|
|
12
|
-
* Casts a number to
|
|
14
|
+
* Casts a `number` to the `NonPositiveSafeInt` branded type.
|
|
15
|
+
*
|
|
16
|
+
* Validates that the value is a non-positive safe integer and returns it with
|
|
17
|
+
* the `NonPositiveSafeInt` brand. Throws a `TypeError` otherwise.
|
|
13
18
|
*
|
|
14
|
-
* @param value The value to cast
|
|
15
|
-
* @returns The value as a NonPositiveSafeInt
|
|
16
|
-
* @throws {TypeError} If the value is not a non-positive safe integer
|
|
19
|
+
* @param value - The value to cast
|
|
20
|
+
* @returns The value as a `NonPositiveSafeInt`
|
|
21
|
+
* @throws {TypeError} If the value is not a non-positive safe integer
|
|
17
22
|
*/
|
|
18
23
|
export declare const asNonPositiveSafeInt: <N extends number>(x: N) => number & {
|
|
19
24
|
readonly "< 2^15": true;
|
|
@@ -29,90 +34,86 @@ export declare const asNonPositiveSafeInt: <N extends number>(x: N) => number &
|
|
|
29
34
|
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
30
35
|
}> & N;
|
|
31
36
|
/**
|
|
32
|
-
* Namespace providing type-safe
|
|
33
|
-
*
|
|
37
|
+
* Namespace providing type-safe operations for the `NonPositiveSafeInt` branded
|
|
38
|
+
* type.
|
|
34
39
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* maintains the non-positive safe integer constraint, with positive results
|
|
38
|
-
* clamped to 0 and underflow results clamped to MIN_VALUE.
|
|
40
|
+
* The `NonPositiveSafeInt` type represents a non-positive safe integer.
|
|
41
|
+
* Division (`div`) uses floor division.
|
|
39
42
|
*/
|
|
40
43
|
export declare const NonPositiveSafeInt: {
|
|
41
44
|
/**
|
|
42
|
-
* Type guard
|
|
45
|
+
* Type guard that checks if a value is a non-positive safe integer.
|
|
43
46
|
*
|
|
44
|
-
* @param value The value to check
|
|
45
|
-
* @returns `true` if the value is a non-positive safe integer, `false`
|
|
46
|
-
*
|
|
47
|
+
* @param value - The value to check
|
|
48
|
+
* @returns `true` if the value is a non-positive safe integer, `false` otherwise
|
|
49
|
+
* @see {@link isNonPositiveSafeInt} for usage examples
|
|
47
50
|
*/
|
|
48
51
|
readonly is: (a: number) => a is TtfImported_NonPositiveSafeInt;
|
|
49
52
|
/**
|
|
50
|
-
* The
|
|
51
|
-
*
|
|
52
|
-
* @readonly
|
|
53
|
+
* The smallest value representable as `NonPositiveSafeInt`.
|
|
53
54
|
*/
|
|
54
55
|
readonly MIN_VALUE: number;
|
|
55
56
|
/**
|
|
56
|
-
* The
|
|
57
|
-
*
|
|
58
|
-
* @readonly
|
|
57
|
+
* The largest value representable as `NonPositiveSafeInt`.
|
|
59
58
|
*/
|
|
60
59
|
readonly MAX_VALUE: 0;
|
|
61
60
|
/**
|
|
62
|
-
* Returns the
|
|
61
|
+
* Returns the smallest of the given non-positive safe integers.
|
|
63
62
|
*
|
|
64
|
-
* @param
|
|
65
|
-
* @
|
|
66
|
-
* @returns The minimum value as a NonPositiveSafeInt.
|
|
63
|
+
* @param values - The non-positive safe integers to compare (at least one required)
|
|
64
|
+
* @returns The smallest value as a `NonPositiveSafeInt`
|
|
67
65
|
*/
|
|
68
66
|
readonly min: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>[]) => TtfImported_NonPositiveSafeInt;
|
|
69
67
|
/**
|
|
70
|
-
* Returns the
|
|
68
|
+
* Returns the largest of the given non-positive safe integers.
|
|
71
69
|
*
|
|
72
|
-
* @param
|
|
73
|
-
* @
|
|
74
|
-
* @returns The maximum value as a NonPositiveSafeInt.
|
|
70
|
+
* @param values - The non-positive safe integers to compare (at least one required)
|
|
71
|
+
* @returns The largest value as a `NonPositiveSafeInt`
|
|
75
72
|
*/
|
|
76
73
|
readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>[]) => TtfImported_NonPositiveSafeInt;
|
|
77
74
|
/**
|
|
78
|
-
* Clamps a number
|
|
75
|
+
* Clamps a `number` into the `NonPositiveSafeInt` range, rounding to the
|
|
76
|
+
* nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
79
77
|
*
|
|
80
|
-
* @param value The
|
|
81
|
-
* @returns The
|
|
82
|
-
* NonPositiveSafeInt.
|
|
78
|
+
* @param value - The value to clamp
|
|
79
|
+
* @returns The clamped value as a `NonPositiveSafeInt`
|
|
83
80
|
*/
|
|
84
81
|
readonly clamp: (x: number) => TtfImported_NonPositiveSafeInt;
|
|
85
82
|
/**
|
|
86
|
-
* Generates a random NonPositiveSafeInt
|
|
83
|
+
* Generates a random `NonPositiveSafeInt` within the given range.
|
|
84
|
+
*
|
|
85
|
+
* The range is inclusive on both ends.
|
|
87
86
|
*
|
|
88
|
-
* @
|
|
87
|
+
* @param min - The minimum value (inclusive)
|
|
88
|
+
* @param max - The maximum value (inclusive)
|
|
89
|
+
* @returns A random `NonPositiveSafeInt` in `[min, max]`
|
|
89
90
|
*/
|
|
90
91
|
readonly random: (min?: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt> | undefined, max?: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt> | undefined) => TtfImported_NonPositiveSafeInt;
|
|
91
92
|
/**
|
|
92
|
-
* Raises a
|
|
93
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveSafeInt`
|
|
94
|
+
* (floored to an integer).
|
|
93
95
|
*
|
|
94
|
-
* @param a The base
|
|
95
|
-
* @param b The exponent
|
|
96
|
-
* @returns `a ** b`
|
|
97
|
-
* NonPositiveSafeInt.
|
|
96
|
+
* @param a - The base non-positive safe integer
|
|
97
|
+
* @param b - The exponent non-positive safe integer
|
|
98
|
+
* @returns `a ** b` as a `NonPositiveSafeInt`
|
|
98
99
|
*/
|
|
99
100
|
readonly pow: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>) => TtfImported_NonPositiveSafeInt;
|
|
100
101
|
/**
|
|
101
|
-
* Adds two
|
|
102
|
+
* Adds two non-positive safe integers, returning `a + b` as a
|
|
103
|
+
* `NonPositiveSafeInt`.
|
|
102
104
|
*
|
|
103
|
-
* @param a The first
|
|
104
|
-
* @param b The second
|
|
105
|
-
* @returns `a
|
|
106
|
-
* NonPositiveSafeInt.
|
|
105
|
+
* @param a - The first non-positive safe integer
|
|
106
|
+
* @param b - The second non-positive safe integer
|
|
107
|
+
* @returns The sum of `a` and `b` as a `NonPositiveSafeInt`
|
|
107
108
|
*/
|
|
108
109
|
readonly add: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>) => TtfImported_NonPositiveSafeInt;
|
|
109
110
|
/**
|
|
110
|
-
* Subtracts
|
|
111
|
+
* Subtracts two non-positive safe integers, returning `a - b` as a
|
|
112
|
+
* `NonPositiveSafeInt`.
|
|
111
113
|
*
|
|
112
|
-
* @param a The
|
|
113
|
-
* @param b The
|
|
114
|
-
* @returns `a
|
|
115
|
-
* NonPositiveSafeInt (maximum 0).
|
|
114
|
+
* @param a - The first non-positive safe integer
|
|
115
|
+
* @param b - The second non-positive safe integer
|
|
116
|
+
* @returns The difference of `a` and `b` as a `NonPositiveSafeInt`
|
|
116
117
|
*/
|
|
117
118
|
readonly sub: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>, y: import("ts-type-forge").WithSmallInt<TtfImported_NonPositiveSafeInt>) => TtfImported_NonPositiveSafeInt;
|
|
118
119
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-positive-safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-positive-safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,IAAI,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAG1F,MAAM,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AA6BhE
|
|
1
|
+
{"version":3,"file":"non-positive-safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-positive-safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,IAAI,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAG1F,MAAM,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AA6BhE;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,oDAAK,CAAC;AAEvC;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;MAAW,CAAC;AAE7C;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;;;;;OAMG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
|
|
@@ -23,80 +23,78 @@ const isNonPositiveSafeInt = is;
|
|
|
23
23
|
const asNonPositiveSafeInt = castType;
|
|
24
24
|
const NonPositiveSafeInt = {
|
|
25
25
|
/**
|
|
26
|
-
* Type guard
|
|
26
|
+
* Type guard that checks if a value is a non-positive safe integer.
|
|
27
27
|
*
|
|
28
|
-
* @param value The value to check
|
|
29
|
-
* @returns `true` if the value is a non-positive safe integer, `false`
|
|
30
|
-
*
|
|
28
|
+
* @param value - The value to check
|
|
29
|
+
* @returns `true` if the value is a non-positive safe integer, `false` otherwise
|
|
30
|
+
* @see {@link isNonPositiveSafeInt} for usage examples
|
|
31
31
|
*/
|
|
32
32
|
is,
|
|
33
33
|
/**
|
|
34
|
-
* The
|
|
35
|
-
*
|
|
36
|
-
* @readonly
|
|
34
|
+
* The smallest value representable as `NonPositiveSafeInt`.
|
|
37
35
|
*/
|
|
38
36
|
MIN_VALUE,
|
|
39
37
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
42
|
-
* @readonly
|
|
38
|
+
* The largest value representable as `NonPositiveSafeInt`.
|
|
43
39
|
*/
|
|
44
40
|
MAX_VALUE,
|
|
45
41
|
/**
|
|
46
|
-
* Returns the
|
|
42
|
+
* Returns the smallest of the given non-positive safe integers.
|
|
47
43
|
*
|
|
48
|
-
* @param
|
|
49
|
-
* @
|
|
50
|
-
* @returns The minimum value as a NonPositiveSafeInt.
|
|
44
|
+
* @param values - The non-positive safe integers to compare (at least one required)
|
|
45
|
+
* @returns The smallest value as a `NonPositiveSafeInt`
|
|
51
46
|
*/
|
|
52
47
|
min: min_,
|
|
53
48
|
/**
|
|
54
|
-
* Returns the
|
|
49
|
+
* Returns the largest of the given non-positive safe integers.
|
|
55
50
|
*
|
|
56
|
-
* @param
|
|
57
|
-
* @
|
|
58
|
-
* @returns The maximum value as a NonPositiveSafeInt.
|
|
51
|
+
* @param values - The non-positive safe integers to compare (at least one required)
|
|
52
|
+
* @returns The largest value as a `NonPositiveSafeInt`
|
|
59
53
|
*/
|
|
60
54
|
max: max_,
|
|
61
55
|
/**
|
|
62
|
-
* Clamps a number
|
|
56
|
+
* Clamps a `number` into the `NonPositiveSafeInt` range, rounding to the
|
|
57
|
+
* nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.
|
|
63
58
|
*
|
|
64
|
-
* @param value The
|
|
65
|
-
* @returns The
|
|
66
|
-
* NonPositiveSafeInt.
|
|
59
|
+
* @param value - The value to clamp
|
|
60
|
+
* @returns The clamped value as a `NonPositiveSafeInt`
|
|
67
61
|
*/
|
|
68
62
|
clamp,
|
|
69
63
|
/**
|
|
70
|
-
* Generates a random NonPositiveSafeInt
|
|
64
|
+
* Generates a random `NonPositiveSafeInt` within the given range.
|
|
65
|
+
*
|
|
66
|
+
* The range is inclusive on both ends.
|
|
71
67
|
*
|
|
72
|
-
* @
|
|
68
|
+
* @param min - The minimum value (inclusive)
|
|
69
|
+
* @param max - The maximum value (inclusive)
|
|
70
|
+
* @returns A random `NonPositiveSafeInt` in `[min, max]`
|
|
73
71
|
*/
|
|
74
72
|
random,
|
|
75
73
|
/**
|
|
76
|
-
* Raises a
|
|
74
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveSafeInt`
|
|
75
|
+
* (floored to an integer).
|
|
77
76
|
*
|
|
78
|
-
* @param a The base
|
|
79
|
-
* @param b The exponent
|
|
80
|
-
* @returns `a ** b`
|
|
81
|
-
* NonPositiveSafeInt.
|
|
77
|
+
* @param a - The base non-positive safe integer
|
|
78
|
+
* @param b - The exponent non-positive safe integer
|
|
79
|
+
* @returns `a ** b` as a `NonPositiveSafeInt`
|
|
82
80
|
*/
|
|
83
81
|
pow,
|
|
84
82
|
/**
|
|
85
|
-
* Adds two
|
|
83
|
+
* Adds two non-positive safe integers, returning `a + b` as a
|
|
84
|
+
* `NonPositiveSafeInt`.
|
|
86
85
|
*
|
|
87
|
-
* @param a The first
|
|
88
|
-
* @param b The second
|
|
89
|
-
* @returns `a
|
|
90
|
-
* NonPositiveSafeInt.
|
|
86
|
+
* @param a - The first non-positive safe integer
|
|
87
|
+
* @param b - The second non-positive safe integer
|
|
88
|
+
* @returns The sum of `a` and `b` as a `NonPositiveSafeInt`
|
|
91
89
|
*/
|
|
92
90
|
add,
|
|
93
91
|
/**
|
|
94
|
-
* Subtracts
|
|
92
|
+
* Subtracts two non-positive safe integers, returning `a - b` as a
|
|
93
|
+
* `NonPositiveSafeInt`.
|
|
95
94
|
*
|
|
96
|
-
* @param a The
|
|
97
|
-
* @param b The
|
|
98
|
-
* @returns `a
|
|
99
|
-
* NonPositiveSafeInt (maximum 0).
|
|
95
|
+
* @param a - The first non-positive safe integer
|
|
96
|
+
* @param b - The second non-positive safe integer
|
|
97
|
+
* @returns The difference of `a` and `b` as a `NonPositiveSafeInt`
|
|
100
98
|
*/
|
|
101
99
|
sub
|
|
102
100
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-positive-safe-int.mjs","sources":["../../../src/number/branded-types/non-positive-safe-int.mts"],"sourcesContent":["import { type NonPositiveSafeInt as TtfImported_NonPositiveSafeInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveSafeInt = TtfImported_NonPositiveSafeInt;\n\ntype ElementType = NonPositiveSafeInt;\n\nconst typeNameInMessage = 'a non-positive safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n 0\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: Number.MIN_SAFE_INTEGER,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"non-positive-safe-int.mjs","sources":["../../../src/number/branded-types/non-positive-safe-int.mts"],"sourcesContent":["import { type NonPositiveSafeInt as TtfImported_NonPositiveSafeInt } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveSafeInt = TtfImported_NonPositiveSafeInt;\n\ntype ElementType = NonPositiveSafeInt;\n\nconst typeNameInMessage = 'a non-positive safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n clamp,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n 0\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: Number.MIN_SAFE_INTEGER,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-positive safe integer.\n *\n * Returns `true` for a non-positive safe integer — a value with no fractional\n * component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive safe integer, `false` otherwise\n */\nexport const isNonPositiveSafeInt = is;\n\n/**\n * Casts a `number` to the `NonPositiveSafeInt` branded type.\n *\n * Validates that the value is a non-positive safe integer and returns it with\n * the `NonPositiveSafeInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NonPositiveSafeInt`\n * @throws {TypeError} If the value is not a non-positive safe integer\n */\nexport const asNonPositiveSafeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NonPositiveSafeInt` branded\n * type.\n *\n * The `NonPositiveSafeInt` type represents a non-positive safe integer.\n * Division (`div`) uses floor division.\n */\nexport const NonPositiveSafeInt = {\n /**\n * Type guard that checks if a value is a non-positive safe integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive safe integer, `false` otherwise\n * @see {@link isNonPositiveSafeInt} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `NonPositiveSafeInt`.\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `NonPositiveSafeInt`.\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-positive safe integers.\n *\n * @param values - The non-positive safe integers to compare (at least one required)\n * @returns The smallest value as a `NonPositiveSafeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-positive safe integers.\n *\n * @param values - The non-positive safe integers to compare (at least one required)\n * @returns The largest value as a `NonPositiveSafeInt`\n */\n max: max_,\n\n /**\n * Clamps a `number` into the `NonPositiveSafeInt` range, rounding to the\n * nearest integer and constraining the result to `[MIN_VALUE, MAX_VALUE]`.\n *\n * @param value - The value to clamp\n * @returns The clamped value as a `NonPositiveSafeInt`\n */\n clamp,\n\n /**\n * Generates a random `NonPositiveSafeInt` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `NonPositiveSafeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NonPositiveSafeInt`\n * (floored to an integer).\n *\n * @param a - The base non-positive safe integer\n * @param b - The exponent non-positive safe integer\n * @returns `a ** b` as a `NonPositiveSafeInt`\n */\n pow,\n\n /**\n * Adds two non-positive safe integers, returning `a + b` as a\n * `NonPositiveSafeInt`.\n *\n * @param a - The first non-positive safe integer\n * @param b - The second non-positive safe integer\n * @returns The sum of `a` and `b` as a `NonPositiveSafeInt`\n */\n add,\n\n /**\n * Subtracts two non-positive safe integers, returning `a - b` as a\n * `NonPositiveSafeInt`.\n *\n * @param a - The first non-positive safe integer\n * @param b - The second non-positive safe integer\n * @returns The difference of `a` and `b` as a `NonPositiveSafeInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;AAOA,MAAM,iBAAA,GAAoB,6BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB,SAAA,EAAW,CAAA;AAAA,EACX;AACF,CAAU,CAAA;AAWH,MAAM,oBAAA,GAAuB;AAY7B,MAAM,oBAAA,GAAuB;AAS7B,MAAM,kBAAA,GAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhC,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASL,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
|