@microlib/try
v2.0.5
Published
A Promise like quasi monad for Try.
Downloads
502
Readme
📦 @microlib/try
A Promise like quasi monad but for Try.
🚀 Installation
npm install @microlib/try
bun add @microlib/try
📖 Usage
import { Try } from "@microlib/try";
function task() {
if (Math.random() > 0.5) {
throw new Error("Something went wrong");
} else {
return "Hello";
}
}
const result = Try(task)
.catch(() => "Bye")
.then((v) => v + ", World!")
.unwrap();
console.log(result);
/*
Output can be any of these:
- Hello, World!
- Bye, World!
*/
🍀 Show your Support
Give a ⭐️ if this project helped you!