1.0.1 • Published 1 year ago

@mksudo/ts-result v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Description

A simple library that provides a result model (Inspired by Rust Result) for projects.

Usage

  • Create results
const successfulResult = ok(1);
const unsuccessfulResult = err('oops');
  • Check if a result is successful
const isSuccessful = isOk(result);
const isUnsuccessful = isErr(result);
  • Get the value of a result
const data = expect(result, 'custom error message');
const data = unwrap(result);
const data = unwrapOrDefault(result, defaultValue);
const data = unwrapOrElse(result, func);
const data = unwrapOrUndefined(result);
const data = unwrapOrNull(result);
  • Transform a result
const result = mapResultData(result, func);
const result = mapResultDataOrDefault(result, func, defaultValue);
const result = mapResultError(result, func);
1.0.1

1 year ago

1.0.0

1 year ago