
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
accept-promises
Advanced tools
Let them into your heart and/or functions.
var assert = require('assert');
var acceptPromises = require('./');
var Promise = require('bluebird');
var add = acceptPromises(function (a, b) {
return a + b;
});
var assertIsPromise = function (it) {
assert(Promise.is(it));
};
assertPromise(add(1, 2));
add(1, 2).then(function (three) {
assert.equal(3, three);
});
assertPromise(
add(1, Promise.resolve(2))).then(function (three) {
assert.equal(3, three);
})
);
In addition to decorating individual functions, there is also a helper for walking over an object prototype:
function Calculator () {}
Calculator.prototype = acceptPromises.mutateMethods({
add: function (a, b) { return a + b },
sub: function (a, b) { return a - b },
mul: function (a, b) { return a * b },
div: function (a, b) { return a / b }
});
This module exports a function decorator that will wait for all Promise
arguments to a function to settle. This allows you to avoid writing a lot of
.then
boilerplate in your code, and write things as though they are sync.
This is really just the bindSync
decorator from z-core pulled out into
it's own module, since it was the only part of z-core
that I really wanted.
MIT
FAQs
Accept Promises into your heart and/or functions.
We found that accept-promises demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.