nextcloud-node-client
Version:
Nextcloud client API for node.js TypeScript applications
33 lines (32 loc) • 909 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class FileSizeFormatter {
constructor(bytes) {
this.oneKiloByte = 1024;
this.oneMegaByte = this.oneKiloByte * 1024;
this.oneGigaByte = this.oneMegaByte * 1024;
this.bytes = bytes;
}
getUserFriendlyFileSize() {
let suffix;
let size = this.bytes;
if (size > this.oneGigaByte) {
size /= this.oneGigaByte;
suffix = " GB";
}
else if (this.bytes > this.oneMegaByte) {
size /= this.oneMegaByte;
suffix = " MB";
}
else if (this.bytes > this.oneKiloByte) {
size /= this.oneKiloByte;
suffix = " kB";
}
else {
suffix = " B";
}
size = Math.round(size);
return size + suffix;
}
}
exports.default = FileSizeFormatter;