Home

Awesome

handle-callback npmjs.com The MIT License

Make promise to have support for callback api, it returns promise in that same time.

code climate standard code style travis build status coverage status dependency status

Install

npm i handle-callback --save
npm test

Usage

For more use-cases see the tests

var handleCallback = require('handle-callback')
var got = require('then-got')

function hybridGot (url, callback) {
  var promise = got(url)

  if (callback) {
    promise = handleCallback(promise, callback)
  }

  return promise
}

hybridGot('https://github.com')
.then(function (res) {
  console.log(res[0])
  //=> html content of the page
})
.catch(console.error)

// or both in same time
hybridGot('https://github.com', function (err, res) {
  console.log(err) //=> null
  console.log(res[0]) //=> html of page
})
.then(function (res) {
  console.log(res[0]) //=> html of page
})
.catch(console.error)

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github