simple-md-front-matter
v0.0.4
Published
A library for parse front-matter
Downloads
3
Maintainers
Readme
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 useparseWithGoStyle
API, it is similar toGolang
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
---
`)