UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

93 lines 3.1 kB
/** * Reads and parses a JSON file. * Throws an error if the file content is not valid JSON. * @param {string} filePath * @returns {Promise<any>} */ export function readJsonFileAsync(filePath: string): Promise<any>; /** * Saves an object as JSON to a file. * Automatically creates the directory if it does not exist. * @param {string} filePath * @param {any} data * @param {number} [spaces=2] * @returns {Promise<void>} */ export function writeJsonFileAsync(filePath: string, data: any, spaces?: number): Promise<void>; /** * Clears all contents inside a directory but keeps the directory. * @param {string} dirPath */ export function clearDirectoryAsync(dirPath: string): Promise<void>; /** * Checks whether a directory is empty. * @param {string} dirPath * @returns {Promise<boolean>} */ export function isDirEmptyAsync(dirPath: string): Promise<boolean>; /** * Copies a file to a destination. * @param {string} src * @param {string} dest * @param {number} [mode] * @returns {Promise<void>} */ export function ensureCopyFileAsync(src: string, dest: string, mode?: number): Promise<void>; /** * Deletes a file (If the file exists). * @param {string} filePath * @returns {Promise<boolean>} */ export function tryDeleteFileAsync(filePath: string): Promise<boolean>; /** * Writes text to a file (Ensures that the directory exists, creating it recursively if needed). * @param {string} filePath * @param {string} content * @param {import('fs').WriteFileOptions} [ops='utf-8'] * @returns {Promise<void>} */ export function writeTextFileAsync(filePath: string, content: string, ops?: import("fs").WriteFileOptions): Promise<void>; /** * Lists all files and dirs in a directory (optionally recursive). * @param {string} dirPath * @param {boolean} [recursive=false] * @returns {Promise<{ files: string[]; dirs: string[] }>} */ export function listFilesAsync(dirPath: string, recursive?: boolean): Promise<{ files: string[]; dirs: string[]; }>; /** * Lists all directories in a directory (optionally recursive). * @param {string} dirPath * @param {boolean} [recursive=false] * @returns {Promise<string[]>} */ export function listDirsAsync(dirPath: string, recursive?: boolean): Promise<string[]>; /** * Returns the size of a file in bytes. * @param {string} filePath * @returns {Promise<number>} */ export function fileSizeAsync(filePath: string): Promise<number>; /** * Returns the total size of a directory in bytes. * @param {string} dirPath * @returns {Promise<number>} */ export function dirSizeAsync(dirPath: string): Promise<number>; /** * Restores the most recent backup of a file. * @param {string} filePath * @param {string} [ext='bak'] * @returns {Promise<void>} */ export function restoreLatestBackupAsync(filePath: string, ext?: string): Promise<void>; /** * Creates a backup copy of a file with .bak timestamp suffix. * @param {string} filePath * @param {string} [ext='bak'] * @returns {Promise<void>} */ export function backupFileAsync(filePath: string, ext?: string): Promise<void>; //# sourceMappingURL=asyncFuncs.d.mts.map