mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 18:18:06 +08:00
* fix(core): offending RFC4287 should not leave `<updated>` blank when `<published>` is not blank these two fields MUST conform to the "date-time" production in RFC3339 Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com> * test(common-utils): complete tests Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com> * test(template): restrict expected value of `pubDate` Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com>
38 lines
942 B
JavaScript
38 lines
942 B
JavaScript
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
// convert a string into title case
|
|
const toTitleCase = (str) =>
|
|
str
|
|
.toLowerCase()
|
|
.split(' ')
|
|
.map((word) => word.replace(word[0], word[0].toUpperCase()))
|
|
.join(' ');
|
|
|
|
const rWhiteSpace = /\s+/;
|
|
const rAllWhiteSpace = /\s+/g;
|
|
|
|
// collapse all whitespaces into a single space (like "white-space: normal;" would do), and trim
|
|
const collapseWhitespace = (str) => {
|
|
if (str && rWhiteSpace.test(str)) {
|
|
return str.replace(rAllWhiteSpace, ' ').trim();
|
|
}
|
|
return str;
|
|
};
|
|
|
|
const convertDateToISO8601 = (date) => {
|
|
if (!date) {
|
|
return date;
|
|
}
|
|
if (typeof date !== 'object') {
|
|
// some routes may call `.toUTCString()` before passing the date to ctx...
|
|
date = parseDate(date);
|
|
}
|
|
return date.toISOString();
|
|
};
|
|
|
|
module.exports = {
|
|
toTitleCase,
|
|
collapseWhitespace,
|
|
convertDateToISO8601,
|
|
};
|