UNPKG

@mintlify/common

Version:

Commonly shared code within Mintlify

36 lines (35 loc) 998 B
import fm from 'front-matter'; // eslint-disable-next-line @typescript-eslint/consistent-type-assertions const frontmatter = fm; /** * 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 function parseFrontmatter(content) { return frontmatter(content); } /** * Tests whether a string contains frontmatter * * @param content - The content to test * @returns true if the content contains frontmatter */ export function hasFrontmatter(content) { return frontmatter.test(content); }