Tired of writing repetitive try-catch
blocks? Advance Await introduces an elegant way to handle errors in async functions and Promises using [error, result]
tuples—no more cluttered error handling!
✅ No More try-catch
Hell – Get rid of unnecessary boilerplate.
✅ Effortless Async Handling – Errors are caught automatically.
✅ Works with Functions & Promises – Compatible with fetch()
, JSON parsing
, and more!
✅ Flexible Usage – Use it globally or import per file.
Install the package using npm, yarn, or pnpm:
npm install advance-await
# OR
yarn add advance-await
# OR
pnpm install advance-await
You can use Advance Await in two ways:
To enable Advance Await globally in your project without manual imports, run your script with:
tsx --require=advance-await src/your-script.ts
node --require advance-await src/your-script.js
Now, every async function and promise in your project can use [error, result]
without needing an import!
(async () => {
const [error, response] = await fetch("https://jsonplaceholder.typicode.com/posts/1")[Symbol.result]();
if (error) return console.error("Fetch error:", error.message);
const [jsonError, data] = await response.json()[Symbol.result]();
if (jsonError) return console.error("JSON parsing error:", jsonError.message);
console.log(data);
})();
If you prefer using it in a specific file only, simply import advance-await
at the top:
import "advance-await"; // Just import once per file!
(async () => {
const [error, response] = await fetch("https://jsonplaceholder.typicode.com/posts/1")[Symbol.result]();
if (error) return console.error("Fetch error:", error.message);
const [jsonError, data] = await response.json()[Symbol.result]();
if (jsonError) return console.error("JSON parsing error:", jsonError.message);
console.log(data);
})();
🔹 No need for try-catch
—errors are automatically caught in [error, result]
.
🔹 Works seamlessly with any async function or Promise.
MIT
Say goodbye to try-catch
clutter and write cleaner, more readable async code today! 🚀