# enforce-range

> Enforce a minimum and/or maximum value for a number.

Latest version **1.0.0** (published 2017-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install enforce-range
pnpm add enforce-range
yarn add enforce-range
bun add enforce-range
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-12-09 |
| First published | 2017-12-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John Lamansky |
| Maintainers | lamansky |
| Keywords | number, range, min, minimum, max, maximum, value |

## Links

- npm: https://www.npmjs.com/package/enforce-range
- Repository: https://github.com/lamansky/enforce-range
- Issues: https://github.com/lamansky/enforce-range/issues
- npm.io page: https://npm.io/package/enforce-range

## Dependencies (1)

- [2](https://npm.io/package/2.md) ^1.0.2

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-12-09

## README

# enforce-range

Enforce a minimum and/or maximum value for a number.

## Installation

```bash
npm install enforce-range --save
```

## Usage

```javascript
const enforceRange = require('enforce-range')

// Number should be between 0 and 100
enforceRange(0, 100, 51) // 51
enforceRange(0, 100, -123) // 0
enforceRange(0, 100, 456) // 100
```

### Partial Application

If you provide only the first two arguments (a minimum and a maximum value), the module will create a partially-applied function which enforces that range. Here's the above example repeated with this usage mode:

```javascript
const enforce0to100 = require('enforce-range')(0, 100)

// Number should be between 0 and 100
enforce0to100(51) // 51
enforce0to100(-123) // 0
enforce0to100(456) // 100
```

### Open-Ended Ranges

If, for some reason, you want this module to enforce a range that is only bound on one end, you can do so by passing `null` or ±`Infinity` as the minimum/maximum value. (However, in such a case you’re probably better off cutting the overhead of using a module and just using `Math.min()` or `Math.max()`.)

```javascript
const enforceRange = require('enforce-range')

// Maximum only
enforceRange(null, 100, 200) // 100
enforceRange(-Infinity, 100, 200) // 100

// Minimum only
enforceRange(0, null, 51) // 51
enforceRange(0, Infinity, 51) // 51

// No range enforcement at all (module does nothing)
enforceRange(null, null, 12345) // 12345
enforceRange(-Infinity, Infinity, 12345) // 12345
```

---
_Source: https://npm.io/package/enforce-range · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
