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