{"_id":"unist-util-mdx-define","_rev":"4-c929e4fb6e5e63be640fc65281438db8","name":"unist-util-mdx-define","dist-tags":{"latest":"1.1.2"},"versions":{"1.0.0":{"name":"unist-util-mdx-define","version":"1.0.0","keywords":[],"author":{"name":"Remco Haszing","email":"remcohaszing@gmail.com"},"license":"MIT","_id":"unist-util-mdx-define@1.0.0","maintainers":[{"name":"remcohaszing","email":"remcohaszing@gmail.com"}],"homepage":"https://github.com/remcohaszing/unist-util-mdx-define#readme","bugs":{"url":"https://github.com/remcohaszing/unist-util-mdx-define/issues"},"dist":{"shasum":"04b387bea0aa8d5ea770cfe18188af3a5b6f01da","tarball":"https://registry.npmjs.org/unist-util-mdx-define/-/unist-util-mdx-define-1.0.0.tgz","fileCount":8,"integrity":"sha512-l7Gl3jZ2rLDikLPSpplbCqBIFfjW3+YlgdX08jeWNdfcVZU1ojq+TsdewgVx1fbdAXxgMXeAZeE9Ln1J45EU7g==","signatures":[{"sig":"MEQCIGq0+V2RKnRRHDDmPTu1g18w4x/0bgwpXSDmKSFLGq/JAiAjgoq8VVaQgOPcgF1+K6C5ym2vB07D41udhzKnhDtkiw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":29340},"type":"module","exports":"./dist/unist-util-mdx-define.js","funding":"https://github.com/sponsors/remcohaszing","gitHead":"769dde348919c0e049fb9375abcc7c853d5ef9c6","scripts":{"test":"node --test","prepack":"tsc --build","pretest":"tsc --build"},"_npmUser":{"name":"remcohaszing","email":"remcohaszing@gmail.com"},"repository":{"url":"git+https://github.com/remcohaszing/unist-util-mdx-define.git","type":"git"},"_npmVersion":"10.9.2","description":"A unist utility to define MDX exports.","directories":{},"sideEffects":false,"_nodeVersion":"22.14.0","dependencies":{"c8":"^9.0.0","vfile":"^6.0.0","@types/hast":"^3.0.0","@types/mdast":"^4.0.0","@types/estree":"^1.0.0","estree-walker":"^3.0.0","estree-util-scope":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"acorn":"^8.0.0","eslint":"^8.0.0","astring":"^1.0.0","unified":"^11.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","typescript":"^5.0.0","@mdx-js/mdx":"^3.0.0","vfile-message":"^4.0.0","snapshot-fixtures":"^1.0.0","eslint-plugin-react":"^7.0.0","eslint-plugin-jsx-a11y":"^6.0.0","eslint-config-remcohaszing":"^10.0.0","remark-preset-remcohaszing":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/unist-util-mdx-define_1.0.0_1742671884811_0.06519236808816475","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"unist-util-mdx-define","version":"1.1.0","keywords":[],"author":{"name":"Remco Haszing","email":"remcohaszing@gmail.com"},"license":"MIT","_id":"unist-util-mdx-define@1.1.0","maintainers":[{"name":"remcohaszing","email":"remcohaszing@gmail.com"}],"homepage":"https://github.com/remcohaszing/unist-util-mdx-define#readme","bugs":{"url":"https://github.com/remcohaszing/unist-util-mdx-define/issues"},"dist":{"shasum":"063072f4c449e5f01a6d808682a4d0c9acc941da","tarball":"https://registry.npmjs.org/unist-util-mdx-define/-/unist-util-mdx-define-1.1.0.tgz","fileCount":8,"integrity":"sha512-ddj00mI7YygC0k3wonarnA/qhhYcSAl18oz2IPCLMP2h45gqjDTSIs3nog3NqsRE3eSmcOFkggOS9Hq6wzcG2A==","signatures":[{"sig":"MEUCIQC+0Nao+ccAaOk9NhDPvG5n26ELnwbiF8e643lcnOvYxAIgBk6g04BQnc9W0cu5m/XmmmBgdgXCG4N/t8jIWDf9cac=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/unist-util-mdx-define@1.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":32386},"type":"module","_from":"file:unist-util-mdx-define-1.1.0.tgz","exports":"./dist/unist-util-mdx-define.js","funding":"https://github.com/sponsors/remcohaszing","scripts":{"test":"node --test","prepack":"tsc --build","pretest":"tsc --build"},"_npmUser":{"name":"remcohaszing","email":"remcohaszing@gmail.com"},"_resolved":"/home/runner/work/unist-util-mdx-define/unist-util-mdx-define/unist-util-mdx-define-1.1.0.tgz","_integrity":"sha512-ddj00mI7YygC0k3wonarnA/qhhYcSAl18oz2IPCLMP2h45gqjDTSIs3nog3NqsRE3eSmcOFkggOS9Hq6wzcG2A==","repository":{"url":"git+https://github.com/remcohaszing/unist-util-mdx-define.git","type":"git"},"_npmVersion":"10.9.2","description":"A unist utility to define MDX exports.","directories":{},"sideEffects":false,"_nodeVersion":"22.14.0","dependencies":{"c8":"^9.0.0","vfile":"^6.0.0","@types/hast":"^3.0.0","@types/mdast":"^4.0.0","@types/estree":"^1.0.0","estree-walker":"^3.0.0","estree-util-scope":"^1.0.0","estree-util-is-identifier-name":"^3.0.0"},"_hasShrinkwrap":false,"devDependencies":{"acorn":"^8.0.0","eslint":"^8.0.0","astring":"^1.0.0","unified":"^11.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","typescript":"^5.0.0","@mdx-js/mdx":"^3.0.0","vfile-message":"^4.0.0","snapshot-fixtures":"^1.0.0","eslint-plugin-react":"^7.0.0","eslint-plugin-jsx-a11y":"^6.0.0","eslint-config-remcohaszing":"^10.0.0","remark-preset-remcohaszing":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/unist-util-mdx-define_1.1.0_1742674827925_0.17442006712572788","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"unist-util-mdx-define","version":"1.1.1","keywords":[],"author":{"name":"Remco Haszing","email":"remcohaszing@gmail.com"},"license":"MIT","_id":"unist-util-mdx-define@1.1.1","maintainers":[{"name":"remcohaszing","email":"remcohaszing@gmail.com"}],"homepage":"https://github.com/remcohaszing/unist-util-mdx-define#readme","bugs":{"url":"https://github.com/remcohaszing/unist-util-mdx-define/issues"},"dist":{"shasum":"ce7012ea08be3ad18402ef7225f4ff892ec83918","tarball":"https://registry.npmjs.org/unist-util-mdx-define/-/unist-util-mdx-define-1.1.1.tgz","fileCount":8,"integrity":"sha512-wW3Uq+92zHTCoJRVWBWr4KHMpkOIHMVZ5kyU/HVV4l1UMl6j2Vs6P+uj8tFMUk9QoA3wR/7wOVD23Cx77dXXoA==","signatures":[{"sig":"MEUCIQDtT6mw9eZ5GOu/pkl2NwM5/YJ7z4CFbd5h1APopQHT1gIgNZtNKiyo+5Vs87ApqwY8l7AUd4jRNmlNyCxron1zyVc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/unist-util-mdx-define@1.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":32386},"type":"module","_from":"file:unist-util-mdx-define-1.1.1.tgz","exports":"./dist/unist-util-mdx-define.js","funding":"https://github.com/sponsors/remcohaszing","scripts":{"test":"node --test","prepack":"tsc --build","pretest":"tsc --build"},"_npmUser":{"name":"remcohaszing","email":"remcohaszing@gmail.com"},"_resolved":"/home/runner/work/unist-util-mdx-define/unist-util-mdx-define/unist-util-mdx-define-1.1.1.tgz","_integrity":"sha512-wW3Uq+92zHTCoJRVWBWr4KHMpkOIHMVZ5kyU/HVV4l1UMl6j2Vs6P+uj8tFMUk9QoA3wR/7wOVD23Cx77dXXoA==","repository":{"url":"git+https://github.com/remcohaszing/unist-util-mdx-define.git","type":"git"},"_npmVersion":"10.9.2","description":"A unist utility to define MDX exports.","directories":{},"sideEffects":false,"_nodeVersion":"22.14.0","dependencies":{"vfile":"^6.0.0","@types/hast":"^3.0.0","@types/mdast":"^4.0.0","@types/estree":"^1.0.0","estree-walker":"^3.0.0","estree-util-scope":"^1.0.0","estree-util-is-identifier-name":"^3.0.0"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^9.0.0","acorn":"^8.0.0","eslint":"^8.0.0","astring":"^1.0.0","unified":"^11.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","typescript":"^5.0.0","@mdx-js/mdx":"^3.0.0","vfile-message":"^4.0.0","snapshot-fixtures":"^1.0.0","eslint-plugin-react":"^7.0.0","eslint-plugin-jsx-a11y":"^6.0.0","eslint-config-remcohaszing":"^10.0.0","remark-preset-remcohaszing":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/unist-util-mdx-define_1.1.1_1742677809755_0.40534202773982475","host":"s3://npm-registry-packages-npm-production"}},"1.1.2":{"name":"unist-util-mdx-define","version":"1.1.2","description":"A unist utility to define MDX exports.","keywords":[],"homepage":"https://github.com/remcohaszing/unist-util-mdx-define#readme","bugs":{"url":"https://github.com/remcohaszing/unist-util-mdx-define/issues"},"repository":{"type":"git","url":"git+https://github.com/remcohaszing/unist-util-mdx-define.git"},"funding":"https://github.com/sponsors/remcohaszing","license":"MIT","author":{"name":"Remco Haszing","email":"remcohaszing@gmail.com"},"sideEffects":false,"type":"module","exports":"./dist/unist-util-mdx-define.js","scripts":{"prepack":"tsc --build","pretest":"tsc --build","test":"node --test"},"dependencies":{"@types/estree":"^1.0.0","@types/hast":"^3.0.0","@types/mdast":"^4.0.0","estree-util-is-identifier-name":"^3.0.0","estree-util-scope":"^1.0.0","estree-walker":"^3.0.0","vfile":"^6.0.0"},"devDependencies":{"@mdx-js/mdx":"^3.0.0","acorn":"^8.0.0","astring":"^1.0.0","c8":"^9.0.0","eslint":"^8.0.0","eslint-config-remcohaszing":"^10.0.0","eslint-plugin-jsx-a11y":"^6.0.0","eslint-plugin-react":"^7.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","remark-preset-remcohaszing":"^3.0.0","snapshot-fixtures":"^1.0.0","typescript":"^5.0.0","unified":"^11.0.0","vfile-message":"^4.0.0"},"_id":"unist-util-mdx-define@1.1.2","_integrity":"sha512-9ncH7i7TN5Xn7/tzX5bE3rXgz1X/u877gYVAUB3mLeTKYJmQHmqKTDBi6BTGXV7AeolBCI9ErcVsOt2qryoD0g==","_resolved":"/home/runner/work/unist-util-mdx-define/unist-util-mdx-define/unist-util-mdx-define-1.1.2.tgz","_from":"file:unist-util-mdx-define-1.1.2.tgz","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-9ncH7i7TN5Xn7/tzX5bE3rXgz1X/u877gYVAUB3mLeTKYJmQHmqKTDBi6BTGXV7AeolBCI9ErcVsOt2qryoD0g==","shasum":"f25c46242ee5d1785ec5d2cd9cc4950cae72a05c","tarball":"https://registry.npmjs.org/unist-util-mdx-define/-/unist-util-mdx-define-1.1.2.tgz","fileCount":8,"unpackedSize":32117,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/unist-util-mdx-define@1.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCFkNB+ruMidcrvluCovGA5aPw/uYjDi5/p0a0v7mZTCQIhAKx9M5zeiCf1pU/dbRyCwy4vtSACYN+07vEDzQyGqF2B"}]},"_npmUser":{"name":"remcohaszing","email":"remcohaszing@gmail.com"},"directories":{},"maintainers":[{"name":"remcohaszing","email":"remcohaszing@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/unist-util-mdx-define_1.1.2_1743258653564_0.7897380201645088"},"_hasShrinkwrap":false}},"time":{"created":"2025-03-22T19:31:24.701Z","modified":"2025-03-29T14:30:54.179Z","1.0.0":"2025-03-22T19:31:25.005Z","1.1.0":"2025-03-22T20:20:28.094Z","1.1.1":"2025-03-22T21:10:09.933Z","1.1.2":"2025-03-29T14:30:53.772Z"},"bugs":{"url":"https://github.com/remcohaszing/unist-util-mdx-define/issues"},"author":{"name":"Remco Haszing","email":"remcohaszing@gmail.com"},"license":"MIT","homepage":"https://github.com/remcohaszing/unist-util-mdx-define#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/remcohaszing/unist-util-mdx-define.git"},"description":"A unist utility to define MDX exports.","maintainers":[{"name":"remcohaszing","email":"remcohaszing@gmail.com"}],"readme":"# unist-util-mdx-define\n\n[![github actions](https://github.com/remcohaszing/unist-util-mdx-define/actions/workflows/ci.yaml/badge.svg)](https://github.com/remcohaszing/unist-util-mdx-define/actions/workflows/ci.yaml)\n[![codecov](https://codecov.io/gh/remcohaszing/unist-util-mdx-define/branch/main/graph/badge.svg)](https://codecov.io/gh/remcohaszing/unist-util-mdx-define)\n[![npm version](https://img.shields.io/npm/v/unist-util-mdx-define)](https://www.npmjs.com/package/unist-util-mdx-define)\n[![npm downloads](https://img.shields.io/npm/dm/unist-util-mdx-define)](https://www.npmjs.com/package/unist-util-mdx-define)\n\nA [unist](https://github.com/syntax-tree/unist) utility to define [MDX](https://mdxjs.com) exports.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n  - [`define`](#define)\n- [Compatibility](#compatibility)\n- [Related projects](#related-projects)\n- [License](#license)\n\n## Introduction\n\nThis package provides a utility to define exports in an [MDX](https://mdxjs.com) AST, so you don’t\nhave to worry about the details. It supports [mdast](https://github.com/syntax-tree/mdast)\n([remark](https://github.com/remarkjs)), [hast](https://github.com/syntax-tree/hast)\n([rehype](https://github.com/rehypejs)), and [estree](https://github.com/estree/estree) /\n[esast](https://github.com/syntax-tree/esast) ([recma](https://github.com/mdx-js/recma)). This\npackage supports various options to export the variables you define and to handle name conflicts.\n\n## Installation\n\n```sh\nnpm install unist-util-mdx-define\n```\n\n## Usage\n\nTypically this is used with an MDX plugin.\n\n```ts\nimport { compile } from '@mdx-js/mdx'\nimport type * as estree from 'estree'\nimport type * as hast from 'hast'\nimport type * as mdast from 'mdast'\nimport { type Plugin } from 'unified'\nimport { define } from 'unist-util-mdx-define'\n\nconst yourRemarkMdxPlugin: Plugin<[], mdast.Root> = () => (ast, file) => {\n  define(ast, file, { remarkVariable: { type: 'Literal', value: 'Hello remark plugin!' } })\n}\n\nconst yourRehypeMdxPlugin: Plugin<[], hast.Root> = () => (ast, file) => {\n  define(ast, file, { rehypeVariable: { type: 'Literal', value: 'Hello rehype plugin!' } })\n}\n\nconst yourRecmaMdxPlugin: Plugin<[], estree.Program> = () => (ast, file) => {\n  define(ast, file, { recmaVariable: { type: 'Literal', value: 'Hello recma plugin!' } })\n}\n\nconst { value } = await compile('{remarkVariable} {rehypeVariable} {recmaVariable}', {\n  remarkPlugins: [yourRemarkMdxPlugin],\n  rehypePlugins: [yourRehypeMdxPlugin],\n  recmaPlugins: [yourRecmaMdxPlugin]\n})\n\nconsole.log(value)\n```\n\nMDX remark, rehype, and recma plugins are similar, but not the same. The type of plugin you should\ncreate depends on your goal.\n\nIf your goal is to handle something specific to the markdown content, you should write a remark\nplugin. A practical example is\n[`remark-mdx-frontmatter`](https://github.com/remcohaszing/remark-mdx-frontmatter). This plugin\nhandles frontmatter data, which no longer exists after the mdast is compiled to hast.\n\nIf your goal is to transform or access content, you typically want a rehype plugin. A good example\nis [`rehype-mdx-title`](https://github.com/remcohaszing/rehype-mdx-title), which accesses the title\nof the document.\n\nFor most other purposes, use a recma plugin. For example,\n[`recma-export-filepath`](https://github.com/remcohaszing/recma-export-filepath) exposes file\ninformation. This doesn’t need access to the content.\n\n`unist-util-mdx-define` can define variables in any of these AST types. For mdast and hast, it\nprepends the variable declarations to the root. This way they’ll end up at the start of the module,\nand their value can be used by **user defined** expressions. This does mean the **generated**\nexpressions are not able to use other variables. For ESTree, `unist-util-mdx-define` attempts to do\nthe same.\n\n## API\n\n### `define`\n\nDefine variables in an MDX related AST.\n\n#### Parameters\n\n- `ast` ([mdast.Root](https://github.com/syntax-tree/mdast#root) |\n  [hast.Root](https://github.com/syntax-tree/hast#root) |\n  [estree.Program](https://github.com/estree/estree)) — The AST in which to define an export.\n- `file` ([VFile](https://github.com/vfile/vfile)) — The file to emit warnings to.\n- `variables` (`Record<string, estree.Expression>`) — A mapping of variables to define. They keys\n  are the names. The values are the ESTree expression to represent them.\n- `options` ([Options](#options)) — Additional options to configure behaviour.\n\n#### Options\n\n- `export` — If and how to export the variable. (Default: `'module'`)\n  - `'module'`: Export the value using an ESM const export declaration.\n  - `'namespace'`: Attach the value as a property on `MDXContent`.\n  - `false`: Define the variable locally, but don’t export it.\n- `conflict` — What to do if there’s a name conflict. (Default: `'throw'`)\n  - `'skip'`: Don’t insert the variable if there’s a name conflict.\n  - `'throw'`: Throw if there’s a name conflict.\n  - `'warn'`: Emit a vfile warning, but don’t throw.\n\n## Compatibility\n\nThis project is compatible with Node.js 16 or greater.\n\n## Related projects\n\n- [`estree-util-value-to-estree`](https://github.com/remcohaszing/estree-util-value-to-estree) —\n  Convert a JavaScript value to an estree expression\n\n## License\n\n[MIT](LICENSE.md) © [Remco Haszing](https://github.com/remcohaszing)\n","readmeFilename":"README.md"}