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 when working with mdast or retext.
npm:
npm install unist-util-visit
unist-util-visit is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.
var mdast = require('mdast');
var visit = require('unist-util-visit');
mdast().use(function (ast) {
visit(ast, 'text', console.log.bind(console));
}).process('Some *emphasis*, **strongness**, and `code`.');
Yields:
{'type': 'text', 'value': 'Some '}
{'type': 'text', 'value': 'emphasis'}
{'type': 'text', 'value': ', '}
{'type': 'text', 'value': 'strongness'}
{'type': 'text', 'value': ', and '}
{'type': 'text', 'value': '.'}
visit
is synchronous.
Visit nodes. Optionally by node type. Optionally in reverse.
node
(Node
)
— Unist node;
type
(string
, optional)
— Optional node type to invoke callback
for. By default, all nodes are
visited.
callback
(function(node, index?, parent?)
)
— Callback invoked when a node (matching type
?) is found. Invoked with
the node, its index
in parent
(or null
), and its parent
(or null
).
Can return false
to immediately stop checking.
reverse
(boolean
, default: false
, optional)
— 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.
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.