Comparing version 2.1.0 to 2.2.0
10
index.js
@@ -55,2 +55,10 @@ 'use strict'; | ||
var ret = (typeof obj === 'function') ? function () { | ||
if (opts.excludeMain) { | ||
return obj.apply(this, arguments); | ||
} | ||
return pify(obj, P, opts).apply(this, arguments); | ||
} : {}; | ||
return Object.keys(obj).reduce(function (ret, key) { | ||
@@ -60,3 +68,3 @@ var x = obj[key]; | ||
return ret; | ||
}, {}); | ||
}, ret); | ||
}; |
{ | ||
"name": "pify", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Promisify a callback-style function", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -98,5 +98,37 @@ # pify [![Build Status](https://travis-ci.org/sindresorhus/pify.svg?branch=master)](https://travis-ci.org/sindresorhus/pify) | ||
##### excludeMain | ||
Type: `boolean` | ||
Default: `false` | ||
*Works for `pify.all()` only.* | ||
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 pify = require('pify'); | ||
function fn() { | ||
return true; | ||
} | ||
fn.method = (data, callback) => { | ||
setImmediate(() => { | ||
callback(data, null); | ||
}); | ||
}; | ||
// promisify methods but not fn() | ||
const promiseFn = pify.all(fn, {excludeMain: true}); | ||
if (promiseFn()) { | ||
promiseFn.method('hi').then(data => { | ||
console.log(data); | ||
}); | ||
} | ||
``` | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
5852
54
134