-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
52 lines (45 loc) · 1.27 KB
/
helper.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
var fs = require("fs");
module.exports = {
msToTime: function (s) {
// Pad to 2 or 3 digits, default is 2
function pad(n, z) {
z = z || 2;
return ("00" + n).slice(-z);
}
var ms = s % 1000;
s = (s - ms) / 1000;
var secs = s % 60;
s = (s - secs) / 60;
var mins = s % 60;
var hrs = (s - mins) / 60;
return pad(hrs) + ":" + pad(mins) + ":" + pad(secs) + "." + pad(ms, 3);
},
range: function (start, stop, step) {
if (typeof stop == "undefined") {
// one param defined
stop = start;
start = 0;
}
if (typeof step == "undefined") {
step = 1;
}
if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) {
return [];
}
var result = [];
for (var i = start; step > 0 ? i < stop : i > stop; i += step) {
result.push(i);
}
return result;
},
setUp: function (IMAGE_DIR) {
try {
if (fs.existsSync(`./${IMAGE_DIR}`)) {
fs.rmdirSync(IMAGE_DIR, { recursive: true });
}
fs.mkdirSync(`./${IMAGE_DIR}`);
} catch (e) {
console.error(e);
}
},
};