audible-api
Version:
A Node.js API for searching the audible website
35 lines (27 loc) • 975 B
JavaScript
/** The number of milliseconds in 1 second */
export var MILLISECONDS_IN_SECOND = 1000;
/** The number of seconds in 1 minute */
export var SECONDS_IN_MINUTE = 60;
/** The number of minutes in 1 hour */
export var MINUTES_IN_HOUR = 60;
/** The number of seconds in 1 hour */
export var SECONDS_IN_HOUR = SECONDS_IN_MINUTE * MINUTES_IN_HOUR;
/**
* Get a book's total runtime duration in seconds from it's formatted string
*
* @param {string} runtimeStr A string in the format of `N hrs and N mins` to parse
* @returns {number} The total number of seconds in the book
*/
export function getDurationFromStr(runtimeStr) {
var duration = 0;
var hoursMatch = runtimeStr.match(/(\d+) hrs/);
if (hoursMatch) {
duration += Number(hoursMatch[1]) * SECONDS_IN_HOUR;
}
var minutesMatch = runtimeStr.match(/(\d+) mins/);
if (minutesMatch) {
duration += Number(minutesMatch[1]) * SECONDS_IN_MINUTE;
}
return duration;
}
//# sourceMappingURL=time.js.map