extract

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

function

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

Extracts and parses YAML, TOML, or JSON from the metadata of front matter content, depending on the format.

text: string

The text to extract front matter from.

Returns

The extracted front matter and body content.

Example: Usage

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

const output = `---json
{
  "title": "Three dashes marks the spot"
}
---
Hello, world!`;
const result = extract(output);
assertEquals(result, {
  frontMatter: '{\n  "title": "Three dashes marks the spot"\n}',
  body: "Hello, world!",
  attrs: { title: "Three dashes marks the spot" }
})

Source