std/encoding/front_matter.ts

Deno standard library
Go to Latest
function extract
import { extract } from "https://deno.land/std@0.145.0/encoding/front_matter.ts?s=extract";

Extracts front matter from a string.

Type Parameters

optional
T = unknown
[src]

Parameters

str: string[src]

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");

Returns

Extract<T>[src]