Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/sindresorhus/math-clamp
- Owner: sindresorhus
- License: mit
- Created: 2015-07-05T16:56:05.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-02-03T10:26:43.000Z (about 1 year ago)
- Last Synced: 2025-01-28T20:22:05.399Z (14 days ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 14
- Watchers: 7
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-nodejs-cn - math-clamp - 三个数中取出中间值 (包 / 数学)
- awesome-nodejs - math-clamp - Clamp a number. (Packages / Math)
- awesome-nodejs - math-clamp - Clamp a number - ★ 4 (Math)
- awesome-node - math-clamp - Clamp a number. (Packages / Math)
- awesome-nodejs-cn - math-clamp - 钳制一个数字. (目录 / 数学)
- awesome-nodejs-cn - math-clamp - **star:15** 夹一个数字 (包 / 数学)
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});
//=> 2mathClamp(1, {min: 2});
//=> 2mathClamp(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