https://github.com/remcohaszing/recma-export-filepath
A recma plugin to expose the filepath as a named export
https://github.com/remcohaszing/recma-export-filepath
estree mdx recma unified
Last synced: 26 days ago
JSON representation
A recma plugin to expose the filepath as a named export
- Host: GitHub
- URL: https://github.com/remcohaszing/recma-export-filepath
- Owner: remcohaszing
- License: mit
- Created: 2023-10-12T13:02:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-14T07:47:25.000Z (about 1 month ago)
- Last Synced: 2025-04-14T08:42:06.864Z (about 1 month ago)
- Topics: estree, mdx, recma, unified
- Language: JavaScript
- Homepage:
- Size: 470 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# recma-export-filepath
[](https://github.com/remcohaszing/recma-export-filepath/actions/workflows/ci.yaml)
[](https://codecov.io/gh/remcohaszing/recma-export-filepath)
[](https://www.npmjs.com/package/recma-export-filepath)
[](https://www.npmjs.com/package/recma-export-filepath)A recma plugin to expose the filepath as a named export.
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
- [Options](#options)
- [Compatibility](#compatibility)
- [License](#license)## Installation
```sh
npm install recma-export-filepath
```## Usage
This recma plugin exposes the filepath of the current file as a named export.
For example, given a file named `example.mdx` with the following contents:
```mdx
Hello 👋
```The following script:
```js
import { compile } from '@mdx-js/mdx'
import recmaExportFilepath from 'recma-export-filepath'
import { read } from 'to-vfile'const { contents } = await compile(await read('example.mdx'), {
jsx: true,
recmaPlugins: [recmaExportFilepath]
})console.log(contents)
```Roughly yields:
```jsx
export const filepath = 'example.mdx'export default function MDXContent() {
returnHello 👋
}
```## API
The default export is a recma plugin.
### Options
- `absolute` (`boolean`, default: `false`) — If true, use an absolute path. By default a relative
path is used.
- `cwd` (`string`) The current working directory to use when generating a relative file path.
- `name` (`string`, default: `'filepath'`) — The name to export the file path as.In addition it supports `unist-util-mdx-define`
[options](https://github.com/remcohaszing/unist-util-mdx-define#options).## Compatibility
This project is compatible with Node.js 16 or greater.
## License
[MIT](LICENSE.md) © [Remco Haszing](https://github.com/remcohaszing)