40 lines
1.0 KiB
JavaScript
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);
|