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

    Parameters

    • str: string

      String to test.

    • Optionalformats: Format[]

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

    Returns boolean

    true if the string has valid front matter, otherwise false.

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

    const result = test(
    `---
    title: Three dashes marks the spot
    ---
    `);
    assert(result);
    import { test } from "@std/front-matter/test";
    import { assert } from "@std/assert";

    const result = test(
    `---toml
    title = 'Three dashes followed by format marks the spot'
    ---
    `);
    assert(result);
    import { test } from "@std/front-matter/test";
    import { assert } from "@std/assert";

    const result = test(
    `---json
    {"title": "Three dashes followed by format marks the spot"}
    ---
    `);
    assert(result);
    import { test } from "@std/front-matter/test";
    import { assertFalse } from "@std/assert";

    const result = test(
    `---json
    {"title": "Three dashes followed by format marks the spot"}
    ---
    `, ["yaml"]);
    assertFalse(result);