mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
* chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 64.0.0 to 65.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v64.0.0...v65.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 65.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix: no-array-from-fill * fix: unicorn-js/no-duplicate-set-values * fix: no-this-outside-of-class * fix: no-unnecessary-nested-ternary * fix: prefer-array-last-methods * fix: prefer-queue-microtask * fix: prefer-split-limit * fix: no-array-from-fill * fix: no-unused-array-method-return * fix: prefer-single-call * fix: prefer-includes-over-repeated-comparisons * fix: consistent-compound-words * fix: prefer-includes-over-repeated-comparisons * chore: add eslint-plugin-unicorn v65 recommended preset * fix: correct duration parsing logic in parseDuration function * fix: update oxlint-disable --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import os from 'node:os';
|
|
|
|
import title from 'title';
|
|
|
|
import { config } from '@/config';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
|
|
// convert a string into title case
|
|
const toTitleCase = (str: string) => title(str);
|
|
|
|
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?: string | null) => {
|
|
if (str && rWhitespace.test(str)) {
|
|
return str.replaceAll(rAllWhitespace, ' ').trim();
|
|
}
|
|
return str;
|
|
};
|
|
|
|
const convertDateToISO8601 = (date?: string | Date | number | null) => {
|
|
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();
|
|
};
|
|
|
|
const getSubPath = (ctx) => {
|
|
const subPath = ctx.req.path.replace(/\/[^/]*/, '') || '/';
|
|
return subPath;
|
|
};
|
|
|
|
const getLocalhostAddress = () => {
|
|
const interfaces = os.networkInterfaces();
|
|
const address = Object.keys(interfaces)
|
|
.flatMap((name) => interfaces[name] ?? [])
|
|
.filter((iface) => iface?.family === 'IPv4' && !iface.internal)
|
|
.map((iface) => iface?.address)
|
|
.filter(Boolean);
|
|
if (!config.disableIPv6) {
|
|
address.push('[::]');
|
|
}
|
|
return address;
|
|
};
|
|
|
|
export { collapseWhitespace, convertDateToISO8601, getLocalhostAddress, getSubPath, toTitleCase };
|