1 | export type JSONValue = boolean | number | string | null | JSONArray | JSONObject;
|
2 | export interface JSONArray extends Array<JSONValue> {
|
3 | }
|
4 | export interface JSONObject {
|
5 | [key: string]: JSONValue | undefined;
|
6 | }
|
7 | type Defined<T> = T extends undefined ? never : T;
|
8 | type Options<TJSONObject extends JSONObject> = {
|
9 | badJsonDefault?: TJSONObject;
|
10 | jsonParseErrorDefault?: TJSONObject;
|
11 | cantReadFileDefault?: TJSONObject;
|
12 | ensureDir?: boolean;
|
13 | default?: TJSONObject;
|
14 | json5?: boolean;
|
15 | space?: number;
|
16 | addNewLineAtEOF?: boolean;
|
17 | };
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export default class JsonFile<TJSONObject extends JSONObject> {
|
26 | file: string;
|
27 | options: Options<TJSONObject>;
|
28 | static read: typeof read;
|
29 | static readAsync: typeof readAsync;
|
30 | static parseJsonString: typeof parseJsonString;
|
31 | static writeAsync: typeof writeAsync;
|
32 | static getAsync: typeof getAsync;
|
33 | static setAsync: typeof setAsync;
|
34 | static mergeAsync: typeof mergeAsync;
|
35 | static deleteKeyAsync: typeof deleteKeyAsync;
|
36 | static deleteKeysAsync: typeof deleteKeysAsync;
|
37 | static rewriteAsync: typeof rewriteAsync;
|
38 | constructor(file: string, options?: Options<TJSONObject>);
|
39 | read(options?: Options<TJSONObject>): TJSONObject;
|
40 | readAsync(options?: Options<TJSONObject>): Promise<TJSONObject>;
|
41 | writeAsync(object: TJSONObject, options?: Options<TJSONObject>): Promise<TJSONObject>;
|
42 | parseJsonString(json: string, options?: Options<TJSONObject>): TJSONObject;
|
43 | getAsync<K extends keyof TJSONObject, TDefault extends TJSONObject[K] | null>(key: K, defaultValue: TDefault, options?: Options<TJSONObject>): Promise<Defined<TJSONObject[K]> | TDefault>;
|
44 | setAsync(key: string, value: unknown, options?: Options<TJSONObject>): Promise<TJSONObject>;
|
45 | mergeAsync(sources: Partial<TJSONObject> | Partial<TJSONObject>[], options?: Options<TJSONObject>): Promise<TJSONObject>;
|
46 | deleteKeyAsync(key: string, options?: Options<TJSONObject>): Promise<TJSONObject>;
|
47 | deleteKeysAsync(keys: string[], options?: Options<TJSONObject>): Promise<TJSONObject>;
|
48 | rewriteAsync(options?: Options<TJSONObject>): Promise<TJSONObject>;
|
49 | _getOptions(options?: Options<TJSONObject>): Options<TJSONObject>;
|
50 | }
|
51 | declare function read<TJSONObject extends JSONObject>(file: string, options?: Options<TJSONObject>): TJSONObject;
|
52 | declare function readAsync<TJSONObject extends JSONObject>(file: string, options?: Options<TJSONObject>): Promise<TJSONObject>;
|
53 | declare function parseJsonString<TJSONObject extends JSONObject>(json: string, options?: Options<TJSONObject>, fileName?: string): TJSONObject;
|
54 | declare function getAsync<TJSONObject extends JSONObject, K extends keyof TJSONObject, DefaultValue>(file: string, key: K, defaultValue: DefaultValue, options?: Options<TJSONObject>): Promise<any>;
|
55 | declare function writeAsync<TJSONObject extends JSONObject>(file: string, object: TJSONObject, options?: Options<TJSONObject>): Promise<TJSONObject>;
|
56 | declare function setAsync<TJSONObject extends JSONObject>(file: string, key: string, value: unknown, options?: Options<TJSONObject>): Promise<TJSONObject>;
|
57 | declare function mergeAsync<TJSONObject extends JSONObject>(file: string, sources: Partial<TJSONObject> | Partial<TJSONObject>[], options?: Options<TJSONObject>): Promise<TJSONObject>;
|
58 | declare function deleteKeyAsync<TJSONObject extends JSONObject>(file: string, key: string, options?: Options<TJSONObject>): Promise<TJSONObject>;
|
59 | declare function deleteKeysAsync<TJSONObject extends JSONObject>(file: string, keys: string[], options?: Options<TJSONObject>): Promise<TJSONObject>;
|
60 | declare function rewriteAsync<TJSONObject extends JSONObject>(file: string, options?: Options<TJSONObject>): Promise<TJSONObject>;
|
61 | export {};
|