Project: syntax-tree/unist-util-remove-position

Package: unist-util-remove-position@4.0.1

  1. Dependents: 0
  2. unist utility to remove positions from a tree
  1. util 146
  2. utility 142
  3. unist 130
  4. unist-util 25
  5. remove 10
  6. position 9
  7. clean 6
  8. location 4


Build Coverage Downloads Size Sponsors Backers Chat

unist utility to remove positional info from a tree.


What is this?

This is a small utility that helps you remove the position field from nodes in a unist tree.

When should I use this?

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 14.14+ and 16.0+), install with npm:

npm install unist-util-remove-position

In Deno with esm.sh:

import {removePosition} from 'https://esm.sh/unist-util-remove-position@4'

In browsers with esm.sh:

<script type="module">
  import {removePosition} from 'https://esm.sh/unist-util-remove-position@4?bundle'


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})


  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[, force|options])

Remove the position field from a tree.


The given, modified, tree (Node).


Configuration (TypeScript type).



This package is fully typed with TypeScript. It exports the additional type Options.


Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.


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.


MIT © Titus Wormer