UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

87 lines (86 loc) • 3.51 kB
/** * PowerPoint (PPTX) Processing Utility * * Extracts text content from PowerPoint (.pptx) files by treating them * as ZIP archives and parsing the slide XML files within. * * PPTX files are ZIP archives containing: * - ppt/slides/slide1.xml, slide2.xml, ... — slide content * - ppt/slideMasters/ — master slide templates * - ppt/slideLayouts/ — slide layout definitions * * Text is extracted from `<a:t>` elements in the slide XML files. * Slides are sorted by number and presented in reading order. * * Uses `adm-zip` (already a project dependency) for ZIP extraction. * * **XML-entity attacks are not applicable here.** Unlike `WordProcessor` * (mammoth/@xmldom/xmldom) and `ExcelProcessor` (exceljs/saxes), this * processor never hands slide XML to a DOM or SAX parser at all — extraction * is a single regex (`TEXT_ELEMENT_REGEX`, below) run over the raw decoded * bytes. There is no DOCTYPE/ENTITY resolution path for a payload to reach, * so there is nothing for a `.pptx`-specific XXE or billion-laughs test to * falsify; one is deliberately not written (see * `test/continuous-test-suite-office-security.ts`'s header). * * @module processors/document/PptxProcessor * * @example * ```typescript * import { PptxProcessor } from "./PptxProcessor.js"; * * const text = await PptxProcessor.extractText(buffer); * if (text) { * console.log("Extracted text:", text); * } * ``` */ /** * Static utility class for extracting text from PPTX files. * * Designed as a static class (not extending BaseFileProcessor) because * PPTX processing is straightforward ZIP+XML extraction and does not * need the full download/validate/process pipeline of BaseFileProcessor. */ export declare class PptxProcessor { /** * Extract all text content from a PPTX buffer. * * @param content - Raw PPTX file buffer * @returns Formatted text content with slide headers, or null if no text found * @throws Error if the buffer is not a valid ZIP/PPTX file */ static extractText(content: Buffer): Promise<string | null>; /** * Extract the speaker notes for one slide. * * Speaker notes live in a separate `ppt/notesSlides/notesSlideN.xml` part * whose number is NOT tied to the slide number — the link is declared in the * slide's own relationships file (`ppt/slides/_rels/slideN.xml.rels`) via a * relationship of type `.../notesSlide`. We resolve that target, then pull the * `<a:t>` runs from the notes part. Returns null when the slide has no notes. * * @param zip - The opened PPTX archive * @param slideNumber - 1-indexed slide number * @returns The notes text (runs joined by a space), or null when absent */ private static extractNotesForSlide; /** * Extract text strings from a slide XML document. * Finds all `<a:t>` elements and returns their text content. * * @param xml - Raw XML string from a slide file * @returns Array of text strings found in the slide */ private static extractTextFromXml; /** * Extract text from specific slides in a PPTX file. * * Called by the `extract_file_content` tool for targeted slide access. * * @param content - Raw PPTX file buffer * @param slideNumbers - Array of 1-indexed slide numbers to extract * @returns Formatted text from the requested slides */ static extractSlides(content: Buffer, slideNumbers: number[]): Promise<string>; }