@ts-utilkit/result
v0.2.0
Published
Result type utilities for Ok/Err error handling without exceptions
Maintainers
Readme
@ts-utilkit/result
Discriminated Result<T, E> helpers for explicit success/failure without relying on thrown exceptions.
Installation
npm install @ts-utilkit/resultQuick Example
import { ok, err, map, unwrapOr, fromThrowable } from '@ts-utilkit/result';
const doubled = map(ok(21), (n) => n * 2); // ok(42)
unwrapOr(err('missing'), 0); // 0
const parsed = fromThrowable(() => JSON.parse('{"a":1}'));Available Functions
ok/err— construct resultsisOk/isErr— type guardsmap/mapErr/andThen— transformsunwrap/unwrapOr/match— extract valuesfromThrowable— wrap throwing sync functions
License
MIT © Mykyta Forofontov
