Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function extract
import { extract } from "https://deno.land/std@0.145.0/encoding/front_matter.ts";

Extracts front matter from a string.

Type Parameters

optional
T = unknown

Parameters

str: string

String to extract from.

import { extract } from "https://deno.land/std@0.145.0/encoding/front_matter.ts";
import { assertEquals } from "https://deno.land/std@0.145.0/testing/asserts.ts";

const { attrs, body, frontMatter } = extract<{ title: string }>("---\ntitle: Three dashes marks the spot\n---\n");
assertEquals(attrs.title, "Three dashes marks the spot");
assertEquals(body, "");
assertEquals(frontMatter, "---\ntitle: Three dashes marks the spot\n---\n");