项目作者: await-of

项目描述 :
Syntactic sugar for asynchronous functions, promises, generators and synchronous functions.
高级语言: TypeScript
项目地址: git://github.com/await-of/denof.git
创建时间: 2020-05-28T08:21:34Z
项目社区:https://github.com/await-of/denof

开源协议:MIT License

下载


🍬🦕 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

  1. import {
  2. Of, of,
  3. ofAny, ofAnyCase, ofCase, ofError,
  4. ofIt, ofOutcome, ofResult, ofSync
  5. } from "https://deno.land/x/denof/mod.ts";
  6. const promise = () => new Promise((resolve, _reject) => {
  7. resolve({ data: true });
  8. });
  9. const config = {
  10. defaults: "🤷 Default value in case of error",
  11. error: new Error("💀 Custom error, replaces thrown error"),
  12. retries: 3, // 🔁 Third time's a charm
  13. timeout: 1000, // ⏱️ Delay before timeout error
  14. };
  15. // no error thrown
  16. const [result, error] = await ofAnyCase(promise(), config);
  17. console.log(result); // { data: true }
  18. console.warn(error); // no error thrown, so it's undefined

⚙️Install

Import from URL

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

Import from “importmap.json”

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

🗺️ Discover more

My other projects