canape/frontend/js/utils.js
Grégoire Delattre b6be9488c9
Some checks failed
continuous-integration/drone/push Build is failing
Add a page to display a movie
2021-08-22 11:33:36 -10:00

40 lines
1.0 KiB
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 prettyEpisodeNameWithoutShow = (season, episode) =>
`S${pad(season)}E${pad(episode)}`;
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 / 1000;
i++;
} while (fileSizeInBytes > 1000);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
};
export const upperCaseFirst = (string) =>
string.charAt(0).toUpperCase() + string.slice(1);