promisify-node
Advanced tools
Comparing version 0.2.0 to 0.2.1
43
index.js
@@ -40,2 +40,5 @@ const Promise = require("nodegit-promise"); | ||
// Assign the new function in place. | ||
var wrapped = Promise.denodeify(exports); | ||
// Find methods on the prototype, if there are any. | ||
@@ -46,20 +49,2 @@ if (Object.keys(exports.prototype).length) { | ||
// If a filter function exists, use this to determine if the function | ||
// is asynchronous. | ||
if (test) { | ||
// Pass the function itself, its keyName, and the parent keyName. | ||
if (!test(exports, exports.name || parentKeyName, parentKeyName)) { | ||
return exports; | ||
} | ||
} | ||
// If the callback name exists as the last argument, consider it an | ||
// asynchronous function. Brittle? Fragile? Effective. | ||
else if (callbacks.indexOf(args(exports).slice(-1)[0]) === -1) { | ||
return exports; | ||
} | ||
// Assign the new function in place. | ||
var wrapped = Promise.denodeify(exports); | ||
// Attach the augmented prototype. | ||
@@ -77,3 +62,3 @@ wrapped.prototype = exports.prototype; | ||
return [keyName, exports[keyName]]; | ||
}).forEach(function(keyVal) { | ||
}).filter(function(keyVal) { | ||
var keyName = keyVal[0]; | ||
@@ -86,5 +71,23 @@ var value = keyVal[1]; | ||
} | ||
// Filter to functions with callbacks only. | ||
else if (typeof value === "function") { | ||
// If a filter function exists, use this to determine if the function | ||
// is asynchronous. | ||
if (test) { | ||
// Pass the function itself, its keyName, and the parent keyName. | ||
return test(value, keyName, parentKeyName); | ||
} | ||
// If the callback name exists as the last argument, consider it an | ||
// asynchronous function. Brittle? Fragile? Effective. | ||
if (callbacks.indexOf(args(value).slice(-1)[0]) > -1) { | ||
return true; | ||
} | ||
} | ||
}).forEach(function(keyVal) { | ||
var keyName = keyVal[0]; | ||
var func = keyVal[1]; | ||
// Wrap this function and reassign. | ||
exports[keyName] = processExports(value, test, cached, parentKeyName); | ||
exports[keyName] = processExports(func, test, cached, parentKeyName); | ||
}); | ||
@@ -91,0 +94,0 @@ |
{ | ||
"name": "promisify-node", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Wrap Node-callback functions to return Promises.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -101,4 +101,4 @@ var promisify = require("../"); | ||
promisify(Test, function(func, keyName) { | ||
return keyName === "a"; | ||
promisify(Test, function(func, keyName, parentKeyName) { | ||
return func.name === "a"; | ||
}); | ||
@@ -105,0 +105,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
10329
198