UNPKG

@entro314labs/ai-changelog-generator

Version:

AI-powered changelog generator with MCP server support - works with most providers, online and local models

184 lines (183 loc) 6.31 kB
/** * Comprehensive JSON Operations Utility * Provides advanced JSON parsing, stringification, and error handling capabilities * Handles JSON parsing, validation, and error recovery with detailed diagnostics */ export declare class JsonUtils { [key: string]: any; /** * Stringify data with optional pretty printing * @param {*} data - Data to stringify * @param {boolean} pretty - Whether to pretty print (default: true) * @returns {string} JSON string */ static stringify(data: any, pretty?: boolean): string; /** * Safe JSON parsing with fallback * @param {string} jsonString - JSON string to parse * @param {*} fallback - Fallback value if parsing fails (default: null) * @returns {*} Parsed data or fallback */ static safeParse(jsonString: any, fallback?: any): any; /** * Stringify data for API responses (always pretty printed) * @param {*} data - Data to stringify for response * @returns {string} Pretty-printed JSON string */ static stringifyForResponse(data: any): string; /** * Compact JSON stringify (no pretty printing, for logs/storage) * @param {*} data - Data to stringify compactly * @returns {string} Compact JSON string */ static stringifyCompact(data: any): string; /** * Safe stringify that handles circular references and undefined values * @param {*} data - Data to stringify * @param {boolean} pretty - Whether to pretty print * @returns {string} JSON string with circular references handled */ static safeStringify(data: any, pretty?: boolean): string; /** * Parse JSON with detailed error information * @param {string} jsonString - JSON string to parse * @param {string} context - Context for error reporting (optional) * @returns {Object} {success: boolean, data: *, error: string, position?: Object} */ static parseWithErrorDetails(jsonString: any, context?: string): { success: boolean; data: any; error: null; position?: undefined; } | { success: boolean; data: null; error: string; position: { position: number; line: any; column: any; context: { before: any; after: any; marker: string; }; } | { position?: undefined; line: number; column: number; context: { line: any; column: any; errorLine: any; marker: string; contextLines: any[]; }; } | null; }; /** * Extract error position from JSON parse error * @param {Error} error - JSON parse error * @param {string} jsonString - Original JSON string * @returns {Object|null} Position information with line/column */ static getErrorPosition(error: any, jsonString: any): { position: number; line: any; column: any; context: { before: any; after: any; marker: string; }; } | { position?: undefined; line: number; column: number; context: { line: any; column: any; errorLine: any; marker: string; contextLines: any[]; }; } | null; /** * Get context around error position for debugging * @param {string} jsonString - Original JSON string * @param {number} position - Error position * @returns {Object} Context information */ static getErrorContext(jsonString: any, position: any): { before: any; after: any; marker: string; }; /** * Get context around error line/column for debugging * @param {string} jsonString - Original JSON string * @param {number} line - Error line number (1-based) * @param {number} column - Error column number (1-based) * @returns {Object} Context information */ static getErrorContextByLine(jsonString: any, line: any, column: any): { line: any; column: any; errorLine: any; marker: string; contextLines: any[]; }; /** * Validate JSON string without parsing * @param {string} jsonString - JSON string to validate * @returns {boolean} True if valid JSON */ static isValidJson(jsonString: any): boolean; /** * Deep clone object using JSON serialization * @param {*} obj - Object to clone * @returns {*} Deep cloned object */ static deepClone(obj: any): any; /** * Format JSON for console output with syntax highlighting * @param {*} data - Data to format * @param {boolean} colorize - Whether to add console colors * @returns {string} Formatted JSON string */ static formatForConsole(data: any, colorize?: boolean): string; /** * Minify JSON string by removing unnecessary whitespace * @param {string} jsonString - JSON string to minify * @returns {string} Minified JSON string */ static minify(jsonString: any): any; /** * Pretty print JSON string * @param {string} jsonString - JSON string to format * @param {number} indent - Number of spaces for indentation (default: 2) * @returns {string} Pretty printed JSON string */ static prettify(jsonString: any, indent?: number): any; /** * Compare two JSON objects for equality * @param {*} obj1 - First object * @param {*} obj2 - Second object * @returns {boolean} True if objects are equal */ static areEqual(obj1: any, obj2: any): boolean; /** * Extract all string values from JSON object (useful for text analysis) * @param {*} obj - JSON object * @param {Array} strings - Accumulator array (used internally) * @returns {Array} Array of all string values */ static extractStrings(obj: any, strings?: any[]): any[]; /** * Merge multiple JSON objects deeply * @param {...Object} objects - Objects to merge * @returns {Object} Merged object */ static deepMerge(...objects: any[]): Record<string, any>; } export default JsonUtils;