https://github.com/tiaanduplessis/promisify
Convert function to one returning a promise
https://github.com/tiaanduplessis/promisify
function promise
Last synced: 8 months ago
JSON representation
Convert function to one returning a promise
- Host: GitHub
- URL: https://github.com/tiaanduplessis/promisify
- Owner: tiaanduplessis
- License: mit
- Created: 2017-07-11T12:10:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-06-02T22:50:31.000Z (about 7 years ago)
- Last Synced: 2025-05-08T22:05:45.481Z (about 1 year ago)
- Topics: function, promise
- Language: JavaScript
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
promisify
Convert function to one returning a promise
Table of Contents
Table of Contents
## Install
```sh
$ npm install @tiaanduplessis/promisify
# OR
$ yarn add @tiaanduplessis/promisify
```
## Usage
```js
const fs = require('fs')
const promisify = require('@tiaanduplessis/promisify')
const a = (x) => x;
const b = (x) => Promise.resolve(x)
const c = (x) => Promise.reject(x)
promisify(a)('foo').then(console.log)
promisify(b)('bar').then(console.log)
promisify(c)('baz').catch(console.log)
promisify(fs.readFile)('package.json', 'utf8').then(console.log)
```
# Related
- [es6-promisify](https://github.com/digitaldesignlabs/es6-promisify)
- [pify](https://github.com/sindresorhus/pify)
## Contributing
Contributions are welcome!
1. Fork it.
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
Or open up [a issue](https://github.com/tiaanduplessis/promisify/issues).
## License
Licensed under the MIT License.