# clamp

> Clamps a number into an inclusive `[min, max]` range.

Source: https://ngwr.dev/reference/utils/clamp  
Kind: Util

## Usage

```angular-ts
import { clamp } from 'ngwr/utils';

clamp(140, 0, 100); // 100
clamp(-3, 0, 100);  // 0
clamp(42, 0, 100);  // 42
```

## Why ngwr provides this

Before v7 ten components each carried their own private copy of this three-liner — sliders, knobs, croppers, windows. One shared, tested implementation beats ten identical ones, and your app code gets it for free.

```angular-ts
// Typical: keep a drag position inside its track.
const x = clamp(pointerX - trackLeft, 0, trackWidth);
```

## API

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| `clamp` | Clamps value into the inclusive [min, max] range. | `(value: number, min: number, max: number) => number` | `—` |
