Skip to content

inRange

Checks if a number falls within a given range. Start is inclusive, end is exclusive. If start is greater than end, the bounds are swapped automatically.

import { inRange } from "1o1-utils";
import { inRange } from "1o1-utils/in-range";
function inRange(params: { value: number; start: number; end: number }): boolean
NameTypeRequiredDescription
valuenumberYesThe number to check
startnumberYesThe start of the range (inclusive)
endnumberYesThe end of the range (exclusive)

booleantrue if value is within [start, end), otherwise false.

inRange({ value: 3, start: 1, end: 5 }); // true
inRange({ value: 5, start: 1, end: 5 }); // false — end is exclusive
inRange({ value: 1, start: 1, end: 5 }); // true — start is inclusive
inRange({ value: -1, start: -5, end: 5 }); // true
// Bounds are swapped automatically when start > end
inRange({ value: 3, start: 5, end: 1 }); // true
// Floating-point values
inRange({ value: 1.5, start: 1, end: 2 }); // true
  • Throws if any of value, start, or end is not a number or is NaN.
  • A zero-width range (start === end) always returns false.
  • Works with Infinity bounds — e.g. { value: 1e10, start: 0, end: Infinity } returns true.
  • When start > end, the bounds are swapped silently. The inclusive side follows the lower bound.

between, range check, bounds check, within range, number range

I'm using 1o1-utils (npm: https://www.npmjs.com/package/1o1-utils, GitHub: https://github.com/pedrotroccoli/1o1-utils, LLM context: https://pedrotroccoli.github.io/1o1-utils/llms.txt). Show me how to use inRange to check if a number is within a bounded range.