ts-data-forge 11.0.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/number/branded-types/finite-number.d.mts +47 -61
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +37 -41
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +40 -46
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +29 -31
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +71 -59
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +56 -47
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +71 -59
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +56 -47
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +76 -60
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +62 -49
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +66 -49
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +48 -39
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +64 -57
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +49 -44
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +80 -65
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +65 -53
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +71 -58
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +55 -45
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +71 -59
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +55 -46
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +70 -55
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +55 -43
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +46 -146
- package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +33 -108
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +62 -54
- package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +46 -41
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +62 -49
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +46 -37
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +51 -38
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +31 -27
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +59 -54
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +44 -41
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +59 -55
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +44 -42
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +60 -55
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +44 -42
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +59 -54
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +43 -41
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +82 -64
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +67 -52
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +53 -70
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +42 -52
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +68 -58
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +52 -45
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +68 -58
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +52 -45
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +72 -61
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +56 -48
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +68 -58
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +52 -45
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +68 -59
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +52 -46
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +52 -66
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +45 -47
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +68 -58
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +53 -46
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +72 -55
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +52 -45
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +66 -59
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +51 -45
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +66 -57
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +50 -45
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +62 -66
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +57 -51
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +66 -59
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +57 -51
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +9 -9
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +7 -7
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/package.json +2 -1
- package/src/number/branded-types/finite-number.mts +47 -61
- package/src/number/branded-types/int.mts +40 -46
- package/src/number/branded-types/int16.mts +72 -60
- package/src/number/branded-types/int32.mts +72 -60
- package/src/number/branded-types/negative-finite-number.mts +78 -71
- package/src/number/branded-types/negative-finite-number.test.mts +4 -4
- package/src/number/branded-types/negative-int.mts +68 -60
- package/src/number/branded-types/negative-int.test.mts +5 -5
- package/src/number/branded-types/negative-safe-int.mts +66 -68
- package/src/number/branded-types/negative-safe-int.test.mts +4 -4
- package/src/number/branded-types/non-negative-finite-number.mts +81 -66
- package/src/number/branded-types/non-negative-int16.mts +72 -59
- package/src/number/branded-types/non-negative-int32.mts +72 -60
- package/src/number/branded-types/non-positive-finite-number.mts +71 -56
- package/src/number/branded-types/non-positive-finite-number.test.mts +7 -7
- package/src/number/branded-types/non-positive-int.mts +47 -147
- package/src/number/branded-types/non-positive-int.test.mts +7 -7
- package/src/number/branded-types/non-positive-safe-int.mts +63 -55
- package/src/number/branded-types/non-positive-safe-int.test.mts +7 -7
- package/src/number/branded-types/non-zero-finite-number.mts +62 -51
- package/src/number/branded-types/non-zero-int.mts +51 -38
- package/src/number/branded-types/non-zero-int16.mts +60 -55
- package/src/number/branded-types/non-zero-int32.mts +60 -56
- package/src/number/branded-types/non-zero-safe-int.mts +61 -56
- package/src/number/branded-types/non-zero-uint16.mts +60 -55
- package/src/number/branded-types/non-zero-uint32.mts +60 -55
- package/src/number/branded-types/positive-finite-number.mts +83 -65
- package/src/number/branded-types/positive-int.mts +54 -71
- package/src/number/branded-types/positive-int16.mts +69 -59
- package/src/number/branded-types/positive-int32.mts +69 -59
- package/src/number/branded-types/positive-safe-int.mts +73 -62
- package/src/number/branded-types/positive-uint16.mts +69 -59
- package/src/number/branded-types/positive-uint32.mts +69 -60
- package/src/number/branded-types/safe-int.mts +53 -67
- package/src/number/branded-types/safe-uint.mts +69 -59
- package/src/number/branded-types/uint.mts +73 -56
- package/src/number/branded-types/uint16.mts +67 -60
- package/src/number/branded-types/uint32.mts +67 -58
- package/src/number/enum/int8.mts +70 -73
- package/src/number/enum/int8.test.mts +7 -4
- package/src/number/enum/uint8.mts +74 -66
- package/src/number/enum/uint8.test.mts +7 -4
- package/src/number/refined-number-utils.mts +22 -19
|
@@ -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,CAAG,CAAC,CAAA,EAAG;AACV,QAAA,MAAM,IAAI,SAAA,CAAU,CAAA,SAAA,EAAY,sBAAsB,CAAA,OAAA,EAAU,CAAC,CAAA,CAAE,CAAA;AAAA,MAAA;AAGrE,MAAA,OAAO,CAAA;AAAA,IAAA,CACT;AAiBF,IAAA,MAAM,SAAA,GAAY,CAChB,CAAA,KAC0B,CAAA,KAAM,CAAA;AA4IlC,IAAA,MAAM,eAAA,GAAkB,CACtB,GAAA,EACA,GAAA,KAEA,QAAQ,MAAA,GACJ,GAAA,KAAQ,MAAA,GACN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,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,mBAAAA,KAAV;AACL,IAAA,MAAM,YAAA,GACJ,CACE,EAAA,EACA,sBAAA,KAEF,CAAmB,CAAA,KAA0B;AAC3C,MAAA,IAAI,CAAC,EAAA,CAAG,CAAC,CAAA,EAAG;AACV,QAAA,MAAM,IAAI,SAAA,CAAU,CAAA,SAAA,EAAY,sBAAsB,CAAA,OAAA,EAAU,CAAC,CAAA,CAAE,CAAA;AAAA,MAAA;AAGrE,MAAA,OAAO,CAAA;AAAA,IAAA,CACT;AAiBF,IAAA,MAAM,SAAA,GAAY,CAChB,CAAA,KAC0B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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,OAMF;AAAA,IAAA,CACF;AAAA,EAAA,CAAA,EA5oBeD,qBAAAA,CAAA,kBAAA,KAAAA,qBAAAA,CAAA,kBAAA,GAAA,EAAA,CAAA,CAAA;AAAA,CAAA,EAvBF,oBAAA,KAAA,oBAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-data-forge",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"fmt": "format-uncommitted --cwd .",
|
|
68
68
|
"fmt:diff": "format-diff-from origin/main --cwd .",
|
|
69
69
|
"fmt:full": "pnpm run z:prettier .",
|
|
70
|
+
"gen:branded-number": "tsx ./scripts/gen-branded-number/generate.mts && pnpm run doc:embed:jsdoc && pnpm run z:prettier 'src/number/branded-types/*.mts' 'src/number/enum/*.mts'",
|
|
70
71
|
"gi": "run-s gi:src fmt",
|
|
71
72
|
"gi:src": "tsx scripts/cmd/gen-index.mts",
|
|
72
73
|
"lint": "eslint .",
|
|
@@ -59,47 +59,37 @@ expectType<TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>, Int>(
|
|
|
59
59
|
/**
|
|
60
60
|
* Type guard that checks if a value is a finite number.
|
|
61
61
|
*
|
|
62
|
-
* Returns `true`
|
|
63
|
-
*
|
|
64
|
-
* these special values.
|
|
62
|
+
* Returns `true` only for a finite value — never `NaN`, `Infinity`, or
|
|
63
|
+
* `-Infinity`.
|
|
65
64
|
*
|
|
66
65
|
* @param value - The value to check
|
|
67
|
-
* @returns `true` if the value is finite, `false` otherwise
|
|
66
|
+
* @returns `true` if the value is a finite number, `false` otherwise
|
|
68
67
|
*/
|
|
69
68
|
export const isFiniteNumber = is;
|
|
70
69
|
|
|
71
70
|
/**
|
|
72
|
-
* Casts a number to
|
|
71
|
+
* Casts a `number` to the `FiniteNumber` branded type.
|
|
73
72
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* safety for operations that require finite numeric values.
|
|
73
|
+
* Validates that the value is a finite number and returns it with the
|
|
74
|
+
* `FiniteNumber` brand. Throws a `TypeError` otherwise.
|
|
77
75
|
*
|
|
78
76
|
* @param value - The value to cast
|
|
79
|
-
* @returns The value as a FiniteNumber
|
|
80
|
-
* @throws {TypeError} If the value is
|
|
77
|
+
* @returns The value as a `FiniteNumber`
|
|
78
|
+
* @throws {TypeError} If the value is not a finite number
|
|
81
79
|
*/
|
|
82
80
|
export const asFiniteNumber = castType;
|
|
83
81
|
|
|
84
82
|
/**
|
|
85
|
-
* Namespace providing type-safe operations for FiniteNumber branded
|
|
83
|
+
* Namespace providing type-safe operations for the `FiniteNumber` branded type.
|
|
86
84
|
*
|
|
87
|
-
* The FiniteNumber type represents
|
|
88
|
-
* special values NaN, Infinity, and -Infinity. All operations are guaranteed to
|
|
89
|
-
* maintain the finite constraint when given finite inputs.
|
|
90
|
-
*
|
|
91
|
-
* This type is essential for:
|
|
92
|
-
*
|
|
93
|
-
* - Mathematical operations that require real numbers
|
|
94
|
-
* - Preventing NaN/Infinity propagation in calculations
|
|
95
|
-
* - Ensuring numeric stability in algorithms
|
|
85
|
+
* The `FiniteNumber` type represents a finite number.
|
|
96
86
|
*/
|
|
97
87
|
export const FiniteNumber = {
|
|
98
88
|
/**
|
|
99
89
|
* Type guard that checks if a value is a finite number.
|
|
100
90
|
*
|
|
101
91
|
* @param value - The value to check
|
|
102
|
-
* @returns `true` if the value is finite, `false` otherwise
|
|
92
|
+
* @returns `true` if the value is a finite number, `false` otherwise
|
|
103
93
|
* @see {@link isFiniteNumber} for usage examples
|
|
104
94
|
*/
|
|
105
95
|
is,
|
|
@@ -107,110 +97,106 @@ export const FiniteNumber = {
|
|
|
107
97
|
/**
|
|
108
98
|
* Returns the absolute value of a finite number.
|
|
109
99
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
100
|
+
* The result is non-negative and keeps the `FiniteNumber` brand.
|
|
101
|
+
*
|
|
102
|
+
* @param a - The finite number value
|
|
103
|
+
* @returns The absolute value as a non-negative `FiniteNumber`
|
|
112
104
|
*/
|
|
113
105
|
abs,
|
|
114
106
|
|
|
115
107
|
/**
|
|
116
|
-
* Returns the
|
|
108
|
+
* Returns the smallest of the given finite numbers.
|
|
117
109
|
*
|
|
118
110
|
* @param values - The finite numbers to compare (at least one required)
|
|
119
|
-
* @returns The smallest value as a FiniteNumber
|
|
111
|
+
* @returns The smallest value as a `FiniteNumber`
|
|
120
112
|
*/
|
|
121
113
|
min: min_,
|
|
122
114
|
|
|
123
115
|
/**
|
|
124
|
-
* Returns the
|
|
116
|
+
* Returns the largest of the given finite numbers.
|
|
125
117
|
*
|
|
126
118
|
* @param values - The finite numbers to compare (at least one required)
|
|
127
|
-
* @returns The largest value as a FiniteNumber
|
|
119
|
+
* @returns The largest value as a `FiniteNumber`
|
|
128
120
|
*/
|
|
129
121
|
max: max_,
|
|
130
122
|
|
|
131
123
|
/**
|
|
132
|
-
* Returns the
|
|
124
|
+
* Returns the greatest integer less than or equal to a finite number.
|
|
133
125
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @returns The
|
|
126
|
+
* @param a - The finite number value
|
|
127
|
+
* @returns The floored value as an integer
|
|
136
128
|
*/
|
|
137
129
|
floor,
|
|
138
130
|
|
|
139
131
|
/**
|
|
140
|
-
* Returns the smallest integer greater than or equal to
|
|
141
|
-
* number.
|
|
132
|
+
* Returns the smallest integer greater than or equal to a finite number.
|
|
142
133
|
*
|
|
143
|
-
* @param
|
|
144
|
-
* @returns The
|
|
134
|
+
* @param a - The finite number value
|
|
135
|
+
* @returns The ceiled value as an integer
|
|
145
136
|
*/
|
|
146
137
|
ceil,
|
|
147
138
|
|
|
148
139
|
/**
|
|
149
|
-
*
|
|
140
|
+
* Returns the value of a finite number rounded to the nearest integer.
|
|
150
141
|
*
|
|
151
|
-
* @param
|
|
152
|
-
* @returns The rounded value as an
|
|
142
|
+
* @param a - The finite number value
|
|
143
|
+
* @returns The rounded value as an integer
|
|
153
144
|
*/
|
|
154
145
|
round,
|
|
155
146
|
|
|
156
147
|
/**
|
|
157
|
-
* Generates a random
|
|
148
|
+
* Generates a random `FiniteNumber` within the given range.
|
|
158
149
|
*
|
|
159
|
-
* The
|
|
160
|
-
* bounds are inclusive.
|
|
150
|
+
* The range is inclusive on both ends.
|
|
161
151
|
*
|
|
162
152
|
* @param min - The minimum value (inclusive)
|
|
163
153
|
* @param max - The maximum value (inclusive)
|
|
164
|
-
* @returns A random FiniteNumber in
|
|
154
|
+
* @returns A random `FiniteNumber` in `[min, max]`
|
|
165
155
|
*/
|
|
166
156
|
random,
|
|
167
157
|
|
|
168
158
|
/**
|
|
169
|
-
* Raises a
|
|
159
|
+
* Raises `a` to the power `b`, returning `a ** b` as a `FiniteNumber`.
|
|
170
160
|
*
|
|
171
161
|
* @param a - The base finite number
|
|
172
162
|
* @param b - The exponent finite number
|
|
173
|
-
* @returns `a ** b` as a FiniteNumber
|
|
163
|
+
* @returns `a ** b` as a `FiniteNumber`
|
|
174
164
|
*/
|
|
175
165
|
pow,
|
|
176
166
|
|
|
177
167
|
/**
|
|
178
|
-
* Adds two finite numbers
|
|
168
|
+
* Adds two finite numbers, returning `a + b` as a `FiniteNumber`.
|
|
179
169
|
*
|
|
180
|
-
* @param a -
|
|
181
|
-
* @param b -
|
|
182
|
-
* @returns `a
|
|
170
|
+
* @param a - The first finite number
|
|
171
|
+
* @param b - The second finite number
|
|
172
|
+
* @returns The sum of `a` and `b` as a `FiniteNumber`
|
|
183
173
|
*/
|
|
184
174
|
add,
|
|
185
175
|
|
|
186
176
|
/**
|
|
187
|
-
* Subtracts two finite numbers
|
|
177
|
+
* Subtracts two finite numbers, returning `a - b` as a `FiniteNumber`.
|
|
188
178
|
*
|
|
189
|
-
* @param a -
|
|
190
|
-
* @param b -
|
|
191
|
-
* @returns `a
|
|
179
|
+
* @param a - The first finite number
|
|
180
|
+
* @param b - The second finite number
|
|
181
|
+
* @returns The difference of `a` and `b` as a `FiniteNumber`
|
|
192
182
|
*/
|
|
193
183
|
sub,
|
|
194
184
|
|
|
195
185
|
/**
|
|
196
|
-
* Multiplies two finite numbers
|
|
186
|
+
* Multiplies two finite numbers, returning `a * b` as a `FiniteNumber`.
|
|
197
187
|
*
|
|
198
|
-
* @param a -
|
|
199
|
-
* @param b -
|
|
200
|
-
* @returns `a
|
|
188
|
+
* @param a - The first finite number
|
|
189
|
+
* @param b - The second finite number
|
|
190
|
+
* @returns The product of `a` and `b` as a `FiniteNumber`
|
|
201
191
|
*/
|
|
202
192
|
mul,
|
|
203
193
|
|
|
204
194
|
/**
|
|
205
|
-
* Divides two finite numbers
|
|
206
|
-
*
|
|
207
|
-
* The divisor must be non-zero (enforced by type constraints). The result is
|
|
208
|
-
* guaranteed to be finite when both inputs are finite and the divisor is
|
|
209
|
-
* non-zero.
|
|
195
|
+
* Divides two finite numbers, returning `a / b` as a `FiniteNumber`.
|
|
210
196
|
*
|
|
211
197
|
* @param a - The dividend
|
|
212
198
|
* @param b - The divisor (must be non-zero)
|
|
213
|
-
* @returns
|
|
199
|
+
* @returns `a / b` as a `FiniteNumber`
|
|
214
200
|
*/
|
|
215
201
|
div,
|
|
216
202
|
} as const;
|
|
@@ -34,9 +34,8 @@ const {
|
|
|
34
34
|
/**
|
|
35
35
|
* Type guard that checks if a value is an integer.
|
|
36
36
|
*
|
|
37
|
-
* Returns `true`
|
|
38
|
-
*
|
|
39
|
-
* range, unlike SafeInt.
|
|
37
|
+
* Returns `true` for an integer — a value with no fractional component,
|
|
38
|
+
* including values outside the safe integer range (unlike `SafeInt`).
|
|
40
39
|
*
|
|
41
40
|
* @example
|
|
42
41
|
*
|
|
@@ -54,11 +53,10 @@ const {
|
|
|
54
53
|
export const isInt = is;
|
|
55
54
|
|
|
56
55
|
/**
|
|
57
|
-
* Casts a number to
|
|
56
|
+
* Casts a `number` to the `Int` branded type.
|
|
58
57
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* not a finite number.
|
|
58
|
+
* Validates that the value is an integer and returns it with the `Int` brand.
|
|
59
|
+
* Throws a `TypeError` otherwise.
|
|
62
60
|
*
|
|
63
61
|
* @example
|
|
64
62
|
*
|
|
@@ -71,21 +69,19 @@ export const isInt = is;
|
|
|
71
69
|
* ```
|
|
72
70
|
*
|
|
73
71
|
* @param value - The value to cast
|
|
74
|
-
* @returns The value as an Int
|
|
72
|
+
* @returns The value as an `Int`
|
|
75
73
|
* @throws {TypeError} If the value is not an integer
|
|
76
74
|
*/
|
|
77
75
|
export const asInt = castType;
|
|
78
76
|
|
|
79
77
|
/**
|
|
80
|
-
* Namespace providing type-safe operations for Int branded
|
|
78
|
+
* Namespace providing type-safe operations for the `Int` branded type.
|
|
81
79
|
*
|
|
82
|
-
* The Int type represents
|
|
83
|
-
* range restrictions. All operations preserve the integer constraint, using
|
|
84
|
-
* floor division for division operations.
|
|
80
|
+
* The `Int` type represents an integer. Division (`div`) uses floor division.
|
|
85
81
|
*
|
|
86
|
-
* Unlike SafeInt
|
|
87
|
-
*
|
|
88
|
-
*
|
|
82
|
+
* Unlike `SafeInt`, `Int` allows values outside the safe integer range (±2^53 −
|
|
83
|
+
* 1), so very large magnitudes may lose precision in JavaScript's `number`
|
|
84
|
+
* type.
|
|
89
85
|
*/
|
|
90
86
|
export const Int = {
|
|
91
87
|
/**
|
|
@@ -110,9 +106,9 @@ export const Int = {
|
|
|
110
106
|
/**
|
|
111
107
|
* Returns the absolute value of an integer.
|
|
112
108
|
*
|
|
113
|
-
* The result is
|
|
114
|
-
* Math.abs(Number.MIN_SAFE_INTEGER) exceeds Number.MAX_SAFE_INTEGER
|
|
115
|
-
* SafeInt for guaranteed precision.
|
|
109
|
+
* The result is non-negative and keeps the `Int` brand. Note that
|
|
110
|
+
* `Math.abs(Number.MIN_SAFE_INTEGER)` exceeds `Number.MAX_SAFE_INTEGER`, so
|
|
111
|
+
* use `SafeInt` for guaranteed precision.
|
|
116
112
|
*
|
|
117
113
|
* @example
|
|
118
114
|
*
|
|
@@ -127,12 +123,12 @@ export const Int = {
|
|
|
127
123
|
* ```
|
|
128
124
|
*
|
|
129
125
|
* @param a - The integer value
|
|
130
|
-
* @returns The absolute value as a non-negative Int
|
|
126
|
+
* @returns The absolute value as a non-negative `Int`
|
|
131
127
|
*/
|
|
132
128
|
abs,
|
|
133
129
|
|
|
134
130
|
/**
|
|
135
|
-
* Returns the
|
|
131
|
+
* Returns the smallest of the given integers.
|
|
136
132
|
*
|
|
137
133
|
* @example
|
|
138
134
|
*
|
|
@@ -143,12 +139,12 @@ export const Int = {
|
|
|
143
139
|
* ```
|
|
144
140
|
*
|
|
145
141
|
* @param values - The integers to compare (at least one required)
|
|
146
|
-
* @returns The smallest value as an Int
|
|
142
|
+
* @returns The smallest value as an `Int`
|
|
147
143
|
*/
|
|
148
144
|
min: min_,
|
|
149
145
|
|
|
150
146
|
/**
|
|
151
|
-
* Returns the
|
|
147
|
+
* Returns the largest of the given integers.
|
|
152
148
|
*
|
|
153
149
|
* @example
|
|
154
150
|
*
|
|
@@ -159,15 +155,14 @@ export const Int = {
|
|
|
159
155
|
* ```
|
|
160
156
|
*
|
|
161
157
|
* @param values - The integers to compare (at least one required)
|
|
162
|
-
* @returns The largest value as an Int
|
|
158
|
+
* @returns The largest value as an `Int`
|
|
163
159
|
*/
|
|
164
160
|
max: max_,
|
|
165
161
|
|
|
166
162
|
/**
|
|
167
|
-
* Generates a random
|
|
163
|
+
* Generates a random `Int` within the given range.
|
|
168
164
|
*
|
|
169
|
-
* The range is inclusive on both ends
|
|
170
|
-
* 2, 3, 4, 5, or 6.
|
|
165
|
+
* The range is inclusive on both ends.
|
|
171
166
|
*
|
|
172
167
|
* @example
|
|
173
168
|
*
|
|
@@ -185,12 +180,13 @@ export const Int = {
|
|
|
185
180
|
*
|
|
186
181
|
* @param min - The minimum value (inclusive)
|
|
187
182
|
* @param max - The maximum value (inclusive)
|
|
188
|
-
* @returns A random Int in
|
|
183
|
+
* @returns A random `Int` in `[min, max]`
|
|
189
184
|
*/
|
|
190
185
|
random,
|
|
191
186
|
|
|
192
187
|
/**
|
|
193
|
-
* Raises an
|
|
188
|
+
* Raises `a` to the power `b`, returning `a ** b` as an `Int` (floored to an
|
|
189
|
+
* integer).
|
|
194
190
|
*
|
|
195
191
|
* @example
|
|
196
192
|
*
|
|
@@ -206,12 +202,12 @@ export const Int = {
|
|
|
206
202
|
*
|
|
207
203
|
* @param a - The base integer
|
|
208
204
|
* @param b - The exponent integer
|
|
209
|
-
* @returns `a ** b` as an Int
|
|
205
|
+
* @returns `a ** b` as an `Int`
|
|
210
206
|
*/
|
|
211
207
|
pow,
|
|
212
208
|
|
|
213
209
|
/**
|
|
214
|
-
* Adds two integers
|
|
210
|
+
* Adds two integers, returning `a + b` as an `Int`.
|
|
215
211
|
*
|
|
216
212
|
* @example
|
|
217
213
|
*
|
|
@@ -221,14 +217,14 @@ export const Int = {
|
|
|
221
217
|
* assert.isTrue(sum === 20);
|
|
222
218
|
* ```
|
|
223
219
|
*
|
|
224
|
-
* @param a -
|
|
225
|
-
* @param b -
|
|
226
|
-
* @returns `a
|
|
220
|
+
* @param a - The first integer
|
|
221
|
+
* @param b - The second integer
|
|
222
|
+
* @returns The sum of `a` and `b` as an `Int`
|
|
227
223
|
*/
|
|
228
224
|
add,
|
|
229
225
|
|
|
230
226
|
/**
|
|
231
|
-
* Subtracts two integers
|
|
227
|
+
* Subtracts two integers, returning `a - b` as an `Int`.
|
|
232
228
|
*
|
|
233
229
|
* @example
|
|
234
230
|
*
|
|
@@ -238,14 +234,14 @@ export const Int = {
|
|
|
238
234
|
* assert.isTrue(difference === 4);
|
|
239
235
|
* ```
|
|
240
236
|
*
|
|
241
|
-
* @param a -
|
|
242
|
-
* @param b -
|
|
243
|
-
* @returns `a
|
|
237
|
+
* @param a - The first integer
|
|
238
|
+
* @param b - The second integer
|
|
239
|
+
* @returns The difference of `a` and `b` as an `Int`
|
|
244
240
|
*/
|
|
245
241
|
sub,
|
|
246
242
|
|
|
247
243
|
/**
|
|
248
|
-
* Multiplies two integers
|
|
244
|
+
* Multiplies two integers, returning `a * b` as an `Int`.
|
|
249
245
|
*
|
|
250
246
|
* @example
|
|
251
247
|
*
|
|
@@ -255,17 +251,15 @@ export const Int = {
|
|
|
255
251
|
* assert.isTrue(product === -24);
|
|
256
252
|
* ```
|
|
257
253
|
*
|
|
258
|
-
* @param a -
|
|
259
|
-
* @param b -
|
|
260
|
-
* @returns `a
|
|
254
|
+
* @param a - The first integer
|
|
255
|
+
* @param b - The second integer
|
|
256
|
+
* @returns The product of `a` and `b` as an `Int`
|
|
261
257
|
*/
|
|
262
258
|
mul,
|
|
263
259
|
|
|
264
260
|
/**
|
|
265
|
-
* Divides two integers using floor division
|
|
266
|
-
*
|
|
267
|
-
* Performs mathematical floor division: `⌊a / b⌋`. The result is always an
|
|
268
|
-
* integer, rounding toward negative infinity.
|
|
261
|
+
* Divides two integers using floor division (`⌊a / b⌋`): the result is `a /
|
|
262
|
+
* b` rounded toward negative infinity, as an `Int`.
|
|
269
263
|
*
|
|
270
264
|
* @example
|
|
271
265
|
*
|
|
@@ -281,7 +275,7 @@ export const Int = {
|
|
|
281
275
|
*
|
|
282
276
|
* @param a - The dividend
|
|
283
277
|
* @param b - The divisor (must be non-zero)
|
|
284
|
-
* @returns The
|
|
278
|
+
* @returns The floored quotient as an `Int`
|
|
285
279
|
*/
|
|
286
280
|
div,
|
|
287
281
|
} as const;
|