Update to node v21.7.3
Use "Object::groupBy"
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
"prepare": "husky"
|
||||
},
|
||||
"engines": {
|
||||
"node": "20.11.1"
|
||||
"node": "21.7.3"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{ts,tsx,js,jsx}": "eslint --fix --cache"
|
||||
|
||||
@@ -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(
|
||||
return Object.values(chapterNumberToChapters)
|
||||
.map(
|
||||
(groupedChapters) =>
|
||||
groupedChapters.find((chapter) => chapter.id === currentChapter.id) ??
|
||||
groupedChapters.findLast((chapter) => chapter.scanlator === currentChapter.scanlator) ??
|
||||
groupedChapters.slice(-1)[0],
|
||||
);
|
||||
// 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>(
|
||||
|
||||
@@ -41,6 +41,7 @@ export default defineConfig(() => ({
|
||||
'es/array/to-sorted',
|
||||
'es/array/find-last',
|
||||
'es/array/find-last-index',
|
||||
'es/object/group-by',
|
||||
],
|
||||
}),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user