@opentf/std
The Modern JavaScript Standard Library.
A lightweight, high-accuracy, runtime-agnostic collection of essential utilities.
📦 Installation
Install @opentf/std using your preferred package manager:
bun add @opentf/stdpnpm add @opentf/stdnpm install @opentf/stdyarn add @opentf/stddeno add @opentf/std🚀 Quick Start
Beyond the everyday helpers, @opentf/std ships capabilities you'd normally reach for a separate package to get:
import { DateTime, Decimal, color, colorContrast, formatBytes, formatCurrency, uuidv7, stringWidth, } from "@opentf/std"; // 🕒 Dates in any IANA zone — no time-zone database, no dependency const t = new DateTime("2026-03-07T12:00", { timeZone: "America/New_York" }); t.add({ days: 1 }).format("HH:mm ZZ"); //=> "12:00 -04:00" DST-safe: 23 real hours // 🎯 Exact decimal math — no floating-point errors new Decimal("0.1").add("0.2").toString(); //=> "0.3" // 🎨 Color parsing, conversion & WCAG accessibility color("rebeccapurple", "hex"); //=> "#663399" colorContrast("white", "black"); //=> 21 (WCAG ratio) // 💾 Human-readable, locale-aware formatting formatBytes(1234567); //=> "1.18 MiB" formatCurrency(1200, { currency: "EUR", locale: "de-DE" }); //=> "1.200,00 €" // 🆔 Time-sortable UUID via runtime-agnostic crypto uuidv7(); //=> "0195e2a4-8c3d-7000-…" // 📏 Emoji & CJK aware string width (terminal-safe) stringWidth("🔥こんにちは"); //=> 12
🧩 API shape
Arguments are named, not positional. Each function takes its primary input positionally, and everything else arrives in one final options object:
clamp(10, { min: -5, max: 5 }); //=> 5 — (data, options) pad("abc", 8, { chars: "_-" }); //=> "_-abc_-_" — (data, secondary, options) lerp({ start: 0, end: 10, progress: 0.5 }); //=> 5 — one object, no positionals move([1, 2, 3], { from: 0, to: 2 }); //=> [2, 3, 1]
Three rules, applied everywhere:
One primary input stays positional — the array, string, number or function being worked on.
At most one secondary positional —
length,limit,interval. A second setting onwards joins the options object.Peer values share one object —
start/end/progressorfrom/tohave no primary, so all of them are named.
Options are validated: passing anything that isn't an object throws a TypeError, and required keys (like set's { value } or pollRun's { until }) are enforced — a misspelled key fails loud instead of silently using the default.
👉 Next Steps
🎮 Try the Interactive Playground — visualize
idleRun,paceRun,batchRun,rateLimitRun&retryRunin real time.🧪 Explore standout utilities:
DateTime,Decimal,color,uuidv7,formatCurrency, lazyIteratorsand set math.📚 Browse every utility by category from the sidebar.
🔒 Read the Security page — supported versions and how to report a vulnerability.