Registry / serialization / unist-util-remove-position

unist-util-remove-position

JSON →
library5.0.0jsnpmunverified

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.

npm install unist-util-remove-position
INSTALL
IMPORT
SIG · UNIST-UTIL-REMOVE-
U
unist-util-remove-position
serializationjavascriptv5.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

removePosition
✓ import { removePosition } from 'unist-util-remove-position'
✗ const removePosition = require('unist-util-remove-position')
This package is ESM-only since v4.0.0. CommonJS `require()` is not supported.
Options
✓ import type { Options } from 'unist-util-remove-position'
This is a TypeScript type import for configuring the `removePosition` function. It's not a runtime value.

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})
Debug
Known issues
breakingVersion 5.0.0 changes to require Node.js 16 or higher. Older Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 16 or newer, or stick to `unist-util-remove-position@^4` for older Node.js versions.
affects: >=5.0.0
breakingVersion 5.0.0 removed the `force` shortcut. Previously, `removePosition(tree, true)` would work. Now, the `force` option must be passed as an object: `{ force: true }`.
fix
Change calls from `removePosition(node, true)` to `removePosition(node, { force: true })`.
affects: >=5.0.0
breakingVersion 5.0.0 changed the return value of `removePosition` to `undefined`. Previously, it might have returned the `node` itself.
fix
Adjust any code that expects a return value from `removePosition`. The function now mutates the tree in-place and explicitly yields `undefined`.
affects: >=5.0.0
breakingVersion 4.0.0 switched to being an ESM-only package. It no longer supports CommonJS `require()` syntax.
fix
Migrate your project to use ES modules (`import`/`export`) or use a tool like Rollup/Webpack to bundle for CJS environments. For Node.js, ensure your `package.json` specifies `"type": "module"` or use `.mjs` files.
affects: >=4.0.0
breakingVersion 3.0.0 introduced TypeScript types. While generally beneficial, it could cause compilation errors if your TypeScript configuration or dependent types are incompatible.
fix
Ensure `@types/unist` is updated to a compatible version and check your `tsconfig.json` for strictness settings that might expose new type issues.
affects: >=3.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/unist-util-remove-position/index.js not supported.
Attempting to import an ESM-only package using CommonJS `require()` in a non-ESM context.
fix
Update your import statement to `import { removePosition } from 'unist-util-remove-position'` and ensure your Node.js project or file is configured for ES Modules (e.g., `"type": "module"` in `package.json`).
TypeError: removePosition is not a function
Incorrect import syntax for an ESM module, or attempting to access a named export as a default export, or a CommonJS `require()` failure.
fix
Use `import { removePosition } from 'unist-util-remove-position'` for ESM. Double-check your environment is correctly configured for ESM if you're getting `ERR_REQUIRE_ESM`.
TypeError: Argument of type 'boolean' is not assignable to parameter of type 'Options | undefined'.
Using the old `force: true` shortcut with `removePosition(node, true)` after upgrading to v5.0.0.
fix
Update the call to `removePosition(node, { force: true })` to use the new options object syntax.
Node.js version X is not supported by 'unist-util-remove-position@5.0.0'.
Running the package with an unsupported Node.js version (specifically, older than 16.0).
fix
Upgrade your Node.js environment to version 16 or newer. Alternatively, if forced to use an older Node.js, downgrade to `unist-util-remove-position@^4`.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
unist-util-remove-position — npm install unist-util-remove-position · libregistry