Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/tanishqmanuja/lib.result
- Owner: tanishqmanuja
- Created: 2023-08-19T07:55:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-30T08:58:06.000Z (9 months ago)
- Last Synced: 2024-11-08T23:54:14.925Z (about 2 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@tqman/result
- Size: 63.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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}`);
```