extract

import { extract } from "jsr:@ende/front-matter/json";

function

function extract<T>(text: string): Extract<T>

Extracts and parses JSON from the metadata of front matter content.

text: string

The text to extract JSON front matter from.

Returns

The extracted JSON front matter and body content.

Example: Extract JSON front matter

import { extract } from "@ende/front-matter/json";
import { assertEquals } from "@ende/assert";

const output = `---json
{ "title": "Three dashes marks the spot" }
---
Hello, world!`;
const result = extract(output);

assertEquals(result, {
  frontMatter: '{ "title": "Three dashes marks the spot" }',
  body: "Hello, world!",
  attrs: { title: "Three dashes marks the spot" },
});

Source