Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/helpers/movie.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
parseLastIdFromUrl
} from './global.helper';

// Optimization: Extract regex from mapping loops to avoid recompilation overhead
const CLEAN_TEXT_REGEX = /(\r\n|\n|\r|\t)/gm;

const CREATOR_LABELS: Record<
string,
Record<string, CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak>
Expand Down Expand Up @@ -264,7 +267,7 @@ export const getMovieRandomPhoto = (el: HTMLElement | null): string => {
export const getMovieTrivia = (el: HTMLElement | null): string[] => {
const triviaNodes = el.querySelectorAll('.article-trivia ul li');
if (triviaNodes?.length) {
return triviaNodes.map((node) => node.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, ''));
return triviaNodes.map((node) => node.textContent.trim().replace(CLEAN_TEXT_REGEX, ''));
} else {
return null;
}
Expand All @@ -273,7 +276,7 @@ export const getMovieTrivia = (el: HTMLElement | null): string[] => {
export const getMovieDescriptions = (el: HTMLElement): string[] => {
return el
.querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')
.map((movie) => movie.textContent?.trim().replace(/(\r\n|\n|\r|\t)/gm, ''));
.map((movie) => movie.textContent?.trim().replace(CLEAN_TEXT_REGEX, ''));
};

const parseMoviePeople = (el: HTMLElement): CSFDMovieCreator[] => {
Expand Down
Loading