forked from DebaucheryLibrarian/traxxx
Added upcoming support to Nubiles. Renamed q's formatDate to extractDate, added actual formatDate.
This commit is contained in:
@@ -8,6 +8,23 @@ function trim(str) {
|
||||
return str.trim().replace(/\s+/g, ' ');
|
||||
}
|
||||
|
||||
function extractDate(dateString, format, match) {
|
||||
if (match) {
|
||||
const dateStamp = trim(dateString).match(match);
|
||||
|
||||
if (dateStamp) return moment.utc(dateStamp[0], format).toDate();
|
||||
return null;
|
||||
}
|
||||
|
||||
return moment.utc(trim(dateString), format).toDate();
|
||||
}
|
||||
|
||||
function formatDate(date, format, inputFormat) {
|
||||
if (inputFormat) return moment(date, inputFormat).format(format);
|
||||
|
||||
return moment(date).format(format);
|
||||
}
|
||||
|
||||
function prefixProtocol(url, protocol = 'https') {
|
||||
if (protocol && /^\/\//.test(url)) {
|
||||
return `${protocol}:${url}`;
|
||||
@@ -61,23 +78,12 @@ function qmeta(context, selector, attrArg = 'content', applyTrim = true) {
|
||||
return q(context, `meta[${selector}]`, attrArg, applyTrim);
|
||||
}
|
||||
|
||||
function formatDate(dateString, format, match) {
|
||||
if (match) {
|
||||
const dateStamp = trim(dateString).match(match);
|
||||
|
||||
if (dateStamp) return moment.utc(dateStamp[0], format).toDate();
|
||||
return null;
|
||||
}
|
||||
|
||||
return moment.utc(trim(dateString), format).toDate();
|
||||
}
|
||||
|
||||
function qdate(context, selector, format, match, attr = 'textContent') {
|
||||
const dateString = q(context, selector, attr, true);
|
||||
|
||||
if (!dateString) return null;
|
||||
|
||||
return formatDate(dateString, format, match);
|
||||
return extractDate(dateString, format, match);
|
||||
}
|
||||
|
||||
function qimage(context, selector = 'img', attr = 'src', protocol = 'https') {
|
||||
@@ -234,21 +240,24 @@ async function getAll(url, selector, headers) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatDate,
|
||||
extractDate,
|
||||
extract,
|
||||
extractAll,
|
||||
init,
|
||||
initAll,
|
||||
formatDate,
|
||||
get,
|
||||
getAll,
|
||||
context: init,
|
||||
contextAll: initAll,
|
||||
fd: formatDate,
|
||||
ed: extractDate,
|
||||
ex: extract,
|
||||
exa: extractAll,
|
||||
fd: formatDate,
|
||||
ctx: init,
|
||||
ctxa: initAll,
|
||||
geta: getAll,
|
||||
edate: extractDate,
|
||||
fdate: formatDate,
|
||||
...funcs,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user