Introduction

@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:

  1. Accuracy First 🎯: We prioritize correct results over extreme micro-optimizations.
  2. Deep Everything 🧬: Built-in support for complex types like Map, Set, Date, and RegExp in equality and cloning.
  3. Consistent API 🤝: The same behavior across all runtimes, so you can write once and run anywhere.
  4. Zero Bloat 🧊: Only the code you use ends up in your bundle.
  5. 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); //=> true

2. 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 support

5. 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]); //=> true

6. 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 second

7. Functional Patterns

import { pipe } from "@opentf/std";
 
const result = pipe(
  1,
  (x) => x + 1,
  (x) => x * 5
); //=> 10

8. 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

Libraryops/secAverage TimeNotes
@opentf/std (clone)466,736~2.1μsFull accuracy, supports all modern types.
copy (fast-copy)434,805~2.3μsMissing some modern features.
cloneDeep (clone-deep)397,935~2.5μsNo circular ref support.
structuredClone (Native)228,477~4.4μsBuilt-in native support.
_.cloneDeep (Lodash)161,017~6.2μsLacks some modern features.

sortBy

Libraryops/secAverage 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

Libraryops/secAverage TimeNotes
@opentf/std (isEql)75,675~13.2μsFull accuracy, Map/Set ordering, Symbols.
deepStrictEqual (Native)717,658~1.4μsLimited features, no browser support.
fastDeepEqual586,098~1.7μsMissing many modern features.
dequal375,797~2.6μsNo cyclic refs or Map ordering.
_.isEqual (Lodash)137,667~7.2μsMissing 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:


📄 License

This project is licensed under the MIT License (opens in a new tab).