# remark-parse-frontmatter

> 🎓 Parses and validates Markdown frontmatter (YAML) to data object.

Latest version **1.0.3** (published 2021-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install remark-parse-frontmatter
pnpm add remark-parse-frontmatter
yarn add remark-parse-frontmatter
bun add remark-parse-frontmatter
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-04-02 |
| First published | 2020-12-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 3 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Minh-Phuc Tran |
| Maintainers | phuctm97 |
| Keywords | markdown, frontmatter, yaml, remark, commonmark, unified, remark-plugin, unified-plugin, plugin, extension |

## Links

- npm: https://www.npmjs.com/package/remark-parse-frontmatter
- Repository: https://github.com/phuctm97/remark-parse-frontmatter
- npm.io page: https://npm.io/package/remark-parse-frontmatter

## Dependencies (3)

- [yaml](https://npm.io/package/yaml.md) ^1.10.0
- [revalidator](https://npm.io/package/revalidator.md) ^0.3.1
- [unist-util-find](https://npm.io/package/unist-util-find.md) ^1.0.2

## Alternatives

- [monaco-yaml](https://npm.io/package/monaco-yaml.md) — 420.1K weekly downloads
- [@crewx/workflow](https://npm.io/package/@crewx/workflow.md) — 3.1K weekly downloads
- [yaml-cat](https://npm.io/package/yaml-cat.md) — 38 weekly downloads
- [nunjucks-in-yaml](https://npm.io/package/nunjucks-in-yaml.md) — 9 weekly downloads
- [shopify-symlinks](https://npm.io/package/shopify-symlinks.md) — 3 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2021-04-02
- 1.0.2 — 2021-01-02
- 1.0.1 — 2020-12-26
- 1.0.0 — 2020-12-25
- 0.0.2 — 2020-12-25
- 0.0.1 — 2020-12-25

## README

# 🎓 remark-parse-frontmatter

[![Github checks][checks badge]][checks url]
[![npm version][npm badge]][npm url]
[![Code style][code style badge]][code style url]
[![GitHub license][license badge]][license url]

Parses and validates Markdown frontmatter (YAML) to `file.data.frontmatter`.

Validation is done by [revalidator].

Built for Remark 12, won't work with Remark 13. Requires [remark-frontmatter].

## Example

`example.js`:

```js
const processor = remark()
  .use(require("remark-frontmatter"))
  .use(require("remark-parse-frontmatter"))
  .freeze();

const file = processor.processSync(`
---
title: Hello, World!
---
`);

console.log(file.data.frontmatter);
```

Output:

```
{
  title: "Hello, World!"
}
```

## Usage

### Install

```bash
yarn add remark-parse-frontmatter
```

### Configure

Unified / Remark:

```js
// Without validation
unified()
  .use(require("remark-parse"))
  .use(require("remark-frontmatter"))
  .use(require("remark-parse-frontmatter"))
  .use(require("remark-stringify"));

// With validation
unified()
  .use(require("remark-parse"))
  .use(require("remark-frontmatter"))
  .use(require("remark-parse-frontmatter"), {
    properties: {
      title: { type: "string", required: true },
      tags: { type: "array", maxItems: 4 },
    },
  })
  .use(require("remark-stringify"));
```

```js
// Without validation.
remark()
  .use(require("remark-frontmatter"))
  .use(require("remark-parse-frontmatter"));

// With validation.
remark()
  .use(require("remark-frontmatter"))
  .use(require("remark-parse-frontmatter"), {
    properties: {
      title: { type: "string", required: true },
      tags: { type: "array", maxItems: 4 },
    },
  });
```

MDX:

```js
// Without validation.
mdx(mdxText, {
  remarkPlugins: [
    require("remark-unwrap-texts"),
    require("remark-parse-frontmatter"),
  ],
});

// With validation.
mdx(mdxText, {
  remarkPlugins: [
    require("remark-unwrap-texts"),
    [
      require("remark-parse-frontmatter"),
      {
        properties: {
          title: { type: "string", required: true },
          tags: { type: "array", maxItems: 4 },
        },
      },
    ],
  ],
});
```

---

Made by [@phuctm97].

<!-- Badges -->

[checks badge]:
  https://img.shields.io/github/checks-status/phuctm97/remark-parse-frontmatter/master?logo=Github
[npm badge]: https://img.shields.io/npm/v/remark-parse-frontmatter?logo=npm
[code style badge]:
  https://img.shields.io/badge/code%20style-prettier-F7B93E?logo=Prettier
[license badge]:
  https://img.shields.io/github/license/phuctm97/remark-parse-frontmatter
[checks url]:
  https://github.com/phuctm97/remark-parse-frontmatter/actions?query=workflow%3APR+branch%3Amaster
[npm url]: https://www.npmjs.com/package/remark-parse-frontmatter
[code style url]: /.prettierrc.json
[license url]: /LICENSE

<!-- Links -->

[@phuctm97]: https://twitter.com/phuctm97
[remark-frontmatter]: https://github.com/remarkjs/remark-frontmatter
[revalidator]: https://github.com/flatiron/revalidator

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