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.
@n1ru4l/toposort
Advanced tools
@n1ru4l/toposort
All toposort libraries I found where either JavaScript only, had a lot of dependencies, were cumbersome to deal with or did not produce dependency list that allowed detecting which tasks could be executed in parallel.
This library is basically a port of batching-toposort to TypeScript that uses modern ECMA structures such as Map
and Set
, as well as providing a utility toposortReverse
function that I needed most of the time, when dealing with dependency lists.
This library also provides CommonJS and ES Module builds.
yarn install -E @n1ru4l/toposort
toposort
Sort list of tasks.
import { toposort } from "@n1ru4l/toposort";
const tasks = new Map([
// after wakeUp is done we can do drinkCoffee and eatBreakfast
["wakeUp", ["drinkCoffee", "eatBreakfast"]],
["drinkCoffee", ["brushTeeth"]],
["eatBreakfast", ["brushTeeth"]],
["brushTeeth", ["floss"]],
// after flossing is done no further task must be done
["floss", []],
]);
const sorted = toposort(tasks);
console.log(sorted);
// [
// Set(1) { 'wakeUp' },
// Set(2) { 'drinkCoffee', 'eatBreakfast' },
// Set(1) { 'brushTeeth' },
// Set(1) { 'floss' }
// ]
toposortReverse
Most of the time I needed this instead of toposort
. It is easier to grasp for my mind that task a depends on task b and c instead of declaring it the other way around. I am not sure about the naming. If you think a better naming is possible please send a pull request.
import { toposortReverse } from "@n1ru4l/toposort";
const graph = new Map([
// before we can drinkCoffee, we need to wakeUp
["drinkCoffee", ["wakeUp"]],
// before we can eatBreakfast, we need to wakeUp
["eatBreakfast", ["wakeUp"]],
// before we can brushTeeth, we need to drinkCoffee and eatBreakfast
["brushTeeth", ["drinkCoffee", "eatBreakfast"]],
// before we can floss, we need to brushTeeth
["floss", ["brushTeeth"]],
// wakeUp can be done without any dependencies
["wakeUp", []],
]);
const sorted = toposortReverse(graph);
// [
// Set(1) { 'wakeUp' },
// Set(2) { 'drinkCoffee', 'eatBreakfast' },
// Set(1) { 'brushTeeth' },
// Set(1) { 'floss' }
// ]
FAQs
toposort using modern ecma script data structures
The npm package @n1ru4l/toposort receives a total of 6,846 weekly downloads. As such, @n1ru4l/toposort popularity was classified as popular.
We found that @n1ru4l/toposort 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.