Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
unist-util-visit
Advanced tools
The unist-util-visit package is a utility for visiting nodes in a unist syntax tree. It allows for traversal of the tree and application of functions to nodes that match specified conditions. This can be useful for manipulating or inspecting the tree in various ways, such as filtering nodes, applying transformations, or extracting information.
Visiting nodes
This feature allows you to visit all nodes in a unist syntax tree that match a specified type. The provided function is called for each matching node. This can be useful for performing operations on specific types of nodes.
visit(tree, 'type', node => { console.log(node) })
Visiting nodes with a test function
This feature allows you to visit all nodes that pass a test implemented by a function. The test function is called with each node, and if it returns true, the node is considered a match. This allows for more complex matching conditions beyond just type.
visit(tree, node => node.value === 'specific value', node => { console.log(node) })
Exiting early
This feature allows you to exit the traversal early by returning `visit.EXIT` from the visitor function. This can be useful for optimizing performance by avoiding unnecessary traversal once a certain condition is met.
visit(tree, 'type', (node, index, parent) => { if (node.value === 'stop') return visit.EXIT })
This package provides a way to select nodes in a unist syntax tree using CSS-like selectors. It's similar to unist-util-visit in that it allows for node selection, but it uses a different approach based on selectors rather than explicit traversal and testing.
unist-util-filter offers functionality to create a new tree by filtering nodes in a unist syntax tree based on a given condition. It's similar to unist-util-visit in its ability to apply conditions to nodes, but instead of visiting nodes, it filters them to produce a new tree.
This package allows for the creation of a new unist syntax tree by applying a function to every node in an input tree. It's related to unist-util-visit in that it involves applying functions to nodes, but unist-util-map applies the function to all nodes and constructs a new tree based on the results.
Unist node visitor. Useful with working with remark, retext, or rehype.
npm:
npm install unist-util-visit
var remark = require('remark');
var visit = require('unist-util-visit');
remark().use(plugin).process('Some _emphasis_, **importance**, and `code`.');
function plugin() {
return transformer;
function transformer(tree) {
visit(tree, 'text', visitor);
}
function visitor(node) {
console.log(node);
}
}
Yields:
{type: 'text', value: 'Some '}
{type: 'text', value: 'emphasis'}
{type: 'text', value: ', '}
{type: 'text', value: 'strongness'}
{type: 'text', value: ', and '}
{type: 'text', value: '.'}
visit(node[, type], visitor[, reverse])
Visit nodes. Optionally by node type. Optionally in reverse.
node
(Node
)
— Node to search;type
(string
, optional)
— Node type;visitor
(Function)
— Visitor invoked when a node is found;reverse
(boolean
, default: false
)
— When falsey, checking starts at the first child and continues
through to later children. When truthy, this is reversed.
This does not mean checking starts at the deepest node and
continues on to the highest node.stop? = visitor(node, index, parent)
Invoked when a node (when type
is given, matching type
) is found.
node
(Node
) — Found node;index
(number?
) — Position of node
in parent
;index
(Node?
) — Parent of node
.boolean?
- When false
, visiting is immediately stopped.
FAQs
unist utility to visit nodes
We found that unist-util-visit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.