UNPKG

@codervisor/devlog-ai

Version:

AI Chat History Extractor & Docker-based Automation - TypeScript implementation for GitHub Copilot and other AI coding assistants with automated testing capabilities

56 lines (55 loc) 1.73 kB
/** * Simple JSON exporter for AI chat data * * TypeScript implementation without complex configuration. */ import { writeFile, mkdir } from 'fs/promises'; import { dirname } from 'path'; export class JSONExporter { defaultOptions = { indent: 2, ensureAscii: false, }; /** * Export arbitrary data to JSON file */ async exportData(data, outputPath, options) { const exportOptions = { ...this.defaultOptions, ...options }; // Ensure output directory exists await mkdir(dirname(outputPath), { recursive: true }); // Convert data to JSON string const jsonString = JSON.stringify(data, this.jsonReplacer, exportOptions.indent); // Write JSON file await writeFile(outputPath, jsonString, 'utf-8'); } /** * Export chat data specifically */ async exportChatData(data, outputPath, options) { return this.exportData(data, outputPath, options); } /** * Custom JSON replacer function for objects that aren't JSON serializable by default */ jsonReplacer(key, value) { // Handle Date objects if (value instanceof Date) { return value.toISOString(); } // Handle objects with toDict method if (value && typeof value === 'object' && 'toDict' in value && typeof value.toDict === 'function') { return value.toDict(); } // Handle objects with toJSON method if (value && typeof value === 'object' && 'toJSON' in value && typeof value.toJSON === 'function') { return value.toJSON(); } return value; } }