-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutils.js
53 lines (47 loc) · 1.65 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Unvanquished Updater
* Copyright (C) Unvanquished Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
.pragma library
function humanSize(bytes) {
var sizes = ['Bytes', 'KiB', 'MiB', 'GiB'];
var i = 0;
var size = bytes;
while (size > 1024 && i++ < sizes.length) {
size /= 1024;
}
return '' + Number(size).toFixed(1) + ' ' + sizes[Math.min(i, sizes.length - 1)];
}
function padZeros(input, padding) {
var str = input.toString();
var paddingStr = '';
if (str.length < padding) {
for (var i = 0; i < padding - str.length; ++i)
paddingStr += '0'
}
return paddingStr + str;
}
function humanTime(time) {
var hours = Math.floor(time / 3600.0)
var mins = Math.floor((time % 3600) / 60.0)
var secs = time % 60.0
return '' + padZeros(hours, 2) + ':' + padZeros(mins, 2) + ':' + padZeros(secs, 2) + ' left';
}
// Suitable for use outside tags
function htmlEscape(text) {
return text.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
}