@visulima/fs
Version:
Human friendly file system utilities for Node.js
29 lines (28 loc) • 962 B
TypeScript
import type { RetryOptions } from "../types.d.ts";
/**
* Ensures that a directory is empty.
* Deletes directory contents if the directory is not empty.
* If the directory does not exist, it is created.
* The directory itself is not deleted.
* @param dir The path to the directory to empty.
* @param options Optional configuration for the operation. See {@link RetryOptions}.
* @returns A promise that resolves when the directory is empty.
* @example
* ```javascript
* import { emptyDir } from "@visulima/fs";
* import { join } from "node:path";
*
* const clearTempDir = async () => {
* try {
* await emptyDir(join("/tmp", "my-app-temp"));
* console.log("Temporary directory emptied or created.");
* } catch (error) {
* console.error("Failed to empty directory:", error);
* }
* };
*
* clearTempDir();
* ```
*/
declare const emptyDir: (dir: URL | string, options?: RetryOptions) => Promise<void>;
export default emptyDir;