# remark-extract-frontmatter

> Stores front matter from markdown in VFiles data property

Latest version **3.2.0** (published 2021-09-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2021-09-30 |
| First published | 2018-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Paul Zimmer |
| Maintainers | mrzmmr |
| Keywords | remark, frontmatter, plugin, yaml, toml, markdown |

## Links

- npm: https://www.npmjs.com/package/remark-extract-frontmatter
- Repository: https://github.com/mrzmmr/remark-extract-frontmatter
- Homepage: https://github.com/mrzmmr/remark-extract-frontmatter#readme
- Issues: https://github.com/mrzmmr/remark-extract-frontmatter/issues
- npm.io page: https://npm.io/package/remark-extract-frontmatter

## 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

- 3.2.0 (latest) — 2021-09-30
- 3.1.0 — 2021-01-11
- 3.0.0 — 2020-10-25
- 2.0.3 — 2020-07-19
- 2.0.2 — 2020-04-03
- 2.0.1 — 2019-12-10
- 2.0.0 — 2018-09-24
- 1.1.1 — 2018-09-12
- 1.1.0 — 2018-09-12
- 1.0.0 — 2018-08-30

## README

# remark-extract-frontmatter

[Remark](http://github.com/syntax-tree/remark) plugin to store front matter from markdown.

[![Travis](https://img.shields.io/travis/mrzmmr/remark-extract-frontmatter.svg)](https://travis-ci.org/mrzmmr/remark-extract-frontmatter)
[![Coverage
Status](https://coveralls.io/repos/github/mrzmmr/remark-extract-frontmatter/badge.svg?branch=master)](https://coveralls.io/github/mrzmmr/remark-extract-frontmatter?branch=master)

## Install

```
npm install --save remark-extract-frontmatter
```

## Usage

If we have some markdown using yaml frontmatter, example.md

```
---
title: Example
list:
  - one
  - 0
  - false
---

# Other markdown
```

and

```js
const extract = require('remark-extract-frontmatter')
const frontmatter = require('remark-frontmatter')
const compiler = require('remark-stringify')
const report = require('vfile-reporter')
const parser = require('remark-parse')
const toVfile = require('to-vfile')
const unified = require('unified')
const yaml = require('yaml').parse

unified()
  .use(parser)
  .use(compiler)
  .use(frontmatter)
  .use(extract, { yaml: yaml })
  .process(toVfile.readSync('./example.md'), function (err, file) {
    console.error(report(err || file))
    console.log(file.toString())
    console.log(file.data)
  })
```

will output

```
./example.md: no issues found
---
title: 'Example'
list:
  - one
  - 0
  - false
---

# Other markdown

{ title: 'Example', list: [ 'one', 0, false ] }
```

### Options

#### Options[parser]

Type: `Function`

Default: `null`

Specify the function (value) to use when parsing a frontmatter type (key). For example for yaml, options could be `{ yaml: require('yaml').parse }`, or for toml `{ toml: require('toml').parse }`. If no parsing function is set then this plugin will do nothing by default.

#### name

Type: `String`

Default: `null`

Specify a key to store frontmatter in for example, `{ name: 'frontmatter' }` will store any parsed frontmatter as `data: { frontmatter: { ... } }`. By default the parsed frontmatter is merged into the data object.

Example:

```js
unified()
  .use(parser)
  .use(compiler)
  .use(frontmatter, [ 'toml' ])
  .use(extract, { name: 'frontmatter', toml: toml.parse })
  .process('+++\ntitle: "Example"\n+++', function (err, file) {
    console.log(file.data)
  })
```

will output

```
{ frontmatter: { title: 'Example' } }
```

#### throws

Type: `Boolean`

Default: `false`

Specify if when an error parsing frontmatter occurs, to fail and throw error using `VFile.fail` or continue and set a warning using `VFile.message`.


#### remove

Type: `Boolean`

Default: `false`

Indicate if we should remove parsed frontmatter from the `VFile`. The default behavior is to leave the parsed content in the `VFile`

### License

MIT &copy; Paul Zimmer

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