forked from sindresorhus/write-json-file
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
79 lines (59 loc) · 1.46 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
export type Replacer = (this: unknown, key: string, value: unknown) => unknown;
export type SortKeys = (a: string, b: string) => number;
export interface Options {
/**
Indentation as a string or number of spaces.
Pass in `undefined` for no formatting.
If you set both this and `detectIndent`, this value will be used when the indentation cannot be detected.
@default '\t'
*/
readonly indent?: string | number | undefined;
/**
Detect indentation automatically if the file exists.
@default false
*/
readonly detectIndent?: boolean;
/**
Sort the keys recursively.
Optionally pass in a compare function.
@default false
*/
readonly sortKeys?: boolean | SortKeys;
/**
Passed into `JSON.stringify`.
*/
readonly replacer?: Replacer | ReadonlyArray<number | string>;
/**
The mode used when writing the file.
@default 0o666
*/
readonly mode?: number;
}
/**
Stringify and write JSON to a file atomically.
Creates directories for you as needed.
@example
```
import {writeJsonFile} from 'write-json-file';
await writeJsonFile('foo.json', {foo: true});
```
*/
export function writeJsonFile(
filePath: string,
data: unknown,
options?: Options
): Promise<void>;
/**
Stringify and write JSON to a file atomically.
Creates directories for you as needed.
@example
```
import {writeJsonFileSync} from 'write-json-file';
writeJsonFileSync('foo.json', {foo: true});
```
*/
export function writeJsonFileSync(
filePath: string,
data: unknown,
options?: Options
): void;