$ npm install handle-callback
Make promise to have support for callback api, it returns promise in that same time.
npm i handle-callback --save
npm test
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)
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.
© 2010 - cnpmjs.org x YWFE | Home | YWFE