UNPKG

@tomjs/node-utils

Version:

A collection of functions for `node.js` projects

90 lines (75 loc) • 2.86 kB
declare const _default: {}; export default _default; /** * 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 */ export declare function mkdir(dir: string, mode?: string | number): Promise<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 */ export declare function mkdirSync(dir: string, mode?: string | number): string | undefined; /** * Asynchronously reads the entire contents of a file. * @param path A path to a file */ export declare function readFile(path: string): Promise<string>; /** * Synchronously reads the entire contents of a file. * @param path A path to a file */ export declare function readFileSync(path: string): string; /** * Asynchronously reads the entire contents of a file, and returns the parsed JSON. * @param path path to json file */ export declare function readJson(path: string): Promise<any>; /** * Synchronously reads the entire contents of a file, and returns the parsed JSON. * @param path path to json file */ export declare function readJsonSync(path: string): any; /** * Removes files and directories (modeled on the standard POSIX rm utility). * @returns */ export declare function removeFile(path: string): Promise<void>; /** * Removes files and directories (modeled on the standard POSIX rm utility). * @returns */ export declare function removeFileSync(path: 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 */ export declare function writeFile(path: string, data: string): Promise<void>; /** * Synchronously writes data to a file. * @param path A path to a file * @param data Data to write to the file */ export declare function writeFileSync(path: string, data: string): void; /** * Synchronously writes json data to a file. * @param path path to json file * @param data data to write */ export declare function writeJson(path: string, data: string | object, options?: WriteJsonOptions): Promise<void>; export declare 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 */ export declare function writeJsonSync(path: string, data: string | object, options?: WriteJsonOptions): void; export { }