deno.land / std@0.224.0 / front_matter / _formats.ts

_formats.ts
View Documentation
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
type Delimiter = string | [begin: string, end: string];
function getBeginToken(delimiter: Delimiter): string { return Array.isArray(delimiter) ? delimiter[0] : delimiter;}
function getEndToken(delimiter: Delimiter): string { return Array.isArray(delimiter) ? delimiter[1] : delimiter;}
function createRegExps(delimiters: Delimiter[]): [RegExp, RegExp] { const beginPattern = "(" + delimiters.map(getBeginToken).join("|") + ")"; const pattern = "^(" + "\\ufeff?" + // Maybe byte order mark beginPattern + "$([\\s\\S]+?)" + "^(?:" + delimiters.map(getEndToken).join("|") + ")\\s*" + "$" + (globalThis?.Deno?.build?.os === "windows" ? "\\r?" : "") + "(?:\\n)?)";
return [ new RegExp("^" + beginPattern + "$", "im"), new RegExp(pattern, "im"), ];}
const [RECOGNIZE_YAML_REGEXP, EXTRACT_YAML_REGEXP] = createRegExps( [ ["---yaml", "---"], "= yaml =", "---", ],);const [RECOGNIZE_TOML_REGEXP, EXTRACT_TOML_REGEXP] = createRegExps( [ ["---toml", "---"], "\\+\\+\\+", "= toml =", ],);const [RECOGNIZE_JSON_REGEXP, EXTRACT_JSON_REGEXP] = createRegExps( [ ["---json", "---"], "= json =", ],);
export const RECOGNIZE_REGEXP_MAP = { yaml: RECOGNIZE_YAML_REGEXP, toml: RECOGNIZE_TOML_REGEXP, json: RECOGNIZE_JSON_REGEXP,} as const;
export const EXTRACT_REGEXP_MAP = { yaml: EXTRACT_YAML_REGEXP, toml: EXTRACT_TOML_REGEXP, json: EXTRACT_JSON_REGEXP,} as const;
std

Version Info

Tagged at
6 months ago