Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/front_matter/mod.ts>test

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function test
import { test } from "https://deno.land/std@0.191.0/front_matter/mod.ts";

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

Parameters

str: string

String to test.

optional
formats: Format[]

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

import { test, Format } from "https://deno.land/std@0.191.0/front_matter/mod.ts";
import { assert } from "https://deno.land/std@0.191.0/testing/asserts.ts";

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", [Format.YAML]));

Returns

boolean