
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
maybe-promise-factory
Advanced tools
Calls a function and wraps the retval or exception in a Promise only if it didn't already return a Promise; like Twisted's maybeDeferred. Turns a sync-or-Promise API into a Promise API.
Calls a function and wraps the retval or exception in a Promise only if it didn't already return a Promise; like Twisted's maybeDeferred. Turns a sync-or-Promise API into a Promise API.
Install with npm install maybe-promise-factory
.
const maybePromise = require('maybe-promise-factory')(Promise);
function syncSum (a, b) {
if (typeof a !== 'number' || typeof b !== 'number') {
throw new TypeError('Invaild arguments passed to syncSum');
}
return a + b;
}
function asyncSum (a, b) {
return new Promise((resolve, reject) => {
if (typeof a !== 'number' || typeof b !== 'number') {
reject(new TypeError('Invalid arguments passed to asyncSum'));
return;
}
resolve(a + b);
});
}
maybePromise(syncSum, 1, 2).then(res => console.log(res)); // 3
maybePromise(syncSum, 1, 'x').catch(err => console.error(err)); // TypeError
maybePromise(asyncSum, 1, 2).then(res => console.log(res)); // 3
maybePromise(asyncSum, 1, 'x').catch(err => console.error(err)); // TypeError
The maybePromiseFactory accepts two arguments:
promiseConstructor
A Promise implementation (e.g. Bluebird
or Promise
)[useAnyThenable]
If truthy, any Promise implementation is considered a promise; otherwise, only instances of the promiseConstructor
are considered promises.The maybePromiseFactory returns a maybePromise function, which is passed a function (synchronous or asynchronous) and any parameters to invoke it with. It returns an instance of promiseConstructor
.
FAQs
The maybePromiseFactory normalizes synchronous values and asynchronous values by always returning a Promise.
We found that maybe-promise-factory 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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.