UNPKG

audible-api

Version:

A Node.js API for searching the audible website

48 lines (37 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SECONDS_IN_MINUTE = exports.SECONDS_IN_HOUR = exports.MINUTES_IN_HOUR = exports.MILLISECONDS_IN_SECOND = void 0; exports.getDurationFromStr = getDurationFromStr; /** The number of milliseconds in 1 second */ var MILLISECONDS_IN_SECOND = 1000; /** The number of seconds in 1 minute */ exports.MILLISECONDS_IN_SECOND = MILLISECONDS_IN_SECOND; var SECONDS_IN_MINUTE = 60; /** The number of minutes in 1 hour */ exports.SECONDS_IN_MINUTE = SECONDS_IN_MINUTE; var MINUTES_IN_HOUR = 60; /** The number of seconds in 1 hour */ exports.MINUTES_IN_HOUR = MINUTES_IN_HOUR; 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 */ exports.SECONDS_IN_HOUR = SECONDS_IN_HOUR; 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