UNPKG

easy-cli-framework

Version:

A framework for building CLI applications that are robust and easy to maintain. Supports theming, configuration files, interactive prompts, and more.

64 lines (63 loc) 1.78 kB
/** * A class to read and write CSV files. * * @class CsvFile * * @template TFileObject The type of object that the CSV file contains. */ export declare class CsvFile<TFileObject> { private readonly path; constructor(path: string); /** * Read a CSV file and parse it into an array of objects. * * @throws {Error} If the file is not found or there is an error reading the file. * * @returns The parsed CSV file as an array of objects. * * @example * ```typescript * const csvFile = new CsvFile('data.csv'); * const data = await csvFile.read(); * ``` */ read: () => Promise<TFileObject[]>; /** * Write an array of objects to a CSV file overwriting the existing file. * * @param data The data to write to the CSV file. * * @throws {Error} If there is an error writing the file. * * @returns A promise that resolves when the file is written. * * @example * ```typescript * const csvFile = new CsvFile('data.csv'); * await csvFile.write([ * { name: 'Alice', age: 25 }, * { name: 'Bob', age: 30 }, * ]); * ``` */ write: (data: TFileObject[]) => Promise<void>; /** * Append an array of objects to an existing CSV file. * * @param data The data to append to the CSV file. * * @throws {Error} If there is an error writing the file. * * @returns A promise that resolves when the file is written. * * @example * ```typescript * const csvFile = new CsvFile('data.csv'); * await csvFile.append([ * { name: 'Alice', age: 25 }, * { name: 'Bob', age: 30 }, * ]); * ``` */ append: (data: TFileObject[]) => Promise<void>; }