Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 8x | /**
* Format Provider Interface
*
* Format providers handle parsing and serialization of different frontmatter formats
* (YAML, TOML, JSON) in markdown/content files.
*/
/**
* Type guard to check if a value is a plain object (Record<string, unknown>).
* Use this to validate parse() results before spreading or merging.
*/
export function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}
export interface ParsedContent {
mainContent?: string;
[key: string]: unknown;
}
export interface FormatProvider {
/**
* Get the default file extension for this format (without dot)
*/
defaultExt(): string;
/**
* Check if a line matches the start of this format's frontmatter
*/
matchContentFirstLine(line: string): boolean;
/**
* Parse a string in this format to an object.
* Returns unknown since the structure depends on the file content.
* Callers should validate the result with Zod or type guards.
*/
parse(str: string): unknown;
/**
* Serialize an object to a string in this format.
* Accepts unknown since any serializable value can be converted.
*/
dump(obj: unknown): string;
/**
* Serialize an object with mainContent to a full content file string
* (includes frontmatter delimiters)
*/
dumpContent(obj: ParsedContent): string;
/**
* Parse a content file string (with frontmatter and markdown content)
* Returns object with parsed frontmatter and mainContent property
*/
parseFromMdFileString(str: string): ParsedContent;
}
|