Registry / serialization / unist-util-stringify-position

unist-util-stringify-position

JSON →
library4.0.0jsnpmunverified

unist-util-stringify-position is a utility package within the unified (unist) ecosystem designed to consistently serialize positional information from abstract syntax tree (AST) nodes, positions, or points into a human-readable string format. This is particularly useful for generating error messages, warnings, or logging location-specific information in parsers, compilers, and transformers. The current stable version is 4.0.0, which was released recently and is actively maintained by the syntax-tree collective. Its release cadence is tied to breaking changes and necessary updates within the broader unist ecosystem. Key differentiators include its adherence to the unist specification, full TypeScript support, and its focus on standardizing how location data is presented to end-users, ensuring consistency across various unified processors like `remark` or `rehype`.

npm install unist-util-stringify-position
INSTALL
IMPORT
SIG · UNIST-UTIL-STRINGI
U
unist-util-stringify-position
serializationjavascriptv4.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.

stringifyPosition
✓ import { stringifyPosition } from 'unist-util-stringify-position'
✗ const stringifyPosition = require('unist-util-stringify-position')
This package is ESM-only since v3.0.0, and v4.0.0 further enforces this with an `export` map. CommonJS `require` is not supported for direct import.

Demonstrates how to use `stringifyPosition` to convert a point, position range, or a unist node's position into a human-readable string format, returning an empty string for invalid inputs.

import { stringifyPosition } from 'unist-util-stringify-position'; console.log('Point:', stringifyPosition({line: 2, column: 3})); // => '2:3' console.log('Position:', stringifyPosition({start: {line: 2, column: 1}, end: {line: 3, column: 1}})); // => '2:1-3:1' console.log('Node:', stringifyPosition({ type: 'text', value: '!', position: { start: {line: 5, column: 11}, end: {line: 5, column: 12} } })); // => '5:11-5:12' console.log('Invalid input:', stringifyPosition(null)); // => ''
Debug
Known issues
breakingVersion 4.0.0 changes the minimum required Node.js version to 16 or later.
fix
Update your Node.js runtime environment to version 16 or newer to ensure compatibility.
affects: >=4.0.0
breakingThe package switched to ESM-only in v3.0.0 and further adopted `export` maps in v4.0.0, meaning CommonJS `require` statements are no longer supported for importing this package.
fix
Migrate your project to use ES modules (`import`/`export` syntax). If in Node.js, ensure your `package.json` specifies `"type": "module"` or use `.mjs` file extensions. Consult the Node.js documentation on ESM for proper setup.
affects: >=3.0.0
gotchaVersion 4.0.0 includes an update to its `@types/unist` dependency, which might cause type conflicts if your project uses an incompatible older version of `@types/unist`.
fix
Ensure your project's `@types/unist` dependency is also updated to a compatible version (e.g., `^4.0.0` or higher) to align with this package's types.
affects: >=4.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to `require` this ESM-only package in a CommonJS context.
fix
Use `import { stringifyPosition } from 'unist-util-stringify-position'` instead of `require`. Ensure your Node.js project or file is configured for ES modules (e.g., `"type": "module"` in `package.json`).
TypeError: stringifyPosition is not a function
Incorrect CommonJS `require` attempt, often occurring when trying to destructure named exports from an ESM-only package without a default export.
fix
This package exports named exports. If you're in an ESM context, use `import { stringifyPosition } from 'unist-util-stringify-position'`. If you're stuck in CommonJS, consider dynamically `import`ing or transpiling your code.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
unist-util-stringify-position — npm install unist-util-stringify-position · libregistry