UNPKG

ts-data-forge

Version:

[![npm version](https://img.shields.io/npm/v/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![npm downloads](https://img.shields.io/npm/dm/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![License](https://img.shields.

118 lines 3.75 kB
/** * Checks if a number is a Uint8 (8-bit unsigned integer in the range [0, 255]). * * @param value The value to check. * @returns `true` if the value is a Uint8, `false` otherwise. */ export declare const isUint8: (x: number) => x is Uint8; /** * Casts a number to a Uint8 type. This function validates that the input is * within the Uint8 range [0, 255] and is an integer, then returns it with the * Uint8 brand. * * @param value The value to cast. * @returns The value as a Uint8 type. * @throws {TypeError} If the value is not a valid 8-bit unsigned integer. */ export declare const asUint8: (x: number) => Uint8; /** * Namespace providing type-safe arithmetic operations for 8-bit unsigned * integers. * * All operations automatically clamp results to the valid Uint8 range [0, 255]. * This ensures that all arithmetic maintains the 8-bit unsigned integer * constraint, with negative results clamped to 0 and overflow results clamped * to MAX_VALUE. */ export declare const Uint8: { /** * Type guard that checks if a value is an 8-bit unsigned integer. * * @param value The value to check. * @returns `true` if the value is an 8-bit unsigned integer, `false` * otherwise. */ readonly is: (x: number) => x is Uint8; /** * The minimum value for an 8-bit unsigned integer. * * @readonly */ readonly MIN_VALUE: 0; /** * The maximum value for an 8-bit unsigned integer. * * @readonly */ readonly MAX_VALUE: 255; /** * Returns the larger of the given Uint8 values. * * @param values The Uint8 values to compare. * @returns The maximum value as a Uint8. */ readonly max: (...values: readonly Uint8[]) => Uint8; /** * Returns the smaller of the given Uint8 values. * * @param values The Uint8 values to compare. * @returns The minimum value as a Uint8. */ readonly min: (...values: readonly Uint8[]) => Uint8; /** * Clamps a number to the Uint8 range. * * @param value The number to clamp. * @returns The value clamped to [0, 255] as a Uint8. */ readonly clamp: (a: number) => Uint8; /** * Generates a random Uint8 value within the specified range. * * @param min The minimum value (inclusive). * @param max The maximum value (inclusive). * @returns A random Uint8 between min and max. */ readonly random: (min: Uint8, max: Uint8) => Uint8; /** * Raises x to the power of y, clamped to Uint8 range. * * @param x - The base * @param y - The exponent * @returns `x ** y` clamped to [0, 255] */ readonly pow: (x: Uint8, y: Uint8) => Uint8; /** * Adds two Uint8 values, clamped to Uint8 range. * * @param x - First operand * @param y - Second operand * @returns `x + y` clamped to [0, 255] */ readonly add: (x: Uint8, y: Uint8) => Uint8; /** * Subtracts two Uint8 values, clamped to Uint8 range. * * @param x - First operand * @param y - Second operand * @returns `x - y` clamped to [0, 255] */ readonly sub: (x: Uint8, y: Uint8) => Uint8; /** * Multiplies two Uint8 values, clamped to Uint8 range. * * @param x - First operand * @param y - Second operand * @returns `x * y` clamped to [0, 255] */ readonly mul: (x: Uint8, y: Uint8) => Uint8; /** * Divides two Uint8 values, clamped to Uint8 range. * * @param x - The dividend * @param y - The divisor (cannot be 0) * @returns `⌊x / y⌋` clamped to [0, 255] */ readonly div: (x: Uint8, y: Exclude<Uint8, 0>) => Uint8; }; //# sourceMappingURL=uint8.d.mts.map