parse-yaml

A zero-dependency module for parsing YAML and Front Matter


License
CC0-1.0
Install
npm install parse-yaml@0.1.0

Documentation

parse-yaml

NPM Version Build Status Support Chat

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

parseAsYaml

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`);

parseAsYaml Output

{
  "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"
}

parseAsYaml Options

See https://github.com/nodeca/js-yaml#safeload-string---options-

parseAsFrontMatter

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>
`);

parseAsFrontMatter Output

{
  "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---"
}

parseAsFrontMatter Options

See https://github.com/jxson/front-matter#fmstring

Zero Dependency

Only a quarter of the functionality from js-yaml and front-matter is required to parse YAML and Front Matter. These portions are bundled.

Licensing

All functionality imported from js-yaml and front-matter is MIT licensed. https://github.com/nodeca/js-yaml