@simmo/task

0.0.1 • Public • Published

Task

Travis npm downloads License

JavaScript utility that provides a consistent, clean return from promises. Particularly helpful when using await/async.

Install

NPM

npm install @simmo/task

Yarn

yarn add @simmo/task

Usage

task(<Promise>) => { error: <Any>, data: <Any> }

task always returns an object. The object will contain two properties; error and data.

If the promise is resolved, error will be null and data will contain anything the promise has returned. If the promise is rejected, error will return the error provided by the promise and data will be null.

import task from '@simmo/task'

const { error, data } = await task(fetch('/some-api'))

if (error) {
  // Failure
  console.error(error)
} else {
  // Success
  console.log(data)
}

License

MIT © Mike Simmonds

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.11latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.11
0.0.00

Package Sidebar

Install

npm i @simmo/task

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

4.46 kB

Total Files

4

Last publish

Collaborators

  • simmo