promisify-tuple
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

promisify-tuple

Convert a Node.js-style callback API (err, val) => void to a Promise that resolves to a [err, val] array.

npm install --save promisify-tuple

Before:

const fs = require('fs')

function main() {
  fs.readFile('./test.js', (err, val) => {
    if (err) console.error(err)
    else console.log(val)
  })
}

main()

After:

const fs = require('fs')
const run = require('promisify-tuple')

async function main() {
  const [err, val] = await run(fs.readFile)('./test.js')
  if (err) console.error(err)
  else console.log(val)
}

main()

License

MIT

Package Sidebar

Install

npm i promisify-tuple

Weekly Downloads

72

Version

1.2.0

License

MIT

Unpacked Size

3.62 kB

Total Files

6

Last publish

Collaborators

  • staltz