@opentf/std
The Modern JavaScript Standard Library.
A lightweight, high-accuracy, and cross-runtime collection of essential utilities.
Part of theOpen Tech Foundationecosystem.
✨ Features
- 🎨 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.
🤔 Why @opentf/std?
While JavaScript has come a long way, many native methods still have quirks or lack deep comparison/cloning capabilities. @opentf/std aims to fill those gaps with a focus on:
- Accuracy First 🎯: We prioritize correct results over extreme micro-optimizations.
- Deep Everything 🧬: Built-in support for complex types like
Map,Set,Date, andRegExpin equality and cloning. - Consistent API 🤝: The same behavior across all runtimes, so you can write once and run anywhere.
- Zero Bloat 🧊: Only the code you use ends up in your bundle.
- Modern Anywhere 🚀: Get modern language features in any environment without polluting the global namespace.
📦 Installation
Install @opentf/std using your preferred package manager:
bun add @opentf/std 🛠 Usage
Explore the library's capabilities with these common patterns:
1. Robust Type Checking
import { isNumber } from "@opentf/std";
isNumber(NaN); //=> false
isNumber('1'); //=> false
isNumber('1', true); //=> true (strict numeric string check)
isNumber(1); //=> true2. String Manipulation
import { pascalCase } from "@opentf/std";
pascalCase("hello world"); //=> "HelloWorld"3. Advanced Sorting
import { sort } from "@opentf/std";
sort([1, 10, 21, 2], "desc"); //=> [21, 10, 2, 1]4. Deep Cloning
import { clone } from "@opentf/std";
const obj = { a: 1, b: "abc", c: new Map([["key", "val"]]) };
const newObj = clone(obj); // Deeply cloned with Map support5. Smart Equality
import { 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 (Map order matters for equality)
// Compare Arrays ignoring order
isUnorderedEqual([1, 2, 3], [2, 3, 1]); //=> true6. Modern Async
import { sleep, withResolvers } from "@opentf/std";
// Externalized Promise resolution
const { promise, resolve } = withResolvers();
setTimeout(() => resolve("Done!"), 1000);
await promise;
await sleep(1000); // Suspends execution for 1 second7. Functional Patterns
import { pipe } from "@opentf/std";
const result = pipe(
1,
(x) => x + 1,
(x) => x * 5
); //=> 108. Object Transformation
import { pick, omit } from '@opentf/std';
const obj = { a: 1, b: 2, c: 3 };
pick(obj, 'a', 'c'); //=> { a: 1, c: 3 }
omit(obj, 'a', 'c'); //=> { b: 2 }You can try out these examples and more on the Interactive Playground.
📊 Benchmarks
We prioritize reliability and accuracy while maintaining highly competitive speeds.
clone
| 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. |
sortBy
| 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 |
isEql
| 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
❓ FAQ
1. Why another standard library?
Native methods are great, but they often lack depth (e.g., Object.assign is shallow) or have inconsistent behavior across environments. @opentf/std provides a unified, high-fidelity API.
2. Is it production-ready?
Yes. The library is 100% tested, strictly typed, and used in production across the Open Tech Foundation ecosystem.
3. Does it support tree-shaking?
Yes. Every utility is exported individually, ensuring your final bundle only contains what you actually use.
📖 Articles
Dive deeper into our philosophy:
- Introducing Our New JavaScript Standard Library (opens in a new tab)
- You Don't Need JavaScript Native Methods (opens in a new tab)
📄 License
This project is licensed under the MIT License (opens in a new tab).