0.0.5 • Published 5 years ago

destructure-promise v0.0.5

Weekly downloads
45
License
MIT
Repository
github
Last release
5 years ago

destructure-promise

Travis branch Sonarcloud Status LGTM Quality LGTM Alerts Sonarcloud Coverage NPM Downloads NPM License

Make a promise-based function return a destructurifiable object.

Uses the native promise implementation.

Installation

npm install destructure-promise

API

destructure-promise(fn)

Takes a promise-based function and returns the destructuried function. The idea for this was from Go's-like version of a tuple response.

const destructure = require('destructure-promise');

(async () => {
  // Resolved values
  {
    const task = arg => Promise.resolve(arg);
    const destructured = destructure(task);
    const [, response] = await destructured('Hello world'); // 'Hello world'
  }
  // Resolved values
  {
    const task = () => Promise.reject({ message: 'Some error' });
    const destructured = destructure(task);
    const [error] = await destructured(); // { message: 'Some error' }
  }
})();

License

MIT

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

6 years ago