
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
tree-iterator
Advanced tools
Iterator for post-order-walking trees
var PostOrderTree = require('tree-iterator');
root: String|Number. It is the root (key) of tree.getsuccessors: Function. It accepts a node (key), and returns its successors, which can either be Array, or somthing Iterable;visited: Object. Used to avoid revisiting the same node in graph walking. Visited nodes are excluded from later paths.iterable: Iterable.for..of
var PostOrderTree = require('tree-iterator');
var tree = {
0: [1, 2],
2: [3]
};
var ordered = [];
var nodes = PostOrderTree(0, function (node) {
return tree[node];
});
for (var n of nodes) {
ordered.push(n);
}
console.log('ordered:', ordered);
output:
⌘ node examples/no-cycle.js
ordered: [ 1, 3, 2, 0 ]
.on('cycle', cb)
var PostOrderTree = require('tree-iterator');
var tree = {
0: [1],
1: [2],
2: [3, 0]
};
var nodes = PostOrderTree(0, function (node) {
return tree[node];
});
var ordered = [];
nodes.on('cycle', function (cycle) {
// cycle detected: [0, 1, 2, 0]
console.log('cycle detected:', cycle);
});
for (var n of nodes) {
ordered.push(n);
}
// [3, 2, 1, 0]
console.log('ordered:', ordered);
output:
⌘ node examples/cycle.js
ordered: [ 3, 2, 1, 0 ]
cycle detected: [ 0, 1, 2, 0 ]
iterableSymbol.iterator
var PostOrderTree = require('tree-iterator');
var tree = {
0: [1],
1: [2],
2: [3]
};
var nodes = PostOrderTree(0, function (node) {
return tree[node];
});
var iter = nodes[Symbol.iterator]();
console.log(iter.next()); // { value: 3, done: false }
console.log(iter.next()); // { value: 2, done: false }
console.log(iter.next()); // { value: 1, done: false }
console.log(iter.next()); // { value: 0, done: false }
console.log(iter.next()); // { value: undefined, done: true }
output:
⌘ node examples/iter.js
{ value: 3, done: false }
{ value: 2, done: false }
{ value: 1, done: false }
{ value: 0, done: false }
{ value: undefined, done: true }
FAQs
Iterator for walking trees
We found that tree-iterator 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.