A simple YAML frontmatter parser.
$ npm install frontmatter
To parse the YAML frontmatter from a string:
var frontmatter = require('frontmatter');
var parsed = frontmatter(string);
The YAML frontmatter should be defined at the beginning of the string, within a pair of triple-dash lines. For example:
---
title: Welcome
---
Hello!
In this case, the parsed
object would be:
{
"data": {
"title": "Welcome"
},
"content": "\nHello!\n"
}
For untrusted source, the safeLoad
option should be used:
frontmatter(content, { safeLoad: true });
$ npm install
$ npm test
MIT