UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

28 lines (27 loc) 1.04 kB
/** * Asynchronously ensures that a file exists. * If the directory structure for the file does not exist, it is created. * If the file already exists, it is not modified. * @param filePath The path to the file. Can be a string or a URL object. * @returns A Promise that resolves when the file has been created or confirmed to exist. * @throws Will throw an error if the path exists and is not a file. * @throws Will throw an error if directory or file creation fails for reasons other than the path not existing initially. * @example * ```typescript * import { ensureFile } from "@visulima/fs"; * * (async () => { * try { * await ensureFile("path/to/my/file.txt"); * console.log("File ensured!"); * * await ensureFile(new URL("file:///path/to/another/file.log")); * console.log("Another file ensured!"); * } catch (error) { * console.error("Failed to ensure file:", error); * } * })(); * ``` */ declare const ensureFile: (filePath: URL | string) => Promise<void>; export default ensureFile;