UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

151 lines (150 loc) 4.6 kB
/** * RTF Document Processor * * Processes Rich Text Format (.rtf) files by extracting plain text content * from RTF control codes. Uses a lightweight text extraction approach * without requiring external dependencies. * * Key features: * - RTF control code stripping * - Text content extraction * - Raw content preservation for debugging * - No external dependencies required * * Priority: ~110 (document format, processed after binary formats) * * @module processors/document/RtfProcessor * * @example * ```typescript * import { rtfProcessor, processRtf, isRtfFile } from "./document/index.js"; * * // Check if a file is an RTF file * if (isRtfFile("application/rtf", "document.rtf")) { * const result = await processRtf({ * id: "file-123", * name: "document.rtf", * mimetype: "application/rtf", * size: 10240, * buffer: rtfBuffer, * }); * * if (result.success) { * console.log(`Text content: ${result.data.textContent}`); * } * } * ``` */ import { BaseFileProcessor } from "../base/BaseFileProcessor.js"; import type { FileInfo, ProcessorFileProcessingResult, ProcessOptions, ProcessedRtf } from "../../types/index.js"; /** * RTF Processor - handles Rich Text Format files. * * Extracts plain text from RTF documents by stripping RTF control codes. * This is a lightweight implementation that doesn't require external * RTF parsing libraries. * * Priority: ~110 (document format) * * @example * ```typescript * const processor = new RtfProcessor(); * * const result = await processor.processFile({ * id: "file-123", * name: "report.rtf", * mimetype: "application/rtf", * size: 5120, * buffer: rtfBuffer, * }); * * if (result.success) { * console.log("Extracted text:", result.data.textContent); * } * ``` */ export declare class RtfProcessor extends BaseFileProcessor<ProcessedRtf> { constructor(); /** * Validate downloaded RTF document. * Checks for RTF header signature "{\\rtf". * * @param buffer - Downloaded file content * @param fileInfo - Original file information * @returns null if valid, error message if invalid */ protected validateDownloadedFile(buffer: Buffer, _fileInfo: FileInfo): Promise<string | null>; /** * Build the processed RTF result. * Extracts plain text by stripping RTF control codes. * * @param buffer - Raw file content * @param fileInfo - Original file information * @returns Processed RTF with extracted text content */ protected buildProcessedResult(buffer: Buffer, fileInfo: FileInfo): ProcessedRtf; /** * Extract plain text from RTF content. * Strips RTF control codes, groups, and formatting commands. * * This is a basic RTF parser that handles common RTF constructs: * - Control groups like {\fonttbl...} * - Control words like \par, \b, \i * - Special characters like \' hex escapes * - Newlines from \par and \line commands * * @param rtf - Raw RTF content * @returns Extracted plain text */ private extractText; } /** * Singleton instance of the RtfProcessor. * Use this for all RTF document processing to share configuration. */ export declare const rtfProcessor: RtfProcessor; /** * Check if a file is an RTF document. * * @param mimetype - MIME type of the file * @param filename - Filename for detection * @returns true if the file is a supported RTF document * * @example * ```typescript * if (isRtfFile("application/rtf", "document.rtf")) { * console.log("This is an RTF document"); * } * ``` */ export declare function isRtfFile(mimetype: string, filename: string): boolean; /** * Validate RTF document size against configured limit. * * @param sizeBytes - File size in bytes * @returns true if size is within the allowed limit */ export declare function validateRtfSize(sizeBytes: number): boolean; /** * Process an RTF document. * * @param fileInfo - File information (can include URL or buffer) * @param options - Optional processing options * @returns Processing result with success flag and either data or error * * @example * ```typescript * const result = await processRtf({ * id: "file-123", * name: "report.rtf", * mimetype: "application/rtf", * size: 10240, * buffer: rtfBuffer, * }); * * if (result.success) { * console.log("Extracted text:", result.data.textContent); * } * ``` */ export declare function processRtf(fileInfo: FileInfo, options?: ProcessOptions): Promise<ProcessorFileProcessingResult<ProcessedRtf>>;