UNPKG

llm-md

Version:

Convert JSON to Markdown optimized for LLM consumption

62 lines (61 loc) 2.02 kB
/** * Utility functions for JSON to Markdown conversion */ /** * Calculate the maximum depth of a data structure * @param data The data to analyze * @param current Current depth level * @param maxDepth Maximum depth to prevent infinite recursion * @param visited Set to track circular references * @returns Maximum depth found */ export declare function getMaxDepth(data: unknown, current?: number, maxDepth?: number, visited?: WeakSet<object>): number; /** * Escape pipe characters in strings for Markdown tables * @param str String to escape * @returns Escaped string */ export declare function escapePipes(str: string): string; /** * Escape special Markdown characters * @param str String to escape * @returns Escaped string */ export declare function escapeMarkdown(str: string): string; /** * Format a value for display in Markdown * @param value Value to format * @returns Formatted string */ export declare function formatValue(value: unknown): string; /** * Format a value for table cells * @param value Value to format * @returns Formatted string safe for table cells */ export declare function formatCellValue(value: unknown): string; /** * Estimate token count for a string (rough approximation) * Uses a simple heuristic: ~4 characters per token * @param str String to estimate * @returns Estimated token count */ export declare function estimateTokens(str: string): number; /** * Check if all objects in an array have similar keys * @param arr Array of objects to check * @returns Similarity score (0-1) */ export declare function calculateKeySimilarity(arr: unknown[]): number; /** * Get average number of keys in array of objects * @param arr Array to analyze * @returns Average key count */ export declare function getAverageKeyCount(arr: unknown[]): number; /** * Get all unique keys from an array of objects * @param arr Array of objects * @returns Array of unique keys in order of first appearance */ export declare function getAllKeys(arr: unknown[]): string[];