Spec-Zone.ru › Deno 2

@std/front-matter

Обзор

Извлекает вводные данные из строк. Адаптировано из jxson/front-matter.

Поддерживаемые форматы

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 и test поддерживают следующие разделители.

---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 и test поддерживают следующие разделители.

---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 и test поддерживают следующие разделители.

---
these: are
---
---yaml
all: recognized
---
= yaml =
as: yaml
= yaml =

Добавление в проект

›_
deno add jsr:@std/front-matter

Просмотреть все символы в @std/front-matter на

© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/runtime/reference/std/front-matter

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API