zero-dependency module for parsing YAML and Front Matter
OTHER License
parse-yaml is a 10.8 kB “zero-dependency” module for parsing YAML and Front Matter, powered by the cores of js-yaml and front-matter.
npm install parse-yaml
The parseAsYaml
function parses a string as YAML.
const { parseAsYaml } = require('parse-yaml');
parseAsYaml(`title: This is my first post.
description: This is a post on My Blog about agile frameworks.
date: 2018-05-01
tags:
- another-tag
layout: layouts/post.njk`);
{
"title": "This is my first post.",
"description": "This is a post on My Blog about agile frameworks.",
"date": "2018-05-01T00:00:00.000Z",
"tags": [
"another-tag"
],
"layout": "layouts/post.njk"
}
See https://github.com/nodeca/js-yaml#safeload-string---options-
The parseAsFrontMatter
function parses a string as Front Matter.
const { parseAsFrontMatter } = require('parse-yaml');
parseAsFrontMatter(`---
title: This is my first post.
description: This is a post on My Blog about agile frameworks.
date: 2018-05-01
tags:
- another-tag
layout: layouts/post.njk
---
<main>
{{ content | safe }}
</main>
`);
{
"attributes": {
"title": "This is my first post.",
"description": "This is a post on My Blog about agile frameworks.",
"date": "2018-05-01T00:00:00.000Z",
"tags": [
"another-tag"
],
"layout": "layouts/post.njk"
},
"body": "\n<main>\n {{ content | safe }}\n</main>\n",
"frontmatter": "---\ntitle: This is my first post.\ndescription: This is a post on My Blog about agile frameworks.\ndate: 2018-05-01\ntags:\n - another-tag\nlayout: layouts/post.njk\n---"
}
See https://github.com/jxson/front-matter#fmstring
Only a quarter of the functionality from js-yaml and front-matter is required to parse YAML and Front Matter. These portions are bundled.
All functionality imported from js-yaml and front-matter is MIT licensed. https://github.com/nodeca/js-yaml