A TypeScript library for working with numerical ranges in Roblox TS.
npm install @rbxts/range
import { Range } from "@rbxts/range";
const range = new Range(0, 10); // 0..10
Clamps a number within the range.
const range = new Range(0, 10);
print(range.clamp(5)); // 5
print(range.clamp(-1)); // 0
print(range.clamp(11)); // 10
Checks if a number is within the range (inclusive).
print(range.isNumberWithin(5)); // true
print(range.isNumberWithin(-1)); // false
Checks if a number is within the range (exclusive of the min/max values).
print(range.isNumberExclusivelyWithin(5)); // true
print(range.isNumberExclusivelyWithin(0)); // false
Gets the center point of the range.
print(new Range(0, 10).center()); // 5
Gets the size of the range.
print(new Range(5, 10).size()); // 5
Returns a string representation of the range.
print(new Range(5, 10).toString()); // "5..10"
Creates a new range encompassing both ranges.
const result = new Range(1, 3).union(new Range(6, 10));
print(result.minimum, result.maximum); // 1, 10
Gets the overlapping range between two ranges.
const result = new Range(0, 10).intersection(new Range(5, 20));
if (result !== undefined) {
print(result.minimum, result.maximum); // 5, 10
}
Checks if one range is entirely within another.
print(new Range(0, 10).isRangeWithin(new Range(3, 7))); // true
Checks if one range is strictly within another (not touching boundaries).
print(new Range(0, 10).isRangeExclusivelyWithin(new Range(3, 7))); // true
This package uses @rbxts/runit
for unit testing to ensure the library's functionally.