@tqman/result
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Result

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

Install

pnpm add @tqman/result

Example

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

type Config = {
  PORT: number;
};

async function readConfigFile(): Promise<Config> {
  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}`);

Readme

Keywords

Package Sidebar

Install

npm i @tqman/result

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

7.38 kB

Total Files

6

Last publish

Collaborators

  • tanishqmanuja