@leon740727/result
v0.0.1
Published
A tiny Result helper for composing sync and async flows in TypeScript.
Maintainers
Readme
@leon740727/result
A tiny Result helper for composing sync and async flows in TypeScript.
Install
npm install @leon740727/resultUsage
import { Result } from "@leon740727/result";
const value = Result.ok<number, number>(1)
.map((n) => n + 1)
.chain((n) => Result.ok(n * 2));
console.log(value.value); // [null, 4]import { Result } from "@leon740727/result";
const value = await Result.ok<string, number>(Promise.resolve(1))
.map(async (n) => n + 1)
.chain((n) => Result.ok(Promise.resolve(n * 2))).value;
console.log(value); // [null, 4]API
Result.of(value)wraps[error, value]orPromise<[error, value]>.Result.ok(value)creates a success result from a value or promise.Result.fail(error)creates a failed result from an error or promise.Result.all(list)resolves a list of results and returns the first error or all values.assert(condition, message)throws when the condition is falsy.
Publish
pnpm build
npm publish --access public