Skip to main content

latest
Works with
It is unknown whether this package works with Node.js, Deno, Browsers, Cloudflare Workers, Bun
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score64%
Published2 years ago (0.215.0)
function test
test(
str: string,
formats?: ("yaml" | "toml" | "json" | "unknown")[]
): boolean

Tests if a string has valid front matter. Supports YAML, TOML and JSON.

Parameters

String to test.

optional
formats: ("yaml" | "toml" | "json" | "unknown")[]

A list of formats to test for. Defaults to all supported formats.

import { test } from "@std/front-matter";
import { assert } from "@std/assert/assert";

assert(test("---\ntitle: Three dashes marks the spot\n---\n"));
assert(test("---toml\ntitle = 'Three dashes followed by format marks the spot'\n---\n"));
assert(test("---json\n{\"title\": \"Three dashes followed by format marks the spot\"}\n---\n"));

assert(!test("---json\n{\"title\": \"Three dashes followed by format marks the spot\"}\n---\n", ["yaml"]));

Return Type

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 { test } from "@std/front-matter";
or

Import directly with a jsr specifier

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