UNPKG

@stack.thefennec.dev/telegram-export-parser

Version:

TypeScript library for parsing Telegram Desktop's data export with full type safety

107 lines 3.79 kB
#!/usr/bin/env node import { TelegramExportProcessor } from './processors/main'; import type { TelegramMessage, TelegramEvent } from './types'; /** * @fileoverview CLI tool for parsing and analyzing Telegram export files. * * Provides command-line interface for processing Telegram chat exports with * detailed statistics, actor extraction, and message analysis capabilities. * Supports various output formats and filtering options. * * @example * ```bash * # Basic parsing * npm run parse-export ./path/to/export.json * * # With detailed output * npm run parse-export ./export.json --verbose * * # Show only statistics * npm run parse-export ./export.json --stats-only * ``` */ /** * CLI configuration options parsed from command line arguments. * * @interface CliOptions * @property {string} filePath - Path to the Telegram export JSON file * @property {boolean} verbose - Enable detailed output with message previews * @property {boolean} statsOnly - Show only statistics without processing messages * @property {number} limit - Maximum number of messages to process (0 = no limit) */ interface CliOptions { filePath: string; verbose: boolean; statsOnly: boolean; limit: number; } /** * Parses command line arguments into structured options object. * * Handles various argument formats and provides sensible defaults. * Validates file path argument is present and accessible. * * @param args - Raw command line arguments from process.argv * @returns Parsed and validated CLI options * @throws {Error} When required file path argument is missing * * @example * ```typescript * const options = parseCliArgs(['node', 'cli.js', 'export.json', '--verbose']) * // Returns: { filePath: 'export.json', verbose: true, statsOnly: false, limit: 0 } * ``` */ declare function parseCliArgs(args: string[]): CliOptions; /** * Formats message content for console display with length constraints. * * Truncates long text content and handles various message types gracefully. * Provides consistent formatting for different message formats. * * @param message - Telegram message or event to format * @param maxLength - Maximum length for text content (default: 100) * @returns Formatted string representation of message content * * @example * ```typescript * const formatted = formatMessagePreview(textMessage, 50) * // Returns: "Hello world! This is a long message that..." * ``` */ declare function formatMessagePreview(message: TelegramMessage | TelegramEvent, maxLength?: number): string; /** * Processes and displays statistics for the Telegram export. * * Analyzes the entire export to provide comprehensive statistics including * message counts, date ranges, participant information, and message type * distribution. * * @param processor - Initialized TelegramExportProcessor instance * * @example * ```typescript * const processor = TelegramExportProcessor.fromFile('export.json') * displayStatistics(processor) * // Outputs comprehensive chat statistics to console * ``` */ declare function displayStatistics(processor: TelegramExportProcessor): void; /** * Main CLI application entry point. * * Orchestrates the entire parsing and analysis process based on command line * options. Handles file loading, processing, and output formatting with * comprehensive error handling and progress indication. * * @param args - Command line arguments from process.argv * @throws {Error} Various errors related to file access, parsing, or processing * * @example * ```typescript * // Called automatically when script is executed * main(process.argv) * ``` */ declare function main(args: string[]): void; export { main, parseCliArgs, formatMessagePreview, displayStatistics }; //# sourceMappingURL=cli.d.ts.map