Package: effect
Module: Number
Restricts the given number to be within the range specified by the minimum and maximum values.
When to use
Use to force a number into an inclusive range.
Details
number is less than the minimum value, the function returns the minimum value.number is greater than the maximum value, the function returns the maximum value.number.Example (Clamping to a range)
import { Number } from "effect"
import * as assert from "node:assert"
const clamp = Number.clamp({ minimum: 1, maximum: 5 })
assert.equal(clamp(3), 3)
assert.equal(clamp(0), 1)
assert.equal(clamp(6), 5)
See
between for checking whether a number is already inside a rangeSignature
declare const clamp: { (options: { minimum: number; maximum: number; }): (self: number) => number; (self: number, options: { minimum: number; maximum: number; }): number; }
Since v2.0.0