1.2.3 • Published 8 months ago

stupid-simple-result v1.2.3

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

ts-stupid-simple-result

Stupid-Simple Result Type in Typescript

Usage

const someAsyncFn = async (): Promise<string> => {
    if (Math.random() > 0.5) {
        throw new Error("Error Happend!!!")
    }
    return "OK"
}

// Somewhere else
import {toOk, toErr} from 'stupid-simple-result';

const doSomthing = async () => {
    const [ok, err] = await someAsyncFn().then(toOk).catch(toErr)
    if (err) { /* Do some error handling */ }
    console.log(ok) // OK
}

import {wrapPromise} from 'stupid-simple-result';
const doAnother = async () => {
    const [ok, err] = await wrapPromise(someAsyncFn())
    if (err) { /* Do some error handling */ }
    console.log(ok) // OK
}

Why?

"Result" in Rust or some other languages that have Functional Features is great.

But sometime, we like more simple solution if it looks like stupid.

1.2.3

8 months ago

1.2.2

8 months ago

1.2.1

8 months ago

1.2.0

8 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.0

9 months ago