-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (58 loc) · 1.12 KB
/
index.js
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
const fs = require('fs')
module.exports = {
exists,
read,
write,
delete: remove,
remove,
rm: remove,
mkdir,
makeDir: mkdir,
makeDirectory: mkdir,
removeDir: removeDirectory,
removeDirectory,
rmdir: removeDirectory,
rmDir: removeDirectory
};
function exists(path) {
return fs.existsSync(path);
}
function read(fileName) {
try {
const content = fs.readFileSync(fileName).toString();
return content;
} catch (e) {
throw new Error(e);
}
}
function write(fileName, content) {
if (!fileName || typeof content !== 'string') {
throw new Error('Both file name and content must be provided in order to write to file');
}
try {
fs.writeFileSync(fileName, content);
} catch (e) {
throw new Error(e);
}
}
function remove(fileName) {
try {
fs.unlinkSync(fileName);
} catch (e) {
throw new Error(e);
}
}
function mkdir(dirPath) {
try {
fs.mkdirSync(dirPath, { recursive: true });
} catch (e) {
throw new Error(e);
}
}
function removeDirectory(dirName) {
try {
fs.rmdirSync(dirName, { recursive: true });
} catch (e) {
throw new Error(e);
}
}