Skip to main content

Built and signed on GitHub Actions

Extract front matter from strings

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
88%
Published
5 days ago (1.0.9)
function extract
extract<T>(text: string): Extract<T>

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

Examples

Usage

import { extract } from "@std/front-matter/any";
import { assertEquals } from "@std/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" }
})

Type Parameters

The type of the parsed front matter.

Parameters

text: string

The text to extract front matter from.

Return Type

The extracted front matter and body content.

Add Package

deno add jsr:@std/front-matter

Import symbol

import { extract } from "@std/front-matter/any";

---- OR ----

Import directly with a jsr specifier

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

Add Package

npx jsr add @std/front-matter

Import symbol

import { extract } from "@std/front-matter/any";

Add Package

yarn dlx jsr add @std/front-matter

Import symbol

import { extract } from "@std/front-matter/any";

Add Package

pnpm dlx jsr add @std/front-matter

Import symbol

import { extract } from "@std/front-matter/any";

Add Package

bunx jsr add @std/front-matter

Import symbol

import { extract } from "@std/front-matter/any";