promise-wrap

An incredibly easy way to use promises instead of callbacks, as long as they follow standard node callback conventions

Usage no npm install needed!

<script type="module">
  import promiseWrap from 'https://cdn.skypack.dev/promise-wrap';
</script>

README

promise-wrap

License NPM Version Tag Version Build Status

Have you ever wished that something were just wrapped in a promise?

somethingThatRequiresACallback(function(err, data) {
  if (err) {
    //handle error
  }
  //do useful stuff
}

Now it is:

var pw = require('promise-wrap');

pw(somethingThatRequiresACallback).then(function(data) {
  //do useful stuff
}).error(function(err) {
  //handle error
});

Context

By default promise-wrap will .apply the first argument with a null context and use the rest as parameters. If you want to specify a context simply pw.withContextAndArguments(call, context, args...)

Chaining

Very soon there will be support for setting up methods for chaining so that you can

var pw = require('promise-wrap');

somePromise()
.then(pw.chain(somethingThatRequiresACallback))
.then(function(data) {
  //do useful stuff
}).error(function(err) {
  //handle error
});