Comparing version 1.0.0 to 1.1.0
22
index.js
'use strict'; | ||
module.exports = function (fn, P) { | ||
function isFn(fn) { | ||
return ({}).toString.call(fn) === '[object Function]'; | ||
} | ||
var pify = module.exports = function (fn, P) { | ||
P = P || Promise; | ||
if (({}).toString.call(fn) !== '[object Function]') { | ||
if (!isFn(fn)) { | ||
throw new TypeError('Expected a function'); | ||
@@ -28,1 +33,14 @@ } | ||
}; | ||
pify.all = function (module, P) { | ||
var ret = {}; | ||
for (var method in module) { | ||
if (({}).hasOwnProperty.call(module, method)) { | ||
var x = module[method]; | ||
ret[method] = isFn(x) ? pify(x, P) : x; | ||
} | ||
} | ||
return ret; | ||
}; |
{ | ||
"name": "pify", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Promisify a callback-style function", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -23,2 +23,10 @@ # pify [![Build Status](https://travis-ci.org/sindresorhus/pify.svg?branch=master)](https://travis-ci.org/sindresorhus/pify) | ||
}); | ||
// promisify all methods in a module | ||
var promiseFs = pify.all(fs); | ||
promiseFs.readFile('package.json', 'utf8').then(function (data) { | ||
console.log(JSON.parse(data).name); | ||
//=> 'pify' | ||
}); | ||
``` | ||
@@ -41,2 +49,12 @@ | ||
### pify.all(module, [promiseModule]) | ||
Returns a version of the module with all its methods promisified. | ||
#### module | ||
Type: `object` | ||
Module whose methods you want to promisify. | ||
#### promiseModule | ||
@@ -43,0 +61,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3999
36
70