Update to node v21.7.3

Use "Object::groupBy"
This commit is contained in:
schroda
2024-04-20 00:58:29 +02:00
parent db65082a09
commit 8ebd028d25
4 changed files with 13 additions and 13 deletions

2
.nvmrc
View File

@@ -1 +1 @@
v20.11.1
v21.7.3

View File

@@ -19,7 +19,7 @@
"prepare": "husky"
},
"engines": {
"node": "20.11.1"
"node": "21.7.3"
},
"lint-staged": {
"*.{ts,tsx,js,jsx}": "eslint --fix --cache"

View File

@@ -300,18 +300,17 @@ export class Chapters {
}
static removeDuplicates<T extends ChapterScanlatorInfo & ChapterNumberInfo>(currentChapter: T, chapters: T[]): T[] {
const chapterNumberToChapters = new Map<ChapterNumberInfo['chapterNumber'], T[]>();
chapters.forEach((chapter) => {
const duplicateChapters = chapterNumberToChapters.get(chapter.chapterNumber) ?? [];
chapterNumberToChapters.set(chapter.chapterNumber, [...duplicateChapters, chapter]);
});
const chapterNumberToChapters = Object.groupBy(chapters, ({ chapterNumber }) => chapterNumber);
return [...chapterNumberToChapters.values()].map(
(groupedChapters) =>
groupedChapters.find((chapter) => chapter.id === currentChapter.id) ??
groupedChapters.findLast((chapter) => chapter.scanlator === currentChapter.scanlator) ??
groupedChapters.slice(-1)[0],
);
return Object.values(chapterNumberToChapters)
.map(
(groupedChapters) =>
// the result of groupBy can't result in undefined values
groupedChapters!.find((chapter) => chapter.id === currentChapter.id) ??
groupedChapters!.findLast((chapter) => chapter.scanlator === currentChapter.scanlator) ??
groupedChapters!.slice(-1)[0],
)
.sort((a, b) => b.chapterNumber - a.chapterNumber);
}
static getNextChapter<Chapter extends ChapterScanlatorInfo & ChapterNumberInfo & ChapterReadInfo>(

View File

@@ -41,6 +41,7 @@ export default defineConfig(() => ({
'es/array/to-sorted',
'es/array/find-last',
'es/array/find-last-index',
'es/object/group-by',
],
}),
],