1
Fork 0

Add documentation to tomlFrontmatter function.

This commit is contained in:
Bauke 2023-07-29 21:12:14 +02:00
parent d0d4a25470
commit 9dc9c1d79d
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 24 additions and 0 deletions

View File

@ -33,6 +33,30 @@ export async function runAndReturnStdout(
return new TextDecoder().decode(stdout);
}
/**
* Parse the TOML frontmatter of a string, throwing an error if there is no
* frontmatter or returning the parsed frontmatter with the remaining text
* string. For example the following snippet:
*
* ```txt
* ---toml
* example_value = "Hello, world!"
* ---
*
* # Markdown
* ```
*
* Will return:
*
* ```js
* [
* {
* example_value: "Hello, world!"
* },
* "# Markdown\n"
* ]
* ```
*/
export function tomlFrontmatter<T>(
data: string,
): [T, string] {