destructure-promise
v0.0.5
Published
[![Travis branch](https://img.shields.io/travis/JordanSinko/destructure-promise/master.svg)](https://travis-ci.org/JordanSinko/destructure-promise) [![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=com.jordansinko.destructure-
Downloads
3
Readme
destructure-promise
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