New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

aasy

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aasy

Make Promise without undefined behavior

latest
npmnpm
Version
1.0.6
Version published
Weekly downloads
6
50%
Maintainers
1
Weekly downloads
 
Created
Source

aasy

Async - easy.

Zero-library Promise wrapper without pain.

Make Promise without undefined behavior(almost).

Reason to use aasy

  • Typescript types. Promise stantard generic is not accepts Reject generic. aasy does.
  • Less undefined behavior, when using safe function.
  • Inherited from built-in Promise object
  • ESM and CJS support.
type Async<Value, Error = unknown> = intrinsic // from native Promise + API

Wanna be contributor?

See contribute guide

API

safe

Call promise and do not throw an error even if get rejected status.

Arguments: value - Promise

Returns:

  • Promise<Object>
    • success boolean
    • value - Promise Fulfilled result
    • error - Promise Reject reason
    • unwrap Function - Function that accepts new error and returns resolved value. See examples to see it in action

Example safe

import Async from 'aasy';
const promiseThatFails = await Async.safe(Async.reject(123));

promiseThatFails.success // false
promiseThatFails.value // undefined
promiseThatFails.error // 123
promiseThatFails.unwrap() // throws "123"
promiseThatFails.unwrap("Undefined Behavior") // throws "Undefined Behavior"

const promiseSuccess = await Async.safe("Hello!");

promiseSuccess.success // true
promiseSuccess.error // undefined
promiseSuccess.value // "Hello!"
promise.unwrap() // "Hello!"
const value = promise.unwrap("Undefined behavior") // error will be ignored
console.log(value) // "Hello!"

from

Transforms Promise | PromiseLike value into async instance.

Example from

import Async from 'aasy';

const promiseFromSomewhere = fetch(...);
const promise = Async.from(promiseFromSomewhere);
// or you can use await to get result from promise
const awaitdResult = await Async.from(promiseFromSomewhere);

Async.resolve

Inherited from Promise

Async.reject

Inherited from Promise

Async.all

Inherited from Promise

Async.any

Inherited from Promise

then

Inherited from Promise

catch

Inherited from Promise

finally

Inherited from Promise

Tech Stack

  • pnpm
  • esbuild
  • typescript
  • husky
  • github actions
  • jest
  • eslint

Keywords

Promise

FAQs

Package last updated on 28 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts