Skip to content

Plumbiu/simple-md-front-matter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-md-front-matter

Pase markdown front matter syntax like this:

---
foo: bar
baz: 14
---

Installing

npm install simple-md-front-matter

Usage

Basic Usage:

import parseFrontMatter from 'simple-md-front-matter'

try {
  parseFrontMatter(`
---
foo: bar
baz: 14
---
  `)
  /*
{
  foo: bar,
  baz: 14,
}
*/
} catch (err) {
  /* handle error */
}

Golang Style:

If you dont like try catch syntax, you can use parseWithGoStyle API, it is similar to Golang style for handling error.

import { parseWithGoStyle } from 'simple-md-front-matter'

const { err, content } = parseWithGoStyle(`
---
foo: bar
baz: 14
---
`)

if (err) {
  /* handle error */
} else {
  console.log(content)
  /*
{
  foo: bar,
  baz: 14,
}
*/
}

Type Support:

With generics:

import parseFrontMatter from 'simple-md-front-matter'

interface FM {
  foo: string
  baz: number
}

parseFrontMatter<FM>(`
---
foo: bar
baz: 14
---
  `)

const { err, content } = parseWithGoStyle<FM>(`
---
foo: bar
baz: 14
---
`)

About

A library for parse front-matter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published