forked from mongo-express/mongo-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.js
31 lines (28 loc) · 1020 Bytes
/
filters.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
'use strict';
exports.json = function(input) {
return JSON.stringify(input, null, ' ');
};
exports.convertBytes = function(input) {
input = parseInt(input, 10);
if (input < 1024) {
return input.toString() + ' Bytes';
} else if (input < 1024 * 1024) {
//Convert to KB and keep 2 decimal values
input = Math.round((input / 1024) * 100) / 100;
return input.toString() + ' KB';
} else if (input < 1024 * 1024 * 1024) {
input = Math.round((input / (1024 * 1024)) * 100) / 100;
return input.toString() + ' MB';
} else if (input < 1024 * 1024 * 1024 * 1024) {
input = Math.round((input / (1024 * 1024 * 1024)) * 100) / 100;
return input.toString() + ' GB';
} else if (input < 1024 * 1024 * 1024 * 1024 * 1024) {
input = Math.round((input / (1024 * 1024 * 1024 * 1024)) * 100) / 100;
return input.toString() + ' TB';
} else {
return input.toString() + ' Bytes';
}
};
exports.to_string = function (input) {
return input !== null ? input.toString() : '';
};