MCPcopy Create free account
hub / github.com/electric-sql/electric / parseFrontmatter

Function parseFrontmatter

packages/agents/src/docs/knowledge-base.ts:84–100  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

82const DEFAULT_K = 8
83
84function parseFrontmatter(value: string): { title?: string; body: string } {
85 if (!value.startsWith(`---\n`)) {
86 return { body: value }
87 }
88
89 const end = value.indexOf(`\n---\n`, 4)
90 if (end === -1) {
91 return { body: value }
92 }
93
94 const frontmatter = value.slice(4, end)
95 const titleMatch = frontmatter.match(/^title:\s*(.+)$/m)
96 return {
97 title: titleMatch?.[1]?.trim().replace(/^['"]|['"]$/g, ``),
98 body: value.slice(end + 5),
99 }
100}
101
102function firstHeading(value: string): string | undefined {
103 const match = value.match(/^#\s+(.+)$/m)

Callers 3

toDocTitleFunction · 0.85
chunkMarkdownFunction · 0.85
outlineMethod · 0.85

Calls 2

indexOfMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected