chore(deps-dev): bump eslint-plugin-unicorn from 60.0.0 to 61.0.2 (#19998)
* chore(deps-dev): bump eslint-plugin-unicorn from 60.0.0 to 61.0.1 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 60.0.0 to 61.0.1. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v60.0.0...v61.0.1) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 61.0.1 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * refactor: replace `replace(/regex/g)` with replaceAll * refactor: replace sort() with toSorted() for immutability in various routes and utilities * refactor: fix unicorn/prefer-array-find * refactor: fix unicorn/prefer-at * refactor: add unicorn/no-array-sort rule to ESLint configuration --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -141,6 +141,7 @@ unicorn.configs.recommended,
|
||||
|
||||
'unicorn/no-array-callback-reference': 'warn',
|
||||
'unicorn/no-array-reduce': 'warn',
|
||||
'unicorn/no-array-sort': 'warn',
|
||||
'unicorn/no-await-expression-member': 'off',
|
||||
'unicorn/no-empty-file': 'warn',
|
||||
'unicorn/no-hex-escape': 'warn',
|
||||
|
||||
@@ -80,7 +80,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
|
||||
|
||||
// sort items
|
||||
if (ctx.req.query('sorted') !== 'false') {
|
||||
data.item = data.item.sort((a: DataItem, b: DataItem) => +new Date(b.pubDate || 0) - +new Date(a.pubDate || 0));
|
||||
data.item = data.item.toSorted((a: DataItem, b: DataItem) => +new Date(b.pubDate || 0) - +new Date(a.pubDate || 0));
|
||||
}
|
||||
|
||||
const handleItem = (item: DataItem) => {
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ const sortRoutes = (
|
||||
}
|
||||
>
|
||||
) =>
|
||||
Object.entries(routes).sort(([pathA], [pathB]) => {
|
||||
Object.entries(routes).toSorted(([pathA], [pathB]) => {
|
||||
const segmentsA = pathA.split('/');
|
||||
const segmentsB = pathB.split('/');
|
||||
const lenA = segmentsA.length;
|
||||
|
||||
@@ -16,6 +16,6 @@ export const getToken = () =>
|
||||
export const sign = (requestPath: string, payload: Record<string, any> = {}, timestamp: number, token: string) => {
|
||||
payload.timestamp = timestamp;
|
||||
payload.token = token;
|
||||
const sortedParams = Object.keys(payload).sort();
|
||||
const sortedParams = Object.keys(payload).toSorted();
|
||||
return md5(md5(requestPath) + md5(sortedParams + md5(token) + timestamp));
|
||||
};
|
||||
|
||||
@@ -132,7 +132,7 @@ async function handler(ctx) {
|
||||
if (enclosureMatches) {
|
||||
const enclosureMatch = enclosureMatches
|
||||
.map((e) => e.match(new RegExp(enclosurePattern)))
|
||||
.sort((a, b) => Number.parseInt(a[2], 10) - Number.parseInt(b[2], 10))
|
||||
.toSorted((a, b) => Number.parseInt(a[2], 10) - Number.parseInt(b[2], 10))
|
||||
.pop();
|
||||
|
||||
item.enclosure_url = enclosureMatch[3];
|
||||
|
||||
@@ -86,7 +86,7 @@ async function handler(ctx) {
|
||||
uniqueItems.push(item!);
|
||||
}
|
||||
}
|
||||
items = uniqueItems.sort((a, b) => b.pubDate - a.pubDate).slice(0, ctx.req.query('limit') || 20);
|
||||
items = uniqueItems.toSorted((a, b) => b.pubDate - a.pubDate).slice(0, ctx.req.query('limit') || 20);
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
|
||||
@@ -81,7 +81,7 @@ async function handler(ctx) {
|
||||
}
|
||||
})
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => b.pubDate - a.pubDate)
|
||||
.toSorted((a, b) => b.pubDate - a.pubDate)
|
||||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20);
|
||||
|
||||
const items = ctx.req.query('fulltext') === 'true' ? await pMap(list, (item) => fetchArticle(item), { concurrency: 10 }) : list;
|
||||
|
||||
@@ -79,7 +79,7 @@ async function handler(ctx) {
|
||||
return res;
|
||||
})
|
||||
.filter((e) => Boolean(e.link) && !new URL(e.link).pathname.split('/').includes('hub'))
|
||||
.sort((a, b) => (a.pubDate && b.pubDate ? b.pubDate - a.pubDate : b.lastmod - a.lastmod))
|
||||
.toSorted((a, b) => (a.pubDate && b.pubDate ? b.pubDate - a.pubDate : b.lastmod - a.lastmod))
|
||||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20);
|
||||
|
||||
const items = ctx.req.query('fulltext') === 'true' ? await pMap(list, (item) => fetchArticle(item), { concurrency: 20 }) : list;
|
||||
|
||||
@@ -130,7 +130,7 @@ async function handler(ctx) {
|
||||
return {
|
||||
title: `${appName} ${item.versionDisplay} for ${p}`,
|
||||
link: currentUrl,
|
||||
description: item.releaseNotes?.replace(/\n/g, '<br>'),
|
||||
description: item.releaseNotes?.replaceAll('\n', '<br>'),
|
||||
category: [p],
|
||||
guid: `apple/apps/${country}/${id}/${pid}#${item.versionDisplay}`,
|
||||
pubDate: parseDate(item.releaseTimestamp),
|
||||
@@ -147,7 +147,7 @@ async function handler(ctx) {
|
||||
item: items,
|
||||
title: `${title} - Apple App Store`,
|
||||
link: currentUrl,
|
||||
description: description?.replace(/\n/g, ' '),
|
||||
description: description?.replaceAll('\n', ' '),
|
||||
language: $('html').prop('lang'),
|
||||
image: $('meta[property="og:image"]').prop('content'),
|
||||
icon,
|
||||
|
||||
@@ -56,7 +56,7 @@ async function handler(ctx) {
|
||||
date: $el.children().first().find('small').children().remove().end().text().slice(3),
|
||||
};
|
||||
});
|
||||
const finalLatestReplies = [...latestReplies, ...latestSubReplies].sort((a, b) => (a.id < b.id ? 1 : -1));
|
||||
const finalLatestReplies = [...latestReplies, ...latestSubReplies].toSorted((a, b) => (a.id < b.id ? 1 : -1));
|
||||
|
||||
const postTopic = {
|
||||
title,
|
||||
|
||||
@@ -45,7 +45,7 @@ async function handler(ctx) {
|
||||
link,
|
||||
description: `视频 ${name} 的视频选集列表`,
|
||||
item: data
|
||||
.sort((a, b) => b.page - a.page)
|
||||
.toSorted((a, b) => b.page - a.page)
|
||||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10)
|
||||
.map((item) => ({
|
||||
title: item.part,
|
||||
|
||||
@@ -595,7 +595,7 @@
|
||||
}
|
||||
argvPtrs.push(0);
|
||||
|
||||
const keys = Object.keys(this.env).sort();
|
||||
const keys = Object.keys(this.env).toSorted();
|
||||
for (const key of keys) {
|
||||
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ async function handler(ctx) {
|
||||
pubDate: timezone(parseDate(e.find('span').text().replace(':', ''), 'YYYY-MM-DD'), 8),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => b.pubDate - a.pubDate)
|
||||
.toSorted((a, b) => b.pubDate - a.pubDate)
|
||||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10);
|
||||
|
||||
const items = await Promise.all(
|
||||
|
||||
@@ -115,7 +115,7 @@ function getItems(list) {
|
||||
const { data: descrptionResponse } = await got(item.link);
|
||||
const $descrption = load(descrptionResponse);
|
||||
const desc = $descrption('#main > div.content > div.search_height > div.search_con:has(p)').html();
|
||||
item.description = desc?.replace(/(\r|\n)+/g, '<br />');
|
||||
item.description = desc?.replaceAll(/(\r|\n)+/g, '<br />');
|
||||
item.author = $descrption('#main > div.content > div.search_height > span.search_con').text().split('发布者:').at(-1) || '教务部';
|
||||
return item;
|
||||
})
|
||||
|
||||
@@ -94,7 +94,7 @@ async function handler(ctx) {
|
||||
} else {
|
||||
const buildUnitScript = $('script[parseType="bulidstatic"]');
|
||||
const queryUrl = `${baseUrl}${buildUnitScript.attr('url')}`;
|
||||
const queryData = JSON.parse(buildUnitScript.attr('querydata')?.replace(/'/g, '"') ?? '{}');
|
||||
const queryData = JSON.parse(buildUnitScript.attr('querydata')?.replaceAll("'", '"') ?? '{}');
|
||||
queryData.paramJson = `{"pageNo":1,"pageSize":${limit}}`;
|
||||
|
||||
const { data } = await got.get<{ data: { html: string } }>(queryUrl, {
|
||||
|
||||
@@ -82,7 +82,7 @@ async function handler(ctx) {
|
||||
ordered,
|
||||
// index,
|
||||
}))
|
||||
.sort((a, b) => b.ordered - a.ordered);
|
||||
.toSorted((a, b) => b.ordered - a.ordered);
|
||||
|
||||
return chapters;
|
||||
},
|
||||
|
||||
@@ -50,7 +50,7 @@ const handler: Route['handler'] = async (ctx) => {
|
||||
link: absoluteLink,
|
||||
};
|
||||
})
|
||||
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
|
||||
.toSorted((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
|
||||
.slice(0, 10);
|
||||
|
||||
const fetchDataItem = (item: { title: string; date: string; link: string }) =>
|
||||
|
||||
@@ -42,7 +42,7 @@ async function handler(ctx) {
|
||||
|
||||
const items = await Promise.all(
|
||||
chapters.chapters
|
||||
.sort((a, b) => b.idx - a.idx)
|
||||
.toSorted((a, b) => b.idx - a.idx)
|
||||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 3)
|
||||
.map(async (c) => {
|
||||
let pages;
|
||||
|
||||
@@ -26,7 +26,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
|
||||
while ((match = updateRegex.exec(response)) !== null && items.length < limit) {
|
||||
const headerLine: string | undefined = match[2].trim();
|
||||
const description: string | undefined = match[4].trim()?.replace(/(\s[+-])/g, '<br>$1');
|
||||
const description: string | undefined = match[4].trim()?.replaceAll(/(\s[+-])/g, '<br>$1');
|
||||
|
||||
let version: string = 'N/A';
|
||||
let pubDateStr: string | undefined = undefined;
|
||||
|
||||
@@ -3,7 +3,7 @@ import md5 from '@/utils/md5';
|
||||
function hash(images) {
|
||||
const entries = Object.entries(images)
|
||||
.map((x) => `${x[1].os}/${x[1].architecture},${x[1].digest}`)
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
.toSorted((a, b) => a.localeCompare(b));
|
||||
const text = entries.join('|');
|
||||
return md5(text);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ async function getContent(nextBuildId: string, contentId: string) {
|
||||
const description =
|
||||
content
|
||||
.html()
|
||||
?.replace(rubyRegex, '$1($2)')
|
||||
?.replace(/[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]/gm, '') ?? '';
|
||||
?.replaceAll(rubyRegex, '$1($2)')
|
||||
?.replaceAll(/[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]/gm, '') ?? '';
|
||||
return description;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export const route: Route = {
|
||||
item: feed.items.map((item) => ({
|
||||
title: item.title ?? '',
|
||||
link: item.link,
|
||||
description: sanitizeHtml(item.content?.replace(/href="\/(.+?)"/g, `href="https://github.com/$1"`) ?? '', { allowedTags: [...sanitizeHtml.defaults.allowedTags, 'img'] }),
|
||||
description: sanitizeHtml(item.content?.replaceAll(/href="\/(.+?)"/g, `href="https://github.com/$1"`) ?? '', { allowedTags: [...sanitizeHtml.defaults.allowedTags, 'img'] }),
|
||||
pubDate: item.pubDate ? parseDate(item.pubDate) : undefined,
|
||||
author: item.author,
|
||||
guid: item.id,
|
||||
|
||||
@@ -49,7 +49,7 @@ async function handler(ctx) {
|
||||
pubDate: timezone(parseDate($_chapter.find('nobr').text(), 'YYYYMMDD HH:mm'), +9),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => (a.pubDate <= b.pubDate ? 1 : -1))
|
||||
.toSorted((a, b) => (a.pubDate <= b.pubDate ? 1 : -1))
|
||||
.slice(0, limit);
|
||||
|
||||
const item_list = await Promise.all(
|
||||
|
||||
@@ -63,7 +63,7 @@ async function handler(ctx) {
|
||||
gkdiy: 'GK/其他',
|
||||
};
|
||||
|
||||
const filterArr = catType.split('|').sort();
|
||||
const filterArr = catType.split('|').toSorted();
|
||||
|
||||
const filterSet = new Set(filterArr.map((e: string) => classMap[e]));
|
||||
if (catType.includes('all')) {
|
||||
|
||||
@@ -77,7 +77,7 @@ async function handler(ctx) {
|
||||
author: item.paper.authors.map((author) => author.name).join(', '),
|
||||
upvotes: item.paper.upvotes,
|
||||
}))
|
||||
.sort((a, b) => b.upvotes - a.upvotes);
|
||||
.toSorted((a, b) => b.upvotes - a.upvotes);
|
||||
|
||||
return {
|
||||
title: 'Huggingface Daily Papers',
|
||||
|
||||
@@ -57,7 +57,7 @@ export const handler = async (ctx) => {
|
||||
)
|
||||
);
|
||||
|
||||
const title = $('meta[name="keywords"]').prop('content')?.replace(/,/g, ' - ') ?? $('title').text();
|
||||
const title = $('meta[name="keywords"]').prop('content')?.replaceAll(',', ' - ') ?? $('title').text();
|
||||
const image = new URL($('div.logo img').prop('src'), rootUrl).href;
|
||||
|
||||
return {
|
||||
|
||||
@@ -75,7 +75,7 @@ export const handler = async (ctx) => {
|
||||
)
|
||||
);
|
||||
|
||||
const title = $('meta[name="keywords"]').prop('content')?.replace(/,/g, ' - ') ?? $('title').text();
|
||||
const title = $('meta[name="keywords"]').prop('content')?.replaceAll(',', ' - ') ?? $('title').text();
|
||||
const image = new URL($('div.logo img').prop('src'), rootUrl).href;
|
||||
|
||||
return {
|
||||
|
||||
@@ -257,7 +257,7 @@ const generateSignature = () => {
|
||||
|
||||
const appSecret = 'hUzaABtNfDE-6UiyaYhfsmjW-8dnoyVc';
|
||||
const nonce = generateNonce();
|
||||
const r = [appSecret, timestamp, nonce].sort();
|
||||
const r = [appSecret, timestamp, nonce].toSorted();
|
||||
return {
|
||||
nonce,
|
||||
timestamp,
|
||||
@@ -363,7 +363,7 @@ const processItems = async (items, limit, tryGet) => {
|
||||
return {
|
||||
...audioItem,
|
||||
...videoItem,
|
||||
title: (item.title ?? item.summary ?? item.content)?.replace(/<\/?(?:em|br)?>/g, ''),
|
||||
title: (item.title ?? item.summary ?? item.content)?.replaceAll(/<\/?(?:em|br)?>/g, ''),
|
||||
link,
|
||||
description: art(path.join(__dirname, 'templates/description.art'), {
|
||||
image: {
|
||||
|
||||
@@ -90,7 +90,7 @@ export const handler = async (ctx) => {
|
||||
const script = $$('script[type="text/javascript"]').text();
|
||||
const videoSrc = script.match(/P\.s\s=\s'(.*?)';/)?.[1] ?? undefined;
|
||||
const poster = script.match(/P\.c\(.*?isWideScreen,\s'(.*?)',\s/)?.[1] ?? undefined;
|
||||
const topicsStr = script.match(/var\stopicsInPage\s=\sJSON\.parse\('(.*?)'\);/)?.[1]?.replace(/\\/g, '') ?? undefined;
|
||||
const topicsStr = script.match(/var\stopicsInPage\s=\sJSON\.parse\('(.*?)'\);/)?.[1]?.replaceAll('\\', '') ?? undefined;
|
||||
|
||||
if (videoSrc) {
|
||||
$$('div.player').replaceWith(
|
||||
|
||||
@@ -12,7 +12,7 @@ const renderItems = (items) =>
|
||||
switch (productType) {
|
||||
case 'carousel_container': {
|
||||
const images = item.carousel_media.map((i) => ({
|
||||
...i.image_versions2.candidates.sort((a, b) => b.width - a.width)[0],
|
||||
...i.image_versions2.candidates.toSorted((a, b) => b.width - a.width)[0],
|
||||
alt: item.accessibility_caption,
|
||||
}));
|
||||
description = art(path.join(__dirname, 'templates/images.art'), {
|
||||
@@ -25,12 +25,12 @@ const renderItems = (items) =>
|
||||
case 'igtv':
|
||||
description = art(path.join(__dirname, 'templates/video.art'), {
|
||||
summary,
|
||||
image: item.image_versions2.candidates.sort((a, b) => b.width - a.width)[0],
|
||||
image: item.image_versions2.candidates.toSorted((a, b) => b.width - a.width)[0],
|
||||
video: item.video_versions[0],
|
||||
});
|
||||
break;
|
||||
case 'feed': {
|
||||
const images = [{ ...item.image_versions2.candidates.sort((a, b) => b.width - a.width)[0], alt: item.accessibility_caption }];
|
||||
const images = [{ ...item.image_versions2.candidates.toSorted((a, b) => b.width - a.width)[0], alt: item.accessibility_caption }];
|
||||
description = art(path.join(__dirname, 'templates/images.art'), {
|
||||
summary,
|
||||
images,
|
||||
|
||||
@@ -158,7 +158,7 @@ async function handler(ctx) {
|
||||
});
|
||||
|
||||
if (magnets) {
|
||||
item.enclosure_url = magnets.sort((a, b) => b.score - a.score)[0].link;
|
||||
item.enclosure_url = magnets.toSorted((a, b) => b.score - a.score)[0].link;
|
||||
item.enclosure_type = 'application/x-bittorrent';
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -68,7 +68,7 @@ const ProcessItems = async (language, currentUrl, tryGet) => {
|
||||
item.description = art(path.join(__dirname, 'templates/description.art'), {
|
||||
cover: content('#video_jacket_img').attr('src'),
|
||||
info: content('#video_info').html().replaceAll('span><span', 'span>, <span'),
|
||||
comment: item.description?.replace(/\[img]/g, '<img src="')?.replace(/\[\/img]/g, '"/>'),
|
||||
comment: item.description?.replaceAll('[img]', '<img src="')?.replaceAll('[/img]', '"/>'),
|
||||
thumbs: content('.previewthumbs img')
|
||||
.toArray()
|
||||
.map((img) => content(img).attr('src').replaceAll('-', 'jp-')),
|
||||
|
||||
@@ -87,7 +87,7 @@ async function handler(ctx) {
|
||||
const items = response.activities
|
||||
.map((activity) => processActivity(activity, issueId))
|
||||
.filter((item) => item !== null)
|
||||
.sort((a, b) => new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime())
|
||||
.toSorted((a, b) => new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime())
|
||||
.slice(0, limit);
|
||||
|
||||
return {
|
||||
|
||||
@@ -23,7 +23,7 @@ export function sign(payload: Map<string, any>) {
|
||||
}
|
||||
|
||||
const sortedString = lowerCaseKeys
|
||||
.sort()
|
||||
.toSorted()
|
||||
.map((key) => key + '=' + map.get(key))
|
||||
.join('');
|
||||
const linkedString = link('--'.slice(0, 1), '#CEAIWER', '892F', 'KB97', 'JKB6', 'HJ7OC7C8', 'GJZG');
|
||||
|
||||
@@ -49,7 +49,7 @@ async function handler(ctx: Context): Promise<Data> {
|
||||
const episodes = values.filter((value) => value.__typename === 'Episode') as NextDataEpisode[];
|
||||
const items = (await Promise.all(
|
||||
episodes
|
||||
.sort((a, b) => b.publishedAt.localeCompare(a.publishedAt))
|
||||
.toSorted((a, b) => b.publishedAt.localeCompare(a.publishedAt))
|
||||
.slice(0, limit)
|
||||
.map((item) => {
|
||||
const episodeUrl = `https://kakuyomu.jp/works/${id}/episodes/${item.id}`;
|
||||
|
||||
@@ -63,7 +63,7 @@ export const route: Route = {
|
||||
::: tip
|
||||
When \`posts\` is selected as the value of the parameter **source**, the parameter **id** does not take effect.
|
||||
There is an optinal parameter **limit** which controls the number of posts to fetch, default value is 25.
|
||||
|
||||
|
||||
Support for announcements and fancards:
|
||||
- Use \`/:source/:id/announcements\` to get announcements
|
||||
- Use \`/:source/:id/fancards\` to get fancards
|
||||
@@ -201,7 +201,7 @@ async function processDiscordMessages(channels: any[], limit: number) {
|
||||
|
||||
return channelResponse.data
|
||||
.filter((message: DiscordMessage) => message.content || message.attachments)
|
||||
.sort((a, b) => b.id.localeCompare(a.id))
|
||||
.toSorted((a, b) => b.id.localeCompare(a.id))
|
||||
.slice(0, limit)
|
||||
.map((message: DiscordMessage) => ({
|
||||
title: message.content || 'Discord Message',
|
||||
|
||||
@@ -62,7 +62,7 @@ async function handler(ctx) {
|
||||
},
|
||||
});
|
||||
|
||||
const sortedChapters = chapterData.data.chaptersByComicId.sort((a, b) => Date.parse(b.dateUpdated) - Date.parse(a.dateUpdated));
|
||||
const sortedChapters = chapterData.data.chaptersByComicId.toSorted((a, b) => Date.parse(b.dateUpdated) - Date.parse(a.dateUpdated));
|
||||
|
||||
const chapterLimit = Number(limit) || sortedChapters.length;
|
||||
const filteredChapters = sortedChapters.slice(0, chapterLimit);
|
||||
|
||||
@@ -53,7 +53,7 @@ export const route: Route = {
|
||||
title: each.vod_name,
|
||||
image: each.vod_pic,
|
||||
link: `https://${domain}/vod/${each.vod_id}/`,
|
||||
guid: each.vod_play_url?.match(/https:\/\/.+?\.m3u8/g)?.slice(-1)[0],
|
||||
guid: each.vod_play_url?.match(/https:\/\/.+?\.m3u8/g)?.at(-1),
|
||||
pubDate: timezone(parseDate(each.vod_time, 'YYYY-MM-DD HH:mm:ss'), +8),
|
||||
category: [each.type_name, ...each.vod_class!.split(',')],
|
||||
description: render(each, `https://${domain}/vod/${each.vod_id}/`) + each.vod_content,
|
||||
|
||||
@@ -137,7 +137,7 @@ async function handler(ctx) {
|
||||
? $(script)
|
||||
.text()
|
||||
?.match(/\$\('#lower'\)\.prepend\('(.*)'\);/)?.[1]
|
||||
?.replaceAll(/\\"/g, '"')
|
||||
?.replaceAll(String.raw`\"`, '"')
|
||||
: '';
|
||||
if (lowerContent) {
|
||||
const $ = cheerio.load(lowerContent, null, false);
|
||||
|
||||
@@ -49,7 +49,7 @@ async function handler(ctx) {
|
||||
}))
|
||||
);
|
||||
|
||||
items = items.sort((a, b) => b.pubDate - a.pubDate).slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30);
|
||||
items = items.toSorted((a, b) => b.pubDate - a.pubDate).slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30);
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
|
||||
@@ -136,10 +136,7 @@ async function handler(ctx) {
|
||||
|
||||
item.author = content('meta[name="author"]').attr('content');
|
||||
item.title = item.title ?? content('meta[name="twitter:title"]').attr('content');
|
||||
item.description = content('#contentDiv')
|
||||
.html()
|
||||
?.replace(/ /g, '')
|
||||
.replaceAll('<p></p>', '');
|
||||
item.description = content('#contentDiv').html()?.replaceAll(' ', '').replaceAll('<p></p>', '');
|
||||
|
||||
return item;
|
||||
})
|
||||
|
||||
@@ -100,7 +100,7 @@ async function handler(ctx) {
|
||||
link: `https://news.now.com/home/${category}/player?newsId=${item.newsId}`,
|
||||
pubDate: parseDate(item.publishDate, 'x'),
|
||||
category: [...item.sportTypes.map((t) => t.sportTypeNameChi), ...item.players.map((p) => p.playerFullNameChi), ...item.teams.map((t) => t.teamCodeChi)],
|
||||
image: item.newsPhotos?.filter((p) => p.sizeType === '3')?.[0]?.imageUrl,
|
||||
image: item.newsPhotos?.find((p) => p.sizeType === '3')?.imageUrl,
|
||||
newsId: item.newsId,
|
||||
};
|
||||
})
|
||||
|
||||
@@ -136,7 +136,7 @@ async function handler(ctx) {
|
||||
// Match 感谢|謝.*?cn.letters@nytimes.com。
|
||||
const ending = /感(谢|謝);.*?cn\.letters@nytimes\.com。/g;
|
||||
|
||||
single.description = result.description?.replace(ending, '');
|
||||
single.description = result.description?.replaceAll(ending, '');
|
||||
|
||||
if (hasEnVersion) {
|
||||
single.title = result.title;
|
||||
|
||||
@@ -15,7 +15,7 @@ export async function getSFWUserNovels(id: string, fullContent: boolean = false,
|
||||
});
|
||||
|
||||
const novels = Object.keys(allData.body.novels)
|
||||
.sort((a, b) => Number(b) - Number(a))
|
||||
.toSorted((a, b) => Number(b) - Number(a))
|
||||
.slice(0, Number.parseInt(String(limit), 10));
|
||||
|
||||
if (novels.length === 0) {
|
||||
|
||||
@@ -81,6 +81,6 @@ export function processContent($: CheerioAPI, lang: string): string {
|
||||
return (
|
||||
$('.am__body')
|
||||
.html()
|
||||
?.replace(/https:\/\/i\.pximg\.net/g, config.pixiv.imgProxy || '') || ''
|
||||
?.replaceAll('https://i.pximg.net', config.pixiv.imgProxy || '') || ''
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export const route: Route = {
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const category = ctx.req.param('category')?.replace(/-/g, '/') ?? 'zxgg';
|
||||
const category = ctx.req.param('category')?.replaceAll('-', '/') ?? 'zxgg';
|
||||
|
||||
const rootUrl = 'https://hr.pku.edu.cn/';
|
||||
const currentUrl = `${rootUrl}/${category}/index.htm`;
|
||||
|
||||
@@ -56,7 +56,7 @@ async function handler(ctx) {
|
||||
};
|
||||
});
|
||||
|
||||
const sorted = list.sort((a, b) => b.pubDate.getTime() - a.pubDate.getTime()).slice(0, 10);
|
||||
const sorted = list.toSorted((a, b) => b.pubDate.getTime() - a.pubDate.getTime()).slice(0, 10);
|
||||
|
||||
return {
|
||||
title: `北京大学学生就业指导服务中心 - ${feed_title}`,
|
||||
|
||||
@@ -87,7 +87,7 @@ async function handler(ctx) {
|
||||
for (const item of items) {
|
||||
result = [...result, ...item];
|
||||
}
|
||||
result = result.sort((a, b) => new Date(b.pubDate) - new Date(a.pubDate));
|
||||
result = result.toSorted((a, b) => new Date(b.pubDate) - new Date(a.pubDate));
|
||||
|
||||
return {
|
||||
title: `${id} 的 PSN 奖杯`,
|
||||
|
||||
@@ -26,7 +26,7 @@ const generateNonce = (length: number): string => {
|
||||
export const getSignedHeaders = () => {
|
||||
const nonce = generateNonce(6);
|
||||
const timestamp = Date.now().toString();
|
||||
const signature = sha1([salt, timestamp, nonce].sort().join(''));
|
||||
const signature = sha1([salt, timestamp, nonce].toSorted().join(''));
|
||||
return {
|
||||
nonce,
|
||||
timestamp,
|
||||
|
||||
@@ -26,7 +26,7 @@ export const route: Route = {
|
||||
name: '高瓴人工智能学院',
|
||||
maintainers: ['yinhanyan'],
|
||||
handler: async (ctx) => {
|
||||
const category = ctx.req.param('category')?.replace(/-/g, '/') ?? 'newslist/notice';
|
||||
const category = ctx.req.param('category')?.replaceAll('-', '/') ?? 'newslist/notice';
|
||||
const baseURL = `http://ai.ruc.edu.cn/${category}/`;
|
||||
const indexUrl = baseURL + 'index.htm';
|
||||
const response = await ofetch(indexUrl);
|
||||
|
||||
@@ -34,7 +34,7 @@ export const route: Route = {
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const category = ctx.req.param('category')?.replace(/-/g, '/') ?? 'tzgg';
|
||||
const category = ctx.req.param('category')?.replaceAll('-', '/') ?? 'tzgg';
|
||||
|
||||
const rootUrl = 'http://hr.ruc.edu.cn';
|
||||
const currentUrl = `${rootUrl}/${category}/index.htm`;
|
||||
|
||||
@@ -62,7 +62,7 @@ const post = async (requestPath: string, accessToken = md5(Date.now().toString()
|
||||
};
|
||||
|
||||
function sortBy(items: any[], key: string) {
|
||||
return items.sort((a, b) => {
|
||||
return items.toSorted((a, b) => {
|
||||
if (a[key] < b[key]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ async function handler(ctx) {
|
||||
.text()
|
||||
.match(/contentData = (.*)/)?.[1]
|
||||
)
|
||||
.sort((a: any, b: any) => b.length - a.length)[0] || '{}'
|
||||
.toSorted((a: any, b: any) => b.length - a.length)[0] || '{}'
|
||||
);
|
||||
const blockRenderData = JSON.parse(
|
||||
$('script:contains("column_2_text")')
|
||||
|
||||
@@ -41,7 +41,7 @@ const renderMedia = (mediaEntities) =>
|
||||
case 'photo':
|
||||
return `<img src="${e.mediaURL}">`;
|
||||
case 'video': {
|
||||
const video = e.videoInfo.variants.filter((v) => v.type === 'video/mp4').sort((a, b) => b.bitrate - a.bitrate)[0];
|
||||
const video = e.videoInfo.variants.filter((v) => v.type === 'video/mp4').toSorted((a, b) => b.bitrate - a.bitrate)[0];
|
||||
return `<video controls preload="metadata" poster="${e.mediaURL}"><source src="${video.url}" type="video/mp4"></video>`;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -31,7 +31,7 @@ export const route: Route = {
|
||||
const findLargestImgKey = (images) =>
|
||||
Object.keys(images)
|
||||
.filter((key) => key.startsWith('inline_free_') || key.startsWith('hero_landscape_'))
|
||||
.sort((a, b) => Number.parseInt(b.split('_')[2]) - Number.parseInt(a.split('_')[2]))[0];
|
||||
.toSorted((a, b) => Number.parseInt(b.split('_')[2]) - Number.parseInt(a.split('_')[2]))[0];
|
||||
|
||||
const renderFigure = (url, caption) => `<figure><img src="${url}" alt="${caption}" /><figcaption>${caption}</figcaption></figure>`;
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ async function handler(): Promise<Data> {
|
||||
const updates = dates
|
||||
.map((date, index) => ({
|
||||
date,
|
||||
content: contents[index]?.replace(/\n/g, '<br>') ?? '',
|
||||
content: contents[index]?.replaceAll('\n', '<br>') ?? '',
|
||||
}))
|
||||
.filter((update) => update.content);
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ export async function handleIsekaiRanking(type: string, limit: number): Promise<
|
||||
}
|
||||
|
||||
const items = uniqueNovels
|
||||
.sort((a, b) => (b[pointField] || 0) - (a[pointField] || 0))
|
||||
.toSorted((a, b) => (b[pointField] || 0) - (a[pointField] || 0))
|
||||
.map((novel, index) => ({
|
||||
title: `#${index + 1} ${novel.title}`,
|
||||
link: `https://ncode.syosetu.com/${String(novel.ncode).toLowerCase()}`,
|
||||
|
||||
@@ -147,7 +147,7 @@ async function handler(ctx) {
|
||||
alt: item.venueName ?? item.title,
|
||||
}
|
||||
: undefined,
|
||||
description: item.description?.replace(/\["|"]/g, '') ?? undefined,
|
||||
description: item.description?.replaceAll(/\["|"]/g, '') ?? undefined,
|
||||
data: item.parkingLocationId
|
||||
? {
|
||||
title: item.venueName ?? item.title,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { parseDate } from '@/utils/parse-date';
|
||||
import { type CheerioAPI, load } from 'cheerio';
|
||||
import { type Context } from 'hono';
|
||||
|
||||
const escapeHtml = (text: string): string => text?.replace(/&/g, '&')?.replace(/</g, '<')?.replace(/>/g, '>')?.replace(/'/g, '"')?.replace(/'/g, ''') ?? text;
|
||||
const escapeHtml = (text: string): string => text?.replaceAll('&', '&')?.replaceAll('<', '<')?.replaceAll('>', '>')?.replaceAll("'", '"')?.replaceAll("'", ''') ?? text;
|
||||
|
||||
const parseTextChildren = (children: any[]): string => children.map((child: any) => escapeHtml(child.text)).join('');
|
||||
|
||||
|
||||
@@ -57,12 +57,12 @@ async function handler(ctx) {
|
||||
switch (item.cell_type) {
|
||||
case 0:
|
||||
case 49: {
|
||||
const video = item.video.play_addr_list.sort((a, b) => b.bitrate - a.bitrate)[0];
|
||||
const video = item.video.play_addr_list.toSorted((a, b) => b.bitrate - a.bitrate)[0];
|
||||
return {
|
||||
title: item.title,
|
||||
description: art(path.join(__dirname, 'templates/video.art'), {
|
||||
poster: item.video.origin_cover.url_list[0],
|
||||
url: item.video.play_addr_list.sort((a, b) => b.bitrate - a.bitrate)[0].play_url_list[0],
|
||||
url: item.video.play_addr_list.toSorted((a, b) => b.bitrate - a.bitrate)[0].play_url_list[0],
|
||||
}),
|
||||
link: `https://www.toutiao.com/video/${item.id}/`,
|
||||
pubDate: parseDate(item.publish_time, 'X'),
|
||||
|
||||
@@ -280,7 +280,7 @@ const getUserTweets = async (id, params = {}) => {
|
||||
return !idSet.has(id_str) && idSet.add(id_str) && tweet;
|
||||
}) // deduplicate
|
||||
.filter(Boolean) // remove null
|
||||
.sort((a, b) => (b.id_str || b.conversation_id_str) - (a.id_str || a.conversation_id_str)) // desc
|
||||
.toSorted((a, b) => (b.id_str || b.conversation_id_str) - (a.id_str || a.conversation_id_str)) // desc
|
||||
.slice(0, 20);
|
||||
cache.set(cacheKey, JSON.stringify(tweets));
|
||||
return tweets;
|
||||
|
||||
@@ -71,12 +71,12 @@ async function handler(ctx) {
|
||||
.remove()
|
||||
.end()
|
||||
.html()
|
||||
?.replace(/(<img.*?) src=".*?"(.*?>)/g, '$1$2')
|
||||
?.replaceAll(/(<img.*?) src=".*?"(.*?>)/g, '$1$2')
|
||||
.replaceAll(/(<img.*?)zoomfile(.*?>)/g, '$1src$2'),
|
||||
pattl: content(item)
|
||||
.find('div.pattl')
|
||||
.html()
|
||||
?.replace(/(<img.*?) src=".*?"(.*?>)/g, '$1$2')
|
||||
?.replaceAll(/(<img.*?) src=".*?"(.*?>)/g, '$1$2')
|
||||
.replaceAll(/(<img.*?)zoomfile(.*?>)/g, '$1src$2'),
|
||||
author: content(item).find('a.xw1').text().trim(),
|
||||
})
|
||||
|
||||
@@ -77,7 +77,7 @@ export const route: Route = {
|
||||
displayErrors: true,
|
||||
});
|
||||
const md = markdownit('commonmark');
|
||||
const items = context.an.exports.sort((a, b) => a.updatedAt - b.updatedAt);
|
||||
const items = context.an.exports.toSorted((a, b) => a.updatedAt - b.updatedAt);
|
||||
const groups = new Map(items.map((it) => [it.name, it]));
|
||||
const pkgs = [...groups.values()].map((item) => {
|
||||
const $ = load(md.render(item.readme));
|
||||
|
||||
@@ -77,7 +77,7 @@ async function handler(ctx) {
|
||||
.find('ul li') // 定位到附件列表项
|
||||
.each(function () {
|
||||
const $li = $(this);
|
||||
const newText = $li.html()?.replace(/已下载[\s\S]*?<\/span>次/g, '') ?? '';
|
||||
const newText = $li.html()?.replaceAll(/已下载[\s\S]*?<\/span>次/g, '') ?? '';
|
||||
$li.html(newText.replace(/<\/a>\s*$/, '</a>'));
|
||||
})
|
||||
.end()
|
||||
|
||||
@@ -45,7 +45,7 @@ async function handler(ctx) {
|
||||
data.push(...response.data.data);
|
||||
})
|
||||
);
|
||||
data = data.sort((a, b) => b.publishTime - a.publishTime).slice(0, 10);
|
||||
data = data.toSorted((a, b) => b.publishTime - a.publishTime).slice(0, 10);
|
||||
} else {
|
||||
const response = await got(link);
|
||||
data = response.data.data;
|
||||
|
||||
@@ -42,7 +42,7 @@ async function handler() {
|
||||
|
||||
const data = Object.values(parseJSONP(response.data).items)
|
||||
.flat()
|
||||
.sort((a, b) => new Date(b.date) - new Date(a.date))
|
||||
.toSorted((a, b) => new Date(b.date) - new Date(a.date))
|
||||
.map((item) => ({
|
||||
date: item.date,
|
||||
weekDay: item.youbi,
|
||||
|
||||
@@ -84,7 +84,7 @@ export const getSafeLineCookieWithData = async (link): Promise<{ cookie: string;
|
||||
query: {
|
||||
once_id: onceId,
|
||||
v: '1.0.0',
|
||||
hints: hints.sort(() => Math.random() - 0.5).join(','),
|
||||
hints: hints.toSorted(() => Math.random() - 0.5).join(','),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ export const orderContent = (parent) => {
|
||||
for (const [i, e] of parent
|
||||
.children()
|
||||
.toArray()
|
||||
.sort((a, b) => {
|
||||
.toSorted((a, b) => {
|
||||
const index = Buffer.from(base32.parse('GM======')).toString(); // substring(3)
|
||||
a = Buffer.from(
|
||||
base32.parse(
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('puppeteer-utils', () => {
|
||||
await page.goto('https://httpbingo.org/cookies/set?foo=bar&baz=qux', {
|
||||
waitUntil: 'domcontentloaded',
|
||||
});
|
||||
expect((await getCookies(page, 'httpbingo.org')).split('; ').sort()).toEqual(['foo=bar', 'baz=qux'].sort());
|
||||
expect((await getCookies(page, 'httpbingo.org')).split('; ').toSorted()).toEqual(['foo=bar', 'baz=qux'].toSorted());
|
||||
}, 45000);
|
||||
|
||||
it('setCookies httpbingo', async () => {
|
||||
@@ -96,6 +96,6 @@ describe('puppeteer-utils', () => {
|
||||
await page.goto('https://example.org', {
|
||||
waitUntil: 'domcontentloaded',
|
||||
});
|
||||
expect((await getCookies(page, 'example.org')).split('; ').sort()).toEqual(cookieStrAll.split('; ').sort());
|
||||
expect((await getCookies(page, 'example.org')).split('; ').toSorted()).toEqual(cookieStrAll.split('; ').toSorted());
|
||||
}, 45000);
|
||||
});
|
||||
|
||||
+2
-3
@@ -78,7 +78,7 @@ const Index: FC<{ debugQuery: string | undefined }> = ({ debugQuery }) => {
|
||||
{
|
||||
name: 'Hot Routes',
|
||||
value: Object.keys(debug.routes)
|
||||
.sort((a, b) => debug.routes[b] - debug.routes[a])
|
||||
.toSorted((a, b) => debug.routes[b] - debug.routes[a])
|
||||
.slice(0, 30)
|
||||
.map((route) => (
|
||||
<>
|
||||
@@ -90,7 +90,7 @@ const Index: FC<{ debugQuery: string | undefined }> = ({ debugQuery }) => {
|
||||
{
|
||||
name: 'Hot Paths',
|
||||
value: Object.keys(debug.paths)
|
||||
.sort((a, b) => debug.paths[b] - debug.paths[a])
|
||||
.toSorted((a, b) => debug.paths[b] - debug.paths[a])
|
||||
.slice(0, 30)
|
||||
.map((path) => (
|
||||
<>
|
||||
@@ -102,7 +102,7 @@ const Index: FC<{ debugQuery: string | undefined }> = ({ debugQuery }) => {
|
||||
{
|
||||
name: 'Hot Error Routes',
|
||||
value: Object.keys(debug.errorRoutes)
|
||||
.sort((a, b) => debug.errorRoutes[b] - debug.errorRoutes[a])
|
||||
|
||||
Reference in New Issue
Block a user