@vanillaes/frontmeta

Front-matter parser for key:value pairs

Usage no npm install needed!

<script type="module">
  import vanillaesFrontmeta from 'https://cdn.skypack.dev/@vanillaes/frontmeta';
</script>

README

FrontMeta

FrontMeta is a minimalist front-matter format that uses key:value pairs rather than YAML. This results in a parser that is optimized for both size and speed.

GitHub Release NPM Release Bundlephobia Latest Status Release Status

Discord

Features

  • ECMAScript Module
  • CommonJS Bundle Included
  • Typescript Compatible

Installation

npm install @vanillaes/frontmeta
import FrontMeta from '@vanillaes/frontmeta';

Usage

Parse and stringify FrontMeta

FrontMeta.parse()

FrontMeta.parse(contents) : object

  • contents - a string representing the document contents

Example

contents

---
key1:value1
key2:value2
---
This is the document body.
import FrontMeta from '@vanillaes/frontmeta';
const frontmeta = // the document contents
const parsed = FrontMeta.parse(frontmeta)
console.log(parsed);
> {
>   "meta": {
>     "key1": "value1",
>     "key2": "value2"
>   },
>   "body": "This is the document body."
> }

FrontMeta.parse()

FrontMeta.stringify(document) : object

  • document - The frontmeta document object
    • meta - the frontmeta key:value data
    • body - the document body

document

{
  "meta": {
    "key1": "value1",
    "key2": "value2"
  },
  "body": "This is the document body."
}
import FrontMeta from '@vanillaes/frontmeta';
const document = // the frontmeta document object
const frontmeta = FrontMeta.stringify(document)
console.log(frontmeta);
> ---
> key1:value1
> key2:value2
> ---
> This is the document body.

CommonJS

A .cjs bundle is included for CommonJS compatibility

FrontMeta.parse()

const FrontMeta = require('@vanillaes/frontmeta');
const frontmeta = // the document frontmeta
const parsed = FrontMeta.parse(frontmeta);

FrontMeta.stringify()

const FrontMeta = require('frontmeta');
const document = // the frontmeta document object
const frontmeta = FrontMeta.stringify(document);

Typings

Typings are generated from JSDoc using Typescript. They are 100% compatible with VSCode Intellisense and will work seamlessly with Typescript.