unified

Project:vfile/vfile-matter

Package:vfile-matter@1.0.1

  1. Dependencies:3·Dependents:0
  2. Parse the YAML front matter in a vfile
  1. file 14
  2. vfile 13
  3. virtual 12
  4. frontmatter 3
  5. yaml 3

vfile-matter

Build Coverage Downloads Size Sponsors Backers Chat

Parse the YAML front matter in a vfile.

Install

npm:

npm install vfile-matter

Use

Say we have a file, example.html:

---
title: Hello, world!
---
<p>Some more text</p>

And our script, example.js, looks like so:

var vfile = require('to-vfile')
var matter = require('vfile-matter')

var file = vfile.readSync('example.html')

matter(file, {strip: true})

console.log(file.data)
console.log(String(file))

Now, running our script (node example) yields:

{ matter: { title: 'Hello, world!' } }
<p>Some more text</p>

API

matter(file[, options])

Parse the YAML front matter in a vfile, and add it as file.data.matter.

If no matter is found in the file, nothing happens, except that file.data.matter is set to an empty object ({}).

Parameters
Returns

The given file.

Contribute

See contributing.md in vfile/.github for ways to get started. See support.md for ways to get help.

This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer