vfile-matter

vfile utility to parse the YAML front matter in a file

Stats

StarsIssuesVersionUpdatedCreatedSize
vfile-matter
903.0.14 months ago2 years agoMinified + gzip package size for vfile-matter in KB

Readme

vfile-matter

Build Coverage Downloads Size Sponsors Backers Chat

Parse the YAML front matter in a vfile.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

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:

import {toVFile as vfile} from 'to-vfile'
import {matter} from '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

This package exports the following identifiers: matter. There is no default export.

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
  • file (VFile) — Virtual file
  • options.strip (boolean, default: false) — Remove the YAML front matter from the file
  • options.yaml (Object, default: {}) — Options passed to jsYaml.load()
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, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.