Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@kwsites/promise-deferred
Advanced tools
Minimalist creation of promise wrappers, exposing the ability to resolve or reject the inner promise
@kwsites/promise-deferred is a utility package that provides a simple way to create deferred promises. This can be useful in scenarios where you need to create a promise and resolve or reject it at a later time, outside of the initial promise executor function.
Creating a Deferred Promise
This feature allows you to create a deferred promise that can be resolved or rejected at a later time. The code sample demonstrates creating a deferred promise, simulating an asynchronous operation with setTimeout, and resolving the promise after 1 second.
const { deferred } = require('@kwsites/promise-deferred');
const def = deferred();
// Simulate an asynchronous operation
setTimeout(() => {
def.resolve('Success!');
}, 1000);
// Use the promise
async function asyncOperation() {
const result = await def.promise;
console.log(result); // Outputs: 'Success!'
}
asyncOperation();
Handling Deferred Promise Rejection
This feature allows you to handle the rejection of a deferred promise. The code sample demonstrates creating a deferred promise, simulating an asynchronous operation with setTimeout, and rejecting the promise after 1 second. The async function catches and logs the error.
const { deferred } = require('@kwsites/promise-deferred');
const def = deferred();
// Simulate an asynchronous operation
setTimeout(() => {
def.reject(new Error('Failure!'));
}, 1000);
// Use the promise
async function asyncOperation() {
try {
const result = await def.promise;
} catch (error) {
console.error(error.message); // Outputs: 'Failure!'
}
}
asyncOperation();
p-defer is a similar package that provides a way to create deferred promises. It offers a simple API to create a deferred promise and resolve or reject it at a later time. Compared to @kwsites/promise-deferred, p-defer is more widely used and has more community support.
promise-deferred is another package that provides deferred promise functionality. It allows you to create a deferred promise and resolve or reject it later. This package is similar in functionality to @kwsites/promise-deferred but has a different API design.
FAQs
Minimalist creation of promise wrappers, exposing the ability to resolve or reject the inner promise
We found that @kwsites/promise-deferred 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.