{"library":"mdast-util-definitions","title":"mdast-util-definitions","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mdast-util-definitions"],"cli":null},"imports":["import { definitions } from 'mdast-util-definitions'","import type { GetDefinition } from 'mdast-util-definitions'","/* No default export available */"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import {definitions} from 'mdast-util-definitions'\nimport {fromMarkdown} from 'mdast-util-from-markdown'\n\nconst markdownInput = `\n[example]: https://example.com \"Example\"\n[another]: /path/to/another \"Another Link\"\n\nThis is some text with a reference to [example].\nAnd another one to [another].\n\nA non-existent [foo] reference.\n`\n\nconst tree = fromMarkdown(markdownInput)\n\nconst getDefinition = definitions(tree)\n\nconsole.log('Definition for \"example\":', getDefinition('example'))\n// Expected: {type: 'definition', title: 'Example', url: 'https://example.com', identifier: 'example', label: 'example', ...}\n\nconsole.log('Definition for \"another\":', getDefinition('another'))\n// Expected: {type: 'definition', title: 'Another Link', url: '/path/to/another', identifier: 'another', label: 'another', ...}\n\nconsole.log('Definition for \"foo\":', getDefinition('foo'))\n// Expected: undefined\n\n// To illustrate how one might access all definitions, though 'definitions' returns a getter function\nconst allDefinitions = {}\ntree.children.forEach(node => {\n  if (node.type === 'definition') {\n    allDefinitions[node.identifier] = node\n  }\n})\nconsole.log('All definitions found in tree:', allDefinitions)","lang":"javascript","description":"Demonstrates how to use `mdast-util-definitions` to find definition nodes by identifier in an mdast tree generated from Markdown input.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}