1.0.3 • Published 9 years ago

@urban/promisify v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 years ago

Promisify

js-standard-style

Transforms a callback-based function into a Promise. A user can optionally provide their own callback function. If provided, use this.resolve() and this.reject() within the callback.

Install

npm i --save @urban/promisify

Example

import fs from 'fs'
import promisify from '@urban/promisify'

const stat = promisify(fs.stat)

stat('file.txt')
  .then(stat => {
    console.log('File Stat', stat)
  })
  .catch(err => {
    // Error - could not `stat` file.
  })

// With custom callback.
const fileExists = promisify(fs.stat, function (err, result) {
  this.resolve(err === null)
})

fileExists('file.txt')
  .then(exists => {
    console.log('File exists', exists)
  })

License

The MIT License (MIT). Copyright (c) Urban Faubion.

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago