--- title: "@std/front-matter" description: "Extract front matter from strings" jsr: jsr:@std/front-matter pkg: front-matter version: 1.0.9 generated: true stability: stable --- ## Overview

Extracts front matter from strings. Adapted from jxson/front-matter.

Supported formats

JSON

```js import { test, extractJson } from "@std/front-matter"; import { assertEquals } from "@std/assert"; const str = "---json\n{\"and\": \"this\"}\n---\ndeno is awesome"; assertEquals(test(str), true); assertEquals(extractJson(str), { frontMatter: "{\"and\": \"this\"}", body: "deno is awesome", attrs: { and: "this" } }); ```

extract and test support the following delimiters.

```js ---json { "and": "this" } --- ``` ```js { "is": "JSON" } ```

TOML

```js import { test, extractToml } from "@std/front-matter"; import { assertEquals } from "@std/assert"; const str = "---toml\nmodule = 'front_matter'\n---\ndeno is awesome"; assertEquals(test(str), true); assertEquals(extractToml(str), { frontMatter: "module = 'front_matter'", body: "deno is awesome", attrs: { module: "front_matter" } }); ```

extract and test support the following delimiters.

```js ---toml this = 'is' --- ``` ```js = toml = parsed = 'as' toml = 'data' = toml = ``` ```js +++ is = 'that' not = 'cool?' +++ ```

YAML

```js import { test, extractYaml } from "@std/front-matter"; import { assertEquals } from "@std/assert"; const str = "---yaml\nmodule: front_matter\n---\ndeno is awesome"; assertEquals(test(str), true); assertEquals(extractYaml(str), { frontMatter: "module: front_matter", body: "deno is awesome", attrs: { module: "front_matter" } }); ```

extract and test support the following delimiters.

```js --- these: are --- ``` ```js ---yaml all: recognized --- ``` ```js = yaml = as: yaml = yaml = ``` ### Add to your project ```sh deno add jsr:@std/front-matter ``` See all symbols in @std/front-matter on