Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
unist-util-remove-position
Advanced tools
The unist-util-remove-position npm package is designed to work with Unist syntax trees. It allows users to remove the position information from nodes in the tree. This can be particularly useful when you want to compare nodes based on their content rather than their position in the source file, or when you want to minimize the size of the tree for serialization.
Remove position from a single node
This feature allows you to remove the position information from a single node in the syntax tree. The code sample shows a node before the position information has been removed.
{"type": "text", "value": "Hello, world!", "position": {"start": {"line": 1, "column": 1, "offset": 0}, "end": {"line": 1, "column": 13, "offset": 12}}}
Remove position from an entire tree
This feature allows you to remove the position information from all nodes in a syntax tree, effectively stripping out all position data. The code sample shows a simple tree before the position information has been removed.
{"type": "root", "children": [{"type": "paragraph", "children": [{"type": "text", "value": "Hello, world!", "position": {"start": {"line": 1, "column": 1, "offset": 0}, "end": {"line": 1, "column": 13, "offset": 12}}}], "position": {"start": {"line": 1, "column": 1, "offset": 0}, "end": {"line": 1, "column": 13, "offset": 12}}}]
While unist-util-visit is designed for traversing Unist nodes and performing operations on them, it can be used in conjunction with other utilities to modify nodes, including removing position information. However, unist-util-remove-position is specifically tailored for removing position data, making it more straightforward for this particular task.
unist-util-map can be used to create a new tree by applying a function to each node in the input tree. This function could theoretically remove position information from each node, similar to unist-util-remove-position. However, unist-util-remove-position provides a more direct and optimized approach for this specific purpose.
unist utility to remove positional info from a tree.
This is a small utility that helps you remove the position
field from nodes in
a unist tree.
Often, positional info is the whole reason, or an important reason, for using
ASTs.
Sometimes, especially when comparing trees, or when inserting one tree into
another, the positional info is at best useless and at worst harmful.
In those cases, you can use this utility to remove position
fields from a
tree.
You might find the utility unist-util-position
useful to instead get clean position info from a tree, or
unist-util-generated
useful to check whether a node is
considered to be generated (not in the original input file).
You might also enjoy
unist-util-stringify-position
when you want
to display positional info to users.
This package is ESM only. In Node.js (version 16+), install with npm:
npm install unist-util-remove-position
In Deno with esm.sh
:
import {removePosition} from 'https://esm.sh/unist-util-remove-position@5'
In browsers with esm.sh
:
<script type="module">
import {removePosition} from 'https://esm.sh/unist-util-remove-position@5?bundle'
</script>
import {fromMarkdown} from 'mdast-util-from-markdown'
import {removePosition} from 'unist-util-remove-position'
const tree = fromMarkdown('Some _emphasis_, **importance**, and `code`.')
removePosition(tree, {force: true})
console.dir(tree, {depth: null})
Yields:
{
type: 'root',
children: [
{
type: 'paragraph',
children: [
{type: 'text', value: 'Some '},
{type: 'emphasis', children: [{type: 'text', value: 'emphasis'}]},
{type: 'text', value: ', '},
{type: 'strong', children: [{type: 'text', value: 'importance'}]},
{type: 'text', value: ', and '},
{type: 'inlineCode', value: 'code'},
{type: 'text', value: '.'}
]
}
]
}
This package exports the identifier removePosition
.
There is no default export.
removePosition(node[, options])
Remove the position
field from a tree.
Nothing (undefined
).
Options
Configuration (TypeScript type).
force
(boolean
, default: false
)
— whether to use delete
to remove position
fields, the default is to
set them to undefined
This package is fully typed with TypeScript.
It exports the additional type Options
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
unist-util-remove-position@^5
, compatible with Node.js 16.
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 remove positions from a tree
The npm package unist-util-remove-position receives a total of 4,108,815 weekly downloads. As such, unist-util-remove-position popularity was classified as popular.
We found that unist-util-remove-position 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
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.