-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
46 lines (41 loc) · 1.1 KB
/
index.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
import {tempPath} from "../utils";
import {FileAsync} from "./FileAsync";
import {FileSync} from "./FileSync";
interface WriteOptions {
encoding?: string | null;
mode?: string | number;
flag?: string;
}
interface FileWriteOptions extends WriteOptions {
name?: string;
base?: string;
parent?: string;
}
export * from "./FileSync";
export * from "./FileAsync";
/**
* Creates a temporary file with custom options
* @param content Optional file content
* @param options Optional file write options
*/
export async function file(content: any = "", options: FileWriteOptions = {}) {
const f = new FileAsync({
filepath: tempPath(options),
options,
});
await f.init(content);
return f;
}
/**
* Creates a temporary file with custom options in sync mode
* @param content Optional file content
* @param options Optional file write options
*/
export function fileSync(content: any = "", options: FileWriteOptions = {}) {
const {name, base, parent} = options;
return new FileSync({
content,
filepath: tempPath(options),
options,
});
}