Skip to main content
Home

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
9 months ago (1.0.9)

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

Supported formats

JSON

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.

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

TOML

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.

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

YAML

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.

---
these: are
---
---yaml
all: recognized
---
= yaml =
as: yaml
= yaml =
Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/front-matter

Import symbol

import * as front_matter from "@std/front-matter";
or

Import directly with a jsr specifier

import * as front_matter from "jsr:@std/front-matter";

Add Package

pnpm i jsr:@std/front-matter
or (using pnpm 10.8 or older)
pnpm dlx jsr add @std/front-matter

Import symbol

import * as front_matter from "@std/front-matter";

Add Package

yarn add jsr:@std/front-matter
or (using Yarn 4.8 or older)
yarn dlx jsr add @std/front-matter

Import symbol

import * as front_matter from "@std/front-matter";

Add Package

vlt install jsr:@std/front-matter

Import symbol

import * as front_matter from "@std/front-matter";

Add Package

npx jsr add @std/front-matter

Import symbol

import * as front_matter from "@std/front-matter";

Add Package

bunx jsr add @std/front-matter

Import symbol

import * as front_matter from "@std/front-matter";