Skip to content

Latest commit

 

History

History
76 lines (50 loc) · 980 Bytes

README.md

File metadata and controls

76 lines (50 loc) · 980 Bytes

ts-results

Library for returning results from functions. Follows a similar-ish Syntax to Rust's Result enum.

installation

With npm:

npm install @karim-w/ts-results

With yarn:

yarn add @karim-w/ts-results

With pnpm:

pnpm i @karim-w/ts-results

Usage

import the library:

import { Result } from "@karim-w/ts-results";

Creating a Successful Result

const result = Result.Ok("Hello World");

Creating an Erroneous Result

const result = Result.Err("Something went wrong");

Handling a Result

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());
}

LICENSE

BSD-3-Clause

Contributing

Feel free to open an issue or a pull request.

Author

Karim-w