Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sindresorhus/math-clamp

Clamp a number
https://github.com/sindresorhus/math-clamp

Last synced: 7 days ago
JSON representation

Clamp a number

Awesome Lists containing this project

README

        

# math-clamp

> [Clamp](https://en.wikipedia.org/wiki/Clamping_(graphics)) a number

## Install

```sh
npm install math-clamp
```

## Usage

```js
import mathClamp from 'math-clamp';

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

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

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

## API

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

## Related

- [math-sum](https://github.com/sindresorhus/math-sum) - Sum numbers
- [math-average](https://github.com/sindresorhus/math-average) - Get the average of numbers