Parsing YAML frontmatter from a string.
$ npm install frontmatter
To parse the content of a string:
var frontmatter = require('frontmatter');
var parsed = frontmatter(content);
As in Jekyll, the YAML frontmatter should be delimited with triple-dash lines and defined at the beginning. For example:
---
title: Welcome
---
Hello!
In this case, the parsed
object would be:
{
"data": {
"title": "Welcome"
},
"content": "\nHello!\n"
}
Use the safeLoad
option for untrusted source:
frontmatter(content, { safeLoad: true });
$ npm install
$ npm test
MIT