@mintlify/common
Version:
Commonly shared code within Mintlify
35 lines (34 loc) • 1.17 kB
TypeScript
import type { FrontMatterResult } from 'front-matter';
/**
* Default type for frontmatter attributes when no specific type is provided.
* Represents a flexible object that can contain any valid JSON-like values.
*/
export type FrontmatterAttributes = Record<string, string | undefined>;
/**
* Type-safe wrapper for parsing front-matter from markdown content.
*
* @template T - The expected type of the frontmatter attributes
* @param content - The markdown content string to parse
* @returns A FrontMatterResult with properly typed attributes
*
* @example
* ```ts
* interface MyFrontmatter {
* title: string;
* description?: string;
* tags?: string[];
* }
*
* const result = parseFrontmatter<MyFrontmatter>(content);
* // result.attributes is now typed as MyFrontmatter
* console.log(result.attributes.title);
* ```
*/
export declare function parseFrontmatter<T = FrontmatterAttributes>(content: string): FrontMatterResult<T>;
/**
* Tests whether a string contains frontmatter
*
* @param content - The content to test
* @returns true if the content contains frontmatter
*/
export declare function hasFrontmatter(content: string): boolean;