promise-unified

1.0.2 • Public • Published

Promise-unified

Node Version Build Status Coverage Status Npm Downlaod

NPM

中文说明

Add a unified operation for Promise

Promise lacks an unified operation method, so I add a unified method of operation for it

Attention please: This library is a prototype chain that directly modifies the Promise

install

# Install with npm
$ npm install Promise-unified --save
 
# Install with yarn
$ yarn add Promise-unified
 
# Install with bower
$ bower install Promise-unified --save

Usage

require('promise-unified')
 
let promise = new Promise(function(resolve, reject) {
  if (false){
    setTimeout(() => resolve('success'), 1000)
  } else {
    setTimeout(() => reject('error'), 1000)
  }
})
 
promise.unified((state, data) => {
  const msg = state ? 'operation successful' : 'operation failed'
  console.log(
    state,
    data,
    msg
  ) // => false, error, operation failed
})

If you do not want to use this library, you can also use the following method:

promise.then(
  data => ({state: true, data}),
  data => ({state: false, data}),
).then(({state, data}) => {
  const msg = state ? 'operation successful' : 'operation failed'
  console.log(
    state,
    data,
    msg
  )
})

Contributing

Commits Contributor
5 Black-Hole

Author

Black-Hole

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i promise-unified

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

8.6 kB

Total Files

8

Last publish

Collaborators

  • black_hole