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.
p-map-series
Advanced tools
The p-map-series npm package allows you to map over promises serially. It processes each promise one after another, ensuring that only one promise is running at a time. This is useful for tasks that need to be performed in sequence rather than in parallel.
Serial Processing
This feature allows you to process an array of promise-returning functions in series. Each task is executed one after another, ensuring that only one task is running at any given time.
const pMapSeries = require('p-map-series');
const tasks = [
() => Promise.resolve('Task 1'),
() => Promise.resolve('Task 2'),
() => Promise.resolve('Task 3')
];
pMapSeries(tasks).then(results => {
console.log(results); // ['Task 1', 'Task 2', 'Task 3']
});
Error Handling
This feature demonstrates how p-map-series handles errors. If any task in the series fails, the entire process stops, and the error is caught in the catch block.
const pMapSeries = require('p-map-series');
const tasks = [
() => Promise.resolve('Task 1'),
() => Promise.reject(new Error('Task 2 failed')),
() => Promise.resolve('Task 3')
];
pMapSeries(tasks).then(results => {
console.log(results);
}).catch(error => {
console.error(error); // Error: Task 2 failed
});
The p-series package allows you to run promise-returning & async functions in series. It is similar to p-map-series but focuses solely on running promises in sequence without the mapping functionality.
The promise-sequential package runs an array of promise-returning functions sequentially. It is similar to p-map-series but is designed to be lightweight and straightforward, focusing solely on sequential execution.
Map over promises serially
Useful as a side-effect mapper. Use p-map
if you don't need side-effects, as it's concurrent.
$ npm install p-map-series
import pMapSeries from 'p-map-series';
const keywords = [
getTopKeyword() //=> Promise
'rainbow',
'pony'
];
let scores = [];
const mapper = async keyword => {
const score = await fetchScore(keyword);
scores.push(score);
return {keyword, score};
});
console.log(await pMapSeries(keywords, mapper));
/*
[
{
keyword: 'unicorn',
score: 99
},
{
keyword: 'rainbow',
score: 70
},
{
keyword: 'pony',
score: 79
}
]
*/
Returns a Promise
that is fulfilled when all promises in input
and ones returned from mapper
are fulfilled, or rejects if any of the promises reject. The fulfilled value is an Array
of the mapper
created promises fulfillment values.
Type: Iterable<Promise | unknown>
Mapped over serially in the mapper
function.
Type: Function
Expected to return a value. If it's a Promise
, it's awaited before continuing with the next iteration.
FAQs
Map over promises serially
The npm package p-map-series receives a total of 1,544,601 weekly downloads. As such, p-map-series popularity was classified as popular.
We found that p-map-series 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.