UNPKG

llm-md

Version:

Convert JSON to Markdown optimized for LLM consumption

83 lines (82 loc) 3.08 kB
/** * Headers Converter - converts medium-depth objects to hierarchical headers * Now supports hybrid mode: Markdown headers for top levels, YAML blocks for deep nesting */ import { Converter, ConversionOptions } from '../types'; export declare class HeadersConverter implements Converter { private visited; constructor(); /** * Convert data to hierarchical headers format * Supports hybrid mode: uses YAML blocks for deeply nested sub-objects * @param data Data to convert * @param options Conversion options * @returns Markdown with hierarchical headers */ convert(data: unknown, options?: ConversionOptions): string; /** * Recursively convert values with headers * @param data Data to convert * @param level Current header level (2-6) * @param depth Current depth in object hierarchy * @param options Conversion options * @returns Markdown string */ private convertValue; /** * Convert an object with headers and code blocks (Markdown-KV format) * @param obj Object to convert * @param level Current header level * @param depth Current depth in object hierarchy * @param options Conversion options * @returns Markdown string */ private convertObject; /** * Convert nested object - uses headers, key-value pairs, or YAML blocks * based on current depth in hierarchy * @param obj Object to convert * @param currentDepth Current depth in object hierarchy * @param maxHeaderDepth Maximum depth before switching to YAML * @param level Current header level (for recursive headers) * @returns Markdown string */ private convertNestedObject; /** * Convert object with headers + code blocks (Markdown-KV format) * Separates simple properties (shown in code blocks) from nested objects (shown as sub-headers) * @param obj Object to convert * @param level Current header level * @param currentDepth Current depth in hierarchy * @param maxHeaderDepth Maximum depth before switching to YAML * @returns Markdown with headers and code blocks */ private convertObjectWithHeaders; /** * Convert object to key-value pairs with depth-aware nesting * @param obj Object to convert * @param currentDepth Current depth in hierarchy * @param maxHeaderDepth Maximum depth before switching to YAML * @returns Key-value formatted string */ private convertToKeyValue; /** * Convert simple key-value pairs to plain code block (Markdown-KV format) * Format: ```\nkey1: value1\nkey2: value2\n``` * @param obj Object with simple properties * @returns Plain text code block */ private convertToCodeBlock; /** * Convert object to YAML code block * @param obj Object to convert * @returns YAML code block string */ private convertToYAML; /** * Convert array to numbered list * @param arr Array to convert * @returns Markdown string */ private convertArray; }