The Modern JavaScript Standard Library.
Part of the Open Tech Foundation ecosystem.
A lightweight, high-accuracy, and cross-runtime collection of essential utilities.
- 🎨 Intuitive API: Designed for clarity, simplicity, and ease of use.
- 🌍 Runtime Agnostic: Seamless execution across all JavaScript environments.
- ⚡ 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.
| Environment | Supported Versions | Note |
|---|---|---|
| Node.js | >= 18.0.0 | Polyfill required for Node 18 |
| Browsers | All modern browsers | Native |
| Bun | >= 1.0.0 | Native |
| Deno | >= 1.0.0 | Native |
To use features like uuid or randomBytes in Node.js 18, you must manually polyfill the webcrypto API:
import crypto from 'node:crypto';
if (typeof globalThis.crypto === 'undefined') {
Object.defineProperty(globalThis, 'crypto', {
value: crypto.webcrypto,
writable: true,
configurable: true,
});
}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 } from "@opentf/std";
isNumber(NaN); //=> false
isNumber('1'); //=> false
isNumber('1', true); //=> true
isNumber(1); //=> trueimport { 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); // Returns deeply cloned valueimport { 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.