recma-export-filepath
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

recma-export-filepath

github actions codecov npm version npm downloads

A recma plugin to expose the filepath as a named export.

Table of Contents

Installation

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:

Hello 👋

The following script:

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:

export const filepath = 'example.mdx'

export default function MDXContent() {
  return <p>Hello 👋</p>
}

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.

Compatibility

This project is compatible with Node.js 16 or greater.

License

MIT © Remco Haszing

Readme

Keywords

Package Sidebar

Install

npm i recma-export-filepath

Weekly Downloads

8,603

Version

1.1.0

License

MIT

Unpacked Size

7.06 kB

Total Files

6

Last publish

Collaborators

  • remcohaszing