UNPKG

@accounter/server

Version:
132 lines (131 loc) 4.02 kB
/** * File Helper Utilities for SHAAM Uniform Format Generator * Provides utilities for creating and managing File objects */ /** * Creates a File object with the given text content and filename * This is a utility function to standardize File creation across the package * * @param text - The text content for the file * @param name - The filename (should include extension) * @param options - Optional File constructor options * @returns A File object containing the text content * * @example * ```typescript * const iniFile = createFile(iniText, 'report.INI.TXT'); * const dataFile = createFile(dataText, 'report.BKMVDATA.TXT'); * ``` */ export declare function createFile(text: string, name: string, options?: FilePropertyBag): File; /** * Creates an INI.TXT File object with standardized naming * * @param iniText - The INI text content * @param baseFileName - Base filename (without extension) * @returns A File object for the INI file * * @example * ```typescript * const iniFile = createIniFile(iniText, 'my-report'); * // Creates file named: my-report.INI.TXT * ``` */ export declare function createIniFile(iniText: string, baseFileName?: string): File; /** * Creates a BKMVDATA.TXT File object with standardized naming * * @param dataText - The data text content * @param baseFileName - Base filename (without extension) * @returns A File object for the data file * * @example * ```typescript * const dataFile = createDataFile(dataText, 'my-report'); * // Creates file named: my-report.BKMVDATA.TXT * ``` */ export declare function createDataFile(dataText: string, baseFileName?: string): File; /** * Creates both INI and Data File objects from the report output * * @param iniText - The INI text content * @param dataText - The data text content * @param baseFileName - Base filename (without extension) * @returns An object containing both File objects * * @example * ```typescript * const { iniFile, dataFile } = createShaamFiles(iniText, dataText, 'my-report'); * ``` */ export declare function createShaamFiles(iniText: string, dataText: string, baseFileName?: string): { iniFile: File; dataFile: File; }; /** * Validates that a File object appears to be a valid SHAAM format file * * @param file - The File object to validate * @param expectedType - Expected file type ('ini' | 'data') * @returns True if the file appears valid * * @example * ```typescript * const isValidIni = validateShaamFile(iniFile, 'ini'); * const isValidData = validateShaamFile(dataFile, 'data'); * ``` */ export declare function validateShaamFile(file: File, expectedType: 'ini' | 'data'): boolean; /** * Reads text content from a File object * This is an async utility for reading File objects back to text * * @param file - The File object to read * @returns Promise that resolves to the text content * * @example * ```typescript * const text = await readFileAsText(file); * ``` */ export declare function readFileAsText(file: File): Promise<string>; /** * Gets file information from a File object * * @param file - The File object to inspect * @returns File information object * * @example * ```typescript * const info = getFileInfo(iniFile); * console.log(`File: ${info.name}, Size: ${info.size} bytes`); * ``` */ export declare function getFileInfo(file: File): { name: string; size: number; type: string; lastModified: number; }; /** * File naming utilities for SHAAM format files */ export declare const FileNaming: { /** * Generates a standardized INI filename */ readonly iniFileName: (base?: string) => string; /** * Generates a standardized data filename */ readonly dataFileName: (base?: string) => string; /** * Extracts base filename from a SHAAM file */ readonly extractBaseName: (fileName: string) => string; /** * Validates filename follows SHAAM conventions */ readonly isValidShaamFileName: (fileName: string) => boolean; };