file-converter-nodejs
Version:
A powerful Node.js package for converting files between various formats, splitting and merging files, and automating complex file operations. Backed by LibreOffice and Python, this tool makes file processing seamless for developers.
68 lines (67 loc) • 2.37 kB
TypeScript
import { ConversionMap, Format } from './types';
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
/**
* File Processor configuration
*
* @property pythonPath - The path to the python executable
* @property libreOfficePath - The path to the libreoffice executable
*/
interface GlobalConfig {
pythonPath: string;
libreOfficePath: string;
}
interface ConvertFileParams<From extends Format> {
outdir: string;
filePath: string;
from: From;
to: ConversionMap[From];
}
export declare class FileProcessor {
private globalConfig;
private pythonProcessor;
constructor(globalConfig?: Partial<GlobalConfig>);
runSofficeCommand: (command: string) => void;
private handleProcessor;
private handleMultiConversion;
private handleSingleConversion;
/**
* Converts a file from one format to another
*
* @param params - The parameters for the file conversion
* @param params.from - The format of the input file
* @param params.to - The format to convert the file to
* @param params.outdir - The output directory for the converted file
* @param params.filePath - The path to the input file
* @returns void
*/
convertFile: <From extends keyof ConversionMap>(params: Optional<ConvertFileParams<From>, "outdir">) => Promise<void>;
/**
* Merges multiple files into a single file
*
* @param params - The parameters for the file merge
* @param params.filePaths - The paths to the files to merge
* @param params.fileType - The type of the files to merge
* @param params.outputFilePath - The path to the output file
* @returns void
*/
mergeFiles: (params: {
filePaths: string | string[];
fileType: 'pdf' | 'docx' | 'pptx';
outputFilePath: string;
}) => void;
/**
* Splits a file into multiple files
*
* @param params - The parameters for the file split
* @param params.filePath - The path to the file to split
* @param params.fileType - The type of the file to split
* @param params.outputDir - The output directory for the split files
* @returns string[] - Array of all the generated file paths
*/
splitFile: (params: {
filePath: string;
fileType: 'pdf' | 'pptx';
outputDir: string;
}) => string[];
}
export {};