UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

37 lines 1.4 kB
//#region src/bigint/clamp.d.ts /** * Clamps a bigint within the inclusive lower and upper bounds. * * This function takes a bigint and returns it constrained to the given range. Unlike `Math.min` and * `Math.max`, which cannot accept bigints, it compares values directly so large integers stay exact. * * @param value - The bigint to clamp. * @param maximum - The upper bound to clamp to. * @returns The clamped bigint. * * @example * const result = clamp(10n, 5n); * // result will be 5n, because 10n is greater than the maximum */ declare function clamp(value: bigint, maximum: bigint): bigint; /** * Clamps a bigint within the inclusive lower and upper bounds. * * This function takes a bigint and returns it constrained to the given range. Unlike `Math.min` and * `Math.max`, which cannot accept bigints, it compares values directly so large integers stay exact. * * @param value - The bigint to clamp. * @param minimum - The lower bound to clamp to. * @param maximum - The upper bound to clamp to. * @returns The clamped bigint. * * @example * const result = clamp(10n, 0n, 5n); * // result will be 5n, because 10n is greater than the maximum * * const result2 = clamp(-10n, 0n, 5n); * // result2 will be 0n, because -10n is less than the minimum */ declare function clamp(value: bigint, minimum: bigint, maximum: bigint): bigint; //#endregion export { clamp };