UNPKG

@egodigital/egoose

Version:

Helper classes and functions for Node.js 10 or later.

213 lines (212 loc) 8.25 kB
/** * This file is part of the @egodigital/egoose distribution. * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/) * * @egodigital/egoose is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, version 3. * * @egodigital/egoose is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /// <reference types="node" /> import * as fastGlob from 'fast-glob'; import * as fs from 'fs-extra'; /** * A value, that can be used as file system path. */ export declare type FileSystemPath = string | Buffer; /** * Options for temp file execution. */ export interface TempFileOptions { /** * The custom directory for the file. */ dir?: string; /** * Keep file or delete it after execution. */ keep?: boolean; /** * Prefix for the filename. */ prefix?: string; /** * Suffix for the filename. */ suffix?: string; } /** * Promise version of 'fs.exists()'. * * @param {string} path The path. * * @return {Promise<boolean>} The promise that indicates if path exists or not. */ export declare function exists(path: fs.PathLike): Promise<boolean>; /** * Scans for files. * * @param {string|string[]} patterns One or more glob patterns. * @param {FastGlob.Options} [opts] Custom options. * * @return {Promise<string[]>} The promise with the found items. */ export declare function glob(patterns: string | string[], opts?: fastGlob.Options): Promise<string[]>; /** * Scans for files (synchronious). * * @param {string|string[]} patterns One or more glob patterns. * @param {FastGlob.Options} [opts] Custom options. * * @return {string[]} The found items. */ export declare function globSync(patterns: string | string[], opts?: fastGlob.Options): string[]; /** * Checks if a path represents an existing block device. * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'. * * @return {Promise<boolean>} The promise with the boolean that represents if path is a block device or not. */ export declare function isBlockDevice(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>; /** * Checks if a path represents an existing block device (synchronous). * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'. * * @return {boolean} The boolean that represents if path is a block device or not. */ export declare function isBlockDeviceSync(path: FileSystemPath, useLSTAT?: boolean): boolean; /** * Checks if a path represents an existing block device. * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'. * * @return {Promise<boolean>} The promise with the boolean that represents if path is a block device or not. */ export declare function isCharDevice(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>; /** * Checks if a path represents an existing character device (synchronous). * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'. * * @return {boolean} The boolean that represents if path is a character device or not. */ export declare function isCharDeviceSync(path: FileSystemPath, useLSTAT?: boolean): boolean; /** * Checks if a path represents an existing FIFO. * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'. * * @return {Promise<boolean>} The promise with the boolean that represents if path is a FIFO or not. */ export declare function isFIFO(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>; /** * Checks if a path represents an existing FIFO (synchronous). * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'. * * @return {boolean} The boolean that represents if path is a FIFO or not. */ export declare function isFIFOSync(path: FileSystemPath, useLSTAT?: boolean): boolean; /** * Checks if a path represents an existing directory. * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'. * * @return {Promise<boolean>} The promise with the boolean that represents if path is a directory or not. */ export declare function isDir(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>; /** * Checks if a path represents an existing directory (synchronous). * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'. * * @return {boolean} The boolean that represents if path is a directory or not. */ export declare function isDirSync(path: FileSystemPath, useLSTAT?: boolean): boolean; /** * Checks if a path represents an existing file. * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'. * * @return {Promise<boolean>} The promise with the boolean that represents if path is a file or not. */ export declare function isFile(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>; /** * Checks if a path represents an existing file (synchronous). * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'. * * @return {boolean} The boolean that represents if path is a file or not. */ export declare function isFileSync(path: FileSystemPath, useLSTAT?: boolean): boolean; /** * Checks if a path represents an existing socket. * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'. * * @return {Promise<boolean>} The promise with the boolean that represents if path is a socket or not. */ export declare function isSocket(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>; /** * Checks if a path represents an existing socket (synchronous). * * @param {FileSystemPath} path The path to check. * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'. * * @return {boolean} The boolean that represents if path is a socket or not. */ export declare function isSocketSync(path: FileSystemPath, useLSTAT?: boolean): boolean; /** * Checks if a path represents an existing symbolic link. * * @param {FileSystemPath} path The path to check. * * @return {Promise<boolean>} The promise with the boolean that represents if path is a symbolic link or not. */ export declare function isSymLink(path: FileSystemPath): Promise<boolean>; /** * Checks if a path represents an existing symbolic link (synchronous). * * @param {FileSystemPath} path The path to check. * * @return {boolean} The boolean that represents if path is a symbolic link or not. */ export declare function isSymLinkSync(path: FileSystemPath): boolean; /** * Executes an action for a temp file. * * @param {Function} action The action to invoke. * @param {TempFileOptions} [opts] Custom options. * * @return {Promise<TResult>} The promise with the result of the action. */ export declare function tempFile<TResult = any>(action: (tmpFile: string) => Promise<TResult> | TResult, opts?: TempFileOptions): Promise<TResult>; /** * Executes an action for a temp file (sync). * * @param {Function} action The action to invoke. * @param {TempFileOptions} [opts] Custom options. * * @return {TResult} The result of the action. */ export declare function tempFileSync<TResult = any>(action: (tmpFile: string) => TResult, opts?: TempFileOptions): TResult;