extra-fs
Version:
Useful additions to Deno's inbuilt file system API and [`@std/fs`].
58 lines (57 loc) • 2.48 kB
TypeScript
export * from "@std/fs";
/**
* Read a text file and normalize line endings.
* @param path file path or URL
* @returns file text with normalized line endings
*/ export declare function readTextFile(path: string | URL): Promise<string>;
/**
* Read a text file and normalize line endings (synchronously).
* @param path file path or URL
* @returns file text with normalized line endings
*/ export declare function readTextFileSync(path: string | URL): string;
/**
* Write a text file and normalize line endings.
* @param path file path or URL
* @param text file text
*/ export declare function writeTextFile(path: string | URL, text: string): Promise<void>;
/**
* Write a text file and normalize line endings (synchronously).
* @param path file path or URL
* @param text file text
*/ export declare function writeTextFileSync(path: string | URL, text: string): void;
/**
* Read a JSON file and parse it.
* @param path file path or URL
* @returns parsed JSON data
*/ export declare function readJsonFile(path: string | URL): Promise<unknown>;
/**
* Read a JSON file and parse it (synchronously).
* @param path file path or URL
* @returns parsed JSON data
*/ export declare function readJsonFileSync(path: string | URL): unknown;
/**
* Write data to a JSON file.
* @param path file path or URL
* @param data data to write
*/ export declare function writeJsonFile(path: string | URL, data: unknown): Promise<void>;
/**
* Write data to a JSON file (synchronously).
* @param path file path or URL
* @param data data to write
*/ export declare function writeJsonFileSync(path: string | URL, data: unknown): void;
/**
* Remove outer one-item directories.
* Given `dir/a/b/c/` where `a` and `b` each contain only one directory,
* `unwrapDir("dir")` moves `c` up to `dir` and returns `"dir/a/b/c"`.
* @param dir outer directory
* @param depth maximum depth (-ve ⇒ all) [-1]
* @returns seed directory (its path before it was moved)
*/ export declare function unwrapDir(dir: string | URL, depth?: number): Promise<string>;
/**
* Remove outer one-item directories (synchronously).
* Given `dir/a/b/c/` where `a` and `b` each contain only one directory,
* `unwrapDirSync("dir")` moves `c` up to `dir` and returns `"dir/a/b/c"`.
* @param dir outer directory
* @param depth maximum depth (-ve ⇒ all) [-1]
* @returns seed directory (its path before it was moved)
*/ export declare function unwrapDirSync(dir: string | URL, depth?: number): string;