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.
The 'spex' npm package is a specialized library for handling advanced promise operations in JavaScript. It provides a set of tools for managing and orchestrating multiple promises, making it easier to handle complex asynchronous workflows.
Batch Processing
Batch processing allows you to execute multiple promise-returning functions in parallel and collect their results. The example demonstrates how to use the 'batch' method to run an array of tasks and handle their results.
const spex = require('spex')();
const tasks = [
() => Promise.resolve(1),
() => Promise.resolve(2),
() => Promise.resolve(3)
];
spex.batch(tasks)
.then(data => {
console.log(data); // [1, 2, 3]
})
.catch(error => {
console.error(error);
});
Sequence Processing
Sequence processing allows you to execute multiple promise-returning functions in sequence, one after another. The example demonstrates how to use the 'sequence' method to run an array of tasks sequentially and handle their results.
const spex = require('spex')();
const tasks = [
() => Promise.resolve(1),
() => Promise.resolve(2),
() => Promise.resolve(3)
];
spex.sequence(tasks)
.then(data => {
console.log(data); // [1, 2, 3]
})
.catch(error => {
console.error(error);
});
Page Processing
Page processing allows you to handle paginated data sources. The example demonstrates how to use the 'page' method to process pages of data until the source function returns null.
const spex = require('spex')();
let pageIndex = 0;
const source = (index) => {
if (index < 3) {
return Promise.resolve(index);
} else {
return null;
}
};
spex.page(source)
.then(data => {
console.log(data); // {pages: 3, total: 3}
})
.catch(error => {
console.error(error);
});
Bluebird is a fully-featured promise library that provides a wide range of utilities for working with promises, including advanced control flow, collection methods, and more. Compared to spex, Bluebird offers a broader set of features but may be more complex to use for specific batch and sequence processing tasks.
Async is a utility module that provides straightforward, powerful functions for working with asynchronous JavaScript. It includes methods for parallel and sequential execution of tasks, similar to spex, but uses callbacks instead of promises. Async is a good choice if you prefer callback-based APIs.
p-map is a promise-based utility for mapping over iterables concurrently. It allows you to control the concurrency level, making it similar to spex's batch processing. However, p-map is more focused on mapping operations and does not provide sequence or page processing features.
Specialized Promise Extensions.
batch, page, sequence - promise methods for the following patterns:
$ npm i spex
const promise = require('bluebird');
const spex = require('spex')(promise);
const spex = require('spex')(Promise);
See also: client-side usage.
$ git clone https://github.com/vitaly-t/spex
$ npm install
$ npm test
$ npm run coverage
Copyright © 2020 Vitaly Tomilov; Released under the MIT license.
FAQs
Specialized Promise Extensions
We found that spex demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
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.