-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.js
73 lines (60 loc) · 1.78 KB
/
util.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
67
68
69
70
71
72
73
'use strict';
const logger = exports.logger = {
infoConsole(str) {
return `\x1b[35;1m${str}\x1b[0m`;
},
infoConsole2(str) {
return `\x1b[32;1m${str}\x1b[0m`;
},
debugConsole(str) {
return `\x1b[36;1m${str}\x1b[0m`;
},
errorConsole(str) {
return `\x1b[31;1m${str}\x1b[0m`;
},
warnConsole(str) {
return `\x1b[33;1m${str}\x1b[0m`;
},
lineConsole(str) {
return `\x1b[4;1m${str}\x1b[0m`;
}
};
exports.helpText = `
Usage: devtoolx [CMD]... [ARGS]
${logger.infoConsole(`-v --version`)} show devtoolx version
${logger.infoConsole(`version`)}
${logger.infoConsole(`-h --help`)} show devtoolx usage
${logger.infoConsole(`help`)}
${logger.infoConsole(`-s <file> [-p <port>]`)} analysis js heapsnapshot, start web sever
with default port 3000, change port by "-p <port>"
${logger.infoConsole(`--no-open`)} don't auto open browser when analysis completed
`;
exports.formatTime = function (ts) {
ts = !isNaN(ts) && ts || 0;
let str = '';
if (ts < 1e3) {
str = `${ts.toFixed(2)} ms`;
} else if (ts < 1e3 * 60) {
str = `${(ts / 1e3).toFixed(2)} s`;
} else if (ts < 1e3 * 60 * 60) {
str = `${(ts / (1e3 * 60)).toFixed(2)} min`;
} else if (ts < 1e3 * 60 * 60 * 60) {
str = `${(ts / (1e3 * 60 * 60)).toFixed(2)} h`;
} else {
str = `${ts.toFixed(2)} ms`;
}
return str;
}
exports.formatSize = function (size) {
let str = '';
if (size / 1024 < 1) {
str = `${(size).toFixed(2)} Bytes`;
} else if (size / 1024 / 1024 < 1) {
str = `${(size / 1024).toFixed(2)} KB`;
} else if (size / 1024 / 1024 / 1024 < 1) {
str = `${(size / 1024 / 1024).toFixed(2)} MB`;
} else {
str = `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`;
}
return str;
}