@lacspace/result
Typed, functional error handling — Result<T,E> (Ok/Err) and Option<T> (Some/None) so functions return errors as values instead of throwing. Constructors, guards, map/andThen/match, unwrap variants, trySync/tryAsync to wrap throwing code, and an all() combinator that short-circuits on the first error. Tree-shakeable, zero-dependency, isomorphic.
npm i @lacspace/resultUsage
import { trySync, match, all, ok, err } from "@lacspace/result";
// wrap throwing code — errors become values, not exceptions
const parsed = trySync(() => JSON.parse(input)); // Result<any, Error>
const message = match(parsed, {
ok: (v) => `parsed: ${JSON.stringify(v)}`,
err: (e) => `bad json: ${e.message}`,
});
// chain fallible steps; the first Err short-circuits
const combined = all([ok(1), ok(2), ok(3)]); // Ok([1, 2, 3])
const stopped = all([ok(1), err("nope"), ok(3)]); // Err("nope")
// async, too
const res = await tryAsync(() => fetch(url).then((r) => r.json()));Exports 16
okerrsomenonefromNullableisOkisErrmapandThenunwrapunwrapOrmatchtrySynctryAsyncokOrallKeywords
More in Core Runtime Kit
A tiny structured logger for Node and the browser — leveled JSON logging, child loggers, field redaction and pluggable transports (JSON, pretty, in-memory). A log below the active level costs almost nothing: the record is never even built. Errors serialise automatically; secrets get redacted before they leave the logger. Zero-dependency, isomorphic.
@lacspace/eventsA fully type-safe event emitter / tiny pub-sub for Node and the browser. Declare an events map (name → payload type) and get compile-time-checked on/emit. A throwing listener never blocks the others (errors are isolated), adding or removing listeners mid-emit is safe, and once/waitFor/onAny round it out. Comparable to mitt or nanoevents but strongly typed. Zero-dependency, isomorphic.
@lacspace/queueAn in-memory async task queue with a concurrency limit — run up to N async tasks at once and await individual results or the whole drain. Priority ordering, pause/start, clear, onIdle/onEmpty draining, and per-task abort via AbortSignal. A rejected task never stalls the queue. Comparable to p-queue/p-limit but tiny and dependency-free. Isomorphic.