Added Top Web Models framework.
This commit is contained in:
@@ -40,6 +40,18 @@ function formatDate(dateValue, format, inputFormat) {
|
||||
return moment(dateValue).format(format);
|
||||
}
|
||||
|
||||
function durationToSeconds(durationString, match) {
|
||||
const durationMatch = durationString.match(match || /(\d+:)?\d+:\d+/);
|
||||
|
||||
if (durationMatch) {
|
||||
const segments = ['00'].concat(durationMatch[0].split(/[:hm]/)).slice(-3);
|
||||
|
||||
return moment.duration(segments.join(':')).asSeconds();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function prefixUrl(urlValue, origin, protocol = 'https') {
|
||||
if (!urlValue) {
|
||||
return null;
|
||||
@@ -316,12 +328,10 @@ function duration(context, selector, match, attr = 'textContent') {
|
||||
const durationString = q(context, selector, attr);
|
||||
|
||||
if (!durationString) return null;
|
||||
const durationMatch = durationString.match(match || /(\d+:)?\d+:\d+/);
|
||||
const durationMatch = durationToSeconds(durationString, match);
|
||||
|
||||
if (durationMatch) {
|
||||
const segments = ['00'].concat(durationMatch[0].split(/[:hm]/)).slice(-3);
|
||||
|
||||
return moment.duration(segments.join(':')).asSeconds();
|
||||
return durationMatch;
|
||||
}
|
||||
|
||||
const timestampMatch = durationString.match(/(\d+H)?\s*(\d+M)?\s*\d+S?/i);
|
||||
@@ -526,6 +536,7 @@ module.exports = {
|
||||
extractDate,
|
||||
extract,
|
||||
extractAll,
|
||||
durationToSeconds,
|
||||
init,
|
||||
initAll,
|
||||
formatDate,
|
||||
|
||||
Reference in New Issue
Block a user