ts-data-forge 11.0.1 → 12.1.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/array/impl/array-utils-length-bounded-array-cast.d.mts +65 -5
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +69 -27
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/index.mjs +1 -1
- 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/dist/string/str.d.mts +70 -5
- package/dist/string/str.d.mts.map +1 -1
- package/dist/string/str.mjs +72 -26
- package/dist/string/str.mjs.map +1 -1
- package/package.json +1 -1
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +204 -39
- package/src/array/impl/array-utils-length-bounded-array-cast.test.mts +126 -0
- 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/src/string/str.mts +201 -39
- package/src/string/str.test.mts +76 -0
|
@@ -6,8 +6,8 @@ const {
|
|
|
6
6
|
MIN_VALUE,
|
|
7
7
|
add,
|
|
8
8
|
castType,
|
|
9
|
-
clamp,
|
|
10
9
|
div,
|
|
10
|
+
fromNumber,
|
|
11
11
|
is,
|
|
12
12
|
max: max_,
|
|
13
13
|
min: min_,
|
|
@@ -34,11 +34,13 @@ const SafeUint = {
|
|
|
34
34
|
*/
|
|
35
35
|
is,
|
|
36
36
|
/**
|
|
37
|
-
* The smallest value representable as `SafeUint
|
|
37
|
+
* The smallest value representable as `SafeUint` (the lower saturation target
|
|
38
|
+
* of `fromNumber`).
|
|
38
39
|
*/
|
|
39
40
|
MIN_VALUE,
|
|
40
41
|
/**
|
|
41
|
-
* The largest value representable as `SafeUint
|
|
42
|
+
* The largest value representable as `SafeUint` (the upper saturation target
|
|
43
|
+
* of `fromNumber`).
|
|
42
44
|
*/
|
|
43
45
|
MAX_VALUE,
|
|
44
46
|
/**
|
|
@@ -56,13 +58,16 @@ const SafeUint = {
|
|
|
56
58
|
*/
|
|
57
59
|
max: max_,
|
|
58
60
|
/**
|
|
59
|
-
*
|
|
60
|
-
* integer and
|
|
61
|
+
* Converts an arbitrary `number` into a `SafeUint`, rounding to the nearest
|
|
62
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
61
63
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
+
* Unlike `asSafeUint`, this is total: out-of-range inputs are clamped to the
|
|
65
|
+
* nearest representable `SafeUint` instead of throwing.
|
|
66
|
+
*
|
|
67
|
+
* @param value - The value to convert
|
|
68
|
+
* @returns The value as a `SafeUint`
|
|
64
69
|
*/
|
|
65
|
-
|
|
70
|
+
fromNumber,
|
|
66
71
|
/**
|
|
67
72
|
* Generates a random `SafeUint` within the given range.
|
|
68
73
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-uint.mjs","sources":["../../../src/number/branded-types/safe-uint.mts"],"sourcesContent":["import { type SafeUint as TtfImported_SafeUint } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type SafeUint = TtfImported_SafeUint;\n\ntype ElementType = SafeUint;\n\nconst typeNameInMessage = 'a non-negative safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"safe-uint.mjs","sources":["../../../src/number/branded-types/safe-uint.mts"],"sourcesContent":["import { type SafeUint as TtfImported_SafeUint } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type SafeUint = TtfImported_SafeUint;\n\ntype ElementType = SafeUint;\n\nconst typeNameInMessage = 'a non-negative safe integer';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\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 0,\n SafeUint\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 0,\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer\n MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-negative safe integer.\n *\n * Returns `true` for a non-negative safe integer — a value with no fractional\n * component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative safe integer, `false` otherwise\n */\nexport const isSafeUint = is;\n\n/**\n * Casts a `number` to the `SafeUint` branded type.\n *\n * Validates that the value is a non-negative safe integer and returns it with\n * the `SafeUint` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `SafeUint`\n * @throws {TypeError} If the value is not a non-negative safe integer\n */\nexport const asSafeUint = castType;\n\n/**\n * Namespace providing type-safe operations for the `SafeUint` branded type.\n *\n * The `SafeUint` type represents a non-negative safe integer. Division (`div`)\n * uses floor division.\n */\nexport const SafeUint = {\n /**\n * Type guard that checks if a value is a non-negative safe integer.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative safe integer, `false` otherwise\n * @see {@link isSafeUint} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `SafeUint` (the lower saturation target\n * of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `SafeUint` (the upper saturation target\n * of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-negative safe integers.\n *\n * @param values - The non-negative safe integers to compare (at least one required)\n * @returns The smallest value as a `SafeUint`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-negative safe integers.\n *\n * @param values - The non-negative safe integers to compare (at least one required)\n * @returns The largest value as a `SafeUint`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `SafeUint`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asSafeUint`, this is total: out-of-range inputs are clamped to the\n * nearest representable `SafeUint` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `SafeUint`\n */\n fromNumber,\n\n /**\n * Generates a random `SafeUint` 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 `SafeUint` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a `SafeUint` (floored to\n * an integer).\n *\n * @param a - The base non-negative safe integer\n * @param b - The exponent non-negative safe integer\n * @returns `a ** b` as a `SafeUint`\n */\n pow,\n\n /**\n * Adds two non-negative safe integers, returning `a + b` as a `SafeUint`.\n *\n * @param a - The first non-negative safe integer\n * @param b - The second non-negative safe integer\n * @returns The sum of `a` and `b` as a `SafeUint`\n */\n add,\n\n /**\n * Subtracts two non-negative safe integers, returning `a - b` as a\n * `SafeUint`.\n *\n * @param a - The first non-negative safe integer\n * @param b - The second non-negative safe integer\n * @returns The difference of `a` and `b` as a `SafeUint`\n */\n sub,\n\n /**\n * Multiplies two non-negative safe integers, returning `a * b` as a\n * `SafeUint`.\n *\n * @param a - The first non-negative safe integer\n * @param b - The second non-negative safe integer\n * @returns The product of `a` and `b` as a `SafeUint`\n */\n mul,\n\n /**\n * Divides two non-negative safe integers using floor division (`⌊a / b⌋`):\n * the result is `a / b` rounded toward negative infinity, as a `SafeUint`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as a `SafeUint`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof SafeUint,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative' | 'range'\n >\n>('=');\n\nexpectType<\n typeof SafeUint,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,6BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;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,CAAA;AAAA;AAAA,EAEX,WAAW,MAAA,CAAO,gBAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAWH,MAAM,UAAA,GAAa;AAYnB,MAAM,UAAA,GAAa;AAQnB,MAAM,QAAA,GAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQtB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;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;;;;"}
|
|
@@ -83,7 +83,8 @@ export declare const Uint: {
|
|
|
83
83
|
*/
|
|
84
84
|
readonly is: (a: number) => a is import("ts-type-forge").NonNegativeInt;
|
|
85
85
|
/**
|
|
86
|
-
* The smallest value representable as `Uint
|
|
86
|
+
* The smallest value representable as `Uint` (the lower saturation target of
|
|
87
|
+
* `fromNumber`).
|
|
87
88
|
*/
|
|
88
89
|
readonly MIN_VALUE: 0;
|
|
89
90
|
/**
|
|
@@ -117,25 +118,28 @@ export declare const Uint: {
|
|
|
117
118
|
*/
|
|
118
119
|
readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<import("ts-type-forge").NonNegativeInt>[]) => import("ts-type-forge").NonNegativeInt;
|
|
119
120
|
/**
|
|
120
|
-
*
|
|
121
|
-
* and
|
|
121
|
+
* Converts an arbitrary `number` into an `Uint`, rounding to the nearest
|
|
122
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
123
|
+
*
|
|
124
|
+
* Unlike `asUint`, this is total: out-of-range inputs are clamped to the
|
|
125
|
+
* nearest representable `Uint` instead of throwing.
|
|
122
126
|
*
|
|
123
127
|
* @example
|
|
124
128
|
*
|
|
125
129
|
* ```ts
|
|
126
|
-
* const
|
|
130
|
+
* const fromNegative = Uint.fromNumber(-5);
|
|
127
131
|
*
|
|
128
|
-
* const
|
|
132
|
+
* const fromPositive = Uint.fromNumber(42);
|
|
129
133
|
*
|
|
130
|
-
* assert.isTrue(
|
|
134
|
+
* assert.isTrue(fromNegative === 0);
|
|
131
135
|
*
|
|
132
|
-
* assert.isTrue(
|
|
136
|
+
* assert.isTrue(fromPositive === 42);
|
|
133
137
|
* ```
|
|
134
138
|
*
|
|
135
|
-
* @param value - The value to
|
|
136
|
-
* @returns The
|
|
139
|
+
* @param value - The value to convert
|
|
140
|
+
* @returns The value as an `Uint`
|
|
137
141
|
*/
|
|
138
|
-
readonly
|
|
142
|
+
readonly fromNumber: (x: number) => import("ts-type-forge").NonNegativeInt;
|
|
139
143
|
/**
|
|
140
144
|
* Generates a random `Uint` within the given range.
|
|
141
145
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/uint.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,IAAI,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAI9D,MAAM,MAAM,IAAI,GAAG,gBAAgB,CAAC;AA8BpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM,4DAAK,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;MAAW,CAAC;AAE/B;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI;IACf;;;;;;;;;;;;;;;;OAgBG;;IAGH;;
|
|
1
|
+
{"version":3,"file":"uint.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/uint.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,IAAI,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAI9D,MAAM,MAAM,IAAI,GAAG,gBAAgB,CAAC;AA8BpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM,4DAAK,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;MAAW,CAAC;AAE/B;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI;IACf;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;OAGG;;IAGH;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;;;;;;OAaG;;IAGH;;;;;;;;;;;;;;;;;;;;;OAqBG;;IAGH;;;;;;;;;;;;;;;;;;;;;;OAsBG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;IAGH;;;;;;;;;;;;;;OAcG;;IAGH;;;;;;;;;;;;;;OAcG;;IAGH;;;;;;;;;;;;;;OAcG;;IAGH;;;;;;;;;;;;;;;OAeG;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -5,8 +5,8 @@ const {
|
|
|
5
5
|
MIN_VALUE,
|
|
6
6
|
add,
|
|
7
7
|
castType,
|
|
8
|
-
clamp,
|
|
9
8
|
div,
|
|
9
|
+
fromNumber,
|
|
10
10
|
is,
|
|
11
11
|
max: max_,
|
|
12
12
|
min: min_,
|
|
@@ -42,7 +42,8 @@ const Uint = {
|
|
|
42
42
|
*/
|
|
43
43
|
is,
|
|
44
44
|
/**
|
|
45
|
-
* The smallest value representable as `Uint
|
|
45
|
+
* The smallest value representable as `Uint` (the lower saturation target of
|
|
46
|
+
* `fromNumber`).
|
|
46
47
|
*/
|
|
47
48
|
MIN_VALUE,
|
|
48
49
|
/**
|
|
@@ -76,25 +77,28 @@ const Uint = {
|
|
|
76
77
|
*/
|
|
77
78
|
max: max_,
|
|
78
79
|
/**
|
|
79
|
-
*
|
|
80
|
-
* and
|
|
80
|
+
* Converts an arbitrary `number` into an `Uint`, rounding to the nearest
|
|
81
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
82
|
+
*
|
|
83
|
+
* Unlike `asUint`, this is total: out-of-range inputs are clamped to the
|
|
84
|
+
* nearest representable `Uint` instead of throwing.
|
|
81
85
|
*
|
|
82
86
|
* @example
|
|
83
87
|
*
|
|
84
88
|
* ```ts
|
|
85
|
-
* const
|
|
89
|
+
* const fromNegative = Uint.fromNumber(-5);
|
|
86
90
|
*
|
|
87
|
-
* const
|
|
91
|
+
* const fromPositive = Uint.fromNumber(42);
|
|
88
92
|
*
|
|
89
|
-
* assert.isTrue(
|
|
93
|
+
* assert.isTrue(fromNegative === 0);
|
|
90
94
|
*
|
|
91
|
-
* assert.isTrue(
|
|
95
|
+
* assert.isTrue(fromPositive === 42);
|
|
92
96
|
* ```
|
|
93
97
|
*
|
|
94
|
-
* @param value - The value to
|
|
95
|
-
* @returns The
|
|
98
|
+
* @param value - The value to convert
|
|
99
|
+
* @returns The value as an `Uint`
|
|
96
100
|
*/
|
|
97
|
-
|
|
101
|
+
fromNumber,
|
|
98
102
|
/**
|
|
99
103
|
* Generates a random `Uint` within the given range.
|
|
100
104
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint.mjs","sources":["../../../src/number/branded-types/uint.mts"],"sourcesContent":["import { type Uint as TtfImported_Uint } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint = TtfImported_Uint;\n\ntype ElementType = Uint;\n\nconst typeNameInMessage = 'a non-negative integer';\n\nconst {\n MIN_VALUE,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"uint.mjs","sources":["../../../src/number/branded-types/uint.mts"],"sourcesContent":["import { type Uint as TtfImported_Uint } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint = TtfImported_Uint;\n\ntype ElementType = Uint;\n\nconst typeNameInMessage = 'a non-negative integer';\n\nconst {\n MIN_VALUE,\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 0,\n number\n>({\n integerOrSafeInteger: 'Integer',\n MIN_VALUE: 0,\n MAX_VALUE: Number.MAX_VALUE,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-negative integer.\n *\n * Returns `true` for a non-negative integer — a value with no fractional\n * component, including values outside the safe integer range (unlike\n * `SafeInt`).\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isUint(4));\n *\n * assert.isFalse(isUint(-1));\n *\n * assert.isTrue(Uint.is(0));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer, `false` otherwise\n */\nexport const isUint = is;\n\n/**\n * Casts a `number` to the `Uint` branded type.\n *\n * Validates that the value is a non-negative integer and returns it with the\n * `Uint` brand. Throws a `TypeError` otherwise.\n *\n * @example\n *\n * ```ts\n * const branded = asUint(12);\n *\n * assert.isTrue(branded === 12);\n *\n * assert.isTrue(Uint.is(branded));\n * ```\n *\n * @param value - The value to cast\n * @returns The value as an `Uint`\n * @throws {TypeError} If the value is not a non-negative integer\n */\nexport const asUint = castType;\n\n/**\n * Namespace providing type-safe operations for the `Uint` branded type.\n *\n * The `Uint` type represents a non-negative integer. Division (`div`) uses\n * floor division.\n *\n * Unlike `SafeInt`, `Uint` allows values outside the safe integer range (±2^53\n * − 1), so very large magnitudes may lose precision in JavaScript's `number`\n * type.\n */\nexport const Uint = {\n /**\n * Type guard that checks if a value is a non-negative integer.\n *\n * @example\n *\n * ```ts\n * assert.isTrue(isUint(4));\n *\n * assert.isFalse(isUint(-1));\n *\n * assert.isTrue(Uint.is(0));\n * ```\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer, `false` otherwise\n * @see {@link isUint} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Uint` (the lower saturation target of\n * `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * Returns the smallest of the given non-negative integers.\n *\n * @example\n *\n * ```ts\n * const smallest = Uint.min(asUint(7), asUint(3));\n *\n * assert.isTrue(smallest === 3);\n * ```\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The smallest value as an `Uint`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-negative integers.\n *\n * @example\n *\n * ```ts\n * const largest = Uint.max(asUint(7), asUint(3));\n *\n * assert.isTrue(largest === 7);\n * ```\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The largest value as an `Uint`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into an `Uint`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asUint`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Uint` instead of throwing.\n *\n * @example\n *\n * ```ts\n * const fromNegative = Uint.fromNumber(-5);\n *\n * const fromPositive = Uint.fromNumber(42);\n *\n * assert.isTrue(fromNegative === 0);\n *\n * assert.isTrue(fromPositive === 42);\n * ```\n *\n * @param value - The value to convert\n * @returns The value as an `Uint`\n */\n fromNumber,\n\n /**\n * Generates a random `Uint` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @example\n *\n * ```ts\n * const min = asUint(0);\n *\n * const max = asUint(3);\n *\n * const randomValue = Uint.random(min, max);\n *\n * assert.isTrue(Uint.is(randomValue));\n *\n * assert.isTrue(randomValue >= 0 && randomValue <= 3);\n * ```\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `Uint` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Uint` (floored to an\n * integer).\n *\n * @example\n *\n * ```ts\n * const base = asUint(2);\n *\n * const exponent = asUint(5);\n *\n * const power = Uint.pow(base, exponent);\n *\n * assert.isTrue(power === 32);\n * ```\n *\n * @param a - The base non-negative integer\n * @param b - The exponent non-negative integer\n * @returns `a ** b` as an `Uint`\n */\n pow,\n\n /**\n * Adds two non-negative integers, returning `a + b` as an `Uint`.\n *\n * @example\n *\n * ```ts\n * const sum = Uint.add(asUint(5), asUint(8));\n *\n * assert.isTrue(sum === 13);\n * ```\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The sum of `a` and `b` as an `Uint`\n */\n add,\n\n /**\n * Subtracts two non-negative integers, returning `a - b` as an `Uint`.\n *\n * @example\n *\n * ```ts\n * const difference = Uint.sub(asUint(5), asUint(8));\n *\n * assert.isTrue(difference === 0);\n * ```\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The difference of `a` and `b` as an `Uint`\n */\n sub,\n\n /**\n * Multiplies two non-negative integers, returning `a * b` as an `Uint`.\n *\n * @example\n *\n * ```ts\n * const product = Uint.mul(asUint(7), asUint(6));\n *\n * assert.isTrue(product === 42);\n * ```\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The product of `a` and `b` as an `Uint`\n */\n mul,\n\n /**\n * Divides two non-negative integers using floor division (`⌊a / b⌋`): the\n * result is `a / b` rounded toward negative infinity, as an `Uint`.\n *\n * @example\n *\n * ```ts\n * const quotient = Uint.div(asUint(10), asUint(4));\n *\n * assert.isTrue(quotient === 2);\n * ```\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Uint`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Uint,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative'\n >\n>('=');\n\nexpectType<\n typeof Uint,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,wBAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;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,SAAA;AAAA,EACtB,SAAA,EAAW,CAAA;AAAA,EACX,WAAW,MAAA,CAAO,SAAA;AAAA,EAClB;AACF,CAAU,CAAA;AAsBH,MAAM,MAAA,GAAS;AAsBf,MAAM,MAAA,GAAS;AAYf,MAAM,IAAA,GAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBlB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwBL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA;AACF;;;;"}
|
|
@@ -52,11 +52,13 @@ export declare const Uint16: {
|
|
|
52
52
|
*/
|
|
53
53
|
readonly is: (a: number) => a is TtfImported_Uint16;
|
|
54
54
|
/**
|
|
55
|
-
* The smallest value representable as `Uint16
|
|
55
|
+
* The smallest value representable as `Uint16` (the lower saturation target
|
|
56
|
+
* of `fromNumber`).
|
|
56
57
|
*/
|
|
57
58
|
readonly MIN_VALUE: 0;
|
|
58
59
|
/**
|
|
59
|
-
* The largest value representable as `Uint16
|
|
60
|
+
* The largest value representable as `Uint16` (the upper saturation target of
|
|
61
|
+
* `fromNumber`).
|
|
60
62
|
*/
|
|
61
63
|
readonly MAX_VALUE: number;
|
|
62
64
|
/**
|
|
@@ -74,13 +76,16 @@ export declare const Uint16: {
|
|
|
74
76
|
*/
|
|
75
77
|
readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_Uint16>[]) => TtfImported_Uint16;
|
|
76
78
|
/**
|
|
77
|
-
*
|
|
78
|
-
* and
|
|
79
|
+
* Converts an arbitrary `number` into an `Uint16`, rounding to the nearest
|
|
80
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
79
81
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
+
* Unlike `asUint16`, this is total: out-of-range inputs are clamped to the
|
|
83
|
+
* nearest representable `Uint16` instead of throwing.
|
|
84
|
+
*
|
|
85
|
+
* @param value - The value to convert
|
|
86
|
+
* @returns The value as an `Uint16`
|
|
82
87
|
*/
|
|
83
|
-
readonly
|
|
88
|
+
readonly fromNumber: (x: number) => TtfImported_Uint16;
|
|
84
89
|
/**
|
|
85
90
|
* Generates a random `Uint16` within the given range.
|
|
86
91
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/uint16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,IAAI,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIlE,MAAM,MAAM,MAAM,GAAG,kBAAkB,CAAC;AA+BxC;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,wCAAK,CAAC;AAE3B;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;MAAW,CAAC;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,MAAM;IACjB;;;;;;OAMG;;IAGH;;
|
|
1
|
+
{"version":3,"file":"uint16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/uint16.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,IAAI,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIlE,MAAM,MAAM,MAAM,GAAG,kBAAkB,CAAC;AA+BxC;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,wCAAK,CAAC;AAE3B;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;MAAW,CAAC;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,MAAM;IACjB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -6,8 +6,8 @@ const {
|
|
|
6
6
|
MIN_VALUE,
|
|
7
7
|
add,
|
|
8
8
|
castType,
|
|
9
|
-
clamp,
|
|
10
9
|
div,
|
|
10
|
+
fromNumber,
|
|
11
11
|
is,
|
|
12
12
|
max: max_,
|
|
13
13
|
min: min_,
|
|
@@ -33,11 +33,13 @@ const Uint16 = {
|
|
|
33
33
|
*/
|
|
34
34
|
is,
|
|
35
35
|
/**
|
|
36
|
-
* The smallest value representable as `Uint16
|
|
36
|
+
* The smallest value representable as `Uint16` (the lower saturation target
|
|
37
|
+
* of `fromNumber`).
|
|
37
38
|
*/
|
|
38
39
|
MIN_VALUE,
|
|
39
40
|
/**
|
|
40
|
-
* The largest value representable as `Uint16
|
|
41
|
+
* The largest value representable as `Uint16` (the upper saturation target of
|
|
42
|
+
* `fromNumber`).
|
|
41
43
|
*/
|
|
42
44
|
MAX_VALUE,
|
|
43
45
|
/**
|
|
@@ -55,13 +57,16 @@ const Uint16 = {
|
|
|
55
57
|
*/
|
|
56
58
|
max: max_,
|
|
57
59
|
/**
|
|
58
|
-
*
|
|
59
|
-
* and
|
|
60
|
+
* Converts an arbitrary `number` into an `Uint16`, rounding to the nearest
|
|
61
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
60
62
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
+
* Unlike `asUint16`, this is total: out-of-range inputs are clamped to the
|
|
64
|
+
* nearest representable `Uint16` instead of throwing.
|
|
65
|
+
*
|
|
66
|
+
* @param value - The value to convert
|
|
67
|
+
* @returns The value as an `Uint16`
|
|
63
68
|
*/
|
|
64
|
-
|
|
69
|
+
fromNumber,
|
|
65
70
|
/**
|
|
66
71
|
* Generates a random `Uint16` within the given range.
|
|
67
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint16.mjs","sources":["../../../src/number/branded-types/uint16.mts"],"sourcesContent":["import { type Uint16 as TtfImported_Uint16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint16 = TtfImported_Uint16;\n\ntype ElementType = Uint16;\n\nconst typeNameInMessage = 'a non-negative integer less than 2^16';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"uint16.mjs","sources":["../../../src/number/branded-types/uint16.mts"],"sourcesContent":["import { type Uint16 as TtfImported_Uint16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint16 = TtfImported_Uint16;\n\ntype ElementType = Uint16;\n\nconst typeNameInMessage = 'a non-negative integer less than 2^16';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\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 0,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 0,\n MAX_VALUE: 2 ** 16 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-negative integer less than 2^16.\n *\n * Returns `true` for a non-negative integer less than 2^16 — a value with no\n * fractional component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer less than 2^16, `false` otherwise\n */\nexport const isUint16 = is;\n\n/**\n * Casts a `number` to the `Uint16` branded type.\n *\n * Validates that the value is a non-negative integer less than 2^16 and returns\n * it with the `Uint16` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as an `Uint16`\n * @throws {TypeError} If the value is not a non-negative integer less than 2^16\n */\nexport const asUint16 = castType;\n\n/**\n * Namespace providing type-safe operations for the `Uint16` branded type.\n *\n * The `Uint16` type represents a non-negative integer less than 2^16. Division\n * (`div`) uses floor division.\n */\nexport const Uint16 = {\n /**\n * Type guard that checks if a value is a non-negative integer less than 2^16.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer less than 2^16, `false` otherwise\n * @see {@link isUint16} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Uint16` (the lower saturation target\n * of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `Uint16` (the upper saturation target of\n * `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-negative integers.\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The smallest value as an `Uint16`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-negative integers.\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The largest value as an `Uint16`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into an `Uint16`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asUint16`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Uint16` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as an `Uint16`\n */\n fromNumber,\n\n /**\n * Generates a random `Uint16` 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 `Uint16` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Uint16` (floored to\n * an integer).\n *\n * @param a - The base non-negative integer\n * @param b - The exponent non-negative integer\n * @returns `a ** b` as an `Uint16`\n */\n pow,\n\n /**\n * Adds two non-negative integers, returning `a + b` as an `Uint16`.\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The sum of `a` and `b` as an `Uint16`\n */\n add,\n\n /**\n * Subtracts two non-negative integers, returning `a - b` as an `Uint16`.\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The difference of `a` and `b` as an `Uint16`\n */\n sub,\n\n /**\n * Multiplies two non-negative integers, returning `a * b` as an `Uint16`.\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The product of `a` and `b` as an `Uint16`\n */\n mul,\n\n /**\n * Divides two non-negative integers using floor division (`⌊a / b⌋`): the\n * result is `a / b` rounded toward negative infinity, as an `Uint16`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Uint16`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Uint16,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative' | 'range'\n >\n>('=');\n\nexpectType<\n typeof Uint16,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,uCAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;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,CAAA;AAAA,EACX,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,QAAA,GAAW;AAYjB,MAAM,QAAA,GAAW;AAQjB,MAAM,MAAA,GAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;;;;"}
|
|
@@ -50,11 +50,13 @@ export declare const Uint32: {
|
|
|
50
50
|
*/
|
|
51
51
|
readonly is: (a: number) => a is TtfImported_Uint32;
|
|
52
52
|
/**
|
|
53
|
-
* The smallest value representable as `Uint32
|
|
53
|
+
* The smallest value representable as `Uint32` (the lower saturation target
|
|
54
|
+
* of `fromNumber`).
|
|
54
55
|
*/
|
|
55
56
|
readonly MIN_VALUE: 0;
|
|
56
57
|
/**
|
|
57
|
-
* The largest value representable as `Uint32
|
|
58
|
+
* The largest value representable as `Uint32` (the upper saturation target of
|
|
59
|
+
* `fromNumber`).
|
|
58
60
|
*/
|
|
59
61
|
readonly MAX_VALUE: number;
|
|
60
62
|
/**
|
|
@@ -72,13 +74,16 @@ export declare const Uint32: {
|
|
|
72
74
|
*/
|
|
73
75
|
readonly max: (...values: readonly import("ts-type-forge").WithSmallInt<TtfImported_Uint32>[]) => TtfImported_Uint32;
|
|
74
76
|
/**
|
|
75
|
-
*
|
|
76
|
-
* and
|
|
77
|
+
* Converts an arbitrary `number` into an `Uint32`, rounding to the nearest
|
|
78
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
77
79
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
+
* Unlike `asUint32`, this is total: out-of-range inputs are clamped to the
|
|
81
|
+
* nearest representable `Uint32` instead of throwing.
|
|
82
|
+
*
|
|
83
|
+
* @param value - The value to convert
|
|
84
|
+
* @returns The value as an `Uint32`
|
|
80
85
|
*/
|
|
81
|
-
readonly
|
|
86
|
+
readonly fromNumber: (x: number) => TtfImported_Uint32;
|
|
82
87
|
/**
|
|
83
88
|
* Generates a random `Uint32` within the given range.
|
|
84
89
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint32.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/uint32.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,IAAI,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIlE,MAAM,MAAM,MAAM,GAAG,kBAAkB,CAAC;AA+BxC;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,wCAAK,CAAC;AAE3B;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;MAAW,CAAC;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,MAAM;IACjB;;;;;;OAMG;;IAGH;;
|
|
1
|
+
{"version":3,"file":"uint32.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/uint32.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,IAAI,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIlE,MAAM,MAAM,MAAM,GAAG,kBAAkB,CAAC;AA+BxC;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,wCAAK,CAAC;AAE3B;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;MAAW,CAAC;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,MAAM;IACjB;;;;;;OAMG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;OAOG;;;;;;;;;;;;;;;;CAEK,CAAC"}
|
|
@@ -6,8 +6,8 @@ const {
|
|
|
6
6
|
MIN_VALUE,
|
|
7
7
|
add,
|
|
8
8
|
castType,
|
|
9
|
-
clamp,
|
|
10
9
|
div,
|
|
10
|
+
fromNumber,
|
|
11
11
|
is,
|
|
12
12
|
max: max_,
|
|
13
13
|
min: min_,
|
|
@@ -33,11 +33,13 @@ const Uint32 = {
|
|
|
33
33
|
*/
|
|
34
34
|
is,
|
|
35
35
|
/**
|
|
36
|
-
* The smallest value representable as `Uint32
|
|
36
|
+
* The smallest value representable as `Uint32` (the lower saturation target
|
|
37
|
+
* of `fromNumber`).
|
|
37
38
|
*/
|
|
38
39
|
MIN_VALUE,
|
|
39
40
|
/**
|
|
40
|
-
* The largest value representable as `Uint32
|
|
41
|
+
* The largest value representable as `Uint32` (the upper saturation target of
|
|
42
|
+
* `fromNumber`).
|
|
41
43
|
*/
|
|
42
44
|
MAX_VALUE,
|
|
43
45
|
/**
|
|
@@ -55,13 +57,16 @@ const Uint32 = {
|
|
|
55
57
|
*/
|
|
56
58
|
max: max_,
|
|
57
59
|
/**
|
|
58
|
-
*
|
|
59
|
-
* and
|
|
60
|
+
* Converts an arbitrary `number` into an `Uint32`, rounding to the nearest
|
|
61
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
60
62
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
+
* Unlike `asUint32`, this is total: out-of-range inputs are clamped to the
|
|
64
|
+
* nearest representable `Uint32` instead of throwing.
|
|
65
|
+
*
|
|
66
|
+
* @param value - The value to convert
|
|
67
|
+
* @returns The value as an `Uint32`
|
|
63
68
|
*/
|
|
64
|
-
|
|
69
|
+
fromNumber,
|
|
65
70
|
/**
|
|
66
71
|
* Generates a random `Uint32` within the given range.
|
|
67
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint32.mjs","sources":["../../../src/number/branded-types/uint32.mts"],"sourcesContent":["import { type Uint32 as TtfImported_Uint32 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint32 = TtfImported_Uint32;\n\ntype ElementType = Uint32;\n\nconst typeNameInMessage = 'a non-negative integer less than 2^32';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n add,\n castType,\n
|
|
1
|
+
{"version":3,"file":"uint32.mjs","sources":["../../../src/number/branded-types/uint32.mts"],"sourcesContent":["import { type Uint32 as TtfImported_Uint32 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint32 = TtfImported_Uint32;\n\ntype ElementType = Uint32;\n\nconst typeNameInMessage = 'a non-negative integer less than 2^32';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\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 0,\n number\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 0,\n MAX_VALUE: 2 ** 32 - 1,\n typeNameInMessage,\n} as const);\n\n/**\n * Type guard that checks if a value is a non-negative integer less than 2^32.\n *\n * Returns `true` for a non-negative integer less than 2^32 — a value with no\n * fractional component.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer less than 2^32, `false` otherwise\n */\nexport const isUint32 = is;\n\n/**\n * Casts a `number` to the `Uint32` branded type.\n *\n * Validates that the value is a non-negative integer less than 2^32 and returns\n * it with the `Uint32` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as an `Uint32`\n * @throws {TypeError} If the value is not a non-negative integer less than 2^32\n */\nexport const asUint32 = castType;\n\n/**\n * Namespace providing type-safe operations for the `Uint32` branded type.\n *\n * The `Uint32` type represents a non-negative integer less than 2^32. Division\n * (`div`) uses floor division.\n */\nexport const Uint32 = {\n /**\n * Type guard that checks if a value is a non-negative integer less than 2^32.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-negative integer less than 2^32, `false` otherwise\n * @see {@link isUint32} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Uint32` (the lower saturation target\n * of `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `Uint32` (the upper saturation target of\n * `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-negative integers.\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The smallest value as an `Uint32`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-negative integers.\n *\n * @param values - The non-negative integers to compare (at least one required)\n * @returns The largest value as an `Uint32`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into an `Uint32`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asUint32`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Uint32` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as an `Uint32`\n */\n fromNumber,\n\n /**\n * Generates a random `Uint32` 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 `Uint32` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Uint32` (floored to\n * an integer).\n *\n * @param a - The base non-negative integer\n * @param b - The exponent non-negative integer\n * @returns `a ** b` as an `Uint32`\n */\n pow,\n\n /**\n * Adds two non-negative integers, returning `a + b` as an `Uint32`.\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The sum of `a` and `b` as an `Uint32`\n */\n add,\n\n /**\n * Subtracts two non-negative integers, returning `a - b` as an `Uint32`.\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The difference of `a` and `b` as an `Uint32`\n */\n sub,\n\n /**\n * Multiplies two non-negative integers, returning `a * b` as an `Uint32`.\n *\n * @param a - The first non-negative integer\n * @param b - The second non-negative integer\n * @returns The product of `a` and `b` as an `Uint32`\n */\n mul,\n\n /**\n * Divides two non-negative integers using floor division (`⌊a / b⌋`): the\n * result is `a / b` rounded toward negative infinity, as an `Uint32`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Uint32`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Uint32,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative' | 'range'\n >\n>('=');\n\nexpectType<\n typeof Uint32,\n TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n ElementType,\n 'int' | 'non-negative' | 'range'\n >\n>('<=');\n"],"names":[],"mappings":";;AAQA,MAAM,iBAAA,GAAoB,uCAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,SAAA;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,CAAA;AAAA,EACX,SAAA,EAAW,KAAK,EAAA,GAAK,CAAA;AAAA,EACrB;AACF,CAAU,CAAA;AAWH,MAAM,QAAA,GAAW;AAYjB,MAAM,QAAA,GAAW;AAQjB,MAAM,MAAA,GAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;;;;"}
|
|
@@ -37,11 +37,13 @@ export declare const Int8: {
|
|
|
37
37
|
*/
|
|
38
38
|
readonly is: (x: number) => x is Int8;
|
|
39
39
|
/**
|
|
40
|
-
* The smallest value representable as `Int8
|
|
40
|
+
* The smallest value representable as `Int8` (the lower saturation target of
|
|
41
|
+
* `fromNumber`).
|
|
41
42
|
*/
|
|
42
43
|
readonly MIN_VALUE: -128;
|
|
43
44
|
/**
|
|
44
|
-
* The largest value representable as `Int8
|
|
45
|
+
* The largest value representable as `Int8` (the upper saturation target of
|
|
46
|
+
* `fromNumber`).
|
|
45
47
|
*/
|
|
46
48
|
readonly MAX_VALUE: 127;
|
|
47
49
|
/**
|
|
@@ -59,13 +61,16 @@ export declare const Int8: {
|
|
|
59
61
|
*/
|
|
60
62
|
readonly max: (...values: readonly Int8[]) => Int8;
|
|
61
63
|
/**
|
|
62
|
-
*
|
|
63
|
-
* and
|
|
64
|
+
* Converts an arbitrary `number` into an `Int8`, rounding to the nearest
|
|
65
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
64
66
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
+
* Unlike `asInt8`, this is total: out-of-range inputs are clamped to the
|
|
68
|
+
* nearest representable `Int8` instead of throwing.
|
|
69
|
+
*
|
|
70
|
+
* @param value - The value to convert
|
|
71
|
+
* @returns The value as an `Int8`
|
|
67
72
|
*/
|
|
68
|
-
readonly
|
|
73
|
+
readonly fromNumber: (a: number) => Int8;
|
|
69
74
|
/**
|
|
70
75
|
* Returns the absolute value of an integer in [-128, 127].
|
|
71
76
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int8.d.mts","sourceRoot":"","sources":["../../../src/number/enum/int8.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,IAAI,IAAI,gBAAgB,EAC9B,MAAM,eAAe,CAAC;AAIvB,MAAM,MAAM,IAAI,GAAG,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"int8.d.mts","sourceRoot":"","sources":["../../../src/number/enum/int8.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,IAAI,IAAI,gBAAgB,EAC9B,MAAM,eAAe,CAAC;AAIvB,MAAM,MAAM,IAAI,GAAG,gBAAgB,CAAC;AAsDpC;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,MAzCJ,MAAM,KAAG,CAAC,IAAI,IAyCL,CAAC;AAEzB;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,MAnDE,MAAM,KAAG,IAmDA,CAAC;AAE/B;;;;;GAKG;AACH,eAAO,MAAM,IAAI;IACf;;;;;;OAMG;qBApEU,MAAM,KAAG,CAAC,IAAI,IAAI;IAuE/B;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;8BA5EoB,SAAS,IAAI,EAAE,KAAG,IAAI;IA+E7C;;;;;OAKG;8BAjFoB,SAAS,IAAI,EAAE,KAAG,IAAI;IAoF7C;;;;;;;;;OASG;6BAtGkB,MAAM,KAAG,IAAI;IAyGlC;;;;;;;OAOG;mBA9GQ,CAAC,SAAS,IAAI,KAAK,CAAC,KAAG,aAAa,CAAC,CAAC,CAAC;IAiHlD;;;;;;;;OAQG;2BApGgB,IAAI,OAAO,IAAI,KAAG,IAAI;IAuGzC;;;;;;;OAOG;sBAzHW,IAAI,KAAK,IAAI,KAAG,IAAI;IA4HlC;;;;;;OAMG;sBAhIW,IAAI,KAAK,IAAI,KAAG,IAAI;IAmIlC;;;;;;OAMG;sBAvIW,IAAI,KAAK,IAAI,KAAG,IAAI;IA0IlC;;;;;;OAMG;sBA9IW,IAAI,KAAK,IAAI,KAAG,IAAI;IAiJlC;;;;;;;OAOG;sBAtJW,IAAI,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,KAAG,IAAI;CAwJtC,CAAC"}
|
|
@@ -5,7 +5,7 @@ const {
|
|
|
5
5
|
MAX_VALUE,
|
|
6
6
|
MIN_VALUE,
|
|
7
7
|
castType: castTypeImpl,
|
|
8
|
-
|
|
8
|
+
fromNumber: fromNumberImpl,
|
|
9
9
|
is: isImpl,
|
|
10
10
|
random: randomImpl
|
|
11
11
|
} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger({
|
|
@@ -19,18 +19,18 @@ const castType = (x) => (
|
|
|
19
19
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
20
20
|
castTypeImpl(x)
|
|
21
21
|
);
|
|
22
|
-
const
|
|
22
|
+
const fromNumber = (a) => castType(fromNumberImpl(a));
|
|
23
23
|
const abs = (x) => (
|
|
24
24
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
25
25
|
Math.abs(x)
|
|
26
26
|
);
|
|
27
27
|
const min_ = (...values) => castType(Math.min(...values));
|
|
28
28
|
const max_ = (...values) => castType(Math.max(...values));
|
|
29
|
-
const pow = (x, y) =>
|
|
30
|
-
const add = (x, y) =>
|
|
31
|
-
const sub = (x, y) =>
|
|
32
|
-
const mul = (x, y) =>
|
|
33
|
-
const div = (x, y) =>
|
|
29
|
+
const pow = (x, y) => fromNumber(x ** y);
|
|
30
|
+
const add = (x, y) => fromNumber(x + y);
|
|
31
|
+
const sub = (x, y) => fromNumber(x - y);
|
|
32
|
+
const mul = (x, y) => fromNumber(x * y);
|
|
33
|
+
const div = (x, y) => fromNumber(Math.floor(x / y));
|
|
34
34
|
const random = (min, max) => castType(randomImpl(castTypeImpl(min), castTypeImpl(max)));
|
|
35
35
|
const isInt8 = is;
|
|
36
36
|
const asInt8 = castType;
|
|
@@ -44,11 +44,13 @@ const Int8 = {
|
|
|
44
44
|
*/
|
|
45
45
|
is,
|
|
46
46
|
/**
|
|
47
|
-
* The smallest value representable as `Int8
|
|
47
|
+
* The smallest value representable as `Int8` (the lower saturation target of
|
|
48
|
+
* `fromNumber`).
|
|
48
49
|
*/
|
|
49
50
|
MIN_VALUE,
|
|
50
51
|
/**
|
|
51
|
-
* The largest value representable as `Int8
|
|
52
|
+
* The largest value representable as `Int8` (the upper saturation target of
|
|
53
|
+
* `fromNumber`).
|
|
52
54
|
*/
|
|
53
55
|
MAX_VALUE,
|
|
54
56
|
/**
|
|
@@ -66,13 +68,16 @@ const Int8 = {
|
|
|
66
68
|
*/
|
|
67
69
|
max: max_,
|
|
68
70
|
/**
|
|
69
|
-
*
|
|
70
|
-
* and
|
|
71
|
+
* Converts an arbitrary `number` into an `Int8`, rounding to the nearest
|
|
72
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
71
73
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
+
* Unlike `asInt8`, this is total: out-of-range inputs are clamped to the
|
|
75
|
+
* nearest representable `Int8` instead of throwing.
|
|
76
|
+
*
|
|
77
|
+
* @param value - The value to convert
|
|
78
|
+
* @returns The value as an `Int8`
|
|
74
79
|
*/
|
|
75
|
-
|
|
80
|
+
fromNumber,
|
|
76
81
|
/**
|
|
77
82
|
* Returns the absolute value of an integer in [-128, 127].
|
|
78
83
|
*
|