UNPKG

13.7 kBTypeScriptView Raw
1/// <reference types="node" />
2import _fs from 'fs';
3declare function copy(src: string, dist: string, opts?: {
4 /** return true will skip */
5 skip?: (file: string, stat: _fs.Stats) => Promise<boolean | void> | boolean | void;
6 /** override if exists, default is true */
7 override?: boolean;
8}): Promise<void>;
9export declare type WatchDirHandler = (event: string, filename: string) => void;
10export declare type WatchDirOptions = {
11 persistent?: boolean;
12 /** ms, default 300 */
13 threshold?: number;
14};
15declare function watchDir(dir: string, cb: WatchDirHandler): void;
16declare function watchDir(dir: string, options: WatchDirOptions, cb: WatchDirHandler): void;
17export declare const fs: {
18 access: typeof _fs.access.__promisify__;
19 open: typeof _fs.open.__promisify__;
20 rename: typeof _fs.rename.__promisify__;
21 truncate: typeof _fs.truncate.__promisify__;
22 rmdir: typeof _fs.rmdir.__promisify__;
23 mkdir: typeof _fs.mkdir.__promisify__;
24 readdir: typeof _fs.readdir.__promisify__;
25 readlink: typeof _fs.readlink.__promisify__;
26 symlink: typeof _fs.symlink.__promisify__;
27 lstat: typeof _fs.lstat.__promisify__;
28 stat: typeof _fs.stat.__promisify__;
29 link: typeof _fs.link.__promisify__;
30 unlink: typeof _fs.unlink.__promisify__;
31 chmod: typeof _fs.chmod.__promisify__;
32 chown: typeof _fs.chown.__promisify__;
33 utimes: typeof _fs.utimes.__promisify__;
34 realpath: typeof _fs.realpath.__promisify__;
35 mkdtemp: typeof _fs.mkdtemp.__promisify__;
36 writeFile: typeof _fs.writeFile.__promisify__;
37 appendFile: typeof _fs.appendFile.__promisify__;
38 readFile: typeof _fs.readFile.__promisify__;
39 existsSync: typeof _fs.existsSync;
40 createReadString: typeof _fs.createReadStream;
41 createWriteStream: typeof _fs.createWriteStream;
42 constants: typeof _fs.constants;
43 watchDir: typeof watchDir;
44 copy: typeof copy;
45 exists(path: _fs.PathLike): Promise<boolean>;
46 /** exists via lstat, if a symbolic link's target file doesn't exists, `fs.exists` will return false, but `fs.lexists` will return true. */
47 lexists(path: _fs.PathLike): Promise<boolean>;
48 isFile(path: _fs.PathLike): Promise<boolean>;
49 isDirectory(path: _fs.PathLike): Promise<boolean>;
50 isSymbolicLink(path: _fs.PathLike): Promise<boolean>;
51 copyFile: typeof _fs.copyFile.__promisify__ | ((src: _fs.PathLike, dist: _fs.PathLike) => Promise<unknown>);
52 /**
53 * Make directory with parents, like `mkdir -p`
54 * @param dir
55 */
56 mkdirp(dir: string): Promise<void>;
57 /**
58 * Make directory with parents, like `mkdir -p`
59 * @param dir
60 */
61 mkdirpSync(dir: string): void;
62 /**
63 * Remove file or directory recursively, like `rm -rf`
64 * @param path The path to remove
65 * @param opts Options
66 */
67 rmrf(path: string): Promise<void>;
68 outputFile(path: string, data: any, options?: string | (_fs.BaseEncodingOptions & {
69 mode?: string | number | undefined;
70 flag?: string | undefined;
71 }) | null | undefined): Promise<void>;
72 outputFileSync(path: string, data: any, options?: string | (_fs.BaseEncodingOptions & {
73 mode?: string | number | undefined;
74 flag?: string | undefined;
75 }) | null | undefined): void;
76 outputJson(path: string, data: object, options?: ({
77 space?: number | undefined;
78 replacer?: ((key: string, value: any) => any) | undefined;
79 } & string) | ({
80 space?: number | undefined;
81 replacer?: ((key: string, value: any) => any) | undefined;
82 } & _fs.BaseEncodingOptions & {
83 mode?: string | number | undefined;
84 flag?: string | undefined;
85 }) | undefined): Promise<void>;
86 outputJsonSync(path: string, data: any, options?: ({
87 space?: number | undefined;
88 replacer?: ((key: string, value: any) => any) | undefined;
89 } & string) | ({
90 space?: number | undefined;
91 replacer?: ((key: string, value: any) => any) | undefined;
92 } & _fs.BaseEncodingOptions & {
93 mode?: string | number | undefined;
94 flag?: string | undefined;
95 }) | undefined): void;
96 readJson<T = any>(path: string, options?: {
97 encoding?: null | undefined;
98 flag?: string | undefined;
99 } | null | undefined): Promise<T>;
100 readJsonSync<T_1 = any>(path: string, options?: {
101 encoding?: null | undefined;
102 flag?: string | undefined;
103 } | null | undefined): T_1;
104 iter(dir: string, skip: (path: string, stat: _fs.Stats) => Promise<boolean | void> | boolean | void): Promise<void>;
105 renameSync(oldPath: _fs.PathLike, newPath: _fs.PathLike): void;
106 truncateSync(path: _fs.PathLike, len?: number | null | undefined): void;
107 ftruncate: typeof _fs.ftruncate;
108 ftruncateSync(fd: number, len?: number | null | undefined): void;
109 chownSync(path: _fs.PathLike, uid: number, gid: number): void;
110 fchown: typeof _fs.fchown;
111 fchownSync(fd: number, uid: number, gid: number): void;
112 lchown: typeof _fs.lchown;
113 lchownSync(path: _fs.PathLike, uid: number, gid: number): void;
114 chmodSync(path: _fs.PathLike, mode: string | number): void;
115 fchmod: typeof _fs.fchmod;
116 fchmodSync(fd: number, mode: string | number): void;
117 lchmod: typeof _fs.lchmod;
118 lchmodSync(path: _fs.PathLike, mode: string | number): void;
119 statSync(path: _fs.PathLike, options: _fs.BigIntOptions): _fs.BigIntStats;
120 statSync(path: _fs.PathLike, options: _fs.StatOptions): _fs.Stats | _fs.BigIntStats;
121 statSync(path: _fs.PathLike): _fs.Stats;
122 fstat: typeof _fs.fstat;
123 fstatSync(fd: number): _fs.Stats;
124 lstatSync(path: _fs.PathLike): _fs.Stats;
125 linkSync(existingPath: _fs.PathLike, newPath: _fs.PathLike): void;
126 symlinkSync(target: _fs.PathLike, path: _fs.PathLike, type?: "dir" | "file" | "junction" | null | undefined): void;
127 readlinkSync(path: _fs.PathLike, options?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | _fs.BaseEncodingOptions | null | undefined): string;
128 readlinkSync(path: _fs.PathLike, options: _fs.BufferEncodingOption): Buffer;
129 readlinkSync(path: _fs.PathLike, options?: string | _fs.BaseEncodingOptions | null | undefined): string | Buffer;
130 realpathSync: typeof _fs.realpathSync;
131 unlinkSync(path: _fs.PathLike): void;
132 rmdirSync(path: _fs.PathLike, options?: _fs.RmDirOptions | undefined): void;
133 mkdirSync(path: _fs.PathLike, options: _fs.MakeDirectoryOptions & {
134 recursive: true;
135 }): string;
136 mkdirSync(path: _fs.PathLike, options?: string | number | (_fs.MakeDirectoryOptions & {
137 recursive?: false | undefined;
138 }) | null | undefined): void;
139 mkdirSync(path: _fs.PathLike, options?: string | number | _fs.MakeDirectoryOptions | null | undefined): string | undefined;
140 mkdtempSync(prefix: string, options?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | _fs.BaseEncodingOptions | null | undefined): string;
141 mkdtempSync(prefix: string, options: _fs.BufferEncodingOption): Buffer;
142 mkdtempSync(prefix: string, options?: string | _fs.BaseEncodingOptions | null | undefined): string | Buffer;
143 readdirSync(path: _fs.PathLike, options?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | {
144 encoding: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | null;
145 withFileTypes?: false | undefined;
146 } | null | undefined): string[];
147 readdirSync(path: _fs.PathLike, options: "buffer" | {
148 encoding: "buffer";
149 withFileTypes?: false | undefined;
150 }): Buffer[];
151 readdirSync(path: _fs.PathLike, options?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | (_fs.BaseEncodingOptions & {
152 withFileTypes?: false | undefined;
153 }) | null | undefined): string[] | Buffer[];
154 readdirSync(path: _fs.PathLike, options: _fs.BaseEncodingOptions & {
155 withFileTypes: true;
156 }): _fs.Dirent[];
157 close: typeof _fs.close;
158 closeSync(fd: number): void;
159 openSync(path: _fs.PathLike, flags: string | number, mode?: string | number | null | undefined): number;
160 utimesSync(path: _fs.PathLike, atime: string | number | Date, mtime: string | number | Date): void;
161 futimes: typeof _fs.futimes;
162 futimesSync(fd: number, atime: string | number | Date, mtime: string | number | Date): void;
163 fsync: typeof _fs.fsync;
164 fsyncSync(fd: number): void;
165 write: typeof _fs.write;
166 writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null | undefined, length?: number | null | undefined, position?: number | null | undefined): number;
167 writeSync(fd: number, string: string, position?: number | null | undefined, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | null | undefined): number;
168 read: typeof _fs.read;
169 readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: number | null): number;
170 readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: _fs.ReadSyncOptions | undefined): number;
171 readFileSync(path: string | number | Buffer | import("url").URL, options?: {
172 encoding?: null | undefined;
173 flag?: string | undefined;
174 } | null | undefined): Buffer;
175 readFileSync(path: string | number | Buffer | import("url").URL, options: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | {
176 encoding: BufferEncoding;
177 flag?: string | undefined;
178 }): string;
179 readFileSync(path: string | number | Buffer | import("url").URL, options?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | (_fs.BaseEncodingOptions & {
180 flag?: string | undefined;
181 }) | null | undefined): string | Buffer;
182 writeFileSync(path: string | number | Buffer | import("url").URL, data: string | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array, options?: string | (_fs.BaseEncodingOptions & {
183 mode?: string | number | undefined;
184 flag?: string | undefined;
185 }) | null | undefined): void;
186 appendFileSync(file: string | number | Buffer | import("url").URL, data: string | Uint8Array, options?: string | (_fs.BaseEncodingOptions & {
187 mode?: string | number | undefined;
188 flag?: string | undefined;
189 }) | null | undefined): void;
190 watchFile(filename: _fs.PathLike, options: {
191 persistent?: boolean | undefined;
192 interval?: number | undefined;
193 } | undefined, listener: (curr: _fs.Stats, prev: _fs.Stats) => void): void;
194 watchFile(filename: _fs.PathLike, listener: (curr: _fs.Stats, prev: _fs.Stats) => void): void;
195 unwatchFile(filename: _fs.PathLike, listener?: ((curr: _fs.Stats, prev: _fs.Stats) => void) | undefined): void;
196 watch(filename: _fs.PathLike, options: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | {
197 encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | null | undefined;
198 persistent?: boolean | undefined;
199 recursive?: boolean | undefined;
200 } | null | undefined, listener?: ((event: string, filename: string) => void) | undefined): _fs.FSWatcher;
201 watch(filename: _fs.PathLike, options: "buffer" | {
202 encoding: "buffer";
203 persistent?: boolean | undefined;
204 recursive?: boolean | undefined;
205 }, listener?: ((event: string, filename: Buffer) => void) | undefined): _fs.FSWatcher;
206 watch(filename: _fs.PathLike, options: string | {
207 encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | null | undefined;
208 persistent?: boolean | undefined;
209 recursive?: boolean | undefined;
210 } | null, listener?: ((event: string, filename: string | Buffer) => void) | undefined): _fs.FSWatcher;
211 watch(filename: _fs.PathLike, listener?: ((event: string, filename: string) => any) | undefined): _fs.FSWatcher;
212 accessSync(path: _fs.PathLike, mode?: number | undefined): void;
213 createReadStream(path: _fs.PathLike, options?: string | {
214 flags?: string | undefined;
215 encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined;
216 fd?: number | undefined;
217 mode?: number | undefined;
218 autoClose?: boolean | undefined;
219 emitClose?: boolean | undefined;
220 start?: number | undefined;
221 end?: number | undefined;
222 highWaterMark?: number | undefined;
223 } | undefined): _fs.ReadStream;
224 fdatasync: typeof _fs.fdatasync;
225 fdatasyncSync(fd: number): void;
226 copyFileSync(src: _fs.PathLike, dest: _fs.PathLike, flags?: number | undefined): void;
227 writev: typeof _fs.writev;
228 writevSync(fd: number, buffers: NodeJS.ArrayBufferView[], position?: number | undefined): number;
229 readv: typeof _fs.readv;
230 readvSync(fd: number, buffers: NodeJS.ArrayBufferView[], position?: number | undefined): number;
231 opendirSync(path: string, options?: _fs.OpenDirOptions | undefined): _fs.Dir;
232 opendir: typeof _fs.opendir;
233 promises: typeof _fs.promises;
234 Stats: typeof _fs.Stats;
235 Dirent: typeof _fs.Dirent;
236 Dir: typeof _fs.Dir;
237 ReadStream: typeof _fs.ReadStream;
238 WriteStream: typeof _fs.WriteStream;
239 BigIntStats: typeof _fs.BigIntStats;
240};
241export {};
242
\No newline at end of file