function test
test(str: string,formats?: ("yaml" | "toml" | "json" | "unknown")[]): booleanTests if a string has valid front matter. Supports YAML, TOML and JSON.
Parameters
str: stringString 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"]));