-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
39 lines (32 loc) · 828 Bytes
/
utils.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
const { DRIVE_FOLDER_TYPE } = require("./constants");
const bytesToMB = (node) => {
if ("size" in node) node.size = (node.size / (1024 * 1024)).toFixed(2);
};
const isFolder = (node) => {
return node.mimeType === DRIVE_FOLDER_TYPE;
};
function logTree(TREE) {
console.log(JSON.stringify(TREE, null, 2));
}
const jsonToFile = async (filename, jsonObject) => {
const fsp = require("fs").promises;
await fsp.writeFile(filename, JSON.stringify(jsonObject));
};
const fileToJSON = async (filename) => {
const fsp = require("fs").promises;
return await fsp.readFile(filename).then((data) => {
return JSON.parse(data);
});
};
const shutDown = () => {
const process = require("process");
process.exit();
};
module.exports = {
bytesToMB,
isFolder,
logTree,
jsonToFile,
fileToJSON,
shutDown,
};