Library for returning results from functions. Follows a similar-ish Syntax to Rust's Result enum.
With npm:
npm install @karim-w/ts-results
With yarn:
yarn add @karim-w/ts-results
With pnpm:
pnpm i @karim-w/ts-results
import the library:
import { Result } from "@karim-w/ts-results";
const result = Result.Ok("Hello World");
const result = Result.Err("Something went wrong");
const result = getResult();
if (result.isOk()) {
console.log(result.unwrap());
} else {
console.error(result.unwrapErr());
}
// or
if (result.isErr()) {
console.log(result.unwrapErr());
} else {
console.error(result.unwrap());
}
BSD-3-Clause
Feel free to open an issue or a pull request.
Karim-w