unist-util-position is a crucial utility within the unified (unist) ecosystem, designed to robustly extract positional information from Unist (Universal Syntax Tree) nodes. This includes `start` and `end` points, along with `line`, `column`, and `offset` details. It's particularly valuable when processing trees that might have inconsistent or incomplete positional data due to user modifications or external plugins, acting as a safeguard against malformed data. The current stable version is 5.0.0, which mandates Node.js 16 or newer and operates exclusively as an ES module. New major versions are typically released to align with Node.js EOL policies and introduce significant breaking changes, while minor releases provide features and fixes. Its key differentiator is its focus on providing reliable positional data, returning `undefined` for invalid inputs rather than potentially throwing errors or returning partial, incorrect data, making it safer for robust plugin development compared to directly accessing `node.position` properties.
npm install unist-util-positionVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse Markdown into a unist tree and extract its overall position, start point, and end point using the utility functions, including handling potentially undefined results from v5+.
Upgrade your Node.js environment to version 16 or higher.
Migrate your project to use ES modules (`import` syntax) and ensure your `package.json` includes `"type": "module"` or use `.mjs` file extensions.
Update your code to include nullish checks: `const pos = position(node); if (pos) { /* use pos */ }`.Always use the public API surface for imports (e.g., `import { position } from 'unist-util-position'`) and avoid deep imports.Run `npm install @types/unist@latest` or `yarn upgrade @types/unist` alongside `unist-util-position`.
Change your import statements from `const pkg = require('pkg')` to `import pkg from 'pkg'` or `import { namedExport } from 'pkg'`, and ensure your project/file is configured for ESM.Use proper ES module named imports: `import { position, pointStart, pointEnd } from 'unist-util-position'`.Upgrade your Node.js runtime environment to version 16 or a more recent, actively maintained version.
Add a check for `undefined` before accessing properties, e.g., `const pos = position(node); if (pos) { console.log(pos.start.line); }`.No dependency data recorded yet.