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