@tomjs/node
Version:
A collection of functions for `node.js` projects
168 lines (162 loc) • 5.38 kB
TypeScript
/**
* Synchronously copies a file or a directory from the source path to the destination path.
* If the source is a directory, it recursively copies the entire directory structure.
* If the source is a file, it directly copies the file to the destination.
*
* @param src The source path of the file or directory to be copied.
* @param dest The destination path where the file or directory should be copied to.
*/
declare function copySync(src: string, dest: string): void;
/**
* Asynchronously copies a file or a directory from the source path to the destination path.
* If the source is a directory, it recursively copies the entire directory structure.
* If the source is a file, it directly copies the file to the destination.
*
* @param src The source path of the file or directory to be copied.
* @param dest The destination path where the file or directory should be copied to.
*/
declare function copy(src: string, dest: string): Promise<void>;
/**
* Asynchronously creates a directory. Returns undefined, or if recursive is true, the first directory path created.
* @param dir directory path.
* @param mode directory permission mode. If not specified, defaults to 0o777.
* @returns
*/
declare function mkdir(dir: string, mode?: string | number): Promise<string | undefined>;
/**
* Asynchronously creates a directory. Returns undefined, or if recursive is true, the first directory path created.
* @param dir directory path.
* @param mode directory permission mode. If not specified, defaults to 0o777.
* @alias mkdir
* @returns
*/
declare const mkdirp: typeof mkdir;
/**
* Synchronously creates a directory. Returns undefined, or if recursive is true, the first directory path created.
* @param dir directory path.
* @param mode directory permission mode. If not specified, defaults to 0o777.
* @returns
*/
declare function mkdirSync(dir: string, mode?: string | number): string | undefined;
/**
* Synchronously creates a directory. Returns undefined, or if recursive is true, the first directory path created.
* @param dir directory path.
* @param mode directory permission mode. If not specified, defaults to 0o777.
* @returns
*/
declare const mkdirpSync: typeof mkdirSync;
/**
* 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 directory path.
*/
declare function emptyDir(dir: string): Promise<void>;
/**
* 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 directory path.
*/
declare function emptyDirSync(dir: string): void;
/**
* Synchronously reads the entire contents of a file.
* @param path A path to a file
*/
declare function readFileSync(path: string): string;
/**
* Asynchronously reads the entire contents of a file.
* @param path A path to a file
*/
declare function readFile(path: string): Promise<string>;
/**
* Synchronously writes data to a file.
* @param path A path to a file
* @param data Data to write to the file
*/
declare function writeFileSync(path: string, data: string): void;
/**
* Asynchronously writes data to a file, replacing the file if it already exists.
* @param path A path to a file
* @param data Data to write to the file
*/
declare function writeFile(path: string, data: string): Promise<void>;
/**
* Synchronously reads the entire contents of a file, and returns the parsed JSON.
* @param path path to json file
*/
declare function readJsonSync(path: string): any;
/**
* Asynchronously reads the entire contents of a file, and returns the parsed JSON.
* @param path path to json file
*/
declare function readJson(path: string): Promise<any>;
interface WriteJsonOptions {
space?: string | number;
replacer?: (key: string, value: any) => any;
}
/**
* Synchronously writes json data to a file.
* @param path path to json file
* @param data data to write
*/
declare function writeJsonSync(
path: string,
data: string | object,
options?: WriteJsonOptions,
): void;
/**
* Synchronously writes json data to a file.
* @param path path to json file
* @param data data to write
*/
declare function writeJson(
path: string,
data: string | object,
options?: WriteJsonOptions,
): Promise<void>;
/**
* Removes files and directories (modeled on the standard POSIX rm utility).
* @deprecated
* @returns
*/
declare function removeFile(path: string): Promise<void>;
/**
* Removes files and directories (modeled on the standard POSIX rm utility).
* @deprecated
* @returns
*/
declare function removeFileSync(path: string): void;
/**
* Removes files and directories (modeled on the standard POSIX rm utility).
* @returns
*/
declare function rm(path: string): Promise<void>;
/**
* Removes files and directories (modeled on the standard POSIX rm utility).
* @returns
*/
declare function rmSync(path: string): void;
declare const _default: {};
export {
type WriteJsonOptions,
copy,
copySync,
_default as default,
emptyDir,
emptyDirSync,
mkdir,
mkdirSync,
mkdirp,
mkdirpSync,
readFile,
readFileSync,
readJson,
readJsonSync,
removeFile,
removeFileSync,
rm,
rmSync,
writeFile,
writeFileSync,
writeJson,
writeJsonSync,
};