# parser-front-matter

> Front matter parsing middleware based on gray-matter.

Latest version **1.6.4** (published 2017-07-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install parser-front-matter
pnpm add parser-front-matter
yarn add parser-front-matter
bun add parser-front-matter
```

## 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 | 1.6.4 |
| Published | 2017-07-16 |
| First published | 2014-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 7 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Jon Schlinkert |
| Maintainers | doowb, jonschlinkert |
| Keywords | consolidate, data, front, front-matter, gray-matter, matter, meta, metadata, parse, parser, parsers, yaml |

## Links

- npm: https://www.npmjs.com/package/parser-front-matter
- Repository: https://github.com/jonschlinkert/parser-front-matter
- Issues: https://github.com/jonschlinkert/parser-front-matter/issues
- npm.io page: https://npm.io/package/parser-front-matter

## Dependencies (7)

- [isobject](https://npm.io/package/isobject.md) ^3.0.1
- [lazy-cache](https://npm.io/package/lazy-cache.md) ^2.0.2
- [mixin-deep](https://npm.io/package/mixin-deep.md) ^1.2.0
- [gray-matter](https://npm.io/package/gray-matter.md) ^3.0.2
- [extend-shallow](https://npm.io/package/extend-shallow.md) ^2.0.1
- [file-is-binary](https://npm.io/package/file-is-binary.md) ^1.0.0
- [trim-leading-lines](https://npm.io/package/trim-leading-lines.md) ^0.1.1

## 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.6.4 (latest) — 2017-07-16
- 1.6.3 — 2017-05-19
- 1.6.2 — 2016-08-13
- 1.6.1 — 2016-08-13
- 1.6.0 — 2016-08-11
- 1.5.0 — 2016-08-02
- 1.4.2 — 2016-08-02
- 1.4.1 — 2016-07-15
- 1.3.0 — 2015-10-20
- 1.2.5 — 2015-08-03
- 1.2.4 — 2015-08-01
- 1.2.3 — 2015-07-28
- 1.2.2 — 2015-07-28
- 1.2.1 — 2015-04-05
- 1.2.0 — 2015-03-10
- … 11 more at https://npm.io/package/parser-front-matter/versions

## README

# parser-front-matter [![NPM version](https://img.shields.io/npm/v/parser-front-matter.svg?style=flat)](https://www.npmjs.com/package/parser-front-matter) [![NPM monthly downloads](https://img.shields.io/npm/dm/parser-front-matter.svg?style=flat)](https://npmjs.org/package/parser-front-matter) [![NPM total downloads](https://img.shields.io/npm/dt/parser-front-matter.svg?style=flat)](https://npmjs.org/package/parser-front-matter) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/parser-front-matter.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/parser-front-matter)

> Front matter parsing middleware based on gray-matter.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save parser-front-matter
```

This is similar to a consolidate.js engine, but for parsing. Works with [assemble](https://github.com/assemble/assemble), [verb](https://github.com/verbose/verb), [generate](https://github.com/generate/generate), [update](https://github.com/update/update), express.js, parser-cache, or any application with similar conventions.

## Usage

```js
var parser = require('parser-front-matter');
```

## API

### [.parse](index.js#L36)

Parse front matter from the given string or the `contents` in the given `file` and callback `next(err, file)`.

If an object is passed, either `file.contents` or `file.content`
may be used (for gulp and assemble compatibility).

**Params**

* `file` **{String|Object}**: The object or string to parse.
* `options` **{Object|Function}**: or `next` callback function. Options are passed to [gray-matter](https://github.com/jonschlinkert/gray-matter).
* `next` **{Function}**: callback function.

**Example**

```js
// pass a string
parser.parse('---\ntitle: foo\n---\nbar', function (err, file) {
  //=> {content: 'bar', data: {title: 'foo'}}
});

// or an object
var file = {contents: new Buffer('---\ntitle: foo\nbar')};
parser.parse(file, function(err, res) {
  //=> {content: 'bar', data: {title: 'foo'}}
});
```

### [.parseSync](index.js#L72)

Parse front matter from the given string or the `contents` in the given `file`. If an object is passed, either `file.contents` or `file.content` may be used (for gulp and assemble compatibility).

**Params**

* `file` **{String|Object}**: The object or string to parse.
* `options` **{Object}**: passed to [gray-matter](https://github.com/jonschlinkert/gray-matter).

**Example**

```js
// pass a string
var res = parser.parseSync('---\ntitle: foo\n---\nbar');

// or an object
var file = {contents: new Buffer('---\ntitle: foo\nbar')};
var res = parser.parseSync(file);
//=> {content: 'bar', data: {title: 'foo'}}
```

## file object

Returned `file` objects have the following properties (no other properties are modified on the given file):

* `data`: data from parsed front matter
* `content`: the content string, excluding front-matter (assemble compatibility)
* `contents`: the content string as a buffer, excluding front-matter
* `orig`: the original content string with front-matter included

## About

### Related projects

* [gray-matter](https://www.npmjs.com/package/gray-matter): Parse front-matter from a string or file. Fast, reliable and easy to use. Parses YAML… [more](https://github.com/jonschlinkert/gray-matter) | [homepage](https://github.com/jonschlinkert/gray-matter "Parse front-matter from a string or file. Fast, reliable and easy to use. Parses YAML front matter by default, but also has support for YAML, JSON, TOML or Coffee Front-Matter, with options to set custom delimiters. Used by metalsmith, assemble, verb and ")
* [parser-cache](https://www.npmjs.com/package/parser-cache): Cache and load parsers, similiar to consolidate.js engines. | [homepage](https://github.com/jonschlinkert/parser-cache "Cache and load parsers, similiar to consolidate.js engines.")
* [parser-csv](https://www.npmjs.com/package/parser-csv): CSV parser, compatible with [parser-cache](https://github.com/jonschlinkert/parser-cache). | [homepage](https://github.com/jonschlinkert/parser-csv "CSV parser, compatible with [parser-cache].")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Contributors

| **Commits** | **Contributor** | 
| --- | --- |
| 69 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [doowb](https://github.com/doowb) |

### Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)

### License

Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 16, 2017._

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