UNPKG

8.39 kBTypeScriptView Raw
1/**
2 * This file is part of the @egodigital/egoose distribution.
3 * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
4 *
5 * @egodigital/egoose is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation, version 3.
8 *
9 * @egodigital/egoose is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17/// <reference types="node" />
18import * as fs from 'fs-extra';
19import { IOptions } from 'fast-glob/out/managers/options';
20import { EntryItem } from 'fast-glob/out/types/entries';
21/**
22 * A value, that can be used as file system path.
23 */
24export declare type FileSystemPath = string | Buffer;
25/**
26 * Options for temp file execution.
27 */
28export interface TempFileOptions {
29 /**
30 * The custom directory for the file.
31 */
32 dir?: string;
33 /**
34 * Keep file or delete it after execution.
35 */
36 keep?: boolean;
37 /**
38 * Prefix for the filename.
39 */
40 prefix?: string;
41 /**
42 * Suffix for the filename.
43 */
44 suffix?: string;
45}
46/**
47 * Promise version of 'fs.exists()'.
48 *
49 * @param {string} path The path.
50 *
51 * @return {Promise<boolean>} The promise that indicates if path exists or not.
52 */
53export declare function exists(path: fs.PathLike): Promise<boolean>;
54/**
55 * Scans for files.
56 *
57 * @param {string|string[]} patterns One or more glob patterns.
58 * @param {Partial<IOptions<EntryItem>>} [opts] Custom options.
59 *
60 * @return {Promise<EntryItem[]>} The promise with the found items.
61 */
62export declare function glob(patterns: string | string[], opts?: Partial<IOptions<EntryItem>>): Promise<EntryItem[]>;
63/**
64 * Scans for files (synchronious).
65 *
66 * @param {string|string[]} patterns One or more glob patterns.
67 * @param {Partial<IOptions<EntryItem>>} [opts] Custom options.
68 *
69 * @return {EntryItem[]} The found items.
70 */
71export declare function globSync(patterns: string | string[], opts?: Partial<IOptions<EntryItem>>): EntryItem[];
72/**
73 * Checks if a path represents an existing block device.
74 *
75 * @param {FileSystemPath} path The path to check.
76 * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'.
77 *
78 * @return {Promise<boolean>} The promise with the boolean that represents if path is a block device or not.
79 */
80export declare function isBlockDevice(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>;
81/**
82 * Checks if a path represents an existing block device (synchronous).
83 *
84 * @param {FileSystemPath} path The path to check.
85 * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'.
86 *
87 * @return {boolean} The boolean that represents if path is a block device or not.
88 */
89export declare function isBlockDeviceSync(path: FileSystemPath, useLSTAT?: boolean): boolean;
90/**
91 * Checks if a path represents an existing block device.
92 *
93 * @param {FileSystemPath} path The path to check.
94 * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'.
95 *
96 * @return {Promise<boolean>} The promise with the boolean that represents if path is a block device or not.
97 */
98export declare function isCharDevice(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>;
99/**
100 * Checks if a path represents an existing character device (synchronous).
101 *
102 * @param {FileSystemPath} path The path to check.
103 * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'.
104 *
105 * @return {boolean} The boolean that represents if path is a character device or not.
106 */
107export declare function isCharDeviceSync(path: FileSystemPath, useLSTAT?: boolean): boolean;
108/**
109 * Checks if a path represents an existing FIFO.
110 *
111 * @param {FileSystemPath} path The path to check.
112 * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'.
113 *
114 * @return {Promise<boolean>} The promise with the boolean that represents if path is a FIFO or not.
115 */
116export declare function isFIFO(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>;
117/**
118 * Checks if a path represents an existing FIFO (synchronous).
119 *
120 * @param {FileSystemPath} path The path to check.
121 * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'.
122 *
123 * @return {boolean} The boolean that represents if path is a FIFO or not.
124 */
125export declare function isFIFOSync(path: FileSystemPath, useLSTAT?: boolean): boolean;
126/**
127 * Checks if a path represents an existing directory.
128 *
129 * @param {FileSystemPath} path The path to check.
130 * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'.
131 *
132 * @return {Promise<boolean>} The promise with the boolean that represents if path is a directory or not.
133 */
134export declare function isDir(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>;
135/**
136 * Checks if a path represents an existing directory (synchronous).
137 *
138 * @param {FileSystemPath} path The path to check.
139 * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'.
140 *
141 * @return {boolean} The boolean that represents if path is a directory or not.
142 */
143export declare function isDirSync(path: FileSystemPath, useLSTAT?: boolean): boolean;
144/**
145 * Checks if a path represents an existing file.
146 *
147 * @param {FileSystemPath} path The path to check.
148 * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'.
149 *
150 * @return {Promise<boolean>} The promise with the boolean that represents if path is a file or not.
151 */
152export declare function isFile(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>;
153/**
154 * Checks if a path represents an existing file (synchronous).
155 *
156 * @param {FileSystemPath} path The path to check.
157 * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'.
158 *
159 * @return {boolean} The boolean that represents if path is a file or not.
160 */
161export declare function isFileSync(path: FileSystemPath, useLSTAT?: boolean): boolean;
162/**
163 * Checks if a path represents an existing socket.
164 *
165 * @param {FileSystemPath} path The path to check.
166 * @param {boolean} [useLSTAT] Use 'fs.lstat()' function instead of 'fs.stat()'.
167 *
168 * @return {Promise<boolean>} The promise with the boolean that represents if path is a socket or not.
169 */
170export declare function isSocket(path: FileSystemPath, useLSTAT?: boolean): Promise<boolean>;
171/**
172 * Checks if a path represents an existing socket (synchronous).
173 *
174 * @param {FileSystemPath} path The path to check.
175 * @param {boolean} [useLSTAT] Use 'fs.lstatSync()' function instead of 'fs.statSync()'.
176 *
177 * @return {boolean} The boolean that represents if path is a socket or not.
178 */
179export declare function isSocketSync(path: FileSystemPath, useLSTAT?: boolean): boolean;
180/**
181 * Checks if a path represents an existing symbolic link.
182 *
183 * @param {FileSystemPath} path The path to check.
184 *
185 * @return {Promise<boolean>} The promise with the boolean that represents if path is a symbolic link or not.
186 */
187export declare function isSymLink(path: FileSystemPath): Promise<boolean>;
188/**
189 * Checks if a path represents an existing symbolic link (synchronous).
190 *
191 * @param {FileSystemPath} path The path to check.
192 *
193 * @return {boolean} The boolean that represents if path is a symbolic link or not.
194 */
195export declare function isSymLinkSync(path: FileSystemPath): boolean;
196/**
197 * Executes an action for a temp file.
198 *
199 * @param {Function} action The action to invoke.
200 * @param {TempFileOptions} [opts] Custom options.
201 *
202 * @return {Promise<TResult>} The promise with the result of the action.
203 */
204export declare function tempFile<TResult = any>(action: (tmpFile: string) => Promise<TResult> | TResult, opts?: TempFileOptions): Promise<TResult>;
205/**
206 * Executes an action for a temp file (sync).
207 *
208 * @param {Function} action The action to invoke.
209 * @param {TempFileOptions} [opts] Custom options.
210 *
211 * @return {TResult} The result of the action.
212 */
213export declare function tempFileSync<TResult = any>(action: (tmpFile: string) => TResult, opts?: TempFileOptions): TResult;