1.0.3 • Published 1 month ago

@tqman/result v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

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}`);
1.0.3

1 month ago

1.0.2

3 months ago

1.0.1

9 months ago

1.0.0

9 months ago