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

abet

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abet

Make promises eagerly accessable.

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

Abet

Abet allows promises to be chained using the properties and methods of their results.

Install

npm install abet

Example

const promise = Promise.resolve({
  users: [
    {name: 'joe', age: 10},
    {name: 'sally', age: 20},
  ]
});

abet(promise)
  .users
  .reduce((a, b) => {
    if(a.age > b.age) return a;
    return b;
  })
  .name
  .then(name => console.log(name)); // prints 'sally'
  

Or using async/await:


const { name } = await abet(promise)
  .users
  .reduce((a, b) => {
    if(a.age > b.age) return a;
    return b;
  });
  
console.log(name); // prints 'sally'

How it works

Abet relies on ES6 Proxies to keep track of keys being accessed and methods being called. When then or catch is called on a wrapped promise, the result is intercepted and reduced using the keys and methods used on the wrapper.

Take a look at the source. It's only 32 lines.

Keywords

promises

FAQs

Package last updated on 05 Aug 2018

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