Registry / data / mdast-util-definitions

mdast-util-definitions

JSON →
library6.0.0jsnpmunverified

mdast-util-definitions is a small, focused utility within the unified ecosystem designed to efficiently locate definition nodes within an mdast (Markdown Abstract Syntax Tree) based on their `identifier`. Currently at stable version 6.0.0, the package primarily sees updates related to Node.js version compatibility, ESM adoption, and type improvements, consistent with the unified collective's release cadence. A key differentiator is its ability to find definitions regardless of their position in the tree (even after references), its robustness against prototype pollution, and its adherence to CommonMark precedence rules (favoring earlier definitions in case of duplicates). Since version 5.0.0, it is an ESM-only package, requiring Node.js 16+ from version 6.0.0. It provides TypeScript types for enhanced developer experience.

npm install mdast-util-definitions
INSTALL
IMPORT
SIG · MDAST-UTIL-DEFINIT
M
mdast-util-definitions
datajavascriptv6.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

definitions
import { definitions } from 'mdast-util-definitions'
const definitions = require('mdast-util-definitions')
This package is ESM-only since v5.0.0. CommonJS `require` will result in an `ERR_REQUIRE_ESM` error. There is no default export.
GetDefinition
import type { GetDefinition } from 'mdast-util-definitions'
This is a TypeScript type for the function returned by `definitions(tree)`.
Default export
/* No default export available */
import definitions from 'mdast-util-definitions'
The package explicitly states there is no default export. Use named imports only.

Demonstrates how to use `mdast-util-definitions` to find definition nodes by identifier in an mdast tree generated from Markdown input.

import {definitions} from 'mdast-util-definitions' import {fromMarkdown} from 'mdast-util-from-markdown' const markdownInput = ` [example]: https://example.com "Example" [another]: /path/to/another "Another Link" This is some text with a reference to [example]. And another one to [another]. A non-existent [foo] reference. ` const tree = fromMarkdown(markdownInput) const getDefinition = definitions(tree) console.log('Definition for "example":', getDefinition('example')) // Expected: {type: 'definition', title: 'Example', url: 'https://example.com', identifier: 'example', label: 'example', ...} console.log('Definition for "another":', getDefinition('another')) // Expected: {type: 'definition', title: 'Another Link', url: '/path/to/another', identifier: 'another', label: 'another', ...} console.log('Definition for "foo":', getDefinition('foo')) // Expected: undefined // To illustrate how one might access all definitions, though 'definitions' returns a getter function const allDefinitions = {} tree.children.forEach(node => { if (node.type === 'definition') { allDefinitions[node.identifier] = node } }) console.log('All definitions found in tree:', allDefinitions)
Debug
Known issues
breakingVersion 6.0.0 changed to require Node.js 16 or newer. Older Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 16 or later.
affects: >=6.0.0
breakingSince version 5.0.0, this package is ESM-only. CommonJS `require()` statements are no longer supported and will result in an `ERR_REQUIRE_ESM` error.
fix
Migrate your codebase to use ES Modules (ESM) with `import` statements. Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
affects: >=5.0.0
breakingAs of v6.0.0, `definitions(tree)('identifier')` now returns `undefined` when a definition is not found, instead of `null`.
fix
Update your code to check for `undefined` instead of `null` when expecting a potentially missing definition.
affects: >=6.0.0
breakingVersion 6.0.0 changed to use `export` map, preventing direct imports of private APIs (e.g., `mdast-util-definitions/index.js`).
fix
Always use the public API through `import { definitions } from 'mdast-util-definitions'` and avoid internal paths.
affects: >=6.0.0
breakingType definitions were added in v3.0.0, and updated in v5.1.0 to use `mdast` types, then again in v6.0.0 with `@types/mdast`. This might cause type conflicts if your project uses older or incompatible `@types/mdast` versions.
fix
Ensure your project's `@types/mdast` dependency is up-to-date and compatible with `mdast-util-definitions@6`.
affects: >=3.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to `require()` this package in a CommonJS environment, but it is ESM-only since v5.0.0.
fix
Convert your project or specific file to ESM and use `import { definitions } from 'mdast-util-definitions'`.
TypeError: Cannot read properties of null (reading '...')
Your code is expecting `definitions(tree)('identifier')` to return `null` when a definition is not found, but it now returns `undefined` since v6.0.0.
fix
Update your code to check for `undefined` instead of `null`.
SyntaxError: The requested module 'mdast-util-definitions' does not provide an export named 'default'
Attempting to use a default import, e.g., `import definitions from 'mdast-util-definitions'`, when there is no default export.
fix
Use a named import: `import { definitions } from 'mdast-util-definitions'`.
TypeError: definitions is not a function
This error can occur if you're trying to call `definitions()` directly without first passing the `tree` to it, or if there was a problem with the import.
fix
Remember to call `definitions(tree)` first, which returns another function (a getter). Then call the returned getter with your identifier: `const getDefinition = definitions(tree); getDefinition('my-id');`
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
mdast-util-definitions — npm install mdast-util-definitions · libregistry