@georgemiao/qbit.js
Version:
a qBittorrent library made with typescript
25 lines • 671 B
JavaScript
/**
* Format bytes or bytes per second to human readable format
* @param bytes Bytes to format
* @param speed Format as bytes per second, default false
* @returns formatted string
*/
export function prettySize(bytes, speed = false) {
const units = [
["B", 0],
["KiB", 0],
["MiB", 1],
["GiB", 2],
["TiB", 3],
["PiB", 3],
["EiB", 3],
];
let value = bytes;
let depth = 0;
while (value > 1024 && depth < units.length - 1) {
value /= 1024;
depth += 1;
}
return `${value.toFixed(units[depth][1])} ${units[depth][0]}${speed ? "/s" : ""}`;
}
//# sourceMappingURL=Util.js.map