ampache_react/app/utils/misc.js
Phyks (Lucas Verney) d8a7d4f66a Rework webplayer
Full rework of webplayer. Webplayer is back to its previous working
state, and ready for further improvements.
2016-08-10 23:50:23 +02:00

35 lines
703 B
JavaScript

/**
* Miscellaneous helper functions.
*/
/**
* Strict int checking function.
*
* @param value The value to check for int.
* @return Either NaN if the string was not a valid int representation, or the
* int.
*/
export function filterInt(value) {
if (/^(\-|\+)?([0-9]+|Infinity)$/.test(value)) {
return Number(value);
}
return NaN;
}
/**
* Helper to format song length.
*
* @param time Length of the song in seconds.
* @return Formatted length as MM:SS.
*/
export function formatLength(time) {
const min = Math.floor(time / 60);
let sec = (time - 60 * min);
if (sec < 10) {
sec = "0" + sec;
}
return min + ":" + sec;
}