Skip to content

await-of/denof

Repository files navigation

🍬🦕 DenoOf 🍬🦕

Syntactic sugar for asynchronous functions, promises, generators and synchronous functions.

Full documentation here - https://of.js.org/.

If you use this project don't forget to give a ⭐ star ⭐ to it.

•• DenoOf Documentation •• JavaScript Repository •• Deno Repository ••

Buy Me A Coffee Tests

💬 Usage

import {
  Of, of,
  ofAny, ofAnyCase, ofCase, ofError,
  ofIt, ofOutcome, ofResult, ofSync
} from "https://deno.land/x/denof/mod.ts";

const promise = () => new Promise((resolve, _reject) => {
  resolve({ data: true });
});
const config = {
  defaults: "🤷 Default value in case of error",
  error: new Error("💀 Custom error, replaces thrown error"),
  retries: 3, // 🔁 Third time's a charm
  timeout: 1000, // ⏱️ Delay before timeout error
};
// no error thrown
const [result, error] = await ofAnyCase(promise(), config);
console.log(result); // { data: true }
console.warn(error); // no error thrown, so it's undefined

⚙️Install

Import from URL

// From URL
import { of } from "https://deno.land/x/denof/mod.ts";
// Bundled from URL
import { of } from "https://deno.land/x/denof/denof.bundle.js";

Import from "importmap.json"

{
  "imports": {
    "denof": "https://deno.land/x/denof/mod.ts"
  }
}
import { of } from "denof";
deno run --importmap=importmap.json --unstable your-script.js

🗺️ Discover more

My other projects