npm.io
0.18.0 โ€ข Published 1 week ago

@opentf/std

Licence
MIT
Version
0.18.0
Deps
0
Size
2.2 MB
Vulns
0
Weekly
0
Stars
13

@opentf/std

The Modern JavaScript Standard Library.

Website | Docs | Playground


A lightweight, high-accuracy, runtime-agnostic collection of essential utilities.

Installation

Install @opentf/std using your preferred package manager:

# Bun
bun add @opentf/std

# pnpm
pnpm add @opentf/std

# npm
npm install @opentf/std

# Deno
deno add @opentf/std

# yarn
yarn 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
t.withTimeZone("Asia/Kolkata").format("EEE d MMM, HH:mm"); //=> "Sat 7 Mar, 22:30"
new DateTime("2028-02-10").endOf("month"); //=> 2028-02-29  leap-year aware

// ๐ŸŽฏ 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, "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

Next Steps


License

This project is licensed under the MIT License.

Keywords