Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tanishqmanuja/lib.result

A simple lib for wrapping lazy promise or task into result.
https://github.com/tanishqmanuja/lib.result

Last synced: 1 day ago
JSON representation

A simple lib for wrapping lazy promise or task into result.

Awesome Lists containing this project

README

        

# Result

A simple lib for wrapping lazy promise or task into result.

### Install

```sh
pnpm add @tqman/result
```

### Example

```ts
import { readFile } from "fs/promises";
import { resultOf } from "@tqman/result";

type Config = {
PORT: number;
};

async function readConfigFile(): Promise {
return readFile("./config.json", "utf-8").then((data) => JSON.parse(data));
}

const config = await resultOf(readConfigFile);

if (!config.ok) {
console.error("Config file not found");
process.exit(1);
}

console.log(`Listening on port ${config.value.PORT}`);
```