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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int8.mjs","sources":["../../../src/number/enum/int8.mts"],"sourcesContent":["import {\n type AbsoluteValue,\n type Int16,\n type Int8 as TtfImported_Int8,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int8 = TtfImported_Int8;\n\nconst typeNameInMessage = 'an integer in [-128, 127]';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n castType: castTypeImpl,\n
|
|
1
|
+
{"version":3,"file":"int8.mjs","sources":["../../../src/number/enum/int8.mts"],"sourcesContent":["import {\n type AbsoluteValue,\n type Int16,\n type Int8 as TtfImported_Int8,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Int8 = TtfImported_Int8;\n\nconst typeNameInMessage = 'an integer in [-128, 127]';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n castType: castTypeImpl,\n fromNumber: fromNumberImpl,\n is: isImpl,\n random: randomImpl,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n Int16,\n -128,\n 127\n>({\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: -128,\n MAX_VALUE: 127,\n typeNameInMessage,\n} as const);\n\nconst is = (x: number): x is Int8 => isImpl(x);\n\nconst castType = (x: number): Int8 =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n castTypeImpl(x) as Int8;\n\nconst fromNumber = (a: number): Int8 => castType(fromNumberImpl(a));\n\nconst abs = <N extends Int8>(x: N): AbsoluteValue<N> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.abs(x) as unknown as AbsoluteValue<N>;\n\nconst min_ = (...values: readonly Int8[]): Int8 =>\n castType(Math.min(...values));\n\nconst max_ = (...values: readonly Int8[]): Int8 =>\n castType(Math.max(...values));\n\nconst pow = (x: Int8, y: Int8): Int8 => fromNumber(x ** y);\n\nconst add = (x: Int8, y: Int8): Int8 => fromNumber(x + y);\n\nconst sub = (x: Int8, y: Int8): Int8 => fromNumber(x - y);\n\nconst mul = (x: Int8, y: Int8): Int8 => fromNumber(x * y);\n\nconst div = (x: Int8, y: Exclude<Int8, 0>): Int8 =>\n fromNumber(Math.floor(x / y));\n\nconst random = (min: Int8, max: Int8): Int8 =>\n castType(randomImpl(castTypeImpl(min), castTypeImpl(max)));\n\n/**\n * Type guard that checks if a value is an integer in [-128, 127].\n *\n * Returns `true` for an integer in [-128, 127] — 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 [-128, 127], `false` otherwise\n */\nexport const isInt8 = is;\n\n/**\n * Casts a `number` to the `Int8` branded type.\n *\n * Validates that the value is an integer in [-128, 127] and returns it with the\n * `Int8` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as an `Int8`\n * @throws {TypeError} If the value is not an integer in [-128, 127]\n */\nexport const asInt8 = castType;\n\n/**\n * Namespace providing type-safe operations for the `Int8` branded type.\n *\n * The `Int8` type represents an integer in [-128, 127]. Division (`div`) uses\n * floor division.\n */\nexport const Int8 = {\n /**\n * Type guard that checks if a value is an integer in [-128, 127].\n *\n * @param value - The value to check\n * @returns `true` if the value is an integer in [-128, 127], `false` otherwise\n * @see {@link isInt8} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Int8` (the lower saturation target of\n * `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `Int8` (the upper saturation target of\n * `fromNumber`).\n */\n MAX_VALUE,\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 `Int8`\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 `Int8`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into an `Int8`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asInt8`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Int8` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as an `Int8`\n */\n fromNumber,\n\n /**\n * Returns the absolute value of an integer in [-128, 127].\n *\n * The result is non-negative and keeps the `Int8` brand.\n *\n * @param a - The integer value\n * @returns The absolute value as a non-negative `Int8`\n */\n abs,\n\n /**\n * Generates a random `Int8` 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 `Int8` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Int8` (floored to an\n * integer).\n *\n * @param a - The base integer\n * @param b - The exponent integer\n * @returns `a ** b` as an `Int8`\n */\n pow,\n\n /**\n * Adds two integers, returning `a + b` as an `Int8`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The sum of `a` and `b` as an `Int8`\n */\n add,\n\n /**\n * Subtracts two integers, returning `a - b` as an `Int8`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The difference of `a` and `b` as an `Int8`\n */\n sub,\n\n /**\n * Multiplies two integers, returning `a * b` as an `Int8`.\n *\n * @param a - The first integer\n * @param b - The second integer\n * @returns The product of `a` and `b` as an `Int8`\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 `Int8`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Int8`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Int8,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<\n Int16,\n 'int' | 'range'\n >\n>('=');\n"],"names":[],"mappings":";;AAUA,MAAM,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
+
* The smallest value representable as `Uint8` (the lower saturation target of
|
|
41
|
+
* `fromNumber`).
|
|
41
42
|
*/
|
|
42
43
|
readonly MIN_VALUE: 0;
|
|
43
44
|
/**
|
|
44
|
-
* The largest value representable as `Uint8
|
|
45
|
+
* The largest value representable as `Uint8` (the upper saturation target of
|
|
46
|
+
* `fromNumber`).
|
|
45
47
|
*/
|
|
46
48
|
readonly MAX_VALUE: 255;
|
|
47
49
|
/**
|
|
@@ -59,13 +61,16 @@ export declare const Uint8: {
|
|
|
59
61
|
*/
|
|
60
62
|
readonly min: (...values: readonly Uint8[]) => Uint8;
|
|
61
63
|
/**
|
|
62
|
-
*
|
|
63
|
-
* and
|
|
64
|
+
* Converts an arbitrary `number` into an `Uint8`, rounding to the nearest
|
|
65
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
64
66
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
+
* Unlike `asUint8`, this is total: out-of-range inputs are clamped to the
|
|
68
|
+
* nearest representable `Uint8` instead of throwing.
|
|
69
|
+
*
|
|
70
|
+
* @param value - The value to convert
|
|
71
|
+
* @returns The value as an `Uint8`
|
|
67
72
|
*/
|
|
68
|
-
readonly
|
|
73
|
+
readonly fromNumber: (a: number) => Uint8;
|
|
69
74
|
/**
|
|
70
75
|
* Generates a random `Uint8` within the given range.
|
|
71
76
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8.d.mts","sourceRoot":"","sources":["../../../src/number/enum/uint8.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,iBAAiB,EAAe,MAAM,eAAe,CAAC;AAI7E,MAAM,MAAM,KAAK,GAAG,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"uint8.d.mts","sourceRoot":"","sources":["../../../src/number/enum/uint8.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,iBAAiB,EAAe,MAAM,eAAe,CAAC;AAI7E,MAAM,MAAM,KAAK,GAAG,iBAAiB,CAAC;AAgDtC;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,MArCL,MAAM,KAAG,CAAC,IAAI,KAqCJ,CAAC;AAE1B;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,MA/CC,MAAM,KAAG,KA+CC,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,KAAK;IAChB;;;;;;OAMG;qBAhEU,MAAM,KAAG,CAAC,IAAI,KAAK;IAmEhC;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;8BAzEoB,SAAS,KAAK,EAAE,KAAG,KAAK;IA4E/C;;;;;OAKG;8BApFoB,SAAS,KAAK,EAAE,KAAG,KAAK;IAuF/C;;;;;;;;;OASG;6BAlGkB,MAAM,KAAG,KAAK;IAqGnC;;;;;;;;OAQG;2BA1FgB,KAAK,OAAO,KAAK,KAAG,KAAK;IA6F5C;;;;;;;OAOG;sBA/GW,KAAK,KAAK,KAAK,KAAG,KAAK;IAkHrC;;;;;;OAMG;sBAtHW,KAAK,KAAK,KAAK,KAAG,KAAK;IAyHrC;;;;;;OAMG;sBA7HW,KAAK,KAAK,KAAK,KAAG,KAAK;IAgIrC;;;;;;OAMG;sBApIW,KAAK,KAAK,KAAK,KAAG,KAAK;IAuIrC;;;;;;;OAOG;sBA5IW,KAAK,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,KAAG,KAAK;CA8IzC,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(
|
|
@@ -21,14 +21,14 @@ const castType = (x) => (
|
|
|
21
21
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
22
22
|
castTypeImpl(x)
|
|
23
23
|
);
|
|
24
|
-
const
|
|
24
|
+
const fromNumber = (a) => castType(fromNumberImpl(a));
|
|
25
25
|
const min_ = (...values) => castType(Math.min(...values));
|
|
26
26
|
const max_ = (...values) => castType(Math.max(...values));
|
|
27
|
-
const pow = (x, y) =>
|
|
28
|
-
const add = (x, y) =>
|
|
29
|
-
const sub = (x, y) =>
|
|
30
|
-
const mul = (x, y) =>
|
|
31
|
-
const div = (x, y) =>
|
|
27
|
+
const pow = (x, y) => fromNumber(x ** y);
|
|
28
|
+
const add = (x, y) => fromNumber(x + y);
|
|
29
|
+
const sub = (x, y) => fromNumber(x - y);
|
|
30
|
+
const mul = (x, y) => fromNumber(x * y);
|
|
31
|
+
const div = (x, y) => fromNumber(Math.floor(x / y));
|
|
32
32
|
const random = (min, max) => castType(randomImpl(castTypeImpl(min), castTypeImpl(max)));
|
|
33
33
|
const isUint8 = is;
|
|
34
34
|
const asUint8 = castType;
|
|
@@ -42,11 +42,13 @@ const Uint8 = {
|
|
|
42
42
|
*/
|
|
43
43
|
is,
|
|
44
44
|
/**
|
|
45
|
-
* The smallest value representable as `Uint8
|
|
45
|
+
* The smallest value representable as `Uint8` (the lower saturation target of
|
|
46
|
+
* `fromNumber`).
|
|
46
47
|
*/
|
|
47
48
|
MIN_VALUE,
|
|
48
49
|
/**
|
|
49
|
-
* The largest value representable as `Uint8
|
|
50
|
+
* The largest value representable as `Uint8` (the upper saturation target of
|
|
51
|
+
* `fromNumber`).
|
|
50
52
|
*/
|
|
51
53
|
MAX_VALUE,
|
|
52
54
|
/**
|
|
@@ -64,13 +66,16 @@ const Uint8 = {
|
|
|
64
66
|
*/
|
|
65
67
|
min: min_,
|
|
66
68
|
/**
|
|
67
|
-
*
|
|
68
|
-
* and
|
|
69
|
+
* Converts an arbitrary `number` into an `Uint8`, rounding to the nearest
|
|
70
|
+
* integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.
|
|
69
71
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
+
* Unlike `asUint8`, this is total: out-of-range inputs are clamped to the
|
|
73
|
+
* nearest representable `Uint8` instead of throwing.
|
|
74
|
+
*
|
|
75
|
+
* @param value - The value to convert
|
|
76
|
+
* @returns The value as an `Uint8`
|
|
72
77
|
*/
|
|
73
|
-
|
|
78
|
+
fromNumber,
|
|
74
79
|
/**
|
|
75
80
|
* Generates a random `Uint8` within the given range.
|
|
76
81
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8.mjs","sources":["../../../src/number/enum/uint8.mts"],"sourcesContent":["import { type Uint8 as TtfImported_Uint8, type Uint16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint8 = TtfImported_Uint8;\n\nconst typeNameInMessage = 'an non-negative integer less than 256';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n castType: castTypeImpl,\n
|
|
1
|
+
{"version":3,"file":"uint8.mjs","sources":["../../../src/number/enum/uint8.mts"],"sourcesContent":["import { type Uint8 as TtfImported_Uint8, type Uint16 } from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type Uint8 = TtfImported_Uint8;\n\nconst typeNameInMessage = 'an non-negative integer less than 256';\n\nconst {\n MAX_VALUE,\n MIN_VALUE,\n castType: castTypeImpl,\n fromNumber: fromNumberImpl,\n is: isImpl,\n random: randomImpl,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<Uint16, 0, 255>(\n {\n integerOrSafeInteger: 'SafeInteger',\n MIN_VALUE: 0,\n MAX_VALUE: 255,\n typeNameInMessage,\n } as const,\n);\n\nconst is = (x: number): x is Uint8 => isImpl(x);\n\nconst castType = (x: number): Uint8 =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n castTypeImpl(x) as Uint8;\n\nconst fromNumber = (a: number): Uint8 => castType(fromNumberImpl(a));\n\nconst min_ = (...values: readonly Uint8[]): Uint8 =>\n castType(Math.min(...values));\n\nconst max_ = (...values: readonly Uint8[]): Uint8 =>\n castType(Math.max(...values));\n\nconst pow = (x: Uint8, y: Uint8): Uint8 => fromNumber(x ** y);\n\nconst add = (x: Uint8, y: Uint8): Uint8 => fromNumber(x + y);\n\nconst sub = (x: Uint8, y: Uint8): Uint8 => fromNumber(x - y);\n\nconst mul = (x: Uint8, y: Uint8): Uint8 => fromNumber(x * y);\n\nconst div = (x: Uint8, y: Exclude<Uint8, 0>): Uint8 =>\n fromNumber(Math.floor(x / y));\n\nconst random = (min: Uint8, max: Uint8): Uint8 =>\n castType(randomImpl(castTypeImpl(min), castTypeImpl(max)));\n\n/**\n * Type guard that checks if a value is an non-negative integer less than 256.\n *\n * Returns `true` for an non-negative integer less than 256 — a value with no\n * fractional component.\n *\n * @param value - The value to check\n * @returns `true` if the value is an non-negative integer less than 256, `false` otherwise\n */\nexport const isUint8 = is;\n\n/**\n * Casts a `number` to the `Uint8` branded type.\n *\n * Validates that the value is an non-negative integer less than 256 and returns\n * it with the `Uint8` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as an `Uint8`\n * @throws {TypeError} If the value is not an non-negative integer less than 256\n */\nexport const asUint8 = castType;\n\n/**\n * Namespace providing type-safe operations for the `Uint8` branded type.\n *\n * The `Uint8` type represents an non-negative integer less than 256. Division\n * (`div`) uses floor division.\n */\nexport const Uint8 = {\n /**\n * Type guard that checks if a value is an non-negative integer less than 256.\n *\n * @param value - The value to check\n * @returns `true` if the value is an non-negative integer less than 256, `false` otherwise\n * @see {@link isUint8} for usage examples\n */\n is,\n\n /**\n * The smallest value representable as `Uint8` (the lower saturation target of\n * `fromNumber`).\n */\n MIN_VALUE,\n\n /**\n * The largest value representable as `Uint8` (the upper saturation target of\n * `fromNumber`).\n */\n MAX_VALUE,\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 `Uint8`\n */\n max: max_,\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 `Uint8`\n */\n min: min_,\n\n /**\n * Converts an arbitrary `number` into an `Uint8`, rounding to the nearest\n * integer and saturating the result into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asUint8`, this is total: out-of-range inputs are clamped to the\n * nearest representable `Uint8` instead of throwing.\n *\n * @param value - The value to convert\n * @returns The value as an `Uint8`\n */\n fromNumber,\n\n /**\n * Generates a random `Uint8` 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 `Uint8` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as an `Uint8` (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 `Uint8`\n */\n pow,\n\n /**\n * Adds two non-negative integers, returning `a + b` as an `Uint8`.\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 `Uint8`\n */\n add,\n\n /**\n * Subtracts two non-negative integers, returning `a - b` as an `Uint8`.\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 `Uint8`\n */\n sub,\n\n /**\n * Multiplies two non-negative integers, returning `a * b` as an `Uint8`.\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 `Uint8`\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 `Uint8`.\n *\n * @param a - The dividend\n * @param b - The divisor (must be non-zero)\n * @returns The floored quotient as an `Uint8`\n */\n div,\n} as const;\n\nexpectType<\n keyof typeof Uint8,\n keyof TsDataForgeInternals.RefinedNumberUtils.NumberClass<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AW,IAAA,CAAK,KAAA,CAAM,CAAA,GAAI,CAAC,CAAC,CAAA;AAE9B,MAAM,MAAA,GAAS,CAAC,GAAA,EAAY,GAAA,KAC1B,QAAA,CAAS,UAAA,CAAW,YAAA,CAAa,GAAG,CAAA,EAAG,YAAA,CAAa,GAAG,CAAC,CAAC,CAAA;AAWpD,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,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;;;;"}
|
|
@@ -78,16 +78,16 @@ export declare namespace TsDataForgeInternals {
|
|
|
78
78
|
round: (x: N, y: N) => ToInt<N>;
|
|
79
79
|
}>) & ('non-negative' extends classes ? Readonly<{
|
|
80
80
|
MIN_VALUE: number;
|
|
81
|
-
|
|
81
|
+
fromNumber: (a: number) => N;
|
|
82
82
|
}> : unknown) & ('non-negative' extends classes ? unknown : 'positive' extends classes ? unknown : Readonly<{
|
|
83
83
|
abs: (x: N) => ToNonNegative<N>;
|
|
84
84
|
}>) & ('positive' extends classes ? Readonly<{
|
|
85
85
|
MIN_VALUE: number;
|
|
86
|
-
|
|
86
|
+
fromNumber: (a: number) => N;
|
|
87
87
|
}> : unknown) & ('range' extends classes ? Readonly<{
|
|
88
88
|
MIN_VALUE: number;
|
|
89
89
|
MAX_VALUE: number;
|
|
90
|
-
|
|
90
|
+
fromNumber: (a: number) => N;
|
|
91
91
|
}> : unknown) & Pick<Readonly<{
|
|
92
92
|
add: (x: N, y: N) => N;
|
|
93
93
|
sub: (x: N, y: N) => N;
|
|
@@ -115,7 +115,7 @@ export declare namespace TsDataForgeInternals {
|
|
|
115
115
|
random: (min?: ElementTypeWithSmallInt, max?: ElementTypeWithSmallInt) => ElementType;
|
|
116
116
|
randomNonZero: (min?: ElementTypeWithSmallInt, max?: ElementTypeWithSmallInt) => ElementType;
|
|
117
117
|
castType: <N extends number>(x: N) => ElementType & N;
|
|
118
|
-
|
|
118
|
+
fromNumber: TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true ? undefined : (x: number) => ElementType;
|
|
119
119
|
}>;
|
|
120
120
|
/**
|
|
121
121
|
* Factory function that creates a complete set of type-safe operations for
|
|
@@ -157,7 +157,7 @@ export declare namespace TsDataForgeInternals {
|
|
|
157
157
|
*
|
|
158
158
|
* const quotient = intOps.div(six, intOps.castType(2));
|
|
159
159
|
*
|
|
160
|
-
* const
|
|
160
|
+
* const coerced = intOps.fromNumber(1.5);
|
|
161
161
|
*
|
|
162
162
|
* const randomValue = intOps.random();
|
|
163
163
|
*
|
|
@@ -169,7 +169,7 @@ export declare namespace TsDataForgeInternals {
|
|
|
169
169
|
*
|
|
170
170
|
* assert.isTrue(quotient === 3);
|
|
171
171
|
*
|
|
172
|
-
* assert.isTrue(
|
|
172
|
+
* assert.isTrue(coerced === 2);
|
|
173
173
|
*
|
|
174
174
|
* assert.isTrue(Number.isSafeInteger(randomValue));
|
|
175
175
|
* ```
|
|
@@ -210,7 +210,7 @@ export declare namespace TsDataForgeInternals {
|
|
|
210
210
|
random: (min?: ElementType, max?: ElementType) => ElementType;
|
|
211
211
|
randomNonZero: (min?: ElementType, max?: ElementType) => ElementType;
|
|
212
212
|
castType: <N extends number>(x: N) => ElementType & N;
|
|
213
|
-
|
|
213
|
+
fromNumber: TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true ? undefined : (x: number) => ElementType;
|
|
214
214
|
}>;
|
|
215
215
|
/**
|
|
216
216
|
* Factory function that creates a complete set of type-safe operations for
|
|
@@ -248,7 +248,7 @@ export declare namespace TsDataForgeInternals {
|
|
|
248
248
|
*
|
|
249
249
|
* const ratio = floatOps.div(sum, floatOps.castType(10));
|
|
250
250
|
*
|
|
251
|
-
* const
|
|
251
|
+
* const coerced = floatOps.fromNumber(0);
|
|
252
252
|
*
|
|
253
253
|
* const boundedRandom = floatOps.random(
|
|
254
254
|
* floatOps.castType(10),
|
|
@@ -261,7 +261,7 @@ export declare namespace TsDataForgeInternals {
|
|
|
261
261
|
*
|
|
262
262
|
* assert.isTrue(ratio === 5);
|
|
263
263
|
*
|
|
264
|
-
* assert.isTrue(
|
|
264
|
+
* assert.isTrue(coerced >= Number.MIN_VALUE);
|
|
265
265
|
*
|
|
266
266
|
* assert.isTrue(boundedRandom >= 10 && boundedRandom <= 20);
|
|
267
267
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refined-number-utils.d.mts","sourceRoot":"","sources":["../../src/number/refined-number-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,GAAG,EACR,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KA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AoEG;QACH,MAAM,CAAC,MAAM,iBAAiB,GAC5B,WAAW,SAAS,kBAAkB,EACtC,SAAS,SAAS,MAAM,EACxB,SAAS,SAAS,MAAM,yDAMvB,QAAQ,CAAC;YACV,OAAO,CAAC,EAAE,OAAO,CAAC;YAClB,SAAS,EAAE,SAAS,CAAC;YACrB,SAAS,EAAE,SAAS,CAAC;YACrB,iBAAiB,EAAE,MAAM,CAAC;SAC3B,CAAC,KAAG,iBAAiB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAuFvD,CAAC;;KACH;CACF"}
|
|
@@ -23,12 +23,12 @@ var TsDataForgeInternals;
|
|
|
23
23
|
}) => {
|
|
24
24
|
const is = (a) => (integerOrSafeInteger === "Integer" ? Number.isInteger(a) : Number.isSafeInteger(a)) && (nonZero === true ? a !== 0 : true) && (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);
|
|
25
25
|
const castType = castTypeImpl(is, typeNameInMessage);
|
|
26
|
-
const
|
|
26
|
+
const fromNumber = pipe(
|
|
27
27
|
clampFnOrUndefined(MIN_VALUE, MAX_VALUE)
|
|
28
28
|
).mapNullable(
|
|
29
29
|
(cl) => (x) => castType(Math.round(cl(x)))
|
|
30
30
|
).value;
|
|
31
|
-
const clampOrCastFn =
|
|
31
|
+
const clampOrCastFn = fromNumber ?? castType;
|
|
32
32
|
const abs = (x) => (
|
|
33
33
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
34
34
|
Math.abs(clampOrCastFn(x))
|
|
@@ -68,9 +68,9 @@ var TsDataForgeInternals;
|
|
|
68
68
|
random,
|
|
69
69
|
randomNonZero,
|
|
70
70
|
castType,
|
|
71
|
-
|
|
71
|
+
fromNumber: (
|
|
72
72
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
73
|
-
|
|
73
|
+
fromNumber
|
|
74
74
|
)
|
|
75
75
|
};
|
|
76
76
|
};
|
|
@@ -82,12 +82,12 @@ var TsDataForgeInternals;
|
|
|
82
82
|
}) => {
|
|
83
83
|
const is = (a) => Number.isFinite(a) && (nonZero === true ? a !== 0 : true) && (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);
|
|
84
84
|
const castType = castTypeImpl(is, typeNameInMessage);
|
|
85
|
-
const
|
|
85
|
+
const fromNumber = pipe(
|
|
86
86
|
clampFnOrUndefined(MIN_VALUE, MAX_VALUE)
|
|
87
87
|
).mapNullable(
|
|
88
88
|
(cl) => (x) => castType(cl(x))
|
|
89
89
|
).value;
|
|
90
|
-
const clampOrCastFn =
|
|
90
|
+
const clampOrCastFn = fromNumber ?? castType;
|
|
91
91
|
const abs = (x) => (
|
|
92
92
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
93
93
|
Math.abs(x)
|
|
@@ -126,7 +126,7 @@ var TsDataForgeInternals;
|
|
|
126
126
|
randomNonZero,
|
|
127
127
|
castType,
|
|
128
128
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
129
|
-
|
|
129
|
+
fromNumber
|
|
130
130
|
};
|
|
131
131
|
};
|
|
132
132
|
})(TsDataForgeInternals2.RefinedNumberUtils || (TsDataForgeInternals2.RefinedNumberUtils = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refined-number-utils.mjs","sources":["../../src/number/refined-number-utils.mts"],"sourcesContent":["import {\n type Brand,\n type ChangeBaseBrand,\n type GetBrandValuePart,\n type Int,\n type IntersectBrand,\n type NonNegativeNumber,\n type NonZeroNumber,\n type PositiveNumber,\n type RelaxedExclude,\n type TypeEq,\n type UnknownBrand,\n type UnwrapBrandFalseKeys,\n type UnwrapBrandTrueKeys,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { expectType } from '../expect-type.mjs';\nimport { pipe } from '../functional/index.mjs';\nimport { Num } from './num.mjs';\n\n/** @internal */\nexport namespace TsDataForgeInternals {\n /**\n * Internal utilities for creating and managing refined (branded) number\n * types.\n *\n * This namespace provides factory functions and type utilities for building\n * type-safe numeric operations with compile-time constraints. It serves as\n * the foundation for all branded number types in the library, including:\n *\n * - Integer types (Int, SafeInt, Int8, Int16, Int32)\n * - Unsigned types (UInt, UInt8, UInt16, UInt32)\n * - Constrained types (NonZero, NonNegative, Positive)\n * - Range-bounded types\n *\n * The utilities handle:\n *\n * - Type validation and narrowing\n * - Arithmetic operations that preserve type constraints\n * - Automatic clamping for bounded types\n * - Random number generation within type bounds\n *\n * @internal This namespace is not part of the public API\n */\n export namespace RefinedNumberUtils {\n const castTypeImpl =\n <BrandedType extends number>(\n is: (n: number) => n is BrandedType,\n typeNameInErrorMessage: string,\n ) =>\n <N extends number>(a: N): BrandedType & N => {\n if (!is(a)) {\n throw new TypeError(`Expected ${typeNameInErrorMessage}, got: ${a}`);\n }\n\n return a;\n };\n\n type UnknownNumberBrand = ChangeBaseBrand<UnknownBrand, number>;\n\n /**\n * Converts a branded number type to include the Int brand.\n *\n * @template N - A branded number type\n * @internal\n */\n export type ToInt<N extends UnknownNumberBrand> = IntersectBrand<N, Int>;\n\n type ToNonZero<N extends UnknownNumberBrand> = IntersectBrand<\n N,\n NonZeroNumber\n >;\n\n const isNonZero = <N extends UnknownNumberBrand>(\n n: N,\n ): n is N & ToNonZero<N> => n !== 0;\n\n type ToNonZeroIntWithSmallInt<N extends Int> = WithSmallInt<\n CastToInt<ToNonZero<N>>\n >;\n\n /**\n * Converts a branded number type to include the NonNegativeNumber brand.\n *\n * @template N - A branded number type\n * @internal\n */\n export type ToNonNegative<N extends UnknownNumberBrand> =\n '!=0' extends UnwrapBrandTrueKeys<N>\n ? IntersectBrand<N, PositiveNumber>\n : IntersectBrand<N, NonNegativeNumber>;\n\n /**\n * Removes the non-zero brand constraint from a branded number type. Used\n * when operations may produce zero values.\n *\n * @template N - A branded number type\n * @internal\n */\n export type RemoveNonZeroBrandKey<N extends UnknownNumberBrand> = Brand<\n GetBrandValuePart<N>,\n RelaxedExclude<UnwrapBrandTrueKeys<N>, '!=0'> & string,\n RelaxedExclude<UnwrapBrandFalseKeys<N>, '<=0' | '>=0'> & string\n >;\n\n type CastToInt<N> = N extends Int ? N : never;\n\n /**\n * Generates a type-safe API for a branded number type based on its\n * characteristics.\n *\n * This type dynamically constructs an object type with appropriate methods\n * based on the number class. For example:\n *\n * - Integer types don't get floor/ceil/round methods\n * - Non-negative types don't get abs method\n * - Range-bounded types get MIN_VALUE/MAX_VALUE constants\n *\n * @template N - The branded number type\n * @template classes - Union of characteristics: 'int' | 'non-negative' |\n * 'positive' | 'range'\n * @internal\n */\n /** The closed binary arithmetic operations a branded namespace may expose. */\n export type NumberClassBinOp = 'add' | 'div' | 'mul' | 'sub';\n\n export type NumberClass<\n N extends UnknownNumberBrand,\n classes extends 'int' | 'non-negative' | 'positive' | 'range',\n binOps extends NumberClassBinOp = NumberClassBinOp,\n > = ('int' extends classes\n ? unknown\n : 'positive' extends classes\n ? Readonly<{\n floor: (x: N, y: N) => RemoveNonZeroBrandKey<ToInt<N>>;\n ceil: (x: N, y: N) => ToInt<N>;\n round: (x: N, y: N) => RemoveNonZeroBrandKey<ToInt<N>>;\n }>\n : Readonly<{\n floor: (x: N, y: N) => ToInt<N>;\n ceil: (x: N, y: N) => ToInt<N>;\n round: (x: N, y: N) => ToInt<N>;\n }>) &\n ('non-negative' extends classes\n ? Readonly<{\n MIN_VALUE: number;\n clamp: (a: number) => N;\n }>\n : unknown) &\n ('non-negative' extends classes\n ? unknown\n : 'positive' extends classes\n ? unknown\n : Readonly<{\n abs: (x: N) => ToNonNegative<N>;\n }>) &\n ('positive' extends classes\n ? Readonly<{\n MIN_VALUE: number;\n clamp: (a: number) => N;\n }>\n : unknown) &\n ('range' extends classes\n ? Readonly<{\n MIN_VALUE: number;\n MAX_VALUE: number;\n clamp: (a: number) => N;\n }>\n : unknown) &\n Pick<\n Readonly<{\n add: (x: N, y: N) => N;\n sub: (x: N, y: N) => N;\n mul: (x: N, y: N) => N;\n div: (x: N, y: ToNonZero<N>) => N;\n }>,\n binOps\n > &\n Readonly<{\n is: (a: number) => a is N;\n min: (...values: readonly N[]) => N;\n max: (...values: readonly N[]) => N;\n random: (min: N, max: N) => N;\n pow: (x: N, y: N) => N;\n }>;\n\n type BaseKeys =\n 'add' | 'div' | 'is' | 'max' | 'min' | 'mul' | 'pow' | 'random' | 'sub';\n\n type FloatMethods = 'ceil' | 'floor' | 'round';\n\n expectType<keyof NumberClass<UnknownNumberBrand, 'int'>, BaseKeys | 'abs'>(\n '=',\n );\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, never>,\n BaseKeys | FloatMethods | 'abs'\n >('=');\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, 'non-negative'>,\n BaseKeys | FloatMethods | 'clamp' | 'MIN_VALUE'\n >('=');\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, 'positive'>,\n BaseKeys | FloatMethods | 'clamp' | 'MIN_VALUE'\n >('=');\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, 'int' | 'range'>,\n BaseKeys | 'abs' | 'clamp' | 'MAX_VALUE' | 'MIN_VALUE'\n >('=');\n\n const isFnOrUndefined = (\n min: number | undefined,\n max: number | undefined,\n ): ((n: number) => boolean) | undefined =>\n min === undefined\n ? max === undefined\n ? undefined\n : (n) => n <= max\n : max === undefined\n ? (n) => min <= n\n : Num.isInRangeInclusive(min, max);\n\n const clampFnOrUndefined = (\n min: number | undefined,\n max: number | undefined,\n ): ((n: number) => number) | undefined =>\n min === undefined\n ? max === undefined\n ? undefined\n : (n) => Math.min(max, n)\n : max === undefined\n ? (n) => Math.max(min, n)\n : Num.clamp(min, max);\n\n type OperatorsForInteger<\n ElementType extends Int,\n MIN_VALUE extends number,\n MAX_VALUE extends number,\n ElementTypeWithSmallInt extends WithSmallInt<ElementType> =\n WithSmallInt<ElementType>,\n > = Readonly<{\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n\n is: (a: number) => a is ElementType;\n\n abs: (x: ElementTypeWithSmallInt) => ToNonNegative<ElementType>;\n\n min: (...values: readonly ElementTypeWithSmallInt[]) => ElementType;\n\n max: (...values: readonly ElementTypeWithSmallInt[]) => ElementType;\n\n pow: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n add: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n sub: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n mul: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n div: (\n x: ElementTypeWithSmallInt,\n y: ToNonZeroIntWithSmallInt<ElementType>,\n ) => ElementType;\n\n random: (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ) => ElementType;\n\n randomNonZero: (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ) => ElementType;\n\n castType: <N extends number>(x: N) => ElementType & N;\n\n clamp: TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType;\n }>;\n\n /**\n * Factory function that creates a complete set of type-safe operations for\n * integer types.\n *\n * This function generates:\n *\n * - Type guards and validators\n * - Arithmetic operations that preserve type constraints\n * - Utility functions (min, max, abs, random)\n * - Automatic clamping for bounded types\n *\n * All operations ensure results remain within the type's constraints, using\n * clamping when bounds are specified.\n *\n * @example\n *\n * ```ts\n * const intOps = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n * SafeInt,\n * number,\n * number\n * >({\n * integerOrSafeInteger: 'SafeInteger',\n * MIN_VALUE: Number.MIN_SAFE_INTEGER,\n * MAX_VALUE: Number.MAX_SAFE_INTEGER,\n * typeNameInMessage: 'SafeInt',\n * } as const);\n *\n * const six = intOps.castType(6);\n *\n * const four = intOps.castType(4);\n *\n * const sum = intOps.add(six, four);\n *\n * const difference = intOps.sub(six, four);\n *\n * const product = intOps.mul(six, four);\n *\n * const quotient = intOps.div(six, intOps.castType(2));\n *\n * const roundedClamp = intOps.clamp(1.5);\n *\n * const randomValue = intOps.random();\n *\n * assert.isTrue(sum === 10);\n *\n * assert.isTrue(difference === 2);\n *\n * assert.isTrue(product === 24);\n *\n * assert.isTrue(quotient === 3);\n *\n * assert.isTrue(roundedClamp === 2);\n *\n * assert.isTrue(Number.isSafeInteger(randomValue));\n * ```\n *\n * @template ElementType - The integer branded type\n * @template MIN_VALUE - Optional minimum value for bounded types\n * @template MAX_VALUE - Optional maximum value for bounded types\n * @param config - Configuration object\n * @param config.integerOrSafeInteger - Whether to use Number.isInteger or\n * Number.isSafeInteger\n * @param config.nonZero - If true, excludes zero from valid values\n * @param config.MIN_VALUE - Minimum valid value (inclusive)\n * @param config.MAX_VALUE - Maximum valid value (inclusive)\n * @param config.typeNameInMessage - Human-readable type name for error\n * messages\n * @returns Object containing all type-safe operations for the integer type\n * @internal\n */\n export const operatorsForInteger = <\n ElementType extends Int,\n MIN_VALUE extends number,\n MAX_VALUE extends number,\n >({\n integerOrSafeInteger,\n nonZero,\n MIN_VALUE,\n MAX_VALUE,\n typeNameInMessage,\n }: Readonly<{\n integerOrSafeInteger: 'Integer' | 'SafeInteger';\n nonZero?: boolean;\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n typeNameInMessage: string;\n }>): OperatorsForInteger<ElementType, MIN_VALUE, MAX_VALUE> => {\n type ElementTypeWithSmallInt = WithSmallInt<ElementType>;\n\n const is = (a: number): a is ElementType =>\n (integerOrSafeInteger === 'Integer'\n ? Number.isInteger(a)\n : Number.isSafeInteger(a)) &&\n (nonZero === true ? a !== 0 : true) &&\n (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);\n\n const castType = castTypeImpl<ElementType>(is, typeNameInMessage);\n\n const clamp: ((a: number) => ElementType) | undefined = pipe(\n clampFnOrUndefined(MIN_VALUE, MAX_VALUE),\n ).mapNullable(\n (cl) =>\n (x: number): ElementType =>\n castType(Math.round(cl(x))),\n ).value;\n\n const clampOrCastFn: (a: number) => ElementType = clamp ?? castType;\n\n const abs = (x: ElementTypeWithSmallInt): ToNonNegative<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.abs(clampOrCastFn(x)) as ToNonNegative<ElementType>;\n\n const min_ = (\n ...values: readonly ElementTypeWithSmallInt[]\n ): ElementType => clampOrCastFn(Math.min(...values));\n\n const max_ = (\n ...values: readonly ElementTypeWithSmallInt[]\n ): ElementType => clampOrCastFn(Math.max(...values));\n\n const pow = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x ** y);\n\n const add = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x + y);\n\n const sub = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x - y);\n\n const mul = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x * y);\n\n const div = (\n x: ElementTypeWithSmallInt,\n y: ToNonZeroIntWithSmallInt<ElementType>,\n ): ElementType =>\n clampOrCastFn(\n Math.floor(\n // eslint-disable-next-line total-functions/no-partial-division\n x / y,\n ),\n );\n\n const randomImpl = (\n min: number = MIN_VALUE,\n max: number = MAX_VALUE,\n ): number =>\n min + Math.floor((Math.max(max, min) - min + 1) * Math.random());\n\n // [-5, 5] -> floor(11 * Math.random()) + (-5)\n const random = (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(randomImpl(min, max));\n\n const randomNonZero = (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ): ElementType => {\n while (true) {\n const r = randomImpl(min, max);\n\n if (Num.isNonZero(r)) return clampOrCastFn(r);\n }\n };\n\n return {\n MIN_VALUE,\n MAX_VALUE,\n is,\n abs,\n min: min_,\n max: max_,\n pow,\n add,\n sub,\n mul,\n div,\n random,\n randomNonZero,\n castType,\n\n clamp:\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n clamp as TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType,\n } as const;\n };\n\n type OperatorsForFloat<\n ElementType extends UnknownNumberBrand,\n MIN_VALUE extends number | undefined,\n MAX_VALUE extends number | undefined,\n > = Readonly<{\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n\n is: (a: number) => a is ElementType;\n\n abs: (x: ElementType) => ToNonNegative<ElementType>;\n min: (...values: readonly ElementType[]) => ElementType;\n max: (...values: readonly ElementType[]) => ElementType;\n pow: (x: ElementType, y: ElementType) => ElementType;\n add: (x: ElementType, y: ElementType) => ElementType;\n sub: (x: ElementType, y: ElementType) => ElementType;\n mul: (x: ElementType, y: ElementType) => ElementType;\n div: (x: ElementType, y: ToNonZero<ElementType>) => ElementType;\n random: (min?: ElementType, max?: ElementType) => ElementType;\n randomNonZero: (min?: ElementType, max?: ElementType) => ElementType;\n\n castType: <N extends number>(x: N) => ElementType & N;\n\n clamp: TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType;\n }>;\n\n /**\n * Factory function that creates a complete set of type-safe operations for\n * floating-point types.\n *\n * This function generates:\n *\n * - Type guards and validators (checking for finite values)\n * - Arithmetic operations that preserve type constraints\n * - Utility functions (min, max, abs, random)\n * - Automatic clamping for bounded types\n *\n * All operations ensure results remain finite and within any specified\n * bounds. Division by zero is prevented through type constraints.\n *\n * @example\n *\n * ```ts\n * const floatOps = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<\n * PositiveFiniteNumber,\n * number,\n * number\n * >({\n * nonZero: true,\n * MIN_VALUE: Number.MIN_VALUE,\n * MAX_VALUE: Number.MAX_VALUE,\n * typeNameInMessage: 'PositiveFiniteNumber',\n * } as const);\n *\n * const fortyTwo = floatOps.castType(42.5);\n *\n * const seven = floatOps.castType(7.5);\n *\n * const sum = floatOps.add(fortyTwo, seven);\n *\n * const ratio = floatOps.div(sum, floatOps.castType(10));\n *\n * const clamped = floatOps.clamp(0);\n *\n * const boundedRandom = floatOps.random(\n * floatOps.castType(10),\n * floatOps.castType(20),\n * );\n *\n * const nonZeroRandom = floatOps.randomNonZero();\n *\n * assert.isTrue(sum === 50);\n *\n * assert.isTrue(ratio === 5);\n *\n * assert.isTrue(clamped >= Number.MIN_VALUE);\n *\n * assert.isTrue(boundedRandom >= 10 && boundedRandom <= 20);\n *\n * assert.isTrue(nonZeroRandom > 0);\n * ```\n *\n * @template ElementType - The floating-point branded type\n * @template MIN_VALUE - Optional minimum value for bounded types\n * @template MAX_VALUE - Optional maximum value for bounded types\n * @param config - Configuration object\n * @param config.nonZero - If true, excludes zero from valid values\n * @param config.MIN_VALUE - Minimum valid value (inclusive)\n * @param config.MAX_VALUE - Maximum valid value (inclusive)\n * @param config.typeNameInMessage - Human-readable type name for error\n * messages\n * @returns Object containing all type-safe operations for the\n * floating-point type\n * @internal\n */\n export const operatorsForFloat = <\n ElementType extends UnknownNumberBrand,\n MIN_VALUE extends number,\n MAX_VALUE extends number,\n >({\n nonZero,\n MIN_VALUE,\n MAX_VALUE,\n typeNameInMessage,\n }: Readonly<{\n nonZero?: boolean;\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n typeNameInMessage: string;\n }>): OperatorsForFloat<ElementType, MIN_VALUE, MAX_VALUE> => {\n const is = (a: number): a is ElementType =>\n Number.isFinite(a) &&\n (nonZero === true ? a !== 0 : true) &&\n (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);\n\n const castType = castTypeImpl<ElementType>(is, typeNameInMessage);\n\n const clamp: ((a: number) => ElementType) | undefined = pipe(\n clampFnOrUndefined(MIN_VALUE, MAX_VALUE),\n ).mapNullable(\n (cl) =>\n (x: number): ElementType =>\n castType(cl(x)),\n ).value;\n\n const clampOrCastFn: (a: number) => ElementType = clamp ?? castType;\n\n const abs = (x: ElementType): ToNonNegative<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.abs(x) as ToNonNegative<ElementType>;\n\n const min_ = (...values: readonly ElementType[]): ElementType =>\n clampOrCastFn(Math.min(...values));\n\n const max_ = (...values: readonly ElementType[]): ElementType =>\n clampOrCastFn(Math.max(...values));\n\n const pow = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x ** y);\n\n const add = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x + y);\n\n const sub = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x - y);\n\n const mul = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x * y);\n\n const div = (x: ElementType, y: ToNonZero<ElementType>): ElementType =>\n // eslint-disable-next-line total-functions/no-partial-division\n clampOrCastFn(x / y);\n\n const randomImpl = (\n min: number = MIN_VALUE,\n max: number = MAX_VALUE,\n ): number => min + (Math.max(max, min) - min) * Math.random();\n\n const random = (min?: ElementType, max?: ElementType): ElementType =>\n clampOrCastFn(randomImpl(min, max));\n\n const randomNonZero = (\n min?: ElementType,\n max?: ElementType,\n ): ElementType => {\n while (true) {\n const r = random(min, max);\n\n if (isNonZero(r)) return r;\n }\n };\n\n return {\n MIN_VALUE,\n MAX_VALUE,\n is,\n abs,\n min: min_,\n max: max_,\n pow,\n add,\n sub,\n mul,\n div,\n random,\n randomNonZero,\n castType,\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n clamp: clamp as TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType,\n } as const;\n };\n }\n}\n"],"names":["TsDataForgeInternals","RefinedNumberUtils"],"mappings":";;;;IAqBiB;AAAA,CAAV,CAAUA,qBAAAA,KAAV;AAuBE,EAAA,CAAA,CAAUC,mBAAAA,KAAV;AACL,IAAA,MAAM,YAAA,GACJ,CACE,EAAA,EACA,sBAAA,KAEF,CAAmB,CAAA,KAA0B;AAC3C,MAAA,IAAI,CAAC,EAAA,C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AA,MAAM,MAAA,GAAS,CAAC,GAAA,EAAmB,GAAA,KACjC,cAAc,UAAA,CAAW,GAAA,EAAK,GAAG,CAAC,CAAA;AAEpC,MAAA,MAAM,aAAA,GAAgB,CACpB,GAAA,EACA,GAAA,KACgB;AAChB,QAAA,OAAO,IAAA,EAAM;AACX,UAAA,MAAM,CAAA,GAAI,MAAA,CAAO,GAAA,EAAK,GAAG,CAAA;AAEzB,UAAA,IAAI,SAAA,CAAU,CAAC,CAAA,EAAG,OAAO,CAAA;AAAA,QAAA;AAC3B,MAAA,CACF;AAEA,MAAA,OAAO;AAAA,QACL,SAAA;AAAA,QACA,SAAA;AAAA,QACA,EAAA;AAAA,QACA,GAAA;AAAA,QACA,GAAA,EAAK,IAAA;AAAA,QACL,GAAA,EAAK,IAAA;AAAA,QACL,GAAA;AAAA,QACA,GAAA;AAAA,QACA,GAAA;AAAA,QACA,GAAA;AAAA,QACA,GAAA;AAAA,QACA,MAAA;AAAA,QACA,aAAA;AAAA,QACA,QAAA;AAAA;AAAA,QAGA;AAAA,OAGF;AAAA,IAAA,CACF;AAAA,EAAA,CAAA,EAzoBeD,qBAAAA,CAAA,kBAAA,KAAAA,qBAAAA,CAAA,kBAAA,GAAA,EAAA,CAAA,CAAA;AAAA,CAAA,EAvBF,oBAAA,KAAA,oBAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"refined-number-utils.mjs","sources":["../../src/number/refined-number-utils.mts"],"sourcesContent":["import {\n type Brand,\n type ChangeBaseBrand,\n type GetBrandValuePart,\n type Int,\n type IntersectBrand,\n type NonNegativeNumber,\n type NonZeroNumber,\n type PositiveNumber,\n type RelaxedExclude,\n type TypeEq,\n type UnknownBrand,\n type UnwrapBrandFalseKeys,\n type UnwrapBrandTrueKeys,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { expectType } from '../expect-type.mjs';\nimport { pipe } from '../functional/index.mjs';\nimport { Num } from './num.mjs';\n\n/** @internal */\nexport namespace TsDataForgeInternals {\n /**\n * Internal utilities for creating and managing refined (branded) number\n * types.\n *\n * This namespace provides factory functions and type utilities for building\n * type-safe numeric operations with compile-time constraints. It serves as\n * the foundation for all branded number types in the library, including:\n *\n * - Integer types (Int, SafeInt, Int8, Int16, Int32)\n * - Unsigned types (UInt, UInt8, UInt16, UInt32)\n * - Constrained types (NonZero, NonNegative, Positive)\n * - Range-bounded types\n *\n * The utilities handle:\n *\n * - Type validation and narrowing\n * - Arithmetic operations that preserve type constraints\n * - Automatic clamping for bounded types\n * - Random number generation within type bounds\n *\n * @internal This namespace is not part of the public API\n */\n export namespace RefinedNumberUtils {\n const castTypeImpl =\n <BrandedType extends number>(\n is: (n: number) => n is BrandedType,\n typeNameInErrorMessage: string,\n ) =>\n <N extends number>(a: N): BrandedType & N => {\n if (!is(a)) {\n throw new TypeError(`Expected ${typeNameInErrorMessage}, got: ${a}`);\n }\n\n return a;\n };\n\n type UnknownNumberBrand = ChangeBaseBrand<UnknownBrand, number>;\n\n /**\n * Converts a branded number type to include the Int brand.\n *\n * @template N - A branded number type\n * @internal\n */\n export type ToInt<N extends UnknownNumberBrand> = IntersectBrand<N, Int>;\n\n type ToNonZero<N extends UnknownNumberBrand> = IntersectBrand<\n N,\n NonZeroNumber\n >;\n\n const isNonZero = <N extends UnknownNumberBrand>(\n n: N,\n ): n is N & ToNonZero<N> => n !== 0;\n\n type ToNonZeroIntWithSmallInt<N extends Int> = WithSmallInt<\n CastToInt<ToNonZero<N>>\n >;\n\n /**\n * Converts a branded number type to include the NonNegativeNumber brand.\n *\n * @template N - A branded number type\n * @internal\n */\n export type ToNonNegative<N extends UnknownNumberBrand> =\n '!=0' extends UnwrapBrandTrueKeys<N>\n ? IntersectBrand<N, PositiveNumber>\n : IntersectBrand<N, NonNegativeNumber>;\n\n /**\n * Removes the non-zero brand constraint from a branded number type. Used\n * when operations may produce zero values.\n *\n * @template N - A branded number type\n * @internal\n */\n export type RemoveNonZeroBrandKey<N extends UnknownNumberBrand> = Brand<\n GetBrandValuePart<N>,\n RelaxedExclude<UnwrapBrandTrueKeys<N>, '!=0'> & string,\n RelaxedExclude<UnwrapBrandFalseKeys<N>, '<=0' | '>=0'> & string\n >;\n\n type CastToInt<N> = N extends Int ? N : never;\n\n /**\n * Generates a type-safe API for a branded number type based on its\n * characteristics.\n *\n * This type dynamically constructs an object type with appropriate methods\n * based on the number class. For example:\n *\n * - Integer types don't get floor/ceil/round methods\n * - Non-negative types don't get abs method\n * - Range-bounded types get MIN_VALUE/MAX_VALUE constants\n *\n * @template N - The branded number type\n * @template classes - Union of characteristics: 'int' | 'non-negative' |\n * 'positive' | 'range'\n * @internal\n */\n /** The closed binary arithmetic operations a branded namespace may expose. */\n export type NumberClassBinOp = 'add' | 'div' | 'mul' | 'sub';\n\n export type NumberClass<\n N extends UnknownNumberBrand,\n classes extends 'int' | 'non-negative' | 'positive' | 'range',\n binOps extends NumberClassBinOp = NumberClassBinOp,\n > = ('int' extends classes\n ? unknown\n : 'positive' extends classes\n ? Readonly<{\n floor: (x: N, y: N) => RemoveNonZeroBrandKey<ToInt<N>>;\n ceil: (x: N, y: N) => ToInt<N>;\n round: (x: N, y: N) => RemoveNonZeroBrandKey<ToInt<N>>;\n }>\n : Readonly<{\n floor: (x: N, y: N) => ToInt<N>;\n ceil: (x: N, y: N) => ToInt<N>;\n round: (x: N, y: N) => ToInt<N>;\n }>) &\n ('non-negative' extends classes\n ? Readonly<{\n MIN_VALUE: number;\n fromNumber: (a: number) => N;\n }>\n : unknown) &\n ('non-negative' extends classes\n ? unknown\n : 'positive' extends classes\n ? unknown\n : Readonly<{\n abs: (x: N) => ToNonNegative<N>;\n }>) &\n ('positive' extends classes\n ? Readonly<{\n MIN_VALUE: number;\n fromNumber: (a: number) => N;\n }>\n : unknown) &\n ('range' extends classes\n ? Readonly<{\n MIN_VALUE: number;\n MAX_VALUE: number;\n fromNumber: (a: number) => N;\n }>\n : unknown) &\n Pick<\n Readonly<{\n add: (x: N, y: N) => N;\n sub: (x: N, y: N) => N;\n mul: (x: N, y: N) => N;\n div: (x: N, y: ToNonZero<N>) => N;\n }>,\n binOps\n > &\n Readonly<{\n is: (a: number) => a is N;\n min: (...values: readonly N[]) => N;\n max: (...values: readonly N[]) => N;\n random: (min: N, max: N) => N;\n pow: (x: N, y: N) => N;\n }>;\n\n type BaseKeys =\n 'add' | 'div' | 'is' | 'max' | 'min' | 'mul' | 'pow' | 'random' | 'sub';\n\n type FloatMethods = 'ceil' | 'floor' | 'round';\n\n expectType<keyof NumberClass<UnknownNumberBrand, 'int'>, BaseKeys | 'abs'>(\n '=',\n );\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, never>,\n BaseKeys | FloatMethods | 'abs'\n >('=');\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, 'non-negative'>,\n BaseKeys | FloatMethods | 'fromNumber' | 'MIN_VALUE'\n >('=');\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, 'positive'>,\n BaseKeys | FloatMethods | 'fromNumber' | 'MIN_VALUE'\n >('=');\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, 'int' | 'range'>,\n BaseKeys | 'abs' | 'fromNumber' | 'MAX_VALUE' | 'MIN_VALUE'\n >('=');\n\n const isFnOrUndefined = (\n min: number | undefined,\n max: number | undefined,\n ): ((n: number) => boolean) | undefined =>\n min === undefined\n ? max === undefined\n ? undefined\n : (n) => n <= max\n : max === undefined\n ? (n) => min <= n\n : Num.isInRangeInclusive(min, max);\n\n const clampFnOrUndefined = (\n min: number | undefined,\n max: number | undefined,\n ): ((n: number) => number) | undefined =>\n min === undefined\n ? max === undefined\n ? undefined\n : (n) => Math.min(max, n)\n : max === undefined\n ? (n) => Math.max(min, n)\n : Num.clamp(min, max);\n\n type OperatorsForInteger<\n ElementType extends Int,\n MIN_VALUE extends number,\n MAX_VALUE extends number,\n ElementTypeWithSmallInt extends WithSmallInt<ElementType> =\n WithSmallInt<ElementType>,\n > = Readonly<{\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n\n is: (a: number) => a is ElementType;\n\n abs: (x: ElementTypeWithSmallInt) => ToNonNegative<ElementType>;\n\n min: (...values: readonly ElementTypeWithSmallInt[]) => ElementType;\n\n max: (...values: readonly ElementTypeWithSmallInt[]) => ElementType;\n\n pow: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n add: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n sub: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n mul: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n div: (\n x: ElementTypeWithSmallInt,\n y: ToNonZeroIntWithSmallInt<ElementType>,\n ) => ElementType;\n\n random: (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ) => ElementType;\n\n randomNonZero: (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ) => ElementType;\n\n castType: <N extends number>(x: N) => ElementType & N;\n\n fromNumber: TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType;\n }>;\n\n /**\n * Factory function that creates a complete set of type-safe operations for\n * integer types.\n *\n * This function generates:\n *\n * - Type guards and validators\n * - Arithmetic operations that preserve type constraints\n * - Utility functions (min, max, abs, random)\n * - Automatic clamping for bounded types\n *\n * All operations ensure results remain within the type's constraints, using\n * clamping when bounds are specified.\n *\n * @example\n *\n * ```ts\n * const intOps = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n * SafeInt,\n * number,\n * number\n * >({\n * integerOrSafeInteger: 'SafeInteger',\n * MIN_VALUE: Number.MIN_SAFE_INTEGER,\n * MAX_VALUE: Number.MAX_SAFE_INTEGER,\n * typeNameInMessage: 'SafeInt',\n * } as const);\n *\n * const six = intOps.castType(6);\n *\n * const four = intOps.castType(4);\n *\n * const sum = intOps.add(six, four);\n *\n * const difference = intOps.sub(six, four);\n *\n * const product = intOps.mul(six, four);\n *\n * const quotient = intOps.div(six, intOps.castType(2));\n *\n * const coerced = intOps.fromNumber(1.5);\n *\n * const randomValue = intOps.random();\n *\n * assert.isTrue(sum === 10);\n *\n * assert.isTrue(difference === 2);\n *\n * assert.isTrue(product === 24);\n *\n * assert.isTrue(quotient === 3);\n *\n * assert.isTrue(coerced === 2);\n *\n * assert.isTrue(Number.isSafeInteger(randomValue));\n * ```\n *\n * @template ElementType - The integer branded type\n * @template MIN_VALUE - Optional minimum value for bounded types\n * @template MAX_VALUE - Optional maximum value for bounded types\n * @param config - Configuration object\n * @param config.integerOrSafeInteger - Whether to use Number.isInteger or\n * Number.isSafeInteger\n * @param config.nonZero - If true, excludes zero from valid values\n * @param config.MIN_VALUE - Minimum valid value (inclusive)\n * @param config.MAX_VALUE - Maximum valid value (inclusive)\n * @param config.typeNameInMessage - Human-readable type name for error\n * messages\n * @returns Object containing all type-safe operations for the integer type\n * @internal\n */\n export const operatorsForInteger = <\n ElementType extends Int,\n MIN_VALUE extends number,\n MAX_VALUE extends number,\n >({\n integerOrSafeInteger,\n nonZero,\n MIN_VALUE,\n MAX_VALUE,\n typeNameInMessage,\n }: Readonly<{\n integerOrSafeInteger: 'Integer' | 'SafeInteger';\n nonZero?: boolean;\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n typeNameInMessage: string;\n }>): OperatorsForInteger<ElementType, MIN_VALUE, MAX_VALUE> => {\n type ElementTypeWithSmallInt = WithSmallInt<ElementType>;\n\n const is = (a: number): a is ElementType =>\n (integerOrSafeInteger === 'Integer'\n ? Number.isInteger(a)\n : Number.isSafeInteger(a)) &&\n (nonZero === true ? a !== 0 : true) &&\n (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);\n\n const castType = castTypeImpl<ElementType>(is, typeNameInMessage);\n\n const fromNumber: ((a: number) => ElementType) | undefined = pipe(\n clampFnOrUndefined(MIN_VALUE, MAX_VALUE),\n ).mapNullable(\n (cl) =>\n (x: number): ElementType =>\n castType(Math.round(cl(x))),\n ).value;\n\n const clampOrCastFn: (a: number) => ElementType = fromNumber ?? castType;\n\n const abs = (x: ElementTypeWithSmallInt): ToNonNegative<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.abs(clampOrCastFn(x)) as ToNonNegative<ElementType>;\n\n const min_ = (\n ...values: readonly ElementTypeWithSmallInt[]\n ): ElementType => clampOrCastFn(Math.min(...values));\n\n const max_ = (\n ...values: readonly ElementTypeWithSmallInt[]\n ): ElementType => clampOrCastFn(Math.max(...values));\n\n const pow = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x ** y);\n\n const add = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x + y);\n\n const sub = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x - y);\n\n const mul = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x * y);\n\n const div = (\n x: ElementTypeWithSmallInt,\n y: ToNonZeroIntWithSmallInt<ElementType>,\n ): ElementType =>\n clampOrCastFn(\n Math.floor(\n // eslint-disable-next-line total-functions/no-partial-division\n x / y,\n ),\n );\n\n const randomImpl = (\n min: number = MIN_VALUE,\n max: number = MAX_VALUE,\n ): number =>\n min + Math.floor((Math.max(max, min) - min + 1) * Math.random());\n\n // [-5, 5] -> floor(11 * Math.random()) + (-5)\n const random = (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(randomImpl(min, max));\n\n const randomNonZero = (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ): ElementType => {\n while (true) {\n const r = randomImpl(min, max);\n\n if (Num.isNonZero(r)) return clampOrCastFn(r);\n }\n };\n\n return {\n MIN_VALUE,\n MAX_VALUE,\n is,\n abs,\n min: min_,\n max: max_,\n pow,\n add,\n sub,\n mul,\n div,\n random,\n randomNonZero,\n castType,\n\n fromNumber:\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n fromNumber as TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType,\n } as const;\n };\n\n type OperatorsForFloat<\n ElementType extends UnknownNumberBrand,\n MIN_VALUE extends number | undefined,\n MAX_VALUE extends number | undefined,\n > = Readonly<{\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n\n is: (a: number) => a is ElementType;\n\n abs: (x: ElementType) => ToNonNegative<ElementType>;\n min: (...values: readonly ElementType[]) => ElementType;\n max: (...values: readonly ElementType[]) => ElementType;\n pow: (x: ElementType, y: ElementType) => ElementType;\n add: (x: ElementType, y: ElementType) => ElementType;\n sub: (x: ElementType, y: ElementType) => ElementType;\n mul: (x: ElementType, y: ElementType) => ElementType;\n div: (x: ElementType, y: ToNonZero<ElementType>) => ElementType;\n random: (min?: ElementType, max?: ElementType) => ElementType;\n randomNonZero: (min?: ElementType, max?: ElementType) => ElementType;\n\n castType: <N extends number>(x: N) => ElementType & N;\n\n fromNumber: TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType;\n }>;\n\n /**\n * Factory function that creates a complete set of type-safe operations for\n * floating-point types.\n *\n * This function generates:\n *\n * - Type guards and validators (checking for finite values)\n * - Arithmetic operations that preserve type constraints\n * - Utility functions (min, max, abs, random)\n * - Automatic clamping for bounded types\n *\n * All operations ensure results remain finite and within any specified\n * bounds. Division by zero is prevented through type constraints.\n *\n * @example\n *\n * ```ts\n * const floatOps = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<\n * PositiveFiniteNumber,\n * number,\n * number\n * >({\n * nonZero: true,\n * MIN_VALUE: Number.MIN_VALUE,\n * MAX_VALUE: Number.MAX_VALUE,\n * typeNameInMessage: 'PositiveFiniteNumber',\n * } as const);\n *\n * const fortyTwo = floatOps.castType(42.5);\n *\n * const seven = floatOps.castType(7.5);\n *\n * const sum = floatOps.add(fortyTwo, seven);\n *\n * const ratio = floatOps.div(sum, floatOps.castType(10));\n *\n * const coerced = floatOps.fromNumber(0);\n *\n * const boundedRandom = floatOps.random(\n * floatOps.castType(10),\n * floatOps.castType(20),\n * );\n *\n * const nonZeroRandom = floatOps.randomNonZero();\n *\n * assert.isTrue(sum === 50);\n *\n * assert.isTrue(ratio === 5);\n *\n * assert.isTrue(coerced >= Number.MIN_VALUE);\n *\n * assert.isTrue(boundedRandom >= 10 && boundedRandom <= 20);\n *\n * assert.isTrue(nonZeroRandom > 0);\n * ```\n *\n * @template ElementType - The floating-point branded type\n * @template MIN_VALUE - Optional minimum value for bounded types\n * @template MAX_VALUE - Optional maximum value for bounded types\n * @param config - Configuration object\n * @param config.nonZero - If true, excludes zero from valid values\n * @param config.MIN_VALUE - Minimum valid value (inclusive)\n * @param config.MAX_VALUE - Maximum valid value (inclusive)\n * @param config.typeNameInMessage - Human-readable type name for error\n * messages\n * @returns Object containing all type-safe operations for the\n * floating-point type\n * @internal\n */\n export const operatorsForFloat = <\n ElementType extends UnknownNumberBrand,\n MIN_VALUE extends number,\n MAX_VALUE extends number,\n >({\n nonZero,\n MIN_VALUE,\n MAX_VALUE,\n typeNameInMessage,\n }: Readonly<{\n nonZero?: boolean;\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n typeNameInMessage: string;\n }>): OperatorsForFloat<ElementType, MIN_VALUE, MAX_VALUE> => {\n const is = (a: number): a is ElementType =>\n Number.isFinite(a) &&\n (nonZero === true ? a !== 0 : true) &&\n (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);\n\n const castType = castTypeImpl<ElementType>(is, typeNameInMessage);\n\n const fromNumber: ((a: number) => ElementType) | undefined = pipe(\n clampFnOrUndefined(MIN_VALUE, MAX_VALUE),\n ).mapNullable(\n (cl) =>\n (x: number): ElementType =>\n castType(cl(x)),\n ).value;\n\n const clampOrCastFn: (a: number) => ElementType = fromNumber ?? castType;\n\n const abs = (x: ElementType): ToNonNegative<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.abs(x) as ToNonNegative<ElementType>;\n\n const min_ = (...values: readonly ElementType[]): ElementType =>\n clampOrCastFn(Math.min(...values));\n\n const max_ = (...values: readonly ElementType[]): ElementType =>\n clampOrCastFn(Math.max(...values));\n\n const pow = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x ** y);\n\n const add = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x + y);\n\n const sub = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x - y);\n\n const mul = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x * y);\n\n const div = (x: ElementType, y: ToNonZero<ElementType>): ElementType =>\n // eslint-disable-next-line total-functions/no-partial-division\n clampOrCastFn(x / y);\n\n const randomImpl = (\n min: number = MIN_VALUE,\n max: number = MAX_VALUE,\n ): number => min + (Math.max(max, min) - min) * Math.random();\n\n const random = (min?: ElementType, max?: ElementType): ElementType =>\n clampOrCastFn(randomImpl(min, max));\n\n const randomNonZero = (\n min?: ElementType,\n max?: ElementType,\n ): ElementType => {\n while (true) {\n const r = random(min, max);\n\n if (isNonZero(r)) return r;\n }\n };\n\n return {\n MIN_VALUE,\n MAX_VALUE,\n is,\n abs,\n min: min_,\n max: max_,\n pow,\n add,\n sub,\n mul,\n div,\n random,\n randomNonZero,\n castType,\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n fromNumber: fromNumber as TypeEq<\n MAX_VALUE | MIN_VALUE,\n undefined\n > extends true\n ? undefined\n : (x: number) => ElementType,\n } as const;\n };\n }\n}\n"],"names":["TsDataForgeInternals","RefinedNumberUtils"],"mappings":";;;;IAqBiB;AAAA,CAAV,CAAUA,qBAAAA,KAAV;AAuBE,EAAA,CAAA,CAAUC,m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