@augment-vir/common
Version:
A collection of augments, helpers types, functions, and classes for any JavaScript environment.
20 lines (19 loc) • 488 B
JavaScript
/**
* Clamp's the given value to within the min and max bounds, inclusive.
*
* @category Number
* @category Package : @augment-vir/common
* @example
*
* ```ts
* import {clamp} from '@augment-vir/common';
*
* // `result` will be `40`
* const result = clamp(42, {min: 30, max: 40});
* ```
*
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export function clamp(value, { min, max }) {
return Math.min(Math.max(value, min), max);
}