Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
unist-util-position
Advanced tools
Package description
The unist-util-position package is a utility for working with positional information in unist syntax trees. It provides functions to get and manipulate positions of nodes within these trees, which is useful for tasks such as error reporting, syntax highlighting, and more.
position.start
This feature retrieves the starting position of a node. The code sample demonstrates how to use the `position.start` function to get the starting line and column of a node.
const position = require('unist-util-position');
const node = { position: { start: { line: 1, column: 1 }, end: { line: 1, column: 5 } } };
console.log(position.start(node)); // { line: 1, column: 1 }
position.end
This feature retrieves the ending position of a node. The code sample shows how to use the `position.end` function to get the ending line and column of a node.
const position = require('unist-util-position');
const node = { position: { start: { line: 1, column: 1 }, end: { line: 1, column: 5 } } };
console.log(position.end(node)); // { line: 1, column: 5 }
position.point
This feature normalizes a point object. The code sample demonstrates how to use the `position.point` function to ensure a point object has the correct structure.
const position = require('unist-util-position');
const point = { line: 1, column: 1 };
console.log(position.point(point)); // { line: 1, column: 1 }
The unist-util-visit package is used to recursively walk through unist syntax trees. While it doesn't specifically handle positional information, it can be used in conjunction with unist-util-position to traverse nodes and then retrieve their positions.
The unist-util-find package helps in finding nodes in unist syntax trees based on certain criteria. It can be used to locate nodes and then unist-util-position can be used to get their positional information.
The unist-util-select package allows for selecting nodes in unist syntax trees using CSS-like selectors. Once nodes are selected, unist-util-position can be used to get their positions. This package is useful for more complex queries within the tree.
Readme
unist utility to get the positional info of nodes.
npm:
npm install unist-util-position
var remark = require('remark')
var position = require('unist-util-position')
var tree = remark().parse('# foo\n\n* bar\n')
console.log(position(tree))
console.log(position.start(tree))
console.log(position.end(tree))
console.log(position())
console.log(position.start())
console.log(position.end())
Yields:
{start: {line: 1, column: 1, offset: 0}, end: {line: 4, column: 1, offset: 13}}
{line: 1, column: 1, offset: 0}
{line: 4, column: 1, offset: 13}
{start: {line: null, column: null, offset: null}, end: {line: null, column: null, offset: null}}
{line: null, column: null, offset: null}
{line: null, column: null, offset: null}
position(node?)
Get the positional info of node
(Node?
).
Returns Position
.
position.start(node?)
position.end(node?)
Get the start or end points in the positional info of node
(Node?
).
Returns Point
.
See contributing.md
in syntax-tree/.github
for ways to get
started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
FAQs
unist utility to get the position of a node
The npm package unist-util-position receives a total of 4,042,041 weekly downloads. As such, unist-util-position popularity was classified as popular.
We found that unist-util-position demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.