UNPKG

zon-format

Version:

ZON: The most token-efficient serialization format for LLMs - beats CSV, TOON, JSON, and all competitors

69 lines (68 loc) 2.1 kB
/** * Data Complexity Analyzer for Adaptive Encoding * * Analyzes data structures to determine optimal encoding strategies. */ export interface ComplexityMetrics { /** Maximum nesting depth in the data structure */ nesting: number; /** Irregularity score (0.0 = uniform, 1.0 = highly irregular) */ irregularity: number; /** Total number of unique fields across all objects */ fieldCount: number; /** Size of largest array in the structure */ arraySize: number; /** Proportion of arrays vs objects */ arrayDensity: number; /** Average fields per object */ avgFieldsPerObject: number; } export interface AnalysisResult extends ComplexityMetrics { /** Recommended encoding strategy */ recommendation: 'table' | 'inline' | 'json' | 'mixed'; /** Confidence in recommendation (0.0-1.0) */ confidence: number; /** Reasoning for the recommendation */ reason: string; } /** * Analyzes data complexity to guide encoding decisions. */ export declare class DataComplexityAnalyzer { /** * Analyzes a data structure and returns complexity metrics. * * @param data - Data to analyze * @returns Complexity metrics and encoding recommendation */ analyze(data: any): AnalysisResult; /** * Calculates complexity metrics for data. */ private calculateMetrics; /** * Traverses data structure to collect statistics. */ private traverse; /** * Calculates schema irregularity score. * Higher score = more variation in object shapes. */ private calculateIrregularity; /** * Determines encoding recommendation based on metrics. */ private getRecommendation; /** * Checks if data is suitable for table encoding. */ isSuitableForTable(data: any): boolean; /** * Gets optimal complexity threshold for mode selection. */ getComplexityThreshold(mode: 'aggressive' | 'balanced' | 'conservative'): number; } /** * Global analyzer instance. */ export declare const globalAnalyzer: DataComplexityAnalyzer;