Motivation

Why ?

This is a library containing common tools that work in js runtimes that we use in all projects and we believe callback APIs are bad so we use asynchronous APIs.

For example:

Reading files in node or bun can throw an error.

Node:

const fs = require('node:fs');

const badFile = await fs.readFile('/alice/test.json', 'utf8') // can throw an error
const badJson = JSON.parse(badFile); // also can throw an error

Bun:

const foo = await Bun.file('/alice/test.json').json(); // can throw an error

Our solution:

import { toUrl } from "@sirutils/safe-toolbox"

const result = await readJsonFile('/alice/test.json') // ok(Object) or err(FileNotFoundError)