Skip to content

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

License

Notifications You must be signed in to change notification settings

Karim-W/ts-results

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published