# extract-mdx-metadata

> Extract MDX metadata without using babel or webpack loaders.

Latest version **2.0.0** (published 2021-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install extract-mdx-metadata
pnpm add extract-mdx-metadata
yarn add extract-mdx-metadata
bun add extract-mdx-metadata
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-08-08 |
| First published | 2019-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 6 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Michael Novotny |
| Maintainers | manovotny |
| Keywords | extract, markdown, mdx, mdx-js, meta, metadata |

## Links

- npm: https://www.npmjs.com/package/extract-mdx-metadata
- Repository: https://github.com/manovotny/extract-mdx-metadata
- npm.io page: https://npm.io/package/extract-mdx-metadata

## Dependencies (6)

- [@babel/core](https://npm.io/package/@babel/core.md) 7.15.0
- [@mdx-js/mdx](https://npm.io/package/@mdx-js/mdx.md) 1.6.22
- [@babel/parser](https://npm.io/package/@babel/parser.md) 7.15.0
- [@babel/traverse](https://npm.io/package/@babel/traverse.md) 7.15.0
- [@babel/generator](https://npm.io/package/@babel/generator.md) 7.15.0
- [unist-util-visit](https://npm.io/package/unist-util-visit.md) 2.0.3

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2021-08-08
- 3.0.0-beta.1 (beta) — 2021-09-20
- 1.0.0 — 2019-03-15

## README

# extract-mdx-metadata

> Extract MDX metadata without using babel or webpack loaders.

## Installation

### NPM

```
$ npm i extract-mdx-metadata
```

### Yarn

```
$ yarn add extract-mdx-metadata
```

## Usage

Say we have the following file, `example.mdx`:

```
import something from 'something';

export const meta = {
    prop: 'value',
};

# Title

Content.
```

And our script, `example.js`, looks as follows:

```js
const fs = require('fs');

const extractMdxMeta = require('extract-mdx-metadata');

(async () => {
    const path = 'example/example.mdx';
    const content = fs.readFileSync(path);
    const meta = await extractMdxMeta(content);

    console.log('meta', meta);
})();
```

Now, running `node example` yields:

```
meta {
    prop: 'value'
};
```

You can try this yourself by downloading or cloning the project, installing dependencies, and running `yarn example`.

## API

### `extractMdxMeta(content, [options])`

Parses content and returns the metadata object.

#### options

Type: `Object`

##### `defaultReturnValue`

Type: `*`

Default: `{}` (empty `Object`)

The value returned if the content does not contain any metadata.

## License

MIT © [Michael Novotny](https://manovotny.com)

---
_Source: https://npm.io/package/extract-mdx-metadata · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
