ts-data-forge 11.0.1 → 12.0.0
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 +2 -2
- package/dist/number/branded-types/int16.d.mts +12 -7
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +13 -8
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +12 -7
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +13 -8
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +13 -6
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +15 -8
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +11 -6
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +13 -8
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +13 -7
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +15 -9
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +11 -6
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +12 -7
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +13 -7
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +14 -8
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +13 -7
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +14 -8
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +11 -6
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +12 -7
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +11 -6
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +12 -7
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +14 -7
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +15 -8
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +13 -7
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +14 -8
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +13 -7
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +14 -8
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +13 -7
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +14 -8
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +13 -7
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +14 -8
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +13 -7
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +14 -8
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +13 -6
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +14 -7
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +13 -8
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +14 -9
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +13 -7
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +14 -8
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +13 -7
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +14 -8
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +16 -10
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +17 -11
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +13 -7
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +14 -8
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +13 -7
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +14 -8
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +15 -10
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +16 -11
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +12 -7
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +13 -8
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +14 -10
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +15 -11
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +12 -7
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +13 -8
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +12 -7
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +13 -8
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +12 -7
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +19 -14
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +12 -7
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +19 -14
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +9 -9
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +7 -7
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/package.json +1 -1
- package/src/number/branded-types/int16.mts +13 -8
- package/src/number/branded-types/int32.mts +13 -8
- package/src/number/branded-types/negative-finite-number.mts +15 -8
- package/src/number/branded-types/negative-finite-number.test.mts +4 -4
- package/src/number/branded-types/negative-int.mts +13 -8
- package/src/number/branded-types/negative-int.test.mts +5 -5
- package/src/number/branded-types/negative-safe-int.mts +15 -9
- package/src/number/branded-types/negative-safe-int.test.mts +4 -4
- package/src/number/branded-types/non-negative-finite-number.mts +12 -7
- package/src/number/branded-types/non-negative-int16.mts +14 -8
- package/src/number/branded-types/non-negative-int32.mts +14 -8
- package/src/number/branded-types/non-positive-finite-number.mts +12 -7
- package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
- package/src/number/branded-types/non-positive-int.mts +12 -7
- package/src/number/branded-types/non-positive-int.test.mts +7 -7
- package/src/number/branded-types/non-positive-safe-int.mts +15 -8
- package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
- package/src/number/branded-types/non-zero-int16.mts +14 -8
- package/src/number/branded-types/non-zero-int32.mts +14 -8
- package/src/number/branded-types/non-zero-safe-int.mts +14 -8
- package/src/number/branded-types/non-zero-uint16.mts +14 -8
- package/src/number/branded-types/non-zero-uint32.mts +14 -8
- package/src/number/branded-types/positive-finite-number.mts +14 -7
- package/src/number/branded-types/positive-int.mts +14 -9
- package/src/number/branded-types/positive-int16.mts +14 -8
- package/src/number/branded-types/positive-int32.mts +14 -8
- package/src/number/branded-types/positive-safe-int.mts +17 -11
- package/src/number/branded-types/positive-uint16.mts +14 -8
- package/src/number/branded-types/positive-uint32.mts +14 -8
- package/src/number/branded-types/safe-int.mts +16 -11
- package/src/number/branded-types/safe-uint.mts +13 -8
- package/src/number/branded-types/uint.mts +15 -11
- package/src/number/branded-types/uint16.mts +13 -8
- package/src/number/branded-types/uint32.mts +13 -8
- package/src/number/enum/int8.mts +20 -14
- package/src/number/enum/int8.test.mts +7 -4
- package/src/number/enum/uint8.mts +20 -14
- package/src/number/enum/uint8.test.mts +7 -4
- package/src/number/refined-number-utils.mts +22 -19
package/README.md
CHANGED
|
@@ -350,11 +350,11 @@ assert.isTrue(positiveInt === 10);
|
|
|
350
350
|
// Type-safe arithmetic with automatic clamping
|
|
351
351
|
const sum = Int16.add(int16, asInt16(2000)); // Int16 (3000)
|
|
352
352
|
|
|
353
|
-
const
|
|
353
|
+
const coerced = Int16.fromNumber(100_000); // Int16 (32767 - saturated to MAX_VALUE)
|
|
354
354
|
|
|
355
355
|
assert.isTrue(sum === 3000);
|
|
356
356
|
|
|
357
|
-
assert.isTrue(
|
|
357
|
+
assert.isTrue(coerced === 32_767);
|
|
358
358
|
|
|
359
359
|
// Safe division with non-zero types
|
|
360
360
|
const ratio = Num.divInt(asNonZeroInt(10), nonZeroInt); // No division by zero risk
|
|
@@ -52,11 +52,13 @@ export declare const Int16: {
|
|
|
52
52
|
*/
|
|
53
53
|
readonly is: (a: number) => a is TtfImported_Int16;
|
|
54
54
|
/**
|
|
55
|
-
* The smallest value representable as `Int16
|
|
55
|
+
* The smallest value representable as `Int16` (the lower saturation target of
|
|
56
|
+
* `fromNumber`).
|
|
56
57
|
*/
|
|
57
58
|
readonly MIN_VALUE: number;
|
|
58
59
|
/**
|
|
59
|
-
* The largest value representable as `Int16
|
|
60
|
+
* The largest value representable as `Int16` (the upper saturation target of
|
|
61
|
+
* `fromNumber`).
|
|
60
62
|
*/
|
|
61
63
|
readonly MAX_VALUE: number;
|
|
62
64
|
/**
|
|
@@ -83,13 +85,16 @@ export declare const Int16: {
|
|
|
83
85
|
*/
|
|
84
86
|
readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_Int16>[]) => TtfImported_Int16;
|
|
85
87
|
/**
|
|
86
|
-
*
|
|
87
|
-
* and
|
|
88
|
+
* Converts an arbitrary `number` into an `Int16`, rounding to the nearest
|
|
89
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
88
90
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
+
* Unlike `asInt16`, this is total: out-of-range inputs are clamped to the
|
|
92
|
+
* nearest representable `Int16` instead of throwing.
|
|
93
|
+
*
|
|
94
|
+
* @param value - The value to convert
|
|
95
|
+
* @returns The value as an `Int16`
|
|
91
96
|
*/
|
|
92
|
-
readonly
|
|
97
|
+
readonly fromNumber: (x: number) => TtfImported_Int16;
|
|
93
98
|
/**
|
|
94
99
|
* Generates a random `Int16` within the given range.
|
|
95
100
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIhE,MAAM,MAAM,KAAK,GAAG,iBAAiB,CAAC;AAgCtC;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,uCAAK,CAAC;AAE1B;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;MAAW,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,KAAK;IAChB;;;;;;OAMG;;IAGH;;
|
|
1
|
+
{"version":3,"file":"int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIhE,MAAM,MAAM,KAAK,GAAG,iBAAiB,CAAC;AAgCtC;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,uCAAK,CAAC;AAE1B;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;MAAW,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,KAAK;IAChB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;;;OAOG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -7,8 +7,8 @@ const {
|
|
|
7
7
|
abs,
|
|
8
8
|
add,
|
|
9
9
|
castType,
|
|
10
|
-
clamp,
|
|
11
10
|
div,
|
|
11
|
+
fromNumber,
|
|
12
12
|
is,
|
|
13
13
|
max: max_,
|
|
14
14
|
min: min_,
|
|
@@ -34,11 +34,13 @@ const Int16 = {
|
|
|
34
34
|
*/
|
|
35
35
|
is,
|
|
36
36
|
/**
|
|
37
|
-
* The smallest value representable as `Int16
|
|
37
|
+
* The smallest value representable as `Int16` (the lower saturation target of
|
|
38
|
+
* `fromNumber`).
|
|
38
39
|
*/
|
|
39
40
|
MIN_VALUE,
|
|
40
41
|
/**
|
|
41
|
-
* The largest value representable as `Int16
|
|
42
|
+
* The largest value representable as `Int16` (the upper saturation target of
|
|
43
|
+
* `fromNumber`).
|
|
42
44
|
*/
|
|
43
45
|
MAX_VALUE,
|
|
44
46
|
/**
|
|
@@ -65,13 +67,16 @@ const Int16 = {
|
|
|
65
67
|
*/
|
|
66
68
|
max: max_,
|
|
67
69
|
/**
|
|
68
|
-
*
|
|
69
|
-
* and
|
|
70
|
+
* Converts an arbitrary `number` into an `Int16`, rounding to the nearest
|
|
71
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
70
72
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
+
* Unlike `asInt16`, this is total: out-of-range inputs are clamped to the
|
|
74
|
+
* nearest representable `Int16` instead of throwing.
|
|
75
|
+
*
|
|
76
|
+
* @param value - The value to convert
|
|
77
|
+
* @returns The value as an `Int16`
|
|
73
78
|
*/
|
|
74
|
-
|
|
79
|
+
fromNumber,
|
|
75
80
|
/**
|
|
76
81
|
* Generates a random `Int16` within the given range.
|
|
77
82
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int16.mjs","sources":["../../../src/number/branded-types/int16.mts"],"sourcesContent":["import { type Int16 as TtfImported_Int16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int16 = TtfImported_Int16;\n\ntype ElementType = Int16;\n\nconst typeNameInMessage = 'an integer in [-2^15, 2^15)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n abs,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"int16.mjs","sources":["../../../src/number/branded-types/int16.mts"],"sourcesContent":["import { type Int16 as TtfImported_Int16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int16 = TtfImported_Int16;\n\ntype ElementType = Int16;\n\nconst typeNameInMessage = 'an integer in [-2^15, 2^15)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n abs,\n add,\n castType,\n div,\n fromNumber,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: -(2 ** 15),\n MAX_VALUE: 2 ** 15 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is an integer in [-2^15, 2^15).\n *\n * Returns `true` for an integer in [-2^15, 2^15) — a value with no fractional\n * component.\n *\n * @param value - The value to check\n * @returns `true` if the value is an integer in [-2^15, 2^15), `false` otherwise\n */\nexport const isInt16 = is;\n\n/**\n * Casts a `number` to the `Int16` branded type.\n *\n * Validates that the value is an integer in [-2^15, 2^15) and returns it with\n * the `Int16` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as an `Int16`\n * @throws {TypeError} If the value is not an integer in [-2^15, 2^15)\n */\nexport const asInt16 = castType;\n\n/**\n * Namespace providing type-safe operations for the `Int16` branded type.\n *\n * The `Int16` type represents an integer in [-2^15, 2^15). Division (`div`)\n * uses floor division.\n */\nexport const Int16 = {\n /**\n * Type guard that checks if a value is an integer in [-2^15, 2^15).\n *\n * @param value - The value to check\n * @returns `true` if the value is an integer in [-2^15, 2^15), `false` otherwise\n * @see {@link isInt16} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Int16` (the lower saturation target of\n * `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `Int16` (the upper saturation target of\n * `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of an integer in [-2^15, 2^15).\n *\n * The result is non-negative and keeps the `Int16` brand.\n *\n * @param a - The integer value\n * @returns The absolute value as a non-negative `Int16`\n */\n abs,\n\n /**\n * Returns the smallest of the given integers.\n *\n * @param values - The integers to compare (at least one required)\n * @returns The smallest value as an `Int16`\n */\n min: min_,\n\n /**\n * Returns the largest of the given integers.\n *\n * @param values - The integers to compare (at least one required)\n * @returns The largest value as an `Int16`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into an `Int16`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asInt16`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Int16` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as an `Int16`\n */\n fromNumber,\n\n /**\n * Generates a random `Int16` 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 `Int16` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Int16` (floored to\n * an integer).\n *\n * @param a - The base integer\n * @param b - The exponent integer\n * @returns `a ** b` as an `Int16`\n */\n pow,\n\n /**\n * Adds two integers, returning `a + b` as an `Int16`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The sum of `a` and `b` as an `Int16`\n */\n add,\n\n /**\n * Subtracts two integers, returning `a - b` as an `Int16`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The difference of `a` and `b` as an `Int16`\n */\n sub,\n\n /**\n * Multiplies two integers, returning `a * b` as an `Int16`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The product of `a` and `b` as an `Int16`\n */\n mul,\n\n /**\n * Divides two integers using floor division (`⌊a / b⌋`): the result is `a /\n * b` rounded toward negative infinity, as an `Int16`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Int16`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Int16,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('=');\n\nexpectType<\n typeof Int16,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,6BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,MAAO;AAAA,EAClB,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,OAAA,GAAU;AAYhB,MAAM,OAAA,GAAU;AAQhB,MAAM,KAAA,GAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQnB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;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;AAAA;AAAA;AAAA,EAYL,UAAA;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,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
|
|
@@ -48,11 +48,13 @@ export declare const Int32: {
|
|
|
48
48
|
*/
|
|
49
49
|
readonly is: (a: number) => a is TtfImported_Int32;
|
|
50
50
|
/**
|
|
51
|
-
* The smallest value representable as `Int32
|
|
51
|
+
* The smallest value representable as `Int32` (the lower saturation target of
|
|
52
|
+
* `fromNumber`).
|
|
52
53
|
*/
|
|
53
54
|
readonly MIN_VALUE: number;
|
|
54
55
|
/**
|
|
55
|
-
* The largest value representable as `Int32
|
|
56
|
+
* The largest value representable as `Int32` (the upper saturation target of
|
|
57
|
+
* `fromNumber`).
|
|
56
58
|
*/
|
|
57
59
|
readonly MAX_VALUE: number;
|
|
58
60
|
/**
|
|
@@ -79,13 +81,16 @@ export declare const Int32: {
|
|
|
79
81
|
*/
|
|
80
82
|
readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_Int32>[]) => TtfImported_Int32;
|
|
81
83
|
/**
|
|
82
|
-
*
|
|
83
|
-
* and
|
|
84
|
+
* Converts an arbitrary `number` into an `Int32`, rounding to the nearest
|
|
85
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
84
86
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
+
* Unlike `asInt32`, this is total: out-of-range inputs are clamped to the
|
|
88
|
+
* nearest representable `Int32` instead of throwing.
|
|
89
|
+
*
|
|
90
|
+
* @param value - The value to convert
|
|
91
|
+
* @returns The value as an `Int32`
|
|
87
92
|
*/
|
|
88
|
-
readonly
|
|
93
|
+
readonly fromNumber: (x: number) => TtfImported_Int32;
|
|
89
94
|
/**
|
|
90
95
|
* Generates a random `Int32` within the given range.
|
|
91
96
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int32.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int32.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIhE,MAAM,MAAM,KAAK,GAAG,iBAAiB,CAAC;AAgCtC;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,uCAAK,CAAC;AAE1B;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;MAAW,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,KAAK;IAChB;;;;;;OAMG;;IAGH;;
|
|
1
|
+
{"version":3,"file":"int32.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int32.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIhE,MAAM,MAAM,KAAK,GAAG,iBAAiB,CAAC;AAgCtC;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,uCAAK,CAAC;AAE1B;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;MAAW,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,KAAK;IAChB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;;;OAOG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -7,8 +7,8 @@ const {
|
|
|
7
7
|
abs,
|
|
8
8
|
add,
|
|
9
9
|
castType,
|
|
10
|
-
clamp,
|
|
11
10
|
div,
|
|
11
|
+
fromNumber,
|
|
12
12
|
is,
|
|
13
13
|
max: max_,
|
|
14
14
|
min: min_,
|
|
@@ -34,11 +34,13 @@ const Int32 = {
|
|
|
34
34
|
*/
|
|
35
35
|
is,
|
|
36
36
|
/**
|
|
37
|
-
* The smallest value representable as `Int32
|
|
37
|
+
* The smallest value representable as `Int32` (the lower saturation target of
|
|
38
|
+
* `fromNumber`).
|
|
38
39
|
*/
|
|
39
40
|
MIN_VALUE,
|
|
40
41
|
/**
|
|
41
|
-
* The largest value representable as `Int32
|
|
42
|
+
* The largest value representable as `Int32` (the upper saturation target of
|
|
43
|
+
* `fromNumber`).
|
|
42
44
|
*/
|
|
43
45
|
MAX_VALUE,
|
|
44
46
|
/**
|
|
@@ -65,13 +67,16 @@ const Int32 = {
|
|
|
65
67
|
*/
|
|
66
68
|
max: max_,
|
|
67
69
|
/**
|
|
68
|
-
*
|
|
69
|
-
* and
|
|
70
|
+
* Converts an arbitrary `number` into an `Int32`, rounding to the nearest
|
|
71
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
70
72
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
+
* Unlike `asInt32`, this is total: out-of-range inputs are clamped to the
|
|
74
|
+
* nearest representable `Int32` instead of throwing.
|
|
75
|
+
*
|
|
76
|
+
* @param value - The value to convert
|
|
77
|
+
* @returns The value as an `Int32`
|
|
73
78
|
*/
|
|
74
|
-
|
|
79
|
+
fromNumber,
|
|
75
80
|
/**
|
|
76
81
|
* Generates a random `Int32` within the given range.
|
|
77
82
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int32.mjs","sources":["../../../src/number/branded-types/int32.mts"],"sourcesContent":["import { type Int32 as TtfImported_Int32 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int32 = TtfImported_Int32;\n\ntype ElementType = Int32;\n\nconst typeNameInMessage = 'an integer in [-2^31, 2^31)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n abs,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"int32.mjs","sources":["../../../src/number/branded-types/int32.mts"],"sourcesContent":["import { type Int32 as TtfImported_Int32 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int32 = TtfImported_Int32;\n\ntype ElementType = Int32;\n\nconst typeNameInMessage = 'an integer in [-2^31, 2^31)';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n abs,\n add,\n castType,\n div,\n fromNumber,\n is,\n max: max_,\n min: min_,\n mul,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: -(2 ** 31),\n MAX_VALUE: 2 ** 31 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is an integer in [-2^31, 2^31).\n *\n * Returns `true` for an integer in [-2^31, 2^31) — a value with no fractional\n * component.\n *\n * @param value - The value to check\n * @returns `true` if the value is an integer in [-2^31, 2^31), `false` otherwise\n */\nexport const isInt32 = is;\n\n/**\n * Casts a `number` to the `Int32` branded type.\n *\n * Validates that the value is an integer in [-2^31, 2^31) and returns it with\n * the `Int32` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as an `Int32`\n * @throws {TypeError} If the value is not an integer in [-2^31, 2^31)\n */\nexport const asInt32 = castType;\n\n/**\n * Namespace providing type-safe operations for the `Int32` branded type.\n *\n * The `Int32` type represents an integer in [-2^31, 2^31). Division (`div`)\n * uses floor division.\n */\nexport const Int32 = {\n /**\n * Type guard that checks if a value is an integer in [-2^31, 2^31).\n *\n * @param value - The value to check\n * @returns `true` if the value is an integer in [-2^31, 2^31), `false` otherwise\n * @see {@link isInt32} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Int32` (the lower saturation target of\n * `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `Int32` (the upper saturation target of\n * `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of an integer in [-2^31, 2^31).\n *\n * The result is non-negative and keeps the `Int32` brand.\n *\n * @param a - The integer value\n * @returns The absolute value as a non-negative `Int32`\n */\n abs,\n\n /**\n * Returns the smallest of the given integers.\n *\n * @param values - The integers to compare (at least one required)\n * @returns The smallest value as an `Int32`\n */\n min: min_,\n\n /**\n * Returns the largest of the given integers.\n *\n * @param values - The integers to compare (at least one required)\n * @returns The largest value as an `Int32`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into an `Int32`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asInt32`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Int32` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as an `Int32`\n */\n fromNumber,\n\n /**\n * Generates a random `Int32` 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 `Int32` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Int32` (floored to\n * an integer).\n *\n * @param a - The base integer\n * @param b - The exponent integer\n * @returns `a ** b` as an `Int32`\n */\n pow,\n\n /**\n * Adds two integers, returning `a + b` as an `Int32`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The sum of `a` and `b` as an `Int32`\n */\n add,\n\n /**\n * Subtracts two integers, returning `a - b` as an `Int32`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The difference of `a` and `b` as an `Int32`\n */\n sub,\n\n /**\n * Multiplies two integers, returning `a * b` as an `Int32`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The product of `a` and `b` as an `Int32`\n */\n mul,\n\n /**\n * Divides two integers using floor division (`⌊a / b⌋`): the result is `a /\n * b` rounded toward negative infinity, as an `Int32`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Int32`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Int32,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('=');\n\nexpectType<\n typeof Int32,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,6BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,GAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,mBAAA,CAI1C;AAAA,EACA,oBAAA,EAAsB,aAAA;AAAA,EACtB,SAAA,EAAW,WAAO;AAAA,EAClB,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,OAAA,GAAU;AAYhB,MAAM,OAAA,GAAU;AAQhB,MAAM,KAAA,GAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQnB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;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;AAAA;AAAA;AAAA,EAYL,UAAA;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,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
|
|
@@ -52,7 +52,10 @@ export declare const NegativeFiniteNumber: {
|
|
|
52
52
|
*/
|
|
53
53
|
readonly is: (a: number) => a is TtfImported_NegativeFiniteNumber;
|
|
54
54
|
/**
|
|
55
|
-
* The largest value representable as `NegativeFiniteNumber
|
|
55
|
+
* The largest value representable as `NegativeFiniteNumber` (the upper
|
|
56
|
+
* saturation target of `fromNumber`). The domain is open at `0` (excluded),
|
|
57
|
+
* so this is `-Number.MIN_VALUE` — the negative double closest to `0` —
|
|
58
|
+
* rather than `0`.
|
|
56
59
|
*/
|
|
57
60
|
readonly MAX_VALUE: number;
|
|
58
61
|
/**
|
|
@@ -79,13 +82,17 @@ export declare const NegativeFiniteNumber: {
|
|
|
79
82
|
*/
|
|
80
83
|
readonly max: (...values: readonly TtfImported_NegativeFiniteNumber[]) => TtfImported_NegativeFiniteNumber;
|
|
81
84
|
/**
|
|
82
|
-
*
|
|
83
|
-
* MAX_VALUE]`.
|
|
85
|
+
* Converts an arbitrary `number` into a `NegativeFiniteNumber`, saturating it
|
|
86
|
+
* into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
84
87
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
88
|
+
* Unlike `asNegativeFiniteNumber`, this is total: out-of-range inputs are
|
|
89
|
+
* clamped to the nearest representable `NegativeFiniteNumber` instead of
|
|
90
|
+
* throwing.
|
|
91
|
+
*
|
|
92
|
+
* @param value - The value to convert
|
|
93
|
+
* @returns The value as a `NegativeFiniteNumber`
|
|
87
94
|
*/
|
|
88
|
-
readonly
|
|
95
|
+
readonly fromNumber: (x: number) => TtfImported_NegativeFiniteNumber;
|
|
89
96
|
/**
|
|
90
97
|
* Returns the greatest integer less than or equal to a negative finite
|
|
91
98
|
* number.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negative-finite-number.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,IAAI,gCAAgC,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,MAAM,MAAM,oBAAoB,GAAG,gCAAgC,CAAC;AAEpE,KAAK,WAAW,GAAG,oBAAoB,CAAC;AAyDxC;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,sDAAK,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;MAAW,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;;;;;OAMG;;IAGH;;
|
|
1
|
+
{"version":3,"file":"negative-finite-number.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,IAAI,gCAAgC,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,MAAM,MAAM,oBAAoB,GAAG,gCAAgC,CAAC;AAEpE,KAAK,WAAW,GAAG,oBAAoB,CAAC;AAyDxC;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,sDAAK,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;MAAW,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;;;;;OAMG;;IAGH;;;;;OAKG;;IAGH;;;;;;;OAOG;sBArFW,WAAW,KAAG,oBAAoB;IAwFhD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;OAMG;wBAvHA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IAyH3D;;;;;;OAMG;uBA1HA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,qBAAqB,CAC9D,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAC3D;IA0HC;;;;;;OAMG;wBAzHA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,qBAAqB,CAC9D,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAC3D;IAyHC;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
|
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
MAX_VALUE,
|
|
7
7
|
add,
|
|
8
8
|
castType,
|
|
9
|
-
|
|
9
|
+
fromNumber,
|
|
10
10
|
is,
|
|
11
11
|
max: max_,
|
|
12
12
|
min: min_,
|
|
@@ -19,7 +19,7 @@ const {
|
|
|
19
19
|
MAX_VALUE: -Number.MIN_VALUE,
|
|
20
20
|
typeNameInMessage
|
|
21
21
|
});
|
|
22
|
-
const abs = (x) => PositiveFiniteNumber.
|
|
22
|
+
const abs = (x) => PositiveFiniteNumber.fromNumber(Math.abs(x));
|
|
23
23
|
const floor = (x) => (
|
|
24
24
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
25
25
|
Math.floor(x)
|
|
@@ -46,7 +46,10 @@ const NegativeFiniteNumber = {
|
|
|
46
46
|
*/
|
|
47
47
|
is,
|
|
48
48
|
/**
|
|
49
|
-
* The largest value representable as `NegativeFiniteNumber
|
|
49
|
+
* The largest value representable as `NegativeFiniteNumber` (the upper
|
|
50
|
+
* saturation target of `fromNumber`). The domain is open at `0` (excluded),
|
|
51
|
+
* so this is `-Number.MIN_VALUE` — the negative double closest to `0` —
|
|
52
|
+
* rather than `0`.
|
|
50
53
|
*/
|
|
51
54
|
MAX_VALUE,
|
|
52
55
|
/**
|
|
@@ -73,13 +76,17 @@ const NegativeFiniteNumber = {
|
|
|
73
76
|
*/
|
|
74
77
|
max: max_,
|
|
75
78
|
/**
|
|
76
|
-
*
|
|
77
|
-
* MAX_VALUE]`.
|
|
79
|
+
* Converts an arbitrary `number` into a `NegativeFiniteNumber`, saturating it
|
|
80
|
+
* into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
78
81
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
82
|
+
* Unlike `asNegativeFiniteNumber`, this is total: out-of-range inputs are
|
|
83
|
+
* clamped to the nearest representable `NegativeFiniteNumber` instead of
|
|
84
|
+
* throwing.
|
|
85
|
+
*
|
|
86
|
+
* @param value - The value to convert
|
|
87
|
+
* @returns The value as a `NegativeFiniteNumber`
|
|
81
88
|
*/
|
|
82
|
-
|
|
89
|
+
fromNumber,
|
|
83
90
|
/**
|
|
84
91
|
* Returns the greatest integer less than or equal to a negative finite
|
|
85
92
|
* number.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negative-finite-number.mjs","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"sourcesContent":["import { type NegativeFiniteNumber as TtfImported_NegativeFiniteNumber } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveFiniteNumber } from './positive-finite-number.mjs';\n\nexport type NegativeFiniteNumber = TtfImported_NegativeFiniteNumber;\n\ntype ElementType = NegativeFiniteNumber;\n\nconst typeNameInMessage = 'a negative finite number';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"negative-finite-number.mjs","sources":["../../../src/number/branded-types/negative-finite-number.mts"],"sourcesContent":["import { type NegativeFiniteNumber as TtfImported_NegativeFiniteNumber } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveFiniteNumber } from './positive-finite-number.mjs';\n\nexport type NegativeFiniteNumber = TtfImported_NegativeFiniteNumber;\n\ntype ElementType = NegativeFiniteNumber;\n\nconst typeNameInMessage = 'a negative finite number';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<\n ElementType,\n number,\n number\n>({\n nonZero: true,\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: -Number.MIN_VALUE,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: ElementType): PositiveFiniteNumber =>\n PositiveFiniteNumber.fromNumber(Math.abs(x));\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(x) as TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\n/**\n * Type guard that checks if a value is a negative finite number.\n *\n * Returns `true` only for a finite value — never `NaN`, `Infinity`, or\n * `-Infinity`.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative finite number, `false` otherwise\n */\nexport const isNegativeFiniteNumber = is;\n\n/**\n * Casts a `number` to the `NegativeFiniteNumber` branded type.\n *\n * Validates that the value is a negative finite number and returns it with the\n * `NegativeFiniteNumber` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeFiniteNumber`\n * @throws {TypeError} If the value is not a negative finite number\n */\nexport const asNegativeFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeFiniteNumber`\n * branded type.\n *\n * The `NegativeFiniteNumber` type represents a negative finite number.\n */\nexport const NegativeFiniteNumber = {\n /**\n * Type guard that checks if a value is a negative finite number.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative finite number, `false` otherwise\n * @see {@link isNegativeFiniteNumber} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NegativeFiniteNumber` (the upper\n * saturation target of `fromNumber`). The domain is open at `0` (excluded),\n * so this is `-Number.MIN_VALUE` — the negative double closest to `0` —\n * rather than `0`.\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative finite number.\n *\n * The result is non-negative and keeps the `NegativeFiniteNumber` brand.\n *\n * @param a - The negative finite number value\n * @returns The absolute value as a non-negative `NegativeFiniteNumber`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative finite numbers.\n *\n * @param values - The negative finite numbers to compare (at least one required)\n * @returns The smallest value as a `NegativeFiniteNumber`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative finite numbers.\n *\n * @param values - The negative finite numbers to compare (at least one required)\n * @returns The largest value as a `NegativeFiniteNumber`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NegativeFiniteNumber`, saturating it\n * into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asNegativeFiniteNumber`, this is total: out-of-range inputs are\n * clamped to the nearest representable `NegativeFiniteNumber` instead of\n * throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NegativeFiniteNumber`\n */\n fromNumber,\n\n /**\n * Returns the greatest integer less than or equal to a negative finite\n * number.\n *\n * @param a - The negative finite number value\n * @returns The floored value as an integer\n */\n floor,\n\n /**\n * Returns the smallest integer greater than or equal to a negative finite\n * number.\n *\n * @param a - The negative finite number value\n * @returns The ceiled value as an integer\n */\n ceil,\n\n /**\n * Returns the value of a negative finite number rounded to the nearest\n * integer.\n *\n * @param a - The negative finite number value\n * @returns The rounded value as an integer\n */\n round,\n\n /**\n * Generates a random `NegativeFiniteNumber` 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 `NegativeFiniteNumber` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The base negative finite number\n * @param b - The exponent negative finite number\n * @returns `a ** b` as a `NegativeFiniteNumber`\n */\n pow,\n\n /**\n * Adds two negative finite numbers, returning `a + b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The first negative finite number\n * @param b - The second negative finite number\n * @returns The sum of `a` and `b` as a `NegativeFiniteNumber`\n */\n add,\n\n /**\n * Subtracts two negative finite numbers, returning `a - b` as a\n * `NegativeFiniteNumber`.\n *\n * @param a - The first negative finite number\n * @param b - The second negative finite number\n * @returns The difference of `a` and `b` as a `NegativeFiniteNumber`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;;AAQA,MAAM,iBAAA,GAAoB,0BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;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,iBAAA,CAI1C;AAAA,EACA,OAAA,EAAS,IAAA;AAAA,EACT,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,oBAAA,CAAqB,WAAW,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAE7C,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAC;AAAA,CAAA;AAEd,MAAM,OAAO,CACX,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAK,CAAC;AAAA,CAAA;AAIb,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAaK,MAAM,sBAAA,GAAyB;AAY/B,MAAM,sBAAA,GAAyB;AAQ/B,MAAM,oBAAA,GAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlC,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;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;AAAA;AAAA;AAAA;AAAA,EAaL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,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;;;;"}
|
|
@@ -56,7 +56,8 @@ export declare const NegativeInt: {
|
|
|
56
56
|
*/
|
|
57
57
|
readonly is: (a: number) => a is TtfImported_NegativeInt;
|
|
58
58
|
/**
|
|
59
|
-
* The largest value representable as `NegativeInt
|
|
59
|
+
* The largest value representable as `NegativeInt` (the upper saturation
|
|
60
|
+
* target of `fromNumber`).
|
|
60
61
|
*/
|
|
61
62
|
readonly MAX_VALUE: -1;
|
|
62
63
|
/**
|
|
@@ -85,13 +86,17 @@ export declare const NegativeInt: {
|
|
|
85
86
|
*/
|
|
86
87
|
readonly max: (...values: readonly WithSmallInt<TtfImported_NegativeInt>[]) => TtfImported_NegativeInt;
|
|
87
88
|
/**
|
|
88
|
-
*
|
|
89
|
-
* integer and
|
|
89
|
+
* Converts an arbitrary `number` into a `NegativeInt`, rounding to the
|
|
90
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
91
|
+
* MAX_VALUE]`.
|
|
90
92
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
+
* Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to
|
|
94
|
+
* the nearest representable `NegativeInt` instead of throwing.
|
|
95
|
+
*
|
|
96
|
+
* @param value - The value to convert
|
|
97
|
+
* @returns The value as a `NegativeInt`
|
|
93
98
|
*/
|
|
94
|
-
readonly
|
|
99
|
+
readonly fromNumber: (x: number) => TtfImported_NegativeInt;
|
|
95
100
|
/**
|
|
96
101
|
* Generates a random `NegativeInt` within the given range.
|
|
97
102
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negative-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,IAAI,uBAAuB,EAC3C,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAElD,KAAK,WAAW,GAAG,WAAW,CAAC;AA8B/B;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,6CAAK,CAAC;AAEhC;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;MAAW,CAAC;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;OAMG;;IAGH;;
|
|
1
|
+
{"version":3,"file":"negative-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,IAAI,uBAAuB,EAC3C,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAElD,KAAK,WAAW,GAAG,WAAW,CAAC;AA8B/B;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,6CAAK,CAAC;AAEhC;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;MAAW,CAAC;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;;;;;;;OASG;sBA7DW,YAAY,CAAC,WAAW,CAAC,KAAG,WAAW;IAgErD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;CAEK,CAAC"}
|
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
MAX_VALUE,
|
|
7
7
|
add,
|
|
8
8
|
castType,
|
|
9
|
-
|
|
9
|
+
fromNumber,
|
|
10
10
|
is,
|
|
11
11
|
max: max_,
|
|
12
12
|
min: min_,
|
|
@@ -20,7 +20,7 @@ const {
|
|
|
20
20
|
MAX_VALUE: -1,
|
|
21
21
|
typeNameInMessage
|
|
22
22
|
});
|
|
23
|
-
const abs = (x) => PositiveInt.
|
|
23
|
+
const abs = (x) => PositiveInt.fromNumber(Math.abs(x));
|
|
24
24
|
const isNegativeInt = is;
|
|
25
25
|
const asNegativeInt = castType;
|
|
26
26
|
const NegativeInt = {
|
|
@@ -33,7 +33,8 @@ const NegativeInt = {
|
|
|
33
33
|
*/
|
|
34
34
|
is,
|
|
35
35
|
/**
|
|
36
|
-
* The largest value representable as `NegativeInt
|
|
36
|
+
* The largest value representable as `NegativeInt` (the upper saturation
|
|
37
|
+
* target of `fromNumber`).
|
|
37
38
|
*/
|
|
38
39
|
MAX_VALUE,
|
|
39
40
|
/**
|
|
@@ -62,13 +63,17 @@ const NegativeInt = {
|
|
|
62
63
|
*/
|
|
63
64
|
max: max_,
|
|
64
65
|
/**
|
|
65
|
-
*
|
|
66
|
-
* integer and
|
|
66
|
+
* Converts an arbitrary `number` into a `NegativeInt`, rounding to the
|
|
67
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
68
|
+
* MAX_VALUE]`.
|
|
67
69
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
+
* Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to
|
|
71
|
+
* the nearest representable `NegativeInt` instead of throwing.
|
|
72
|
+
*
|
|
73
|
+
* @param value - The value to convert
|
|
74
|
+
* @returns The value as a `NegativeInt`
|
|
70
75
|
*/
|
|
71
|
-
|
|
76
|
+
fromNumber,
|
|
72
77
|
/**
|
|
73
78
|
* Generates a random `NegativeInt` within the given range.
|
|
74
79
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negative-int.mjs","sources":["../../../src/number/branded-types/negative-int.mts"],"sourcesContent":["import {\n type NegativeInt as TtfImported_NegativeInt,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveInt } from './positive-int.mjs';\n\nexport type NegativeInt = TtfImported_NegativeInt;\n\ntype ElementType = NegativeInt;\n\nconst typeNameInMessage = 'a negative integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"negative-int.mjs","sources":["../../../src/number/branded-types/negative-int.mts"],"sourcesContent":["import {\n type NegativeInt as TtfImported_NegativeInt,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\nimport { PositiveInt } from './positive-int.mjs';\n\nexport type NegativeInt = TtfImported_NegativeInt;\n\ntype ElementType = NegativeInt;\n\nconst typeNameInMessage = 'a negative integer';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n ElementType,\n number,\n -1\n>({\n integerOrSafeInteger: 'Integer',\n nonZero: true,\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: -1,\n typeNameInMessage,\n} as const);\n\nconst abs = (x: WithSmallInt<ElementType>): PositiveInt =>\n PositiveInt.fromNumber(Math.abs(x));\n\n/**\n * Type guard that checks if a value is a negative integer.\n *\n * Returns `true` for a negative integer — a value with no fractional component,\n * including values outside the safe integer range (unlike `SafeInt`).\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative integer, `false` otherwise\n */\nexport const isNegativeInt = is;\n\n/**\n * Casts a `number` to the `NegativeInt` branded type.\n *\n * Validates that the value is a negative integer and returns it with the\n * `NegativeInt` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NegativeInt`\n * @throws {TypeError} If the value is not a negative integer\n */\nexport const asNegativeInt = castType;\n\n/**\n * Namespace providing type-safe operations for the `NegativeInt` branded type.\n *\n * The `NegativeInt` type represents a negative integer. Division (`div`) uses\n * floor division.\n *\n * Unlike `SafeInt`, `NegativeInt` allows values outside the safe integer range\n * (±2^53 − 1), so very large magnitudes may lose precision in JavaScript's\n * `number` type.\n */\nexport const NegativeInt = {\n /**\n * Type guard that checks if a value is a negative integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a negative integer, `false` otherwise\n * @see {@link isNegativeInt} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NegativeInt` (the upper saturation\n * target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the absolute value of a negative integer.\n *\n * The result is non-negative and keeps the `NegativeInt` brand. Note that\n * `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so\n * use `SafeInt` for guaranteed precision.\n *\n * @param a - The negative integer value\n * @returns The absolute value as a non-negative `NegativeInt`\n */\n abs,\n\n /**\n * Returns the smallest of the given negative integers.\n *\n * @param values - The negative integers to compare (at least one required)\n * @returns The smallest value as a `NegativeInt`\n */\n min: min_,\n\n /**\n * Returns the largest of the given negative integers.\n *\n * @param values - The negative integers to compare (at least one required)\n * @returns The largest value as a `NegativeInt`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NegativeInt`, rounding to the\n * nearest integer and saturating the result into the range `[MIN_VALUE,\n * MAX_VALUE]`.\n *\n * Unlike `asNegativeInt`, this is total: out-of-range inputs are clamped to\n * the nearest representable `NegativeInt` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NegativeInt`\n */\n fromNumber,\n\n /**\n * Generates a random `NegativeInt` 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 `NegativeInt` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `NegativeInt` (floored\n * to an integer).\n *\n * @param a - The base negative integer\n * @param b - The exponent negative integer\n * @returns `a ** b` as a `NegativeInt`\n */\n pow,\n\n /**\n * Adds two negative integers, returning `a + b` as a `NegativeInt`.\n *\n * @param a - The first negative integer\n * @param b - The second negative integer\n * @returns The sum of `a` and `b` as a `NegativeInt`\n */\n add,\n\n /**\n * Subtracts two negative integers, returning `a - b` as a `NegativeInt`.\n *\n * @param a - The first negative integer\n * @param b - The second negative integer\n * @returns The difference of `a` and `b` as a `NegativeInt`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;;AAWA,MAAM,iBAAA,GAAoB,oBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;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,OAAA,EAAS,IAAA;AAAA,EACT,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,EAAA;AAAA,EACX;AACF,CAAU,CAAA;AAEV,MAAM,GAAA,GAAM,CAAC,CAAA,KACX,WAAA,CAAY,WAAW,IAAA,CAAK,GAAA,CAAI,CAAC,CAAC,CAAA;AAW7B,MAAM,aAAA,GAAgB;AAYtB,MAAM,aAAA,GAAgB;AAYtB,MAAM,WAAA,GAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,GAAA;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;AAAA;AAAA;AAAA;AAAA,EAaL,UAAA;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,EASA;AACF;;;;"}
|
|
@@ -54,11 +54,13 @@ export declare const NegativeSafeInt: {
|
|
|
54
54
|
*/
|
|
55
55
|
readonly is: (a: number) => a is TtfImported_NegativeSafeInt;
|
|
56
56
|
/**
|
|
57
|
-
* The smallest value representable as `NegativeSafeInt
|
|
57
|
+
* The smallest value representable as `NegativeSafeInt` (the lower saturation
|
|
58
|
+
* target of `fromNumber`).
|
|
58
59
|
*/
|
|
59
60
|
readonly MIN_VALUE: number;
|
|
60
61
|
/**
|
|
61
|
-
* The largest value representable as `NegativeSafeInt
|
|
62
|
+
* The largest value representable as `NegativeSafeInt` (the upper saturation
|
|
63
|
+
* target of `fromNumber`).
|
|
62
64
|
*/
|
|
63
65
|
readonly MAX_VALUE: -1;
|
|
64
66
|
/**
|
|
@@ -85,13 +87,17 @@ export declare const NegativeSafeInt: {
|
|
|
85
87
|
*/
|
|
86
88
|
readonly max: (...values: readonly WithSmallInt<TtfImported_NegativeSafeInt>[]) => TtfImported_NegativeSafeInt;
|
|
87
89
|
/**
|
|
88
|
-
*
|
|
89
|
-
* integer and
|
|
90
|
+
* Converts an arbitrary `number` into a `NegativeSafeInt`, rounding to the
|
|
91
|
+
* nearest integer and saturating the result into the range `[MIN_VALUE,
|
|
92
|
+
* MAX_VALUE]`.
|
|
90
93
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
94
|
+
* Unlike `asNegativeSafeInt`, this is total: out-of-range inputs are clamped
|
|
95
|
+
* to the nearest representable `NegativeSafeInt` instead of throwing.
|
|
96
|
+
*
|
|
97
|
+
* @param value - The value to convert
|
|
98
|
+
* @returns The value as a `NegativeSafeInt`
|
|
93
99
|
*/
|
|
94
|
-
readonly
|
|
100
|
+
readonly fromNumber: (x: number) => TtfImported_NegativeSafeInt;
|
|
95
101
|
/**
|
|
96
102
|
* Generates a random `NegativeSafeInt` within the given range.
|
|
97
103
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"negative-safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,IAAI,2BAA2B,EACnD,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAE1D,KAAK,WAAW,GAAG,eAAe,CAAC;AA+BnC;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,iDAAK,CAAC;AAEpC;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;MAAW,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;;OAMG;;IAGH;;
|
|
1
|
+
{"version":3,"file":"negative-safe-int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/negative-safe-int.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,IAAI,2BAA2B,EACnD,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAE1D,KAAK,WAAW,GAAG,eAAe,CAAC;AA+BnC;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,iDAAK,CAAC;AAEpC;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;MAAW,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;;;OAOG;sBA9DW,YAAY,CAAC,WAAW,CAAC,KAAG,eAAe;IAiEzD;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;CAEK,CAAC"}
|