# bounds

> Mixin for checking if value is inside or outside of bounds

Latest version **4.0.0** (published 2025-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install bounds
pnpm add bounds
yarn add bounds
bun add bounds
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-07-07 |
| First published | 2013-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Damian Krzeminski pirxpilot@furkot.com |
| Maintainers | pirxpilot |
| Keywords | bounds, range, compare |

## Links

- npm: https://www.npmjs.com/package/bounds
- Repository: https://github.com/pirxpilot/bounds
- Homepage: https://github.com/pirxpilot/bounds#readme
- Issues: https://github.com/pirxpilot/bounds/issues
- npm.io page: https://npm.io/package/bounds

## Recent versions

- 4.0.0 (latest) — 2025-07-07
- 3.0.2 — 2025-07-07
- 3.0.1 — 2024-01-31
- 3.0.0 — 2022-04-13
- 2.0.0 — 2018-11-29
- 1.0.2 — 2017-02-20
- 1.0.1 — 2015-09-12
- 1.0.0 — 2013-02-28
- 0.0.1 — 2013-02-21

## README

[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]

# bounds

  Mixin for checking if value is inside or outside of bounds You can use `Bounds` for any objects for
  which you can define compare function (dates, vectors etc.)

  In addition to regular range checking `Bounds` supports reversed ranges: if
  min is bigger than max it considers values outside ot the max, min range as valid.

## Installation

    $ npm install bounds

## API

###	.compare(fn)

Sets comparison function. `fn` should take 2 arguments and behave like sort comparison function i.e.
return 0 if items are equal, -1 if the first is smaller than the second, 1 is the first is bigger
than the second.

### .min(v)

Set lower bound (inclusive) to `v`

### .max(v)

Set upper bound (inclusive) to `v`

### .in(v)

Return `true` if `v` is in bounds i.e. `min <= v <= max`

### .out(v)

Return `true` if `v` is outside of bounds i.e. `v < min` OR `max < v`

### .before(v)

Return `true` if `v < min`

### .after(v)

Return `true` if `v > max`

### .valid(v)

For regular ranges it's the same as `in`. For reversed ranges it considers as valid values that are
outside of the range (it's still inclusive so `min` and `max` are still considered valid)

### .restrict(v)

Returns the passed value for `valid` values. For invalid values returns the closest boundary (`min`
or `max`). `restrict` only works for reverse ranges if `distance` function is defined.

###	.distance(fn)

Optional distance function: it's only used when calculating proper restriction for reversed ranges.
If restricted value is closed to `min` than to `max`, then the `min` is returned.

## License

  MIT

[npm-url]: https://npmjs.org/package/bounds
[npm-image]: https://img.shields.io/npm/v/bounds

[build-url]: https://github.com/pirxpilot/bounds/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/bounds/check.yaml?branch=main

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