unist utility to remove positions from a tree
npm install unist-util-remove-position[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[unist][] utility to remove positional info from a tree.
* What is this?
* When should I use this?
* Install
* Use
* API
* [removePosition(node[, options])](#removepositionnode-options)
* Options
* Types
* Compatibility
* Contribute
* License
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][unist-util-position]
useful to instead get clean position info from a tree, or
[unist-util-generated][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][unist-util-stringify-position] when you want
to display positional info to users.
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
``sh`
npm install unist-util-remove-position
In Deno with [esm.sh][esmsh]:
`js`
import {removePosition} from 'https://esm.sh/unist-util-remove-position@5'
In browsers with [esm.sh][esmsh]:
`html`
`js
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:
`js`
{
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][removeposition].
There is no default export.
Remove the position field from a tree.
###### Parameters
* node ([Node][node])options
— tree to clean
* ([Options][options], optional)
— configuration
###### Returns
Nothing (undefined).
Configuration (TypeScript type).
###### Fields
* force (boolean, default: false)delete
— whether to use to remove position fields, the default is toundefined
set them to
This package is fully typed with [TypeScript][].
It exports the additional type [Options][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][contributing] in [syntax-tree/.github][health] forsupport.md`][support] for ways to get help.
ways to get started.
See [
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/syntax-tree/unist-util-remove-position/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/unist-util-remove-position/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-remove-position.svg
[coverage]: https://codecov.io/github/syntax-tree/unist-util-remove-position
[downloads-badge]: https://img.shields.io/npm/dm/unist-util-remove-position.svg
[downloads]: https://www.npmjs.com/package/unist-util-remove-position
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=unist-util-remove-position
[size]: https://bundlejs.com/?q=unist-util-remove-position
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[license]: license
[author]: https://wooorm.com
[health]: https://github.com/syntax-tree/.github
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[unist]: https://github.com/syntax-tree/unist
[node]: https://github.com/syntax-tree/unist#node
[unist-util-position]: https://github.com/syntax-tree/unist-util-position
[unist-util-generated]: https://github.com/syntax-tree/unist-util-generated
[unist-util-stringify-position]: https://github.com/syntax-tree/unist-util-stringify-position
[removeposition]: #removepositionnode-options
[options]: #options