-
Notifications
You must be signed in to change notification settings - Fork 584
/
any.ts
37 lines (35 loc) · 1.01 KB
/
any.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import {
createExtractor,
type Extractor,
type Parser,
} from "./create_extractor.ts";
import { parse as parseYaml } from "@std/yaml/parse";
import { parse as parseToml } from "@std/toml/parse";
/**
* Extracts and parses {@link https://yaml.org | YAML}, {@link https://toml.io |
* TOML}, or {@link https://www.json.org/ | JSON} from the metadata of front
* matter content, depending on the format.
*
* @example
* ```ts
* import { extract } from "@std/front-matter/any";
*
* const output = `---json
* {
* "title": "Three dashes marks the spot"
* }
* ---
* Hello, world!`;
* const result = extract(output);
*
* result.frontMatter; // '{\n "title": "Three dashes marks the spot"\n}'
* result.body; // "Hello, world!"
* result.attrs; // { title: "Three dashes marks the spot" }
* ```
*/
export const extract: Extractor = createExtractor({
yaml: parseYaml as Parser,
toml: parseToml as Parser,
json: JSON.parse as Parser,
});