UNPKG

nope-js-node

Version:

NoPE Runtime for Nodejs. For Browser-Support please use nope-browser

88 lines (87 loc) 3.35 kB
/** * @module files * @author Martin Karkowski * @email m.karkowski@zema.de * * Helper to handle with files. * * * Central Elements are: * - {@link FOLDER_SPLIT}: The folder splitchar of the os. * - {@link createFile}: A Helper to create a file. * - {@link createPath}: A Helper to create a file and the corresponding folders if they doesnt exists. * - {@link deletePath}: A Helper to remove a dir, * - {@link relativePath}: Creates a releative path * - {@link listFiles}: list files of a specific type in defined path. * - {@link listFolders}: list Folders in defined path. */ /// <reference types="node" /> import { exists as __exists, ObjectEncodingOptions } from "fs"; export declare const exists: typeof __exists.__promisify__; /** * Helper to determine the Path Seperator. * @returns */ export declare function getPathSeparator(): "/" | "\\"; /** * Helper to convert the Path to an os specific path. * @param path * @returns */ export declare function convertPathToOsPath(path: string): string; export declare const FOLDER_SPLIT: string; /** * Function to create a File * @param fileName Read the File. * @param content content which should be stored * @param options The options to write the file. See original docu: https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_writefile_file_data_options_callback */ export declare function createFile(fileName: string, content: string, options?: (ObjectEncodingOptions & { mode?: string | number; flag?: string | number; }) | "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"): Promise<string>; /** * Function to create a File at a given Path. If the File or the dir doesnt exists it will be created. * @param path Read the File. * @param content content which should be stored * @param options The options to write the file. See original docu: https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_writefile_file_data_options_callback */ export declare function createPath(path: string): Promise<string>; /** * Deletes the complete Path recursevly. * > *WARNING: * Deletes Everything in the Folder. * * Example: * `deletePath('C:\\Test');` * * This deletes all Files and Subfolders in the given Path. * Furthermore the Folder Test itself is removed. * * @export * @param {string} dirPath */ export declare function deletePath(dirPath: string): Promise<void>; /** * Creates a relative Path based on the Folder where * 'node ...' was typed. * @param _dirPath the path to Check * @param _currentPath the current Path. */ export declare function relativePath(_dirPath: string, _currentPath?: string): string; /** * Returns a List of File-Names. * * @export * @param {string} dirPath Path where the system should look * @param {string} [type=''] specified ending of the File. For Instance '.conf' * @returns {Array<string>} List containing all Files */ export declare function listFiles(dirPath: string, type?: string): Promise<string[]>; /** * Lists all Subfolders in the given Path * * @export * @param {string} dirPath Start path * @returns {Array<string>} Array containing all Pathes to the Subfolders */ export declare function listFolders(dirPath: string): Promise<Array<string>>;