UNPKG

llm-md

Version:

Convert JSON to Markdown optimized for LLM consumption

71 lines (70 loc) 2.69 kB
/** * Hybrid Converter - intelligent converter for medium-depth objects * Uses hierarchical headers for structure, code blocks for simple properties, * and YAML blocks for deeply nested sub-objects */ import { Converter, ConversionOptions } from '../types'; export declare class HybridConverter 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 array to numbered list * @param arr Array to convert * @returns Markdown string */ private convertArray; }