math-clamp

July 12, 2025 ยท View on GitHub

Clamp a number

Install

npm install math-clamp

Usage

import mathClamp from 'math-clamp';

mathClamp(1, {min: 2, max: 4});
//=> 2

mathClamp(1, {min: 2});
//=> 2

mathClamp(5, {max: 4});
//=> 4

mathClamp(3n, {max: 2n});
//=> 2n

API

mathClamp(number, {min?, max?})

Related

  • math-sum - Sum numbers
  • math-average - Get the average of numbers

Contents

  1. 1Install
  2. 2Usage
  3. 3API
  4. 3.1mathClamp(number, {min?, max?})
  5. 4Related