1.0.2 • Published 7 months ago
@rbxts/range v1.0.2
@rbxts/range
A TypeScript library for working with numerical ranges in Roblox TS.
Installation
npm install @rbxts/rangeUsage
import { Range } from "@rbxts/range";
const range = new Range(0, 10); // 0..10API
clamp(value: number): number
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)); // 10isNumberWithin(value: number): boolean
Checks if a number is within the range (inclusive).
print(range.isNumberWithin(5)); // true
print(range.isNumberWithin(-1)); // falseisNumberExclusivelyWithin(value: number): boolean
Checks if a number is within the range (exclusive of the min/max values).
print(range.isNumberExclusivelyWithin(5)); // true
print(range.isNumberExclusivelyWithin(0)); // falsecenter(): number
Gets the center point of the range.
print(new Range(0, 10).center()); // 5size(): number
Gets the size of the range.
print(new Range(5, 10).size()); // 5toString(): string
Returns a string representation of the range.
print(new Range(5, 10).toString()); // "5..10"union(other: Range): Range
Creates a new range encompassing both ranges.
const result = new Range(1, 3).union(new Range(6, 10));
print(result.minimum, result.maximum); // 1, 10intersection(other: Range): Range | undefined
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
}isRangeWithin(other: Range): boolean
Checks if one range is entirely within another.
print(new Range(0, 10).isRangeWithin(new Range(3, 7))); // trueisRangeExclusivelyWithin(other: Range): boolean
Checks if one range is strictly within another (not touching boundaries).
print(new Range(0, 10).isRangeExclusivelyWithin(new Range(3, 7))); // trueTesting
This package uses @rbxts/runit for unit testing to ensure the library's functionally.