@enbox/common
v0.1.5
Published
> **Research Preview** — Enbox is under active development. APIs may change without notice.
Maintainers
Readme
Enbox Common
Research Preview — Enbox is under active development. APIs may change without notice.
Shared utilities used across the Enbox monorepo — data conversion, key-value stores, caching, streams, and type helpers.
Installation
bun add @enbox/commonExports
Convert
Fluent data-format conversion between ArrayBuffer, Base32Z, Base58Btc, Base64Url, Hex, Multibase, JSON objects, strings, and Uint8Array.
import { Convert } from '@enbox/common';
const bytes = Convert.string('hello').toUint8Array();
const hex = Convert.uint8Array(bytes).toHex();
const b64 = Convert.hex(hex).toBase64Url();MemoryStore
Map-backed implementation of the KeyValueStore<K, V> interface.
import { MemoryStore } from '@enbox/common';
const ephemeral = new MemoryStore();LevelStore
LevelDB-backed implementation of the KeyValueStore<K, V> interface. It lives behind a dedicated subpath so default @enbox/common imports do not require LevelDB.
import { LevelStore } from '@enbox/common/level-store';
const persistent = new LevelStore({ location: './data' });
await persistent.set('key', 'value');
const value = await persistent.get('key');TtlCache
Time-to-live in-memory cache with bounded size support. Expired entries are removed by an unref'd background timer and
are also checked on get() / has(), so stale values are not returned if the timer has not fired yet. cancelTimer()
only stops the background timer; lazy expiry checks still run on access. Disposal callbacks are provided with the
constructor's dispose option.
Stream
Utilities for Web Streams API — create streams from blobs/bytes, consume to various formats, type guards.
Multicodec
Multicodec-prefixed binary data utilities. Pre-registers Ed25519, X25519, and secp256k1 key codecs.
Type Utilities
universalTypeOf()— Cross-context type detectionisDefined()/isAsyncIterable()/isArrayBufferSlice()— Type guardsisEmptyObject()/removeEmptyObjects()/removeUndefinedProperties()— Object helpers
Development
bun run build
bun run test:node
bun run lintLicense
Apache-2.0
