Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
promisify-node
Advanced tools
Stable: 0.5.0
Maintained by Tim Branyen @tbranyen.
Wraps Node modules, functions, and methods written in the Node-callback style to return Promises.
npm install promisify-node
Wrap entire Node modules recursively:
var promisify = require("promisify-node");
var fs = promisify("fs");
// This function has been identified as an asynchronous function so it has
// been automatically wrapped.
fs.readFile("/etc/passwd").then(function(contents) {
console.log(contents);
});
Wrap a single function:
var promisify = require("promisify-node");
function async(callback) {
callback(null, true);
}
// Convert the function to return a Promise.
var wrap = promisify(async);
// Invoke the newly wrapped function.
wrap().then(function(value) {
console.log(value === true);
});
Wrap a method on an Object:
var promisify = require("promisify-node");
var myObj = {
myMethod: function(a, b, cb) {
cb(a, b);
}
};
// No need to return anything as the methods will be replaced on the object.
promisify(myObj);
// Intentionally cause a failure by passing an object and inspect the message.
myObj.myMethod({ msg: "Failure!" }, null).then(null, function(err) {
console.log(err.msg);
});
Wrap without mutating the original:
var promisify = require("promisify-node");
var myObj = {
myMethod: function(a, b, cb) {
cb(a, b);
}
};
// Store the original method to check later
var originalMethod = myObj.myMethod;
// Now store the result, since the 'true' value means it won't mutate 'myObj'.
var promisifiedObj = promisify(myObj, undefined, true);
// Intentionally cause a failure by passing an object and inspect the message.
promisifiedObj.myMethod({ msg: "Failure!" }, null).then(null, function(err) {
console.log(err.msg);
});
// The original method is still intact
assert(myObj.myMethod === originalMethod);
assert(promisifiedObj.myMethod !== myObj.myMethod);
Run the tests after installing dependencies with:
npm test
FAQs
Wrap Node-callback functions to return Promises.
We found that promisify-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.