@burmajs/frontmatter
v0.5.0
Published
Extract YAML data from a markdown file
Downloads
87
Readme
Extract YAML data from a markdown file
Install
npm
npm i @burmajs/frontmatter
pnpm
pnpm i @burmajs/frontmatter
deno
deno add @burmajs/frontmatter
Usage
example.md
---
type: "post"
title: "Hello World"
---
## Hello
NODE-JS
index.ts
import Frontmatter from "@burmajs/frontmatter";
import fs from "node:fs";
type MyType = {
type: string;
title: string;
};
const mdcontent = fs.readFileSync("example.md", "utf-8");
const foo = new Frontmatter<MyType>(mdcontent);
console.log(foo.json); // { data: { type: 'post', title: 'Hello World' }, content: '\n\n## Hello\n'}
console.log(foo.data); // { type: 'post', title: 'Hello World' }
console.log(foo.content); // ## Hello
DENO
mod.ts
import { FrontMatter } from "@burmajs/frontmatter";
type MyType = {
type: string;
title: string;
};
const mdcontent = Deno.readTextFileSync("example.md");
const foo = new Frontmatter<MyType>(mdcontent);
console.log(foo.json); // { data: { type: 'post', title: 'Hello World' }, content: '\n\n## Hello\n'}
console.log(foo.data); // { type: 'post', title: 'Hello World' }
console.log(foo.content); // ## Hello