1 |
|
2 |
|
3 | import {
|
4 | PathLike,
|
5 | readFile as fsReadFile,
|
6 | readFileSync as fsReadFileSync,
|
7 | writeFile as fsWriteFile,
|
8 | writeFileSync as fsWriteFileSync,
|
9 | } from "fs";
|
10 | import { Url } from "url";
|
11 |
|
12 | export type Path = PathLike | Url;
|
13 |
|
14 | export interface FS {
|
15 | readFile: typeof fsReadFile;
|
16 | readFileSync: typeof fsReadFileSync;
|
17 | writeFile: typeof fsWriteFile;
|
18 | writeFileSync: typeof fsWriteFileSync;
|
19 | }
|
20 |
|
21 | export type JFReadOptions =
|
22 | | {
|
23 | encoding?: string | null | undefined;
|
24 | flag?: string | undefined;
|
25 | throws?: boolean | undefined;
|
26 | fs?: FS | undefined;
|
27 | reviver?: ((key: any, value: any) => any) | undefined;
|
28 | }
|
29 | | string
|
30 | | null
|
31 | | undefined;
|
32 |
|
33 | export type JFWriteOptions =
|
34 | | {
|
35 | encoding?: string | null | undefined;
|
36 | mode?: string | number | undefined;
|
37 | flag?: string | undefined;
|
38 | fs?: FS | undefined;
|
39 | EOL?: string | undefined;
|
40 | spaces?: string | number | undefined;
|
41 | replacer?: ((key: string, value: any) => any) | undefined;
|
42 | }
|
43 | | string
|
44 | | null;
|
45 |
|
46 | export type ReadCallback = (err: NodeJS.ErrnoException | null, data: any) => void;
|
47 | export type WriteCallback = (err: NodeJS.ErrnoException | null) => void;
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | export function readFile(file: Path, options: JFReadOptions, callback: ReadCallback): void;
|
53 | export function readFile(file: Path, callback: ReadCallback): void;
|
54 | export function readFile(file: Path, options?: JFReadOptions): Promise<any>;
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | export function readFileSync(file: Path, options?: JFReadOptions): any;
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | export function writeFile(file: Path, obj: any, options: JFWriteOptions, callback: WriteCallback): void;
|
65 | export function writeFile(file: Path, obj: any, callback: WriteCallback): void;
|
66 | export function writeFile(file: Path, obj: any, options?: JFWriteOptions): Promise<void>;
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | export function writeFileSync(file: Path, obj: any, options?: JFWriteOptions): void;
|