UNPKG

@oniryk/xlsx

Version:

A lightweight, efficient TypeScript library for generating single-sheet Excel XLSX files with support for large datasets

82 lines (81 loc) 2.71 kB
import { WriteStream } from 'fs'; /** * Escapes special characters in a string for XML content * Converts &, <, >, ", and ' to their XML entity equivalents * * @param value - Value to escape * @returns Escaped string if input is string, otherwise returns original value * * @example * escapeXML('Hello < World') // returns 'Hello &lt; World' */ export declare function escapeXML(value: any): any; /** * Converts a JavaScript Date to Excel serial number format * Excel uses days since December 30, 1899 as its internal date representation * * @param date - JavaScript Date object to convert * @returns Number of days since Excel epoch, with fractional part for time */ export declare function convertToExcelDate(date: Date): number; /** * Formats a date as YYYY-MM-DD * * @param date - Date to format * @returns Date string in YYYY-MM-DD format * * @example * simpleDateFormat(new Date('2024-01-31')) // returns '2024-01-31' */ export declare function simpleDateFormat(date: Date): string; /** * Type guard to check if a value is a valid Date object * * @param value - Value to check * @returns True if value is a Date instance */ export declare function isValidDate(value: any): value is Date; /** * Creates a read stream that automatically deletes the file when finished * Useful for temporary file handling * * @param filePath - Path to the file to stream * @returns ReadStream that will delete the source file when complete */ export declare function destructiveStream(filePath: string): import("fs").ReadStream; /** * Simple performance measurement utility * * @param label - Label to identify the performance measurement * @returns Object with end function to log elapsed time * * @example * const timer = perf('operation'); * // ... do something ... * timer.end(); // logs: "operation: XXXms" */ export declare function perf(label: string): { end: () => void; }; /** Function type for promised write operations */ export type PromisedWriter = (...content: string[]) => Promise<void>; /** * Creates a promise-based writer function for a WriteStream * Allows for easier async/await usage of stream writes * * @param stream - WriteStream to wrap * @returns Promise-based write function * * @example * const writer = promiseWrite(writeStream); * await writer('content1', 'content2'); */ export declare function promiseWrite(stream: WriteStream): PromisedWriter; /** * Safely finishes a write stream * Returns a promise that resolves when the stream is fully closed * * @param stream - WriteStream to finish * @returns Promise that resolves when stream is finished */ export declare function finishStream(stream: WriteStream): Promise<void>;