-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool.js
33 lines (30 loc) · 921 Bytes
/
tool.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
const fs = require('fs');
class Tool{
static moment(){
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth().toString().length>1?date.getMonth():'0'+date.getMonth();
let day = date.getDate().toString().length>1?date.getDate():'0'+date.getDate();
return `${year}${month}${day}`;
}
static mkdirFolder(path){
if(!fs.existsSync(path)){
fs.mkdirSync(path)
}
}
static mkdirFile(path,data){
if(fs.existsSync(path)){
fs.writeFileSync(`${path}/data.json`, JSON.stringify(data));
}
}
static emptyFolder(path){
if(fs.existsSync(path)){
let files = fs.readdirSync(path);
files.forEach(function(file){
var curPath = path + "/" + file;
fs.unlinkSync(curPath);
});
}
}
}
module.exports = Tool;