ecd524ed3c
- Simplify by now all html and javascript. - Added a simple interface using go templates and plain javascript. - Improved REST interface for the use case. - Changed some properties into the config file to make it suitable for future use cases. Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
24 lines
526 B
JavaScript
24 lines
526 B
JavaScript
var sizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
|
|
|
|
function logn(n, b) {
|
|
return Math.log(n) / Math.log(b);
|
|
}
|
|
|
|
var Humanize = {
|
|
bytes: function (s, base) {
|
|
if (s < 10) {
|
|
return s.toFixed(0) + " B";
|
|
}
|
|
var e = Math.floor(logn(s, base));
|
|
var suffix = sizes[e];
|
|
var val = Math.floor(s / Math.pow(base, e) * 10 + 0.5) / 10;
|
|
|
|
var f = val.toFixed(0);
|
|
|
|
if (val < 10) {
|
|
f = val.toFixed(1);
|
|
}
|
|
|
|
return f + suffix;
|
|
}
|
|
};
|