The Modern JavaScript Standard Library.
Part of the Open Tech Foundation ecosystem.
A lightweight, high-accuracy, runtime-agnostic collection of essential utilities.
- 🎨 Intuitive API: Designed for clarity, simplicity, and ease of use.
- 🌍 Runtime Agnostic: Uses standard JavaScript and capability detection instead of named-runtime branching.
- ⚡ High Performance: Optimized for speed without sacrificing accuracy.
- ⏳ Modern Async: Advanced tools for managing complex asynchronous flows.
- 🛡️ Full Type Safety: Built with TypeScript for deep, native type inference.
- 📦 Zero Dependencies: Lightweight, tree-shakeable, and ESM/CJS ready.
- 🌲 Broad Compatibility: Future-proof code with broad environment support.
@opentf/std avoids public runtime detection helpers. Utilities are written against standard JavaScript APIs and use feature/capability detection only where platform APIs are unavoidable.
This keeps the package portable across mainstream runtimes and smaller embeddable engines such as QuickJS, as long as the specific API a utility needs is available or polyfilled.
Crypto helpers use capability detection instead of runtime-name detection:
- Random and UUID helpers use Web Crypto when available and fall back to
node:crypto.webcryptoin Node-compatible environments. - Hash and HMAC helpers use Web Crypto when available and fall back to
node:crypto. - Helpers throw a clear error if neither capability exists.
For runtimes without either API, provide a Web Crypto polyfill before calling crypto utilities:
import crypto from 'node:crypto';
if (typeof globalThis.crypto === 'undefined') {
Object.defineProperty(globalThis, 'crypto', {
value: crypto.webcrypto,
writable: true,
configurable: true,
});
}Run the project validation suite:
bun run ciThe CI suite builds the package, runs Biome linting, checks TypeScript, and executes the full Bun test suite.
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/stdExplore the library's capabilities with these examples:
import { isNumber, toNum } from "@opentf/std";
isNumber(NaN); //=> false
isNumber('1'); //=> false
isNumber(1); //=> true
toNum('1_000'); //=> 1000import { pascalCase } from "@opentf/std";
pascalCase("pascal case"); //=> PascalCaseimport { sort } from "@opentf/std";
sort([1, 10, 21, 2], "desc"); //=> [21, 10, 2, 1]import { clone } from "@opentf/std";
const obj = { a: 1, b: "abc", c: new Map([["key", "val"]]) };
clone(obj); // Fast deep clone for supported built-in typesimport { isEql, isUnorderedEqual } from "@opentf/std";
isEql({a: 1}, {a: 1}); //=> true
const mapA = new Map([["a", 1], ["b", 2]]);
const mapB = new Map([["b", 2], ["a", 1]]);
isEql(mapA, mapB); //=> false
// Compare Arrays ignoring order
isUnorderedEqual([1, 2, 3], [2, 3, 1]); //=> trueimport { color, ColorFormat } from "@opentf/std";
color("orange", ColorFormat.HEX); //=> "#ffa500"
color("#00ffff", "rgba"); //=> "rgba(0, 255, 255, 1)"import { retryRun, rateLimitRun } from "@opentf/std";
// Automatically retry failed operations
await retryRun(fetchData, { retries: 3, delay: 1000 });
// Ensure a function is called no more than 5 times per second
const limitedFetch = rateLimitRun(fetchData, 5, 1000);- 📁 Local API Docs - View the API reference directly in the repository.
- 🌐 Documentation Website - Searchable online version with examples, a live playground, and Visual Flow Control Tools.
We prioritize reliability and accuracy over extreme performance, while maintaining highly competitive speeds.
| Library | ops/sec | Average Time | Notes |
|---|---|---|---|
| @opentf/std (clone) | 466,736 | ~2.1μs | Full accuracy, supports all modern types. |
| copy (fast-copy) | 434,805 | ~2.3μs | Missing some modern features. |
| cloneDeep (clone-deep) | 397,935 | ~2.5μs | No circular ref support. |
| structuredClone (Native) | 228,477 | ~4.4μs | Built-in native support. |
| _.cloneDeep (Lodash) | 161,017 | ~6.2μs | Lacks some modern features. |
| Library | ops/sec | Average Time |
|---|---|---|
| @opentf/std (sortBy) | 2,656,536 | ~376ns |
| sort (Moderndash) | 2,799,559 | ~357ns |
| R2.sortBy (Remeda) | 1,604,434 | ~623ns |
| _.orderBy (Lodash) | 1,263,727 | ~791ns |
| R.sortWith (Ramda) | 1,066,487 | ~937ns |
| Library | ops/sec | Average Time | Notes |
|---|---|---|---|
| @opentf/std (isEql) | 75,675 | ~13.2μs | Full accuracy, Map/Set ordering, Symbols. |
| deepStrictEqual (Native) | 717,658 | ~1.4μs | Limited features, no browser support. |
| fastDeepEqual | 586,098 | ~1.7μs | Missing many modern features. |
| dequal | 375,797 | ~2.6μs | No cyclic refs or Map ordering. |
| _.isEqual (Lodash) | 137,667 | ~7.2μs | Missing Map/Set accuracy. |
Tip
Run your own benchmarks: bun run build && bun benchmark.js
Security is a top priority for @opentf/std. We implement proactive measures to protect your applications:
- Prototype Pollution Protection: All object manipulation utilities (like
set,merge,clone, etc.) include built-in guards against prototype pollution attacks (CWE-1321). - Safe Path Traversal: Path-based utilities strictly filter sensitive keys like
__proto__,constructor, andprototype. - Zero Dependencies: By maintaining a zero-dependency footprint, we eliminate the risk of supply-chain vulnerabilities from third-party packages.
This project is licensed under the MIT License.