yarut

1.3.5 • Public • Published

yarut - Yet Another Result Utility for Typescript

A result/option utility for typescript.

import { Result, Ok, Err } from "yarut";

const apiCall = (): Result<string, Error> => {
    return ResultUtil.Ok("All good!");
}
const result = apiCall();

// With help of these type guards, either `value` or `error` is available
if (result.isOk()) {
    console.log("It works!", result.value);
} else {
    console.log("Oh no :(", result.error);
}

Features

  • Result - Encode errors as type information and explicitly handle them
  • Option - Don't use null/undefined to express values that doesn't exist. Use None and Some to indicate it.

Superjson support

import {optionSuperRegisterRecipe, resultSuperRegisterRecipe } from "yarut";
import superjson from "superjson";

superjson.registerCustom(resultSuperRegisterRecipe(superjson), "yarut/Result");
superjson.registerCustom(optionSuperRegisterRecipe(superjson), "yarut/Option");

Acknowledgements

Inspired by the work of @swan-io/boxed

Dependencies (0)

    Dev Dependencies (14)

    Package Sidebar

    Install

    npm i yarut

    Weekly Downloads

    11

    Version

    1.3.5

    License

    MIT

    Unpacked Size

    16 kB

    Total Files

    7

    Last publish

    Collaborators

    • lilja