ts-data-forge 1.0.0 → 1.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/README.md +1 -1
- package/dist/array/array-utils.d.mts +2617 -0
- package/dist/array/array-utils.d.mts.map +1 -0
- package/dist/array/array-utils.mjs +2915 -0
- package/dist/array/array-utils.mjs.map +1 -0
- package/dist/array/index.d.mts +3 -0
- package/dist/array/index.d.mts.map +1 -0
- package/dist/array/index.mjs +3 -0
- package/dist/array/index.mjs.map +1 -0
- package/dist/array/tuple-utils.d.mts +421 -0
- package/dist/array/tuple-utils.d.mts.map +1 -0
- package/dist/array/tuple-utils.mjs +391 -0
- package/dist/array/tuple-utils.mjs.map +1 -0
- package/dist/collections/imap-mapped.d.mts +445 -0
- package/dist/collections/imap-mapped.d.mts.map +1 -0
- package/dist/collections/imap-mapped.mjs +424 -0
- package/dist/collections/imap-mapped.mjs.map +1 -0
- package/dist/collections/imap.d.mts +359 -0
- package/dist/collections/imap.d.mts.map +1 -0
- package/dist/collections/imap.mjs +338 -0
- package/dist/collections/imap.mjs.map +1 -0
- package/dist/collections/index.d.mts +7 -0
- package/dist/collections/index.d.mts.map +1 -0
- package/dist/collections/index.mjs +7 -0
- package/dist/collections/index.mjs.map +1 -0
- package/dist/collections/iset-mapped.d.mts +576 -0
- package/dist/collections/iset-mapped.d.mts.map +1 -0
- package/dist/collections/iset-mapped.mjs +522 -0
- package/dist/collections/iset-mapped.mjs.map +1 -0
- package/dist/collections/iset.d.mts +426 -0
- package/dist/collections/iset.d.mts.map +1 -0
- package/dist/collections/iset.mjs +437 -0
- package/dist/collections/iset.mjs.map +1 -0
- package/dist/collections/queue.d.mts +190 -0
- package/dist/collections/queue.d.mts.map +1 -0
- package/dist/collections/queue.mjs +317 -0
- package/dist/collections/queue.mjs.map +1 -0
- package/dist/collections/stack.d.mts +210 -0
- package/dist/collections/stack.d.mts.map +1 -0
- package/dist/collections/stack.mjs +353 -0
- package/dist/collections/stack.mjs.map +1 -0
- package/dist/expect-type.d.mts +199 -0
- package/dist/expect-type.d.mts.map +1 -0
- package/dist/expect-type.mjs +201 -0
- package/dist/expect-type.mjs.map +1 -0
- package/dist/functional/index.d.mts +5 -0
- package/dist/functional/index.d.mts.map +1 -0
- package/dist/functional/index.mjs +5 -0
- package/dist/functional/index.mjs.map +1 -0
- package/dist/functional/match.d.mts +215 -0
- package/dist/functional/match.d.mts.map +1 -0
- package/dist/functional/match.mjs +139 -0
- package/dist/functional/match.mjs.map +1 -0
- package/dist/functional/optional.d.mts +517 -0
- package/dist/functional/optional.d.mts.map +1 -0
- package/dist/functional/optional.mjs +532 -0
- package/dist/functional/optional.mjs.map +1 -0
- package/dist/functional/pipe.d.mts +185 -0
- package/dist/functional/pipe.d.mts.map +1 -0
- package/dist/functional/pipe.mjs +129 -0
- package/dist/functional/pipe.mjs.map +1 -0
- package/dist/functional/result.d.mts +796 -0
- package/dist/functional/result.d.mts.map +1 -0
- package/dist/functional/result.mjs +844 -0
- package/dist/functional/result.mjs.map +1 -0
- package/dist/globals.d.mts +38 -0
- package/dist/guard/has-key.d.mts +100 -0
- package/dist/guard/has-key.d.mts.map +1 -0
- package/dist/guard/has-key.mjs +94 -0
- package/dist/guard/has-key.mjs.map +1 -0
- package/dist/guard/index.d.mts +8 -0
- package/dist/guard/index.d.mts.map +1 -0
- package/dist/guard/index.mjs +8 -0
- package/dist/guard/index.mjs.map +1 -0
- package/dist/guard/is-non-empty-string.d.mts +106 -0
- package/dist/guard/is-non-empty-string.d.mts.map +1 -0
- package/dist/guard/is-non-empty-string.mjs +108 -0
- package/dist/guard/is-non-empty-string.mjs.map +1 -0
- package/dist/guard/is-non-null-object.d.mts +105 -0
- package/dist/guard/is-non-null-object.d.mts.map +1 -0
- package/dist/guard/is-non-null-object.mjs +108 -0
- package/dist/guard/is-non-null-object.mjs.map +1 -0
- package/dist/guard/is-primitive.d.mts +146 -0
- package/dist/guard/is-primitive.d.mts.map +1 -0
- package/dist/guard/is-primitive.mjs +161 -0
- package/dist/guard/is-primitive.mjs.map +1 -0
- package/dist/guard/is-record.d.mts +151 -0
- package/dist/guard/is-record.d.mts.map +1 -0
- package/dist/guard/is-record.mjs +155 -0
- package/dist/guard/is-record.mjs.map +1 -0
- package/dist/guard/is-type.d.mts +430 -0
- package/dist/guard/is-type.d.mts.map +1 -0
- package/dist/guard/is-type.mjs +432 -0
- package/dist/guard/is-type.mjs.map +1 -0
- package/dist/guard/key-is-in.d.mts +158 -0
- package/dist/guard/key-is-in.d.mts.map +1 -0
- package/dist/guard/key-is-in.mjs +160 -0
- package/dist/guard/key-is-in.mjs.map +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +61 -0
- package/dist/index.mjs.map +1 -0
- package/dist/iterator/index.d.mts +2 -0
- package/dist/iterator/index.d.mts.map +1 -0
- package/dist/iterator/index.mjs +2 -0
- package/dist/iterator/index.mjs.map +1 -0
- package/dist/iterator/range.d.mts +97 -0
- package/dist/iterator/range.d.mts.map +1 -0
- package/dist/iterator/range.mjs +130 -0
- package/dist/iterator/range.mjs.map +1 -0
- package/dist/json/index.d.mts +2 -0
- package/dist/json/index.d.mts.map +1 -0
- package/dist/json/index.mjs +2 -0
- package/dist/json/index.mjs.map +1 -0
- package/dist/json/json.d.mts +597 -0
- package/dist/json/json.d.mts.map +1 -0
- package/dist/json/json.mjs +687 -0
- package/dist/json/json.mjs.map +1 -0
- package/dist/number/branded-types/finite-number.d.mts +291 -0
- package/dist/number/branded-types/finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/finite-number.mjs +296 -0
- package/dist/number/branded-types/finite-number.mjs.map +1 -0
- package/dist/number/branded-types/index.d.mts +27 -0
- package/dist/number/branded-types/index.d.mts.map +1 -0
- package/dist/number/branded-types/index.mjs +27 -0
- package/dist/number/branded-types/index.mjs.map +1 -0
- package/dist/number/branded-types/int.d.mts +242 -0
- package/dist/number/branded-types/int.d.mts.map +1 -0
- package/dist/number/branded-types/int.mjs +239 -0
- package/dist/number/branded-types/int.mjs.map +1 -0
- package/dist/number/branded-types/int16.d.mts +162 -0
- package/dist/number/branded-types/int16.d.mts.map +1 -0
- package/dist/number/branded-types/int16.mjs +141 -0
- package/dist/number/branded-types/int16.mjs.map +1 -0
- package/dist/number/branded-types/int32.d.mts +155 -0
- package/dist/number/branded-types/int32.d.mts.map +1 -0
- package/dist/number/branded-types/int32.mjs +142 -0
- package/dist/number/branded-types/int32.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-finite-number.d.mts +165 -0
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-finite-number.mjs +160 -0
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-int16.d.mts +160 -0
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-int16.mjs +138 -0
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-int32.d.mts +156 -0
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-int32.mjs +138 -0
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-finite-number.d.mts +154 -0
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-finite-number.mjs +160 -0
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int.d.mts +131 -0
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int.mjs +128 -0
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int16.d.mts +166 -0
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int16.mjs +145 -0
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int32.d.mts +158 -0
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int32.mjs +145 -0
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-safe-int.d.mts +148 -0
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-safe-int.mjs +145 -0
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-uint16.d.mts +160 -0
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-uint16.mjs +140 -0
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-uint32.d.mts +156 -0
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-uint32.mjs +140 -0
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -0
- package/dist/number/branded-types/positive-finite-number.d.mts +171 -0
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/positive-finite-number.mjs +165 -0
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/positive-int.d.mts +270 -0
- package/dist/number/branded-types/positive-int.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int.mjs +257 -0
- package/dist/number/branded-types/positive-int.mjs.map +1 -0
- package/dist/number/branded-types/positive-int16.d.mts +162 -0
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int16.mjs +139 -0
- package/dist/number/branded-types/positive-int16.mjs.map +1 -0
- package/dist/number/branded-types/positive-int32.d.mts +158 -0
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int32.mjs +139 -0
- package/dist/number/branded-types/positive-int32.mjs.map +1 -0
- package/dist/number/branded-types/positive-safe-int.d.mts +152 -0
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/positive-safe-int.mjs +138 -0
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -0
- package/dist/number/branded-types/positive-uint16.d.mts +160 -0
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -0
- package/dist/number/branded-types/positive-uint16.mjs +139 -0
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -0
- package/dist/number/branded-types/positive-uint32.d.mts +156 -0
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -0
- package/dist/number/branded-types/positive-uint32.mjs +139 -0
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -0
- package/dist/number/branded-types/safe-int.d.mts +243 -0
- package/dist/number/branded-types/safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/safe-int.mjs +240 -0
- package/dist/number/branded-types/safe-int.mjs.map +1 -0
- package/dist/number/branded-types/safe-uint.d.mts +151 -0
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -0
- package/dist/number/branded-types/safe-uint.mjs +138 -0
- package/dist/number/branded-types/safe-uint.mjs.map +1 -0
- package/dist/number/branded-types/uint.d.mts +144 -0
- package/dist/number/branded-types/uint.d.mts.map +1 -0
- package/dist/number/branded-types/uint.mjs +132 -0
- package/dist/number/branded-types/uint.mjs.map +1 -0
- package/dist/number/branded-types/uint16.d.mts +157 -0
- package/dist/number/branded-types/uint16.d.mts.map +1 -0
- package/dist/number/branded-types/uint16.mjs +137 -0
- package/dist/number/branded-types/uint16.mjs.map +1 -0
- package/dist/number/branded-types/uint32.d.mts +185 -0
- package/dist/number/branded-types/uint32.d.mts.map +1 -0
- package/dist/number/branded-types/uint32.mjs +169 -0
- package/dist/number/branded-types/uint32.mjs.map +1 -0
- package/dist/number/enum/index.d.mts +3 -0
- package/dist/number/enum/index.d.mts.map +1 -0
- package/dist/number/enum/index.mjs +3 -0
- package/dist/number/enum/index.mjs.map +1 -0
- package/dist/number/enum/int8.d.mts +202 -0
- package/dist/number/enum/int8.d.mts.map +1 -0
- package/dist/number/enum/int8.mjs +296 -0
- package/dist/number/enum/int8.mjs.map +1 -0
- package/dist/number/enum/uint8.d.mts +128 -0
- package/dist/number/enum/uint8.d.mts.map +1 -0
- package/dist/number/enum/uint8.mjs +251 -0
- package/dist/number/enum/uint8.mjs.map +1 -0
- package/dist/number/index.d.mts +5 -0
- package/dist/number/index.d.mts.map +1 -0
- package/dist/number/index.mjs +31 -0
- package/dist/number/index.mjs.map +1 -0
- package/dist/number/num.d.mts +515 -0
- package/dist/number/num.d.mts.map +1 -0
- package/dist/number/num.mjs +513 -0
- package/dist/number/num.mjs.map +1 -0
- package/dist/number/refined-number-utils.d.mts +191 -0
- package/dist/number/refined-number-utils.d.mts.map +1 -0
- package/dist/number/refined-number-utils.mjs +179 -0
- package/dist/number/refined-number-utils.mjs.map +1 -0
- package/dist/object/index.d.mts +2 -0
- package/dist/object/index.d.mts.map +1 -0
- package/dist/object/index.mjs +2 -0
- package/dist/object/index.mjs.map +1 -0
- package/dist/object/object.d.mts +296 -0
- package/dist/object/object.d.mts.map +1 -0
- package/dist/object/object.mjs +295 -0
- package/dist/object/object.mjs.map +1 -0
- package/dist/others/cast-mutable.d.mts +110 -0
- package/dist/others/cast-mutable.d.mts.map +1 -0
- package/dist/others/cast-mutable.mjs +114 -0
- package/dist/others/cast-mutable.mjs.map +1 -0
- package/dist/others/cast-readonly.d.mts +189 -0
- package/dist/others/cast-readonly.d.mts.map +1 -0
- package/dist/others/cast-readonly.mjs +193 -0
- package/dist/others/cast-readonly.mjs.map +1 -0
- package/dist/others/if-then.d.mts +98 -0
- package/dist/others/if-then.d.mts.map +1 -0
- package/dist/others/if-then.mjs +100 -0
- package/dist/others/if-then.mjs.map +1 -0
- package/dist/others/index.d.mts +8 -0
- package/dist/others/index.d.mts.map +1 -0
- package/dist/others/index.mjs +8 -0
- package/dist/others/index.mjs.map +1 -0
- package/dist/others/map-nullable.d.mts +151 -0
- package/dist/others/map-nullable.d.mts.map +1 -0
- package/dist/others/map-nullable.mjs +159 -0
- package/dist/others/map-nullable.mjs.map +1 -0
- package/dist/others/memoize-function.d.mts +173 -0
- package/dist/others/memoize-function.d.mts.map +1 -0
- package/dist/others/memoize-function.mjs +189 -0
- package/dist/others/memoize-function.mjs.map +1 -0
- package/dist/others/tuple.d.mts +159 -0
- package/dist/others/tuple.d.mts.map +1 -0
- package/dist/others/tuple.mjs +161 -0
- package/dist/others/tuple.mjs.map +1 -0
- package/dist/others/unknown-to-string.d.mts +180 -0
- package/dist/others/unknown-to-string.d.mts.map +1 -0
- package/dist/others/unknown-to-string.mjs +211 -0
- package/dist/others/unknown-to-string.mjs.map +1 -0
- package/dist/tsconfig.json +1 -0
- package/package.json +16 -14
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
|
|
3
|
+
const typeNameInMessage = 'a non-negative finite number';
|
|
4
|
+
const { MIN_VALUE, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, clamp, } = TsVerifiedInternals.RefinedNumberUtils.operatorsForFloat({
|
|
5
|
+
MIN_VALUE: 0,
|
|
6
|
+
MAX_VALUE: undefined,
|
|
7
|
+
typeNameInMessage,
|
|
8
|
+
});
|
|
9
|
+
const floor = (x) =>
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
11
|
+
Math.floor(x);
|
|
12
|
+
const ceil = (x) =>
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
14
|
+
Math.ceil(x);
|
|
15
|
+
const round = (x) =>
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
17
|
+
Math.round(x);
|
|
18
|
+
/**
|
|
19
|
+
* Checks if a number is a NonNegativeFiniteNumber (a finite number >= 0).
|
|
20
|
+
* @param value The value to check.
|
|
21
|
+
* @returns `true` if the value is a NonNegativeFiniteNumber, `false` otherwise.
|
|
22
|
+
*/
|
|
23
|
+
const isNonNegativeFiniteNumber = is;
|
|
24
|
+
/**
|
|
25
|
+
* Casts a number to a NonNegativeFiniteNumber type.
|
|
26
|
+
* @param value The value to cast.
|
|
27
|
+
* @returns The value as a NonNegativeFiniteNumber type.
|
|
28
|
+
* @throws {TypeError} If the value is not a non-negative finite number.
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const x = asNonNegativeFiniteNumber(5.5); // NonNegativeFiniteNumber
|
|
32
|
+
* const y = asNonNegativeFiniteNumber(0); // NonNegativeFiniteNumber
|
|
33
|
+
* // asNonNegativeFiniteNumber(-1); // throws TypeError
|
|
34
|
+
* // asNonNegativeFiniteNumber(Infinity); // throws TypeError
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const asNonNegativeFiniteNumber = castType;
|
|
38
|
+
/**
|
|
39
|
+
* Namespace providing type-safe arithmetic operations for non-negative finite numbers.
|
|
40
|
+
*
|
|
41
|
+
* All operations maintain the non-negative constraint by clamping negative results to 0,
|
|
42
|
+
* while ensuring results remain finite (excluding NaN and Infinity). This type is useful
|
|
43
|
+
* for representing measurements, distances, weights, and other inherently non-negative values.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const distance = asNonNegativeFiniteNumber(5.5);
|
|
48
|
+
* const speed = asNonNegativeFiniteNumber(2.2);
|
|
49
|
+
*
|
|
50
|
+
* // Arithmetic operations with non-negative clamping
|
|
51
|
+
* const total = NonNegativeFiniteNumber.add(distance, speed); // NonNegativeFiniteNumber (7.7)
|
|
52
|
+
* const diff = NonNegativeFiniteNumber.sub(speed, distance); // NonNegativeFiniteNumber (0 - clamped)
|
|
53
|
+
* const area = NonNegativeFiniteNumber.mul(distance, speed); // NonNegativeFiniteNumber (12.1)
|
|
54
|
+
* const ratio = NonNegativeFiniteNumber.div(distance, speed); // NonNegativeFiniteNumber (2.5)
|
|
55
|
+
*
|
|
56
|
+
* // Range operations
|
|
57
|
+
* const clamped = NonNegativeFiniteNumber.clamp(-10.5); // NonNegativeFiniteNumber (0)
|
|
58
|
+
* const minimum = NonNegativeFiniteNumber.min(distance, speed); // NonNegativeFiniteNumber (2.2)
|
|
59
|
+
* const maximum = NonNegativeFiniteNumber.max(distance, speed); // NonNegativeFiniteNumber (5.5)
|
|
60
|
+
*
|
|
61
|
+
* // Rounding operations (return Uint)
|
|
62
|
+
* const pixels = NonNegativeFiniteNumber.round(distance); // Uint (6)
|
|
63
|
+
* const floorValue = NonNegativeFiniteNumber.floor(distance); // Uint (5)
|
|
64
|
+
* const ceilValue = NonNegativeFiniteNumber.ceil(distance); // Uint (6)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
const NonNegativeFiniteNumber = {
|
|
68
|
+
/**
|
|
69
|
+
* Type guard to check if a value is a NonNegativeFiniteNumber.
|
|
70
|
+
* @param value The value to check.
|
|
71
|
+
* @returns `true` if the value is a non-negative finite number, `false` otherwise.
|
|
72
|
+
*/
|
|
73
|
+
is,
|
|
74
|
+
/**
|
|
75
|
+
* The minimum value for a non-negative finite number.
|
|
76
|
+
* @readonly
|
|
77
|
+
*/
|
|
78
|
+
MIN_VALUE,
|
|
79
|
+
/**
|
|
80
|
+
* Returns the smaller of two NonNegativeFiniteNumber values.
|
|
81
|
+
* @param a The first NonNegativeFiniteNumber.
|
|
82
|
+
* @param b The second NonNegativeFiniteNumber.
|
|
83
|
+
* @returns The minimum value as a NonNegativeFiniteNumber.
|
|
84
|
+
*/
|
|
85
|
+
min: min_,
|
|
86
|
+
/**
|
|
87
|
+
* Returns the larger of two NonNegativeFiniteNumber values.
|
|
88
|
+
* @param a The first NonNegativeFiniteNumber.
|
|
89
|
+
* @param b The second NonNegativeFiniteNumber.
|
|
90
|
+
* @returns The maximum value as a NonNegativeFiniteNumber.
|
|
91
|
+
*/
|
|
92
|
+
max: max_,
|
|
93
|
+
/**
|
|
94
|
+
* Clamps a number to the non-negative finite range.
|
|
95
|
+
* @param value The number to clamp.
|
|
96
|
+
* @returns The value clamped to [0, +∞) as a NonNegativeFiniteNumber.
|
|
97
|
+
*/
|
|
98
|
+
clamp,
|
|
99
|
+
/**
|
|
100
|
+
* Rounds down a NonNegativeFiniteNumber to the nearest integer.
|
|
101
|
+
* @param x The NonNegativeFiniteNumber to round down.
|
|
102
|
+
* @returns The floor value as a Uint.
|
|
103
|
+
*/
|
|
104
|
+
floor,
|
|
105
|
+
/**
|
|
106
|
+
* Rounds up a NonNegativeFiniteNumber to the nearest integer.
|
|
107
|
+
* @param x The NonNegativeFiniteNumber to round up.
|
|
108
|
+
* @returns The ceiling value as a Uint.
|
|
109
|
+
*/
|
|
110
|
+
ceil,
|
|
111
|
+
/**
|
|
112
|
+
* Rounds a NonNegativeFiniteNumber to the nearest integer.
|
|
113
|
+
* @param x The NonNegativeFiniteNumber to round.
|
|
114
|
+
* @returns The rounded value as a Uint.
|
|
115
|
+
*/
|
|
116
|
+
round,
|
|
117
|
+
/**
|
|
118
|
+
* Generates a random NonNegativeFiniteNumber value.
|
|
119
|
+
* @returns A random non-negative finite number.
|
|
120
|
+
*/
|
|
121
|
+
random,
|
|
122
|
+
/**
|
|
123
|
+
* Raises a NonNegativeFiniteNumber to the power of another NonNegativeFiniteNumber.
|
|
124
|
+
* @param a The base NonNegativeFiniteNumber.
|
|
125
|
+
* @param b The exponent NonNegativeFiniteNumber.
|
|
126
|
+
* @returns `a ** b` clamped to [0, +∞) as a NonNegativeFiniteNumber.
|
|
127
|
+
*/
|
|
128
|
+
pow,
|
|
129
|
+
/**
|
|
130
|
+
* Adds two NonNegativeFiniteNumber values.
|
|
131
|
+
* @param a The first NonNegativeFiniteNumber.
|
|
132
|
+
* @param b The second NonNegativeFiniteNumber.
|
|
133
|
+
* @returns `a + b` clamped to [0, +∞) as a NonNegativeFiniteNumber.
|
|
134
|
+
*/
|
|
135
|
+
add,
|
|
136
|
+
/**
|
|
137
|
+
* Subtracts one NonNegativeFiniteNumber from another.
|
|
138
|
+
* @param a The minuend NonNegativeFiniteNumber.
|
|
139
|
+
* @param b The subtrahend NonNegativeFiniteNumber.
|
|
140
|
+
* @returns `a - b` clamped to [0, +∞) as a NonNegativeFiniteNumber (minimum 0).
|
|
141
|
+
*/
|
|
142
|
+
sub,
|
|
143
|
+
/**
|
|
144
|
+
* Multiplies two NonNegativeFiniteNumber values.
|
|
145
|
+
* @param a The first NonNegativeFiniteNumber.
|
|
146
|
+
* @param b The second NonNegativeFiniteNumber.
|
|
147
|
+
* @returns `a * b` clamped to [0, +∞) as a NonNegativeFiniteNumber.
|
|
148
|
+
*/
|
|
149
|
+
mul,
|
|
150
|
+
/**
|
|
151
|
+
* Divides one NonNegativeFiniteNumber by another.
|
|
152
|
+
* @param a The dividend NonNegativeFiniteNumber.
|
|
153
|
+
* @param b The divisor NonNegativeFiniteNumber.
|
|
154
|
+
* @returns `a / b` clamped to [0, +∞) as a NonNegativeFiniteNumber.
|
|
155
|
+
*/
|
|
156
|
+
div,
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export { NonNegativeFiniteNumber, asNonNegativeFiniteNumber, isNonNegativeFiniteNumber };
|
|
160
|
+
//# sourceMappingURL=non-negative-finite-number.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-negative-finite-number.mjs","sources":["../../../src/number/branded-types/non-negative-finite-number.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,8BAA8B;AAExD,MAAM,EACJ,SAAS,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,EACR,KAAK,GACN,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,iBAAiB,CAI1D;AACA,IAAA,SAAS,EAAE,CAAC;AACZ,IAAA,SAAS,EAAE,SAAS;IACpB,iBAAiB;AACT,CAAA,CAAC;AAEX,MAAM,KAAK,GAAG,CACZ,CAAc;AAEd;AACA,IAAI,CAAC,KAAK,CAAC,CAAC,CAA8D;AAE5E,MAAM,IAAI,GAAG,CACX,CAAc;AAEd;AACA,IAAI,CAAC,IAAI,CAAC,CAAC,CAA8D;AAE3E,MAAM,KAAK,GAAG,CACZ,CAAc;AAEd;AACA,IAAI,CAAC,KAAK,CAAC,CAAC,CAA8D;AAM5E;;;;AAIG;AACI,MAAM,yBAAyB,GAAG;AAEzC;;;;;;;;;;;;AAYG;AACI,MAAM,yBAAyB,GAAG;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACI,MAAM,uBAAuB,GAAG;AACrC;;;;AAIG;IACH,EAAE;AAEF;;;AAGG;IACH,SAAS;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;AAIG;IACH,KAAK;AAEL;;;;AAIG;IACH,KAAK;AAEL;;;;AAIG;IACH,IAAI;AAEJ;;;;AAIG;IACH,KAAK;AAEL;;;AAGG;IACH,MAAM;AAEN;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;;;;;"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is a NonNegativeInt16 (16-bit non-negative signed integer in the range [0, 2^15)).
|
|
3
|
+
* @param value The value to check.
|
|
4
|
+
* @returns `true` if the value is a NonNegativeInt16, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isNonNegativeInt16: (a: number) => a is NonNegativeInt16;
|
|
7
|
+
/**
|
|
8
|
+
* Casts a number to a NonNegativeInt16 type.
|
|
9
|
+
* @param value The value to cast.
|
|
10
|
+
* @returns The value as a NonNegativeInt16 type.
|
|
11
|
+
* @throws {TypeError} If the value is not a non-negative integer in [0, 2^15).
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const x = asNonNegativeInt16(1000); // NonNegativeInt16
|
|
15
|
+
* const y = asNonNegativeInt16(0); // NonNegativeInt16
|
|
16
|
+
* // asNonNegativeInt16(-1); // throws TypeError
|
|
17
|
+
* // asNonNegativeInt16(32768); // throws TypeError
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const asNonNegativeInt16: <N extends number>(x: N) => number & {
|
|
21
|
+
readonly NaNValue: false;
|
|
22
|
+
readonly "> -2^16": true;
|
|
23
|
+
readonly "> -2^32": true;
|
|
24
|
+
readonly ">= -2^15": true;
|
|
25
|
+
readonly ">= -2^31": true;
|
|
26
|
+
readonly ">=0": true;
|
|
27
|
+
readonly "< 2^15": true;
|
|
28
|
+
readonly "< 2^16": true;
|
|
29
|
+
readonly "< 2^31": true;
|
|
30
|
+
readonly "< 2^32": true;
|
|
31
|
+
readonly Finite: true;
|
|
32
|
+
readonly Int: true;
|
|
33
|
+
readonly SafeInt: true;
|
|
34
|
+
} & Readonly<{
|
|
35
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
36
|
+
}> & N;
|
|
37
|
+
/**
|
|
38
|
+
* Namespace providing type-safe arithmetic operations for 16-bit non-negative integers.
|
|
39
|
+
*
|
|
40
|
+
* All operations automatically clamp results to the valid NonNegativeInt16 range [0, 32767].
|
|
41
|
+
* This ensures that all arithmetic maintains the 16-bit non-negative integer constraint,
|
|
42
|
+
* with negative results clamped to 0 and overflow results clamped to MAX_VALUE.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const a = asNonNegativeInt16(30000);
|
|
47
|
+
* const b = asNonNegativeInt16(5000);
|
|
48
|
+
*
|
|
49
|
+
* // Arithmetic operations with automatic clamping
|
|
50
|
+
* const sum = NonNegativeInt16.add(a, b); // NonNegativeInt16 (32767 - clamped to MAX_VALUE)
|
|
51
|
+
* const diff = NonNegativeInt16.sub(a, b); // NonNegativeInt16 (25000)
|
|
52
|
+
* const reverseDiff = NonNegativeInt16.sub(b, a); // NonNegativeInt16 (0 - clamped to MIN_VALUE)
|
|
53
|
+
* const product = NonNegativeInt16.mul(a, b); // NonNegativeInt16 (32767 - clamped due to overflow)
|
|
54
|
+
*
|
|
55
|
+
* // Range operations
|
|
56
|
+
* const clamped = NonNegativeInt16.clamp(-100); // NonNegativeInt16 (0)
|
|
57
|
+
* const minimum = NonNegativeInt16.min(a, b); // NonNegativeInt16 (5000)
|
|
58
|
+
* const maximum = NonNegativeInt16.max(a, b); // NonNegativeInt16 (30000)
|
|
59
|
+
*
|
|
60
|
+
* // Utility operations
|
|
61
|
+
* const random = NonNegativeInt16.random(); // NonNegativeInt16 (random value in [0, 32767])
|
|
62
|
+
* const power = NonNegativeInt16.pow(asNonNegativeInt16(2), asNonNegativeInt16(10)); // NonNegativeInt16 (1024)
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const NonNegativeInt16: {
|
|
66
|
+
/**
|
|
67
|
+
* Type guard to check if a value is a NonNegativeInt16.
|
|
68
|
+
* @param value The value to check.
|
|
69
|
+
* @returns `true` if the value is a 16-bit non-negative integer, `false` otherwise.
|
|
70
|
+
*/
|
|
71
|
+
readonly is: (a: number) => a is NonNegativeInt16;
|
|
72
|
+
/**
|
|
73
|
+
* The minimum value for a 16-bit non-negative integer.
|
|
74
|
+
* @readonly
|
|
75
|
+
*/
|
|
76
|
+
readonly MIN_VALUE: 0;
|
|
77
|
+
/**
|
|
78
|
+
* The maximum value for a 16-bit non-negative integer.
|
|
79
|
+
* @readonly
|
|
80
|
+
*/
|
|
81
|
+
readonly MAX_VALUE: number;
|
|
82
|
+
/**
|
|
83
|
+
* Returns the smaller of two NonNegativeInt16 values.
|
|
84
|
+
* @param a The first NonNegativeInt16.
|
|
85
|
+
* @param b The second NonNegativeInt16.
|
|
86
|
+
* @returns The minimum value as a NonNegativeInt16.
|
|
87
|
+
*/
|
|
88
|
+
readonly min: (...values: readonly WithSmallInt<NonNegativeInt16, 40>[]) => NonNegativeInt16;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the larger of two NonNegativeInt16 values.
|
|
91
|
+
* @param a The first NonNegativeInt16.
|
|
92
|
+
* @param b The second NonNegativeInt16.
|
|
93
|
+
* @returns The maximum value as a NonNegativeInt16.
|
|
94
|
+
*/
|
|
95
|
+
readonly max: (...values: readonly WithSmallInt<NonNegativeInt16, 40>[]) => NonNegativeInt16;
|
|
96
|
+
/**
|
|
97
|
+
* Clamps a number to the NonNegativeInt16 range.
|
|
98
|
+
* @param value The number to clamp.
|
|
99
|
+
* @returns The value clamped to [0, 32767] as a NonNegativeInt16.
|
|
100
|
+
*/
|
|
101
|
+
readonly clamp: (x: number) => NonNegativeInt16;
|
|
102
|
+
/**
|
|
103
|
+
* Generates a random NonNegativeInt16 value within the valid range.
|
|
104
|
+
* @returns A random NonNegativeInt16 between 0 and 32767.
|
|
105
|
+
*/
|
|
106
|
+
readonly random: (min: WithSmallInt<NonNegativeInt16, 40>, max: WithSmallInt<NonNegativeInt16, 40>) => NonNegativeInt16;
|
|
107
|
+
/**
|
|
108
|
+
* Raises a NonNegativeInt16 to the power of another NonNegativeInt16.
|
|
109
|
+
* @param a The base NonNegativeInt16.
|
|
110
|
+
* @param b The exponent NonNegativeInt16.
|
|
111
|
+
* @returns `a ** b` clamped to [0, 32767] as a NonNegativeInt16.
|
|
112
|
+
*/
|
|
113
|
+
readonly pow: (x: WithSmallInt<NonNegativeInt16, 40>, y: WithSmallInt<NonNegativeInt16, 40>) => NonNegativeInt16;
|
|
114
|
+
/**
|
|
115
|
+
* Adds two NonNegativeInt16 values.
|
|
116
|
+
* @param a The first NonNegativeInt16.
|
|
117
|
+
* @param b The second NonNegativeInt16.
|
|
118
|
+
* @returns `a + b` clamped to [0, 32767] as a NonNegativeInt16.
|
|
119
|
+
*/
|
|
120
|
+
readonly add: (x: WithSmallInt<NonNegativeInt16, 40>, y: WithSmallInt<NonNegativeInt16, 40>) => NonNegativeInt16;
|
|
121
|
+
/**
|
|
122
|
+
* Subtracts one NonNegativeInt16 from another.
|
|
123
|
+
* @param a The minuend NonNegativeInt16.
|
|
124
|
+
* @param b The subtrahend NonNegativeInt16.
|
|
125
|
+
* @returns `a - b` clamped to [0, 32767] as a NonNegativeInt16 (minimum 0).
|
|
126
|
+
*/
|
|
127
|
+
readonly sub: (x: WithSmallInt<NonNegativeInt16, 40>, y: WithSmallInt<NonNegativeInt16, 40>) => NonNegativeInt16;
|
|
128
|
+
/**
|
|
129
|
+
* Multiplies two NonNegativeInt16 values.
|
|
130
|
+
* @param a The first NonNegativeInt16.
|
|
131
|
+
* @param b The second NonNegativeInt16.
|
|
132
|
+
* @returns `a * b` clamped to [0, 32767] as a NonNegativeInt16.
|
|
133
|
+
*/
|
|
134
|
+
readonly mul: (x: WithSmallInt<NonNegativeInt16, 40>, y: WithSmallInt<NonNegativeInt16, 40>) => NonNegativeInt16;
|
|
135
|
+
/**
|
|
136
|
+
* Divides one NonNegativeInt16 by another using floor division.
|
|
137
|
+
* @param a The dividend NonNegativeInt16.
|
|
138
|
+
* @param b The divisor NonNegativeInt16.
|
|
139
|
+
* @returns `⌊a / b⌋` clamped to [0, 32767] as a NonNegativeInt16.
|
|
140
|
+
*/
|
|
141
|
+
readonly div: (x: WithSmallInt<NonNegativeInt16, 40>, y: 1 | 2 | 3 | 32 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 10 | 24 | 14 | 34 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | NormalizeBrandUnion<number & {
|
|
142
|
+
readonly NaNValue: false;
|
|
143
|
+
readonly "!=0": true;
|
|
144
|
+
readonly "> -2^16": true;
|
|
145
|
+
readonly "> -2^32": true;
|
|
146
|
+
readonly ">= -2^15": true;
|
|
147
|
+
readonly ">= -2^31": true;
|
|
148
|
+
readonly ">=0": true;
|
|
149
|
+
readonly "< 2^15": true;
|
|
150
|
+
readonly "< 2^16": true;
|
|
151
|
+
readonly "< 2^31": true;
|
|
152
|
+
readonly "< 2^32": true;
|
|
153
|
+
readonly Finite: true;
|
|
154
|
+
readonly Int: true;
|
|
155
|
+
readonly SafeInt: true;
|
|
156
|
+
} & Readonly<{
|
|
157
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
158
|
+
}>>) => NonNegativeInt16;
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=non-negative-int16.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-negative-int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-negative-int16.mts"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,sCAAK,CAAC;AAErC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;MAAW,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,gBAAgB;IAC3B;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { TsVerifiedInternals } from '../refined-number-utils.mjs';
|
|
2
|
+
|
|
3
|
+
const typeNameInMessage = 'a non-negative integer in [0, 2^15)';
|
|
4
|
+
const { MIN_VALUE, MAX_VALUE, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, clamp, } = TsVerifiedInternals.RefinedNumberUtils.operatorsForInteger({
|
|
5
|
+
integerOrSafeInteger: 'SafeInteger',
|
|
6
|
+
MIN_VALUE: 0,
|
|
7
|
+
MAX_VALUE: 2 ** 15 - 1,
|
|
8
|
+
typeNameInMessage,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a number is a NonNegativeInt16 (16-bit non-negative signed integer in the range [0, 2^15)).
|
|
12
|
+
* @param value The value to check.
|
|
13
|
+
* @returns `true` if the value is a NonNegativeInt16, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
const isNonNegativeInt16 = is;
|
|
16
|
+
/**
|
|
17
|
+
* Casts a number to a NonNegativeInt16 type.
|
|
18
|
+
* @param value The value to cast.
|
|
19
|
+
* @returns The value as a NonNegativeInt16 type.
|
|
20
|
+
* @throws {TypeError} If the value is not a non-negative integer in [0, 2^15).
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const x = asNonNegativeInt16(1000); // NonNegativeInt16
|
|
24
|
+
* const y = asNonNegativeInt16(0); // NonNegativeInt16
|
|
25
|
+
* // asNonNegativeInt16(-1); // throws TypeError
|
|
26
|
+
* // asNonNegativeInt16(32768); // throws TypeError
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const asNonNegativeInt16 = castType;
|
|
30
|
+
/**
|
|
31
|
+
* Namespace providing type-safe arithmetic operations for 16-bit non-negative integers.
|
|
32
|
+
*
|
|
33
|
+
* All operations automatically clamp results to the valid NonNegativeInt16 range [0, 32767].
|
|
34
|
+
* This ensures that all arithmetic maintains the 16-bit non-negative integer constraint,
|
|
35
|
+
* with negative results clamped to 0 and overflow results clamped to MAX_VALUE.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const a = asNonNegativeInt16(30000);
|
|
40
|
+
* const b = asNonNegativeInt16(5000);
|
|
41
|
+
*
|
|
42
|
+
* // Arithmetic operations with automatic clamping
|
|
43
|
+
* const sum = NonNegativeInt16.add(a, b); // NonNegativeInt16 (32767 - clamped to MAX_VALUE)
|
|
44
|
+
* const diff = NonNegativeInt16.sub(a, b); // NonNegativeInt16 (25000)
|
|
45
|
+
* const reverseDiff = NonNegativeInt16.sub(b, a); // NonNegativeInt16 (0 - clamped to MIN_VALUE)
|
|
46
|
+
* const product = NonNegativeInt16.mul(a, b); // NonNegativeInt16 (32767 - clamped due to overflow)
|
|
47
|
+
*
|
|
48
|
+
* // Range operations
|
|
49
|
+
* const clamped = NonNegativeInt16.clamp(-100); // NonNegativeInt16 (0)
|
|
50
|
+
* const minimum = NonNegativeInt16.min(a, b); // NonNegativeInt16 (5000)
|
|
51
|
+
* const maximum = NonNegativeInt16.max(a, b); // NonNegativeInt16 (30000)
|
|
52
|
+
*
|
|
53
|
+
* // Utility operations
|
|
54
|
+
* const random = NonNegativeInt16.random(); // NonNegativeInt16 (random value in [0, 32767])
|
|
55
|
+
* const power = NonNegativeInt16.pow(asNonNegativeInt16(2), asNonNegativeInt16(10)); // NonNegativeInt16 (1024)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const NonNegativeInt16 = {
|
|
59
|
+
/**
|
|
60
|
+
* Type guard to check if a value is a NonNegativeInt16.
|
|
61
|
+
* @param value The value to check.
|
|
62
|
+
* @returns `true` if the value is a 16-bit non-negative integer, `false` otherwise.
|
|
63
|
+
*/
|
|
64
|
+
is,
|
|
65
|
+
/**
|
|
66
|
+
* The minimum value for a 16-bit non-negative integer.
|
|
67
|
+
* @readonly
|
|
68
|
+
*/
|
|
69
|
+
MIN_VALUE,
|
|
70
|
+
/**
|
|
71
|
+
* The maximum value for a 16-bit non-negative integer.
|
|
72
|
+
* @readonly
|
|
73
|
+
*/
|
|
74
|
+
MAX_VALUE,
|
|
75
|
+
/**
|
|
76
|
+
* Returns the smaller of two NonNegativeInt16 values.
|
|
77
|
+
* @param a The first NonNegativeInt16.
|
|
78
|
+
* @param b The second NonNegativeInt16.
|
|
79
|
+
* @returns The minimum value as a NonNegativeInt16.
|
|
80
|
+
*/
|
|
81
|
+
min: min_,
|
|
82
|
+
/**
|
|
83
|
+
* Returns the larger of two NonNegativeInt16 values.
|
|
84
|
+
* @param a The first NonNegativeInt16.
|
|
85
|
+
* @param b The second NonNegativeInt16.
|
|
86
|
+
* @returns The maximum value as a NonNegativeInt16.
|
|
87
|
+
*/
|
|
88
|
+
max: max_,
|
|
89
|
+
/**
|
|
90
|
+
* Clamps a number to the NonNegativeInt16 range.
|
|
91
|
+
* @param value The number to clamp.
|
|
92
|
+
* @returns The value clamped to [0, 32767] as a NonNegativeInt16.
|
|
93
|
+
*/
|
|
94
|
+
clamp,
|
|
95
|
+
/**
|
|
96
|
+
* Generates a random NonNegativeInt16 value within the valid range.
|
|
97
|
+
* @returns A random NonNegativeInt16 between 0 and 32767.
|
|
98
|
+
*/
|
|
99
|
+
random,
|
|
100
|
+
/**
|
|
101
|
+
* Raises a NonNegativeInt16 to the power of another NonNegativeInt16.
|
|
102
|
+
* @param a The base NonNegativeInt16.
|
|
103
|
+
* @param b The exponent NonNegativeInt16.
|
|
104
|
+
* @returns `a ** b` clamped to [0, 32767] as a NonNegativeInt16.
|
|
105
|
+
*/
|
|
106
|
+
pow,
|
|
107
|
+
/**
|
|
108
|
+
* Adds two NonNegativeInt16 values.
|
|
109
|
+
* @param a The first NonNegativeInt16.
|
|
110
|
+
* @param b The second NonNegativeInt16.
|
|
111
|
+
* @returns `a + b` clamped to [0, 32767] as a NonNegativeInt16.
|
|
112
|
+
*/
|
|
113
|
+
add,
|
|
114
|
+
/**
|
|
115
|
+
* Subtracts one NonNegativeInt16 from another.
|
|
116
|
+
* @param a The minuend NonNegativeInt16.
|
|
117
|
+
* @param b The subtrahend NonNegativeInt16.
|
|
118
|
+
* @returns `a - b` clamped to [0, 32767] as a NonNegativeInt16 (minimum 0).
|
|
119
|
+
*/
|
|
120
|
+
sub,
|
|
121
|
+
/**
|
|
122
|
+
* Multiplies two NonNegativeInt16 values.
|
|
123
|
+
* @param a The first NonNegativeInt16.
|
|
124
|
+
* @param b The second NonNegativeInt16.
|
|
125
|
+
* @returns `a * b` clamped to [0, 32767] as a NonNegativeInt16.
|
|
126
|
+
*/
|
|
127
|
+
mul,
|
|
128
|
+
/**
|
|
129
|
+
* Divides one NonNegativeInt16 by another using floor division.
|
|
130
|
+
* @param a The dividend NonNegativeInt16.
|
|
131
|
+
* @param b The divisor NonNegativeInt16.
|
|
132
|
+
* @returns `⌊a / b⌋` clamped to [0, 32767] as a NonNegativeInt16.
|
|
133
|
+
*/
|
|
134
|
+
div,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export { NonNegativeInt16, asNonNegativeInt16, isNonNegativeInt16 };
|
|
138
|
+
//# sourceMappingURL=non-negative-int16.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-negative-int16.mjs","sources":["../../../src/number/branded-types/non-negative-int16.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,qCAAqC;AAE/D,MAAM,EACJ,SAAS,EACT,SAAS,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,EACR,KAAK,GACN,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,mBAAmB,CAI5D;AACA,IAAA,oBAAoB,EAAE,aAAa;AACnC,IAAA,SAAS,EAAE,CAAC;AACZ,IAAA,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;IACtB,iBAAiB;AACT,CAAA,CAAC;AAEX;;;;AAIG;AACI,MAAM,kBAAkB,GAAG;AAElC;;;;;;;;;;;;AAYG;AACI,MAAM,kBAAkB,GAAG;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACI,MAAM,gBAAgB,GAAG;AAC9B;;;;AAIG;IACH,EAAE;AAEF;;;AAGG;IACH,SAAS;AAET;;;AAGG;IACH,SAAS;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;AAKG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;AAIG;IACH,KAAK;AAEL;;;AAGG;IACH,MAAM;AAEN;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;AAEH;;;;;AAKG;IACH,GAAG;;;;;"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is a NonNegativeInt32 (32-bit non-negative signed integer in the range [0, 2^31)).
|
|
3
|
+
* @param value The value to check.
|
|
4
|
+
* @returns `true` if the value is a NonNegativeInt32, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isNonNegativeInt32: (a: number) => a is NonNegativeInt32;
|
|
7
|
+
/**
|
|
8
|
+
* Casts a number to a NonNegativeInt32 type.
|
|
9
|
+
* @param value The value to cast.
|
|
10
|
+
* @returns The value as a NonNegativeInt32 type.
|
|
11
|
+
* @throws {TypeError} If the value is not a non-negative integer in [0, 2^31).
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const x = asNonNegativeInt32(1000); // NonNegativeInt32
|
|
15
|
+
* const y = asNonNegativeInt32(0); // NonNegativeInt32
|
|
16
|
+
* // asNonNegativeInt32(-1); // throws TypeError
|
|
17
|
+
* // asNonNegativeInt32(2147483648); // throws TypeError
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const asNonNegativeInt32: <N extends number>(x: N) => number & {
|
|
21
|
+
readonly NaNValue: false;
|
|
22
|
+
readonly "> -2^16": true;
|
|
23
|
+
readonly "> -2^32": true;
|
|
24
|
+
readonly ">= -2^15": true;
|
|
25
|
+
readonly ">= -2^31": true;
|
|
26
|
+
readonly ">=0": true;
|
|
27
|
+
readonly "< 2^31": true;
|
|
28
|
+
readonly "< 2^32": true;
|
|
29
|
+
readonly Finite: true;
|
|
30
|
+
readonly Int: true;
|
|
31
|
+
readonly SafeInt: true;
|
|
32
|
+
} & Readonly<{
|
|
33
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
34
|
+
}> & N;
|
|
35
|
+
/**
|
|
36
|
+
* Namespace providing type-safe arithmetic operations for 32-bit non-negative integers.
|
|
37
|
+
*
|
|
38
|
+
* All operations automatically clamp results to the valid NonNegativeInt32 range [0, 2147483647].
|
|
39
|
+
* This ensures that all arithmetic maintains the 32-bit non-negative integer constraint,
|
|
40
|
+
* with negative results clamped to 0 and overflow results clamped to MAX_VALUE.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const a = asNonNegativeInt32(2000000000);
|
|
45
|
+
* const b = asNonNegativeInt32(500000000);
|
|
46
|
+
*
|
|
47
|
+
* // Arithmetic operations with automatic clamping
|
|
48
|
+
* const sum = NonNegativeInt32.add(a, b); // NonNegativeInt32 (2147483647 - clamped to MAX_VALUE)
|
|
49
|
+
* const diff = NonNegativeInt32.sub(a, b); // NonNegativeInt32 (1500000000)
|
|
50
|
+
* const reverseDiff = NonNegativeInt32.sub(b, a); // NonNegativeInt32 (0 - clamped to MIN_VALUE)
|
|
51
|
+
* const product = NonNegativeInt32.mul(a, b); // NonNegativeInt32 (2147483647 - clamped due to overflow)
|
|
52
|
+
*
|
|
53
|
+
* // Range operations
|
|
54
|
+
* const clamped = NonNegativeInt32.clamp(-1000); // NonNegativeInt32 (0)
|
|
55
|
+
* const minimum = NonNegativeInt32.min(a, b); // NonNegativeInt32 (500000000)
|
|
56
|
+
* const maximum = NonNegativeInt32.max(a, b); // NonNegativeInt32 (2000000000)
|
|
57
|
+
*
|
|
58
|
+
* // Utility operations
|
|
59
|
+
* const random = NonNegativeInt32.random(); // NonNegativeInt32 (random value in [0, 2147483647])
|
|
60
|
+
* const power = NonNegativeInt32.pow(asNonNegativeInt32(2), asNonNegativeInt32(20)); // NonNegativeInt32 (1048576)
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const NonNegativeInt32: {
|
|
64
|
+
/**
|
|
65
|
+
* Type guard to check if a value is a NonNegativeInt32.
|
|
66
|
+
* @param value The value to check.
|
|
67
|
+
* @returns `true` if the value is a 32-bit non-negative integer, `false` otherwise.
|
|
68
|
+
*/
|
|
69
|
+
readonly is: (a: number) => a is NonNegativeInt32;
|
|
70
|
+
/**
|
|
71
|
+
* The minimum value for a 32-bit non-negative integer.
|
|
72
|
+
* @readonly
|
|
73
|
+
*/
|
|
74
|
+
readonly MIN_VALUE: 0;
|
|
75
|
+
/**
|
|
76
|
+
* The maximum value for a 32-bit non-negative integer.
|
|
77
|
+
* @readonly
|
|
78
|
+
*/
|
|
79
|
+
readonly MAX_VALUE: number;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the smaller of two NonNegativeInt32 values.
|
|
82
|
+
* @param a The first NonNegativeInt32.
|
|
83
|
+
* @param b The second NonNegativeInt32.
|
|
84
|
+
* @returns The minimum value as a NonNegativeInt32.
|
|
85
|
+
*/
|
|
86
|
+
readonly min: (...values: readonly WithSmallInt<NonNegativeInt32, 40>[]) => NonNegativeInt32;
|
|
87
|
+
/**
|
|
88
|
+
* Returns the larger of two NonNegativeInt32 values.
|
|
89
|
+
* @param a The first NonNegativeInt32.
|
|
90
|
+
* @param b The second NonNegativeInt32.
|
|
91
|
+
* @returns The maximum value as a NonNegativeInt32.
|
|
92
|
+
*/
|
|
93
|
+
readonly max: (...values: readonly WithSmallInt<NonNegativeInt32, 40>[]) => NonNegativeInt32;
|
|
94
|
+
/**
|
|
95
|
+
* Clamps a number to the NonNegativeInt32 range.
|
|
96
|
+
* @param value The number to clamp.
|
|
97
|
+
* @returns The value clamped to [0, 2147483647] as a NonNegativeInt32.
|
|
98
|
+
*/
|
|
99
|
+
readonly clamp: (x: number) => NonNegativeInt32;
|
|
100
|
+
/**
|
|
101
|
+
* Generates a random NonNegativeInt32 value within the valid range.
|
|
102
|
+
* @returns A random NonNegativeInt32 between 0 and 2147483647.
|
|
103
|
+
*/
|
|
104
|
+
readonly random: (min: WithSmallInt<NonNegativeInt32, 40>, max: WithSmallInt<NonNegativeInt32, 40>) => NonNegativeInt32;
|
|
105
|
+
/**
|
|
106
|
+
* Raises a NonNegativeInt32 to the power of another NonNegativeInt32.
|
|
107
|
+
* @param a The base NonNegativeInt32.
|
|
108
|
+
* @param b The exponent NonNegativeInt32.
|
|
109
|
+
* @returns `a ** b` clamped to [0, 2147483647] as a NonNegativeInt32.
|
|
110
|
+
*/
|
|
111
|
+
readonly pow: (x: WithSmallInt<NonNegativeInt32, 40>, y: WithSmallInt<NonNegativeInt32, 40>) => NonNegativeInt32;
|
|
112
|
+
/**
|
|
113
|
+
* Adds two NonNegativeInt32 values.
|
|
114
|
+
* @param a The first NonNegativeInt32.
|
|
115
|
+
* @param b The second NonNegativeInt32.
|
|
116
|
+
* @returns `a + b` clamped to [0, 2147483647] as a NonNegativeInt32.
|
|
117
|
+
*/
|
|
118
|
+
readonly add: (x: WithSmallInt<NonNegativeInt32, 40>, y: WithSmallInt<NonNegativeInt32, 40>) => NonNegativeInt32;
|
|
119
|
+
/**
|
|
120
|
+
* Subtracts one NonNegativeInt32 from another.
|
|
121
|
+
* @param a The minuend NonNegativeInt32.
|
|
122
|
+
* @param b The subtrahend NonNegativeInt32.
|
|
123
|
+
* @returns `a - b` clamped to [0, 2147483647] as a NonNegativeInt32 (minimum 0).
|
|
124
|
+
*/
|
|
125
|
+
readonly sub: (x: WithSmallInt<NonNegativeInt32, 40>, y: WithSmallInt<NonNegativeInt32, 40>) => NonNegativeInt32;
|
|
126
|
+
/**
|
|
127
|
+
* Multiplies two NonNegativeInt32 values.
|
|
128
|
+
* @param a The first NonNegativeInt32.
|
|
129
|
+
* @param b The second NonNegativeInt32.
|
|
130
|
+
* @returns `a * b` clamped to [0, 2147483647] as a NonNegativeInt32.
|
|
131
|
+
*/
|
|
132
|
+
readonly mul: (x: WithSmallInt<NonNegativeInt32, 40>, y: WithSmallInt<NonNegativeInt32, 40>) => NonNegativeInt32;
|
|
133
|
+
/**
|
|
134
|
+
* Divides one NonNegativeInt32 by another using floor division.
|
|
135
|
+
* @param a The dividend NonNegativeInt32.
|
|
136
|
+
* @param b The divisor NonNegativeInt32.
|
|
137
|
+
* @returns `⌊a / b⌋` clamped to [0, 2147483647] as a NonNegativeInt32.
|
|
138
|
+
*/
|
|
139
|
+
readonly div: (x: WithSmallInt<NonNegativeInt32, 40>, y: 1 | 2 | 3 | 32 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 10 | 24 | 14 | 34 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 35 | 36 | 37 | 38 | 39 | NormalizeBrandUnion<number & {
|
|
140
|
+
readonly NaNValue: false;
|
|
141
|
+
readonly "!=0": true;
|
|
142
|
+
readonly "> -2^16": true;
|
|
143
|
+
readonly "> -2^32": true;
|
|
144
|
+
readonly ">= -2^15": true;
|
|
145
|
+
readonly ">= -2^31": true;
|
|
146
|
+
readonly ">=0": true;
|
|
147
|
+
readonly "< 2^31": true;
|
|
148
|
+
readonly "< 2^32": true;
|
|
149
|
+
readonly Finite: true;
|
|
150
|
+
readonly Int: true;
|
|
151
|
+
readonly SafeInt: true;
|
|
152
|
+
} & Readonly<{
|
|
153
|
+
'TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3': unknown;
|
|
154
|
+
}>>) => NonNegativeInt32;
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=non-negative-int32.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-negative-int32.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/non-negative-int32.mts"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,sCAAK,CAAC;AAErC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;MAAW,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,gBAAgB;IAC3B;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;;;;;;;;;;;;;;;;CAEK,CAAC"}
|