Unist Utility to Remove Position Information

5.0.0 · active · verified Sun Apr 19

unist-util-remove-position is a specialized utility within the unified ecosystem, designed to strip the 'position' field from nodes within a unist Abstract Syntax Tree (AST). This is particularly useful when comparing trees, merging them, or when positional information is no longer relevant, such as after processing or when the AST is being used for structural analysis where source location is a distraction. The package is currently at stable version 5.0.0 and is actively maintained by the unified collective, aligning with their standard release cadence that typically drops support for unmaintained Node.js versions with new major releases. It differentiates itself by offering a focused solution for position removal, contrasting with related utilities that extract or stringify position data.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to parse Markdown into a unist AST using `mdast-util-from-markdown` and then remove all `position` fields from its nodes using `unist-util-remove-position`.

import {fromMarkdown} from 'mdast-util-from-markdown'
import {removePosition} from 'unist-util-remove-position'

// Create a sample Markdown AST with positional information
const markdown = 'Some _emphasis_, **importance**, and `code`.'
const tree = fromMarkdown(markdown)

console.log('Tree with positions:')
console.dir(tree, {depth: null})

// Remove positional information from the tree, forcing deletion of fields
removePosition(tree, {force: true})

console.log('\nTree without positions:')
console.dir(tree, {depth: null})

view raw JSON →