<commit_before># Fastmatter [![npm Version](http://img.shields.io/npm/v/fastmatter.svg?style=flat)](https://www.npmjs.org/package/fastmatter) [![Build Status](https://img.shields.io/travis/yuanqing/fastmatter.svg?branch=master&style=flat)](https://travis-ci.org/yuanqing/fastmatter) [![Coverage Status](https://img.shields.io/coveralls/yuanqing/fastmatter.svg?style=flat)](https://coveralls.io/r/yuanqing/fastmatter)

> A faster frontmatter parser. Supports both string and stream inputs.

Fastmatter is faster than the [front-matter](https://github.com/jxson/front-matter) module because fastmatter [does not use regular expressions](index.js).

## Usage

Given a document `foo.md` containing YAML frontmatter and content:

```
---
title: Hello, World!
tags: [ foo, bar, baz ]
---
Lorem ipsum dolor sit amet consectetur adipisicing elit.
```

&hellip;we can parse this document as a string, via [`fastmatter(string)`](#fastmatterstring):

```js
const fastmatter = require('..')
const fs = require('fs')
const concat = require('concat-stream')

fs.createReadStream('foo.md').pipe(
  fastmatter.stream(function (attributes) {
    console.log(attributes)
    /* =>
     * {
     *   title: 'Hello, World!',
     *   tags: [ 'foo', 'bar', 'baz' ]
     * }
     */
    this.pipe(
      concat(function (body) {
        console.log(body.toString())
        //=> Lorem ipsum dolor sit amet consectetur adipisicing elit.
      })
    )
  })
)
```

&hellip;or as a stream, via [`fastmatter.stream([callback])`](#fastmatterstreamcallback):

```js
const fastmatter = require('..')
const fs = require('fs')
const concat = require('concat-stream')

fs.createReadStream('foo.md').pipe(
  fastmatter.stream(function (attributes) {
    console.log(attributes)
    /* =>
     * {
     *   title: 'Hello, World!',
     *   tags: [ 'foo', 'bar', 'baz' ]
     * }
     */
    this.pipe(
      concat(function (body) {
        console.log(body.toString())
        //=> Lorem ipsum dolor sit amet consectetur adipisicing elit.
      })
    )
  })
)
```

`callback` is called with the frontmatter `attributes`, while the document `body` is simply passed through the stream. Also note that the `this` context of `callback` is the stream itself; this is useful if we want to change the flow of the stream depending on the parsed `attributes`.

## API

```js
var fastmatter = require('fastmatter');
```

### fastmatter(string)

Parses the `string` and returns the parsed frontmatter `attributes` and document `body`.

### fastmatter.stream([callback])

Calls `callback` with the parsed frontmatter `attributes`. The `this` context of `callback` is the stream itself. The document `body` is passed through the stream.

## Installation

Install via [yarn](https://yarnpkg.com):

```bash<commit_msg>Edit README.md<commit_after># Fastmatter [![npm Version](http://img.shields.io/npm/v/fastmatter.svg?style=flat)](https://www.npmjs.org/package/fastmatter) [![Build Status](https://img.shields.io/travis/yuanqing/fastmatter.svg?branch=master&style=flat)](https://travis-ci.org/yuanqing/fastmatter) [![Coverage Status](https://img.shields.io/coveralls/yuanqing/fastmatter.svg?style=flat)](https://coveralls.io/r/yuanqing/fastmatter)

> A faster frontmatter parser. Supports both string and stream inputs.

Fastmatter is faster than the [front-matter](https://github.com/jxson/front-matter) module because fastmatter [does not use regular expressions](index.js).

## Usage

Given a document `foo.md` containing YAML frontmatter and content:

```
---
title: Hello, World!
tags: [ foo, bar, baz ]
---
Lorem ipsum dolor sit amet consectetur adipisicing elit.
```

&hellip;we can parse this document as a string, via [`fastmatter(string)`](#fastmatterstring):

```js
const fastmatter = require('fastmatter')
const fs = require('fs')
const concat = require('concat-stream')

fs.createReadStream('foo.md').pipe(
  fastmatter.stream(function (attributes) {
    console.log(attributes)
    /* =>
     * {
     *   title: 'Hello, World!',
     *   tags: [ 'foo', 'bar', 'baz' ]
     * }
     */
    this.pipe(
      concat(function (body) {
        console.log(body.toString())
        //=> Lorem ipsum dolor sit amet consectetur adipisicing elit.
      })
    )
  })
)
```

&hellip;or as a stream, via [`fastmatter.stream([callback])`](#fastmatterstreamcallback):

```js
const fastmatter = require('fastmatter')
const fs = require('fs')
const concat = require('concat-stream')

fs.createReadStream('foo.md').pipe(
  fastmatter.stream(function (attributes) {
    console.log(attributes)
    /* =>
     * {
     *   title: 'Hello, World!',
     *   tags: [ 'foo', 'bar', 'baz' ]
     * }
     */
    this.pipe(
      concat(function (body) {
        console.log(body.toString())
        //=> Lorem ipsum dolor sit amet consectetur adipisicing elit.
      })
    )
  })
)
```

`callback` is called with the frontmatter `attributes`, while the document `body` is simply passed through the stream. Also note that the `this` context of `callback` is the stream itself; this is useful if we want to change the flow of the stream depending on the parsed `attributes`.

## API

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

### fastmatter(string)

Parses the `string` and returns the parsed frontmatter `attributes` and document `body`.

### fastmatter.stream([callback])

Calls `callback` with the parsed frontmatter `attributes`. The `this` context of `callback` is the stream itself. The document `body` is passed through the stream.

## Installation

Install via [yarn](https://yarnpkg.com):

```bash
{'fraction_non_alphanumeric': 0.15231073547923035, 'fraction_numerical': 0.0, 'mean_word_length': 3.8832309043020192, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 14, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '32484', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1742, 'n_words': 468}