https://github.com/open-tech-foundation/js-std
An Extensive JavaScript Standard Library.
https://github.com/open-tech-foundation/js-std
browser bun deno javascript library nodejs standard stdlib typescript
Last synced: 5 days ago
JSON representation
An Extensive JavaScript Standard Library.
- Host: GitHub
- URL: https://github.com/open-tech-foundation/js-std
- Owner: Open-Tech-Foundation
- License: mit
- Created: 2021-07-09T09:40:06.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T19:43:32.000Z (almost 2 years ago)
- Last Synced: 2025-09-30T19:26:13.345Z (7 months ago)
- Topics: browser, bun, deno, javascript, library, nodejs, standard, stdlib, typescript
- Language: TypeScript
- Homepage: https://js-std.pages.dev/
- Size: 3.95 MB
- Stars: 11
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# @opentf/std
**The Modern JavaScript Standard Library.**
*A lightweight, high-accuracy, and cross-runtime collection of essential utilities.*
[](https://github.com/open-tech-foundation/js-std/actions/workflows/ci.yml)
[](https://jsr.io/@opentf/std)
*Part of the
[Open Tech Foundation](https://github.com/Open-Tech-Foundation) ecosystem.*
[**Live Demo**](https://js-std.pages.dev/playground) | [**Documentation**](https://js-std.pages.dev) | [**Report Bug**](https://github.com/open-tech-foundation/js-std/issues)
---
## ✨ 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.
## 🌍 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 |
### 🛠️ Node.js 18 Support
To use features like `uuid` or `randomBytes` in Node.js 18, you must manually polyfill the `webcrypto` API:
```js
import crypto from 'node:crypto';
if (typeof globalThis.crypto === 'undefined') {
Object.defineProperty(globalThis, 'crypto', {
value: crypto.webcrypto,
writable: true,
configurable: true,
});
}
```
## 📦 Installation
Install `@opentf/std` using your preferred package manager:
```sh
# Bun
bun add @opentf/std
# pnpm
pnpm add @opentf/std
# npm
npm install @opentf/std
# Deno
deno add @opentf/std
```
## 🛠 Usage
Explore the library's capabilities with these examples:
### 1. Checking if a Value is Numeric
```js
import { isNumber } from "@opentf/std";
isNumber(NaN); //=> false
isNumber('1'); //=> false
isNumber('1', true); //=> true
isNumber(1); //=> true
```
### 2. Converting Strings to Pascal Case
```js
import { pascalCase } from "@opentf/std";
pascalCase("pascal case"); //=> PascalCase
```
### 3. Sorting an Array in Descending Order
```js
import { sort } from "@opentf/std";
sort([1, 10, 21, 2], "desc"); //=> [21, 10, 2, 1]
```
### 4. Deep Cloning an Object
```js
import { clone } from "@opentf/std";
const obj = { a: 1, b: "abc", c: new Map([["key", "val"]]) };
clone(obj); // Returns deeply cloned value
```
### 5. Smart Equality
```js
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
// Compare Arrays ignoring order
isUnorderedEqual([1, 2, 3], [2, 3, 1]); //=> true
```
### 6. Unified Color Conversion
```js
import { color, ColorFormat } from "@opentf/std";
color("orange", ColorFormat.HEX); //=> "#ffa500"
color("#00ffff", "rgba"); //=> "rgba(0, 255, 255, 1)"
```
## 📖 API
- 📁 [**Local API Docs**](./packages/std/docs/README.md) - View the API reference directly in the repository.
- 🌐 [**Documentation Website**](https://js-std.pages.dev) - Searchable online version with examples and a live playground.
---
## 📊 Benchmarks
We prioritize **reliability and accuracy** over extreme performance, 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`
---
## 📖 Articles
- [Introducing Our New JavaScript Standard Library](https://ganapathy.hashnode.dev/introducing-our-new-javascript-standard-library)
- [You Don't Need JavaScript Native Methods](https://ganapathy.hashnode.dev/you-dont-need-javascript-native-methods)
---
## 📄 License
This project is licensed under the [MIT License](./LICENSE).