Utilities Module

Number Utilities (num)

Optimized mathematical operations and locale-aware unit formatting.

.clamp(value, min, max)

Ensures a number stays within the specified range. Essential for validating sensory inputs or bounding UI elements.

typescript
let health = 150;
health = __sys__.utils.num.clamp(health, 0, 100); // → 100

.lerp(start, end, t)

Performs linear interpolation between two values. Commonly used for smooth UI animations and progress tracking.

typescript
const opacity = __sys__.utils.num.lerp(0, 1, progress);

.randomInt(min, max)

Returns a pseudo-random integer within the inclusive range [min, max].

typescript
const roll = __sys__.utils.num.randomInt(1, 6); // Dice roll

.formatBytes(bytes, decimals?)

Converts raw byte counts into human-readable formats (KB, MB, GB, TB) using base-1024.

typescript
const readable = __sys__.utils.num.formatBytes(15728640); // → "15 MB"

.formatNumber(value, locale?, options?)

A wrapper around the Intl.NumberFormat API for localized currency, percentage, and number formatting.

typescript
const price = __sys__.utils.num.formatNumber(1250.5, "en-US", {
    style: "currency",
    currency: "USD",
}); // → "$1,250.50"
Date Utilities

Learn about calendar arithmetic and relative time formatting.