Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@micromint1npm/aperiam-perferendis-suscipit
Advanced tools
Make a callback-based or promise-based functions to support both promises and callbacks. Uses the native promise implementation. with typescript support.
Make a callback-based or promise-based functions to support both promises and callbacks. Uses the native promise implementation. with typescript support.
npm i @micromint1npm/aperiam-perferendis-suscipit
import ppc from "@micromint1npm/aperiam-perferendis-suscipit";
OR
import {fromCallback,fromPromise} from "@micromint1npm/aperiam-perferendis-suscipit";
OR
const ppc = require("@micromint1npm/aperiam-perferendis-suscipit");
OR
const fromCallback = require("@micromint1npm/aperiam-perferendis-suscipit");
OR
const fromPromise = require("@micromint1npm/aperiam-perferendis-suscipit");
fromCallback
function:Suppose you have an asynchronous function readFile that reads a file and takes a callback as the last argument:
function readFile(filename, callback) {
// Asynchronous operation to read file
}
You can convert this function to return a Promise with fromCallback
function as follows:
import {fromCallback} from "@micromint1npm/aperiam-perferendis-suscipit";
const readFilePromise = fromCallback(readFile);
// You can now call the function with a Promise:
readFilePromise(filename)
.then((data) => console.log(data))
.catch((err) => console.error(err));
// Or with a callback:
readFilePromise(filename, (err, data) => {
if (err) {
console.error(err);
} else {
console.log(data);
}
});
This allows you to use the same function in either Promise-based or callback-based code.
fromPromise
function:Suppose we have a function getUser that returns a promise:
function getUser(userId) {
return new Promise((resolve, reject) => {
// some async operation to fetch user
setTimeout(() => {
if (userId === '123') {
resolve({ id: '123', name: 'John Doe' });
} else {
reject(new Error('User not found'));
}
}, 100);
});
}
We can use fromPromise
to create a function that can be called with a callback:
import {fromPromise} from "@micromint1npm/aperiam-perferendis-suscipit";
const getUserCallback = fromPromise(getUser);
getUserCallback('123', (err, user) => {
if (err) {
console.error(err);
} else {
console.log(user); // { id: '123', name: 'John Doe' }
}
});
In the above example, the getUserCallback function accepts a callback as its last argument. If a callback is provided, it calls the original getUser function with the provided arguments and passes the result or error to the callback. If no callback is provided, it returns a promise.
We can also call getUserCallback without a callback to get a promise:
getUserCallback('123')
.then(user => console.log(user)) // { id: '123', name: 'John Doe' }
.catch(err => console.error(err));
@micromint1npm/aperiam-perferendis-suscipit is licensed under the MIT License.
FAQs
Make a callback-based or promise-based functions to support both promises and callbacks. Uses the native promise implementation. with typescript support.
We found that @micromint1npm/aperiam-perferendis-suscipit demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.