{"id":12303,"library":"unist-util-stringify-position","title":"Unist Utility to Stringify Position","description":"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`.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/unist-util-stringify-position","tags":["javascript","unist","unist-util","util","utility","position","location","point","node","typescript"],"install":[{"cmd":"npm install unist-util-stringify-position","lang":"bash","label":"npm"},{"cmd":"yarn add unist-util-stringify-position","lang":"bash","label":"yarn"},{"cmd":"pnpm add unist-util-stringify-position","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const stringifyPosition = require('unist-util-stringify-position')","symbol":"stringifyPosition","correct":"import { stringifyPosition } from 'unist-util-stringify-position'"}],"quickstart":{"code":"import { stringifyPosition } from 'unist-util-stringify-position';\n\nconsole.log('Point:', stringifyPosition({line: 2, column: 3}));\n// => '2:3'\n\nconsole.log('Position:', stringifyPosition({start: {line: 2, column: 1}, end: {line: 3, column: 1}}));\n// => '2:1-3:1'\n\nconsole.log('Node:', stringifyPosition({\n  type: 'text',\n  value: '!',\n  position: {\n    start: {line: 5, column: 11},\n    end: {line: 5, column: 12}\n  }\n}));\n// => '5:11-5:12'\n\nconsole.log('Invalid input:', stringifyPosition(null));\n// => ''","lang":"typescript","description":"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."},"warnings":[{"fix":"Update your Node.js runtime environment to version 16 or newer to ensure compatibility.","message":"Version 4.0.0 changes the minimum required Node.js version to 16 or later.","severity":"breaking","affected_versions":">=4.0.0"},{"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.","message":"The 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.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"Version 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`.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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`).","cause":"Attempting to `require` this ESM-only package in a CommonJS context.","error":"ERR_REQUIRE_ESM"},{"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.","cause":"Incorrect CommonJS `require` attempt, often occurring when trying to destructure named exports from an ESM-only package without a default export.","error":"TypeError: stringifyPosition is not a function"}],"ecosystem":"npm"}