https://github.com/samverschueren/rfpify
[DEPRECATED] Promisify a result-first callback function.
https://github.com/samverschueren/rfpify
Last synced: 8 months ago
JSON representation
[DEPRECATED] Promisify a result-first callback function.
- Host: GitHub
- URL: https://github.com/samverschueren/rfpify
- Owner: SamVerschueren
- License: mit
- Created: 2015-10-13T10:08:57.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-05T19:45:32.000Z (over 8 years ago)
- Last Synced: 2025-03-11T18:03:11.250Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-nodejs-precise - rfpify - square)]() | Promisify a result-first callback-style function. | (Packages / Control flow Promises)
- awesome-nodejs-cn - rfpify - Promisify a result-first callback-style function. (包 / Control flow)
README
# rfpify
> Promisify a result-first callback-style function.
---
Deprecated in favour of pify with the errorFirst option.
---
## Install
```
$ npm install --save rfpify
```
## Usage
```js
const rfpify = require('rfpify');
rfpify(stream.once.bind(stream))('data').then(data => {
// handle data
});
```
## API
### rfpify(input, [promiseModule], [options])
Returns a promise wrapped version of the supplied function or module.
#### input
Type: `function`, `object`
Result-first callback-style function.
#### promiseModule
Type: `function`
Custom promise module to use instead of the native one.
Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill.
#### options
##### multiArgs
Type: `boolean`
Default: `false`
By default, the promisified function will only return the first argument from the callback, which works fine for most APIs. Turning this on will make it return an array of
all arguments from the callback, instead of just the first argument.
##### include
Type: `array` of (`string`|`regex`)
Methods in a module to promisify. Remaining methods will be left untouched.
##### exclude
Type: `array`
Default: `[/.+Sync$/]`
Methods in a module **not** to promisify. Methods with names ending with 'Sync' are excluded by default.
##### excludeMain
Type: `boolean`
Default: `false`
By default, if given module is a function itself, this function will be promisified. Turn this option on if you want to promisify only methods of the module.
```js
const rfpify = require('rfpify');
function fn() {
return true;
}
fn.method = (data, callback) => {
setImmediate(() => {
callback(data);
});
};
// promisify methods but not fn()
const promiseFn = rfpify.all(fn, {excludeMain: true});
if (promiseFn()) {
promiseFn.method('hi').then(data => {
console.log(data);
});
}
```
## Related
- [pify](https://github.com/sindresorhus/pify) - Promisify a callback-style function
## License
MIT © [Sam Verschueren](http://github.com/SamVerschueren)