scb2promise

callback promise async

Usage no npm install needed!

<script type="module">
  import scb2promise from 'https://cdn.skypack.dev/scb2promise';
</script>

README

scb2promise

transfer callback async function to a function which return a promise

npm version build status npm downloads

usage

$ npm i -S scb2promise

example

scb2promise(fs.readFile)(filename).than(buffer => {
  const fileContent = buffer.toString();
}, err => {
  console.error(err);
});

which is equalent to :

fs.readFile(filename, (buffer, err) => {
  if (err) {
    console.log(err);
  }

  const fileContent = buffer.toString();
});

notation

the callback function must follow the laws below:

  • callback is the last param

  • callback params should like fs API which receive (err, data)