Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexbinary/callbackify
Minimalist callbackification 👍
https://github.com/alexbinary/callbackify
Last synced: 1 day ago
JSON representation
Minimalist callbackification 👍
- Host: GitHub
- URL: https://github.com/alexbinary/callbackify
- Owner: alexbinary
- License: mit
- Created: 2016-12-18T11:27:40.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-29T09:47:53.000Z (almost 8 years ago)
- Last Synced: 2024-11-01T23:36:56.573Z (15 days ago)
- Language: JavaScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# callbackify
Naive callbackification 🙈
[![npm](https://img.shields.io/npm/v/@alexbinary/callbackify.svg)](https://www.npmjs.com/package/@alexbinary/callbackify)
[![GitHub release](https://img.shields.io/github/release/alexbinary/callbackify.svg?label="github")](https://github.com/alexbinary/callbackify/releases/latest)
[![Build Status](https://travis-ci.org/alexbinary/callbackify.svg)](https://travis-ci.org/alexbinary/callbackify)
[![dependencies Status](https://david-dm.org/alexbinary/callbackify/status.svg)](https://david-dm.org/alexbinary/callbackify)
[![devDependencies Status](https://david-dm.org/alexbinary/callbackify/dev-status.svg)](https://david-dm.org/alexbinary/callbackify?type=dev)WARNING: This is a very basic implementation that works in simple cases but will probably break in more advanced situations.
## Install
Install using npm or yarn :
```bash
$ npm install @alexbinary/callbackify
# or
$ yarn add @alexbinary/callbackify
```## Usage
```javascript
let callbackify = require('@alexbinary/callbackify')function f () { return Promise.resolve('ok') }
callbackify(f)((err, result) => {
if (err) console.error(err)
else console.log(result) // 'ok'
})```
## Documentation
```javascript
let callbackify = require('@alexbinary/callbackify')
```### callbackify(function)
Returns a function that forwards all its arguments to `function` and takes a callback as last argument.
`function` is expected to return a Promise.
If the promise rejects then the callback is called with the error as first argument.
If the promise resolves then the callback is called with null as first argument and then all the resolved arguments (node callback style).Note that the returned function can still be used with a Promise style.
This method is idempotent, i.e. if `function` is the result of calling `callbackify` then the returned value is `function` itself. This is done by defining a Symbol property on the returned object and checking for that property before processing.
### callbackify(object, methods)
Replaces methods in given `object` whose names are listed in `methods` by the result of `callbackify(method)`.
Returns `object`.
## Licence
MIT