canape/frontend/js/utils.js
Grégoire Delattre 302d59c6c2
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Add torrent metadata
2020-04-08 18:14:16 +02:00

34 lines
829 B
JavaScript

export const prettyDurationFromMinutes = (runtime) => {
const hours = Math.floor(runtime / 60);
const minutes = runtime % 60;
let duration = "";
if (hours > 0) {
duration += hours + "h";
}
if (minutes > 0) {
duration += ("0" + minutes).slice(-2);
}
if (hours === 0) {
duration += " min";
}
return duration;
};
const pad = (d) => (d < 10 ? "0" + d.toString() : d.toString());
export const prettyEpisodeName = (showName, season, episode) =>
`${showName} S${pad(season)}E${pad(episode)}`;
export const prettySize = (fileSizeInBytes) => {
var i = -1;
var byteUnits = [" kB", " MB", " GB", " TB", "PB", "EB", "ZB", "YB"];
do {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
} while (fileSizeInBytes > 1024);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
};